/* Xilinx MicroBlaze-specific support for 32-bit ELF
- Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+ Copyright (C) 2009-2016 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
/* This reloc does nothing. */
HOWTO (R_MICROBLAZE_NONE, /* Type. */
0, /* Rightshift. */
- 2, /* Size (0 = byte, 1 = short, 2 = long). */
- 32, /* Bitsize. */
+ 3, /* Size (0 = byte, 1 = short, 2 = long). */
+ 0, /* Bitsize. */
FALSE, /* PC_relative. */
0, /* Bitpos. */
- complain_overflow_bitfield, /* Complain on overflow. */
+ complain_overflow_dont, /* Complain on overflow. */
NULL, /* Special Function. */
"R_MICROBLAZE_NONE", /* Name. */
FALSE, /* Partial Inplace. */
/* This reloc does nothing. Used for relaxation. */
HOWTO (R_MICROBLAZE_64_NONE, /* Type. */
0, /* Rightshift. */
- 2, /* Size (0 = byte, 1 = short, 2 = long). */
- 32, /* Bitsize. */
+ 3, /* Size (0 = byte, 1 = short, 2 = long). */
+ 0, /* Bitsize. */
TRUE, /* PC_relative. */
0, /* Bitpos. */
- complain_overflow_bitfield, /* Complain on overflow. */
+ complain_overflow_dont, /* Complain on overflow. */
NULL, /* Special Function. */
"R_MICROBLAZE_64_NONE",/* Name. */
FALSE, /* Partial Inplace. */
arelent * cache_ptr,
Elf_Internal_Rela * dst)
{
+ unsigned int r_type;
+
if (!microblaze_elf_howto_table [R_MICROBLAZE_32])
/* Initialize howto table if needed. */
microblaze_elf_howto_init ();
- BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_MICROBLAZE_max);
+ r_type = ELF32_R_TYPE (dst->r_info);
+ if (r_type >= R_MICROBLAZE_max)
+ {
+ (*_bfd_error_handler) (_("%B: unrecognised MicroBlaze reloc number: %d"),
+ abfd, r_type);
+ bfd_set_error (bfd_error_bad_value);
+ r_type = R_MICROBLAZE_NONE;
+ }
- cache_ptr->howto = microblaze_elf_howto_table [ELF32_R_TYPE (dst->r_info)];
+ cache_ptr->howto = microblaze_elf_howto_table [r_type];
}
/* Microblaze ELF local labels start with 'L.' or '$L', not '.L'. */
howto = microblaze_elf_howto_table[r_type];
r_symndx = ELF32_R_SYM (rel->r_info);
- if (info->relocatable)
+ if (bfd_link_relocatable (info))
{
/* This is a relocatable link. We don't have to change
anything, unless the reloc is against a section symbol,
{
/* External symbol. */
bfd_boolean warned ATTRIBUTE_UNUSED;
+ bfd_boolean ignored ATTRIBUTE_UNUSED;
RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
h, sec, relocation,
- unresolved_reloc, warned);
+ unresolved_reloc, warned, ignored);
sym_name = h->root.root.string;
}
bfd_boolean dyn =
elf_hash_table (info)->dynamic_sections_created;
- if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
- && (!info->shared || !SYMBOL_REFERENCES_LOCAL (info, h)))
+ if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
+ bfd_link_pic (info),
+ h)
+ && (!bfd_link_pic (info)
+ || !SYMBOL_REFERENCES_LOCAL (info, h)))
indx = h->dynindx;
}
/* Need to generate relocs ? */
- if ((info->shared || indx != 0)
+ if ((bfd_link_pic (info) || indx != 0)
&& (h == NULL
|| ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|| h->root.type != bfd_link_hash_undefweak))
/* Process module-id */
if (IS_TLS_LD(tls_type))
{
- if (! info->shared)
+ if (! bfd_link_pic (info))
{
bfd_put_32 (output_bfd, 1, htab->sgot->contents + off);
}
/* Relocs for dyn symbols generated by
finish_dynamic_symbols */
- if (info->shared && h == NULL)
+ if (bfd_link_pic (info) && h == NULL)
{
*offp |= 1;
microblaze_elf_output_dynamic_relocation (output_bfd,
break;
}
- if ((info->shared
+ if ((bfd_link_pic (info)
&& (h == NULL
|| ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|| h->root.type != bfd_link_hash_undefweak)
&& h->dynindx != -1
&& (!info->symbolic
|| !h->def_regular))))
- || (!info->shared
+ || (!bfd_link_pic (info)
&& h != NULL
&& h->dynindx != -1
&& !h->non_got_ref
switch (r)
{
case bfd_reloc_overflow:
- if (!((*info->callbacks->reloc_overflow)
- (info, (h ? &h->root : NULL), name, howto->name,
- (bfd_vma) 0, input_bfd, input_section, offset)))
- return FALSE;
+ (*info->callbacks->reloc_overflow)
+ (info, (h ? &h->root : NULL), name, howto->name,
+ (bfd_vma) 0, input_bfd, input_section, offset);
break;
case bfd_reloc_undefined:
- if (!((*info->callbacks->undefined_symbol)
- (info, name, input_bfd, input_section, offset, TRUE)))
- return FALSE;
+ (*info->callbacks->undefined_symbol)
+ (info, name, input_bfd, input_section, offset, TRUE);
break;
case bfd_reloc_outofrange:
errmsg = _("internal error: unknown error");
/* Fall through. */
common_error:
- if (!((*info->callbacks->warning)
- (info, errmsg, name, input_bfd, input_section, offset)))
- return FALSE;
+ (*info->callbacks->warning) (info, errmsg, name, input_bfd,
+ input_section, offset);
break;
}
}
/* Calculate fixup value for reference. */
static int
-calc_fixup (bfd_vma addr, asection *sec)
+calc_fixup (bfd_vma start, bfd_vma size, asection *sec)
{
+ bfd_vma end = start + size;
int i, fixup = 0;
if (sec == NULL || sec->relax == NULL)
/* Look for addr in relax table, total fixup value. */
for (i = 0; i < sec->relax_count; i++)
{
- if (addr <= sec->relax[i].addr)
+ if (end <= sec->relax[i].addr)
break;
+ if ((end != start) && (start > sec->relax[i].addr))
+ continue;
fixup += sec->relax[i].size;
}
-
return fixup;
}
*again = FALSE;
/* Only do this for a text section. */
- if (link_info->relocatable
+ if (bfd_link_relocatable (link_info)
|| (sec->flags & SEC_RELOC) == 0
|| (sec->reloc_count == 0)
|| (sec->flags & SEC_CODE) == 0)
bfd_vma nraddr;
/* Get the new reloc address. */
- nraddr = irel->r_offset - calc_fixup (irel->r_offset, sec);
+ nraddr = irel->r_offset - calc_fixup (irel->r_offset, 0, sec);
switch ((enum elf_microblaze_reloc_type) ELF32_R_TYPE (irel->r_info))
{
default:
/* Only handle relocs against .text. */
if (isym->st_shndx == shndx
&& ELF32_ST_TYPE (isym->st_info) == STT_SECTION)
- irel->r_addend -= calc_fixup (irel->r_addend, sec);
+ irel->r_addend -= calc_fixup (irel->r_addend, 0, sec);
}
break;
case R_MICROBLAZE_NONE:
int sfix, efix;
bfd_vma target_address;
target_address = irel->r_addend + irel->r_offset;
- sfix = calc_fixup (irel->r_offset, sec);
- efix = calc_fixup (target_address, sec);
+ sfix = calc_fixup (irel->r_offset, 0, sec);
+ efix = calc_fixup (target_address, 0, sec);
irel->r_addend -= (efix - sfix);
/* Should use HOWTO. */
microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset,
int sfix, efix;
bfd_vma target_address;
target_address = irel->r_addend + irel->r_offset + INST_WORD_SIZE;
- sfix = calc_fixup (irel->r_offset + INST_WORD_SIZE, sec);
- efix = calc_fixup (target_address, sec);
+ sfix = calc_fixup (irel->r_offset + INST_WORD_SIZE, 0, sec);
+ efix = calc_fixup (target_address, 0, sec);
irel->r_addend -= (efix - sfix);
microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset
+ INST_WORD_SIZE, irel->r_addend);
}
}
- irelscan->r_addend -= calc_fixup (irelscan->r_addend, sec);
+ irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
}
else if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_SYM_OP_SYM)
{
}
irelscan->r_addend -= calc_fixup (irel->r_addend
+ isym->st_value,
+ 0,
sec);
}
}
unsigned long instr = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
immediate = instr & 0x0000ffff;
target_address = immediate;
- offset = calc_fixup (target_address, sec);
+ offset = calc_fixup (target_address, 0, sec);
immediate -= offset;
irelscan->r_addend -= offset;
microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
+ INST_WORD_SIZE);
immediate = (instr_hi & 0x0000ffff) << 16;
immediate |= (instr_lo & 0x0000ffff);
- offset = calc_fixup (irelscan->r_addend, sec);
+ offset = calc_fixup (irelscan->r_addend, 0, sec);
immediate -= offset;
irelscan->r_addend -= offset;
}
immediate = (instr_hi & 0x0000ffff) << 16;
immediate |= (instr_lo & 0x0000ffff);
target_address = immediate;
- offset = calc_fixup (target_address, sec);
+ offset = calc_fixup (target_address, 0, sec);
immediate -= offset;
irelscan->r_addend -= offset;
microblaze_bfd_write_imm_value_64 (abfd, ocontents
for (isym = isymbuf; isym < isymend; isym++)
{
if (isym->st_shndx == shndx)
- isym->st_value =- calc_fixup (isym->st_value, sec);
+ {
+ isym->st_value -= calc_fixup (isym->st_value, 0, sec);
+ if (isym->st_size)
+ isym->st_size -= calc_fixup (isym->st_value, isym->st_size, sec);
+ }
}
/* Now adjust the global symbols defined in this section. */
isym = isymbuf + symtab_hdr->sh_info;
- isymend = isymbuf + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
- for (sym_index = 0; isym < isymend; isym++, sym_index++)
+ symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)) - symtab_hdr->sh_info;
+ for (sym_index = 0; sym_index < symcount; sym_index++)
{
sym_hash = elf_sym_hashes (abfd)[sym_index];
- if (isym->st_shndx == shndx
- && (sym_hash->root.type == bfd_link_hash_defined
+ if ((sym_hash->root.type == bfd_link_hash_defined
|| sym_hash->root.type == bfd_link_hash_defweak)
&& sym_hash->root.u.def.section == sec)
- {
- sym_hash->root.u.def.value -= calc_fixup (sym_hash->root.u.def.value,
- sec);
- }
- }
+ {
+ sym_hash->root.u.def.value -= calc_fixup (sym_hash->root.u.def.value,
+ 0, sec);
+ if (sym_hash->size)
+ sym_hash->size -= calc_fixup (sym_hash->root.u.def.value,
+ sym_hash->size, sec);
+ }
+ }
/* Physically move the code and change the cooked size. */
dest = sec->relax[0].addr;
struct elf32_mb_link_hash_table *htab;
asection *sreloc = NULL;
- if (info->relocatable)
+ if (bfd_link_relocatable (info))
return TRUE;
htab = elf32_mb_hash_table (info);
if (r_symndx < symtab_hdr->sh_info)
h = NULL;
else
- h = sym_hashes [r_symndx - symtab_hdr->sh_info];
+ {
+ h = sym_hashes [r_symndx - symtab_hdr->sh_info];
+
+ /* PR15323, ref flags aren't set for references in the same
+ object. */
+ h->root.non_ir_ref = 1;
+ }
switch (r_type)
{
case R_MICROBLAZE_64_PCREL:
case R_MICROBLAZE_32:
{
- if (h != NULL && !info->shared)
+ if (h != NULL && !bfd_link_pic (info))
{
/* we may need a copy reloc. */
h->non_got_ref = 1;
dynamic library if we manage to avoid copy relocs for the
symbol. */
- if ((info->shared
+ if ((bfd_link_pic (info)
&& (sec->flags & SEC_ALLOC) != 0
&& (r_type != R_MICROBLAZE_64_PCREL
|| (h != NULL
&& (! info->symbolic
|| h->root.type == bfd_link_hash_defweak
|| !h->def_regular))))
- || (!info->shared
+ || (!bfd_link_pic (info)
&& (sec->flags & SEC_ALLOC) != 0
&& h != NULL
&& (h->root.type == bfd_link_hash_defweak
htab->splt = bfd_get_linker_section (dynobj, ".plt");
htab->srelplt = bfd_get_linker_section (dynobj, ".rela.plt");
htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
- if (!info->shared)
+ if (!bfd_link_pic (info))
htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
if (!htab->splt || !htab->srelplt || !htab->sdynbss
- || (!info->shared && !htab->srelbss))
+ || (!bfd_link_pic (info) && !htab->srelbss))
abort ();
return TRUE;
only references to the symbol are via the global offset table.
For such cases we need not do anything here; the relocations will
be handled correctly by relocate_section. */
- if (info->shared)
+ if (bfd_link_pic (info))
return TRUE;
/* If there are no references to this symbol that do not use the
return FALSE;
}
- if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
+ if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
{
asection *s = htab->splt;
location in the .plt. This is required to make function
pointers compare as equal between the normal executable and
the shared library. */
- if (! info->shared
+ if (! bfd_link_pic (info)
&& !h->def_regular)
{
h->root.u.def.section = s;
space for pc-relative relocs that have become local due to symbol
visibility changes. */
- if (info->shared)
+ if (bfd_link_pic (info))
{
if (h->def_regular
&& (h->forced_local
/* Set up .got offsets for local syms, and space for local dynamic
relocs. */
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
bfd_signed_vma *local_got;
bfd_signed_vma *end_local_got;
{
*local_got = s->size;
s->size += need;
- if (info->shared)
+ if (bfd_link_pic (info))
srel->size += need * (sizeof (Elf32_External_Rela) / 4);
}
}
{
htab->tlsld_got.offset = htab->sgot->size;
htab->sgot->size += 8;
- if (info->shared)
+ if (bfd_link_pic (info))
htab->srelgot->size += sizeof (Elf32_External_Rela);
}
else
#define add_dynamic_entry(TAG, VAL) \
_bfd_elf_add_dynamic_entry (info, TAG, VAL)
- if (info->executable)
+ if (bfd_link_executable (info))
{
if (!add_dynamic_entry (DT_DEBUG, 0))
return FALSE;
got_addr = got_offset;
/* For non-PIC objects we need absolute address of the GOT entry. */
- if (!info->shared)
+ if (!bfd_link_pic (info))
got_addr += htab->sgotplt->output_section->vma + sgotplt->output_offset;
/* Fill in the entry in the procedure linkage table. */
bfd_put_32 (output_bfd, PLT_ENTRY_WORD_0 + ((got_addr >> 16) & 0xffff),
splt->contents + h->plt.offset);
- if (info->shared)
+ if (bfd_link_pic (info))
bfd_put_32 (output_bfd, PLT_ENTRY_WORD_1 + (got_addr & 0xffff),
splt->contents + h->plt.offset + 4);
else
BFD_ASSERT (sgot != NULL && srela != NULL);
offset = (sgot->output_section->vma + sgot->output_offset
- + (h->got.offset &~ (bfd_vma) 1));
+ + (h->got.offset &~ (bfd_vma) 1));
/* If this is a -Bsymbolic link, and the symbol is defined
locally, we just want to emit a RELATIVE reloc. Likewise if
the symbol was forced to be local because of a version file.
The entry in the global offset table will already have been
initialized in the relocate_section function. */
- if (info->shared
- && (info->symbolic || h->dynindx == -1)
- && h->def_regular)
+ if (bfd_link_pic (info)
+ && ((info->symbolic && h->def_regular)
+ || h->dynindx == -1))
{
asection *sec = h->root.u.def.section;
microblaze_elf_output_dynamic_relocation (output_bfd,
{
asection *s;
- s = bfd_get_section_by_name (output_bfd, name);
+ s = bfd_get_linker_section (dynobj, name);
if (s == NULL)
dyn.d_un.d_val = 0;
else
{
if (! size)
- dyn.d_un.d_ptr = s->vma;
+ dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
else
dyn.d_un.d_val = s->size;
}
bfd_vma *valp)
{
if (sym->st_shndx == SHN_COMMON
- && !info->relocatable
+ && !bfd_link_relocatable (info)
&& sym->st_size <= elf_gp_size (abfd))
{
/* Common symbols less than or equal to -G nn bytes are automatically
return TRUE;
}
-#define TARGET_LITTLE_SYM bfd_elf32_microblazeel_vec
+#define TARGET_LITTLE_SYM microblaze_elf32_le_vec
#define TARGET_LITTLE_NAME "elf32-microblazeel"
-#define TARGET_BIG_SYM bfd_elf32_microblaze_vec
+#define TARGET_BIG_SYM microblaze_elf32_vec
#define TARGET_BIG_NAME "elf32-microblaze"
#define ELF_ARCH bfd_arch_microblaze