/* 32-bit ELF support for Nios II.
- Copyright (C) 2012-2015 Free Software Foundation, Inc.
+ Copyright (C) 2012-2016 Free Software Foundation, Inc.
Contributed by Nigel Gray (ngray@altera.com).
Contributed by Mentor Graphics, Inc.
0xfe00,
0xfe00,
TRUE),
-
+
HOWTO (R_NIOS2_R2_T1I7_2,
2,
1,
0xfe00,
0xfe00,
FALSE),
-
+
HOWTO (R_NIOS2_R2_T2I4,
0,
1,
0x1fc0,
0x1fc0,
FALSE),
-
+
HOWTO (R_NIOS2_R2_X2L5,
0,
1,
0x07c0,
0x07c0,
FALSE),
-
+
HOWTO (R_NIOS2_R2_F1I5_2,
2,
1,
0x7e00,
0x7e00,
FALSE),
-
+
HOWTO (R_NIOS2_R2_T1X1I6_2,
2,
2,
0x7e00,
0x7e00,
FALSE),
-
+
/* Add other relocations here. */
};
/* Assorted information used by nios2_elf32_size_stubs. */
unsigned int bfd_count;
- int top_index;
+ unsigned int top_index;
asection **input_list;
Elf_Internal_Sym **all_local_syms;
{
bfd_vma word = bfd_get_32 (sec->owner, sec->contents + offset);
- BFD_ASSERT(value <= 0xffff);
+ BFD_ASSERT (value <= 0xffff || ((bfd_signed_vma) value) >= -0xffff);
bfd_put_32 (sec->owner, word | ((value & 0xffff) << 6),
sec->contents + offset);
TRUE, FALSE);
if (hsh == NULL)
{
- (*_bfd_error_handler) (_("%B: cannot create stub entry %s"),
- section->owner,
- stub_name);
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%B: cannot create stub entry %s"),
+ section->owner,
+ stub_name);
return NULL;
}
{
bfd *input_bfd;
unsigned int bfd_count;
- int top_id, top_index;
+ unsigned int top_id, top_index;
asection *section;
asection **input_list, **list;
bfd_size_type amt;
}
else if (hh->root.root.type == bfd_link_hash_undefweak)
{
- if (! info->shared)
+ if (! bfd_link_pic (info))
continue;
}
else if (hh->root.root.type == bfd_link_hash_undefined)
SEC_LINKER_CREATED flag set, while stub sections do not
have that flag. Ignore any non-stub sections here. */
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
- {
+ {
bfd_size_type size;
/* Allocate memory to hold the linker stubs. */
object file when linking. */
static bfd_boolean
-nios2_elf32_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
+nios2_elf32_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
{
+ bfd *obfd = info->output_bfd;
flagword old_flags;
flagword new_flags;
return TRUE;
/* Check if we have the same endianness. */
- if (! _bfd_generic_verify_endian_match (ibfd, obfd))
+ if (! _bfd_generic_verify_endian_match (ibfd, info))
return FALSE;
new_flags = elf_elfheader (ibfd)->e_flags;
case EF_NIOS2_ARCH_R2:
if (bfd_big_endian (ibfd))
{
- (*_bfd_error_handler)
+ _bfd_error_handler
(_("error: %B: Big-endian R2 is not supported."), ibfd);
bfd_set_error (bfd_error_bad_value);
return FALSE;
{
/* So far, the only incompatible flags denote incompatible
architectures. */
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("error: %B: Conflicting CPU architectures %d/%d"),
ibfd, new_flags, old_flags);
bfd_set_error (bfd_error_bad_value);
}
/* Merge Tag_compatibility attributes and any common GNU ones. */
- _bfd_elf_merge_object_attributes (ibfd, obfd);
+ _bfd_elf_merge_object_attributes (ibfd, info);
return TRUE;
}
bfd_reloc_code_real_type code)
{
int i;
-
+
for (i = 0;
i < (int) (sizeof (nios2_reloc_map) / sizeof (struct elf_reloc_map));
++i)
howto_tbl_size = (int) (sizeof (elf_nios2_r1_howto_table_rel)
/ sizeof (elf_nios2_r1_howto_table_rel[0]));
}
-
+
for (i = 0; i < howto_tbl_size; i++)
if (howto_tbl[i].name && strcasecmp (howto_tbl[i].name, r_name) == 0)
return howto_tbl + i;
- return NULL;
+ return NULL;
}
/* Implement elf_info_to_howto:
case bfd_link_hash_defined:
case bfd_link_hash_defweak:
gp_found = TRUE;
- *pgp = lh->u.def.value;
+ {
+ asection *sym_sec = lh->u.def.section;
+ bfd_vma sym_value = lh->u.def.value;
+
+ if (sym_sec->output_section)
+ sym_value = (sym_value + sym_sec->output_offset
+ + sym_sec->output_section->vma);
+ *pgp = sym_value;
+ }
break;
case bfd_link_hash_indirect:
case bfd_link_hash_warning:
symbol value for an external symbol if we are producing relocatable
output. */
static bfd_reloc_status_type
-nios2_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
+nios2_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
char **error_message, bfd_vma *pgp)
{
if (bfd_is_und_section (symbol->section) && !relocatable)
/* Do the relocations that require special handling. */
static bfd_reloc_status_type
-nios2_elf32_do_hi16_relocate (bfd *abfd, reloc_howto_type *howto,
+nios2_elf32_do_hi16_relocate (bfd *abfd, reloc_howto_type *howto,
asection *input_section,
- bfd_byte *data, bfd_vma offset,
+ bfd_byte *data, bfd_vma offset,
bfd_vma symbol_value, bfd_vma addend)
{
symbol_value = symbol_value + addend;
static bfd_reloc_status_type
nios2_elf32_do_lo16_relocate (bfd *abfd, reloc_howto_type *howto,
asection *input_section,
- bfd_byte *data, bfd_vma offset,
+ bfd_byte *data, bfd_vma offset,
bfd_vma symbol_value, bfd_vma addend)
{
symbol_value = symbol_value + addend;
static bfd_reloc_status_type
nios2_elf32_do_pcrel16_relocate (bfd *abfd, reloc_howto_type *howto,
asection *input_section,
- bfd_byte *data, bfd_vma offset,
+ bfd_byte *data, bfd_vma offset,
bfd_vma symbol_value, bfd_vma addend)
{
- /* NIOS2 pc relative relocations are relative to the next 32-bit instruction
+ /* NIOS2 pc relative relocations are relative to the next 32-bit instruction
so we need to subtract 4 before doing a final_link_relocate. */
symbol_value = symbol_value + addend - 4;
addend = 0;
static bfd_reloc_status_type
nios2_elf32_do_call26_relocate (bfd *abfd, reloc_howto_type *howto,
asection *input_section,
- bfd_byte *data, bfd_vma offset,
+ bfd_byte *data, bfd_vma offset,
bfd_vma symbol_value, bfd_vma addend)
{
/* Check that the relocation is in the same page as the current address. */
- if (CALL26_SEGMENT (symbol_value + addend)
+ if (CALL26_SEGMENT (symbol_value + addend)
!= CALL26_SEGMENT (input_section->output_section->vma
+ input_section->output_offset
+ offset))
static bfd_reloc_status_type
nios2_elf32_do_gprel_relocate (bfd *abfd, reloc_howto_type *howto,
asection *input_section,
- bfd_byte *data, bfd_vma offset,
+ bfd_byte *data, bfd_vma offset,
bfd_vma symbol_value, bfd_vma addend)
{
/* Because we need the output_bfd, the special handling is done
static bfd_reloc_status_type
nios2_elf32_do_ujmp_relocate (bfd *abfd, reloc_howto_type *howto,
asection *input_section,
- bfd_byte *data, bfd_vma offset,
+ bfd_byte *data, bfd_vma offset,
bfd_vma symbol_value, bfd_vma addend)
{
bfd_vma symbol_lo16, symbol_hi16;
static bfd_reloc_status_type
nios2_elf32_do_cjmp_relocate (bfd *abfd, reloc_howto_type *howto,
asection *input_section,
- bfd_byte *data, bfd_vma offset,
+ bfd_byte *data, bfd_vma offset,
bfd_vma symbol_value, bfd_vma addend)
{
bfd_vma symbol_lo16, symbol_hi16;
static bfd_reloc_status_type
nios2_elf32_do_callr_relocate (bfd *abfd, reloc_howto_type *howto,
asection *input_section,
- bfd_byte *data, bfd_vma offset,
+ bfd_byte *data, bfd_vma offset,
bfd_vma symbol_value, bfd_vma addend)
{
bfd_vma symbol_lo16, symbol_hi16;
changes in size of section don't screw up .align. */
static bfd_reloc_status_type
nios2_elf32_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
- asymbol *symbol ATTRIBUTE_UNUSED,
- void *data ATTRIBUTE_UNUSED, asection *input_section,
- bfd *output_bfd,
+ asymbol *symbol ATTRIBUTE_UNUSED,
+ void *data ATTRIBUTE_UNUSED, asection *input_section,
+ bfd *output_bfd,
char **error_message ATTRIBUTE_UNUSED)
{
if (output_bfd != NULL)
}
static bfd_reloc_status_type
-nios2_elf32_hi16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
- void *data, asection *input_section,
- bfd *output_bfd,
+nios2_elf32_hi16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
+ void *data, asection *input_section,
+ bfd *output_bfd,
char **error_message ATTRIBUTE_UNUSED)
{
/* This part is from bfd_elf_generic_reloc. */
static bfd_reloc_status_type
nios2_elf32_lo16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
- void *data, asection *input_section,
- bfd *output_bfd,
+ void *data, asection *input_section,
+ bfd *output_bfd,
char **error_message ATTRIBUTE_UNUSED)
{
/* This part is from bfd_elf_generic_reloc. */
static bfd_reloc_status_type
nios2_elf32_hiadj16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
- void *data, asection *input_section,
- bfd *output_bfd,
+ void *data, asection *input_section,
+ bfd *output_bfd,
char **error_message ATTRIBUTE_UNUSED)
{
/* This part is from bfd_elf_generic_reloc. */
static bfd_reloc_status_type
nios2_elf32_pcrel16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
- void *data, asection *input_section,
- bfd *output_bfd,
+ void *data, asection *input_section,
+ bfd *output_bfd,
char **error_message ATTRIBUTE_UNUSED)
{
/* This part is from bfd_elf_generic_reloc. */
static bfd_reloc_status_type
nios2_elf32_call26_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
- void *data, asection *input_section,
- bfd *output_bfd,
+ void *data, asection *input_section,
+ bfd *output_bfd,
char **error_message ATTRIBUTE_UNUSED)
{
/* This part is from bfd_elf_generic_reloc. */
static bfd_reloc_status_type
nios2_elf32_gprel_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
- void *data, asection *input_section,
+ void *data, asection *input_section,
bfd *output_bfd, char **msg)
{
bfd_vma relocation;
static bfd_reloc_status_type
nios2_elf32_ujmp_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
- void *data, asection *input_section,
+ void *data, asection *input_section,
bfd *output_bfd, char **msg ATTRIBUTE_UNUSED)
{
/* This part is from bfd_elf_generic_reloc. */
static bfd_reloc_status_type
nios2_elf32_cjmp_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
- void *data, asection *input_section,
+ void *data, asection *input_section,
bfd *output_bfd, char **msg ATTRIBUTE_UNUSED)
{
/* This part is from bfd_elf_generic_reloc. */
static bfd_reloc_status_type
nios2_elf32_callr_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
- void *data, asection *input_section,
+ void *data, asection *input_section,
bfd *output_bfd, char **msg ATTRIBUTE_UNUSED)
{
/* This part is from bfd_elf_generic_reloc. */
reloc_entry->addend);
}
-
+
/* Implement elf_backend_relocate_section. */
static bfd_boolean
nios2_elf32_relocate_section (bfd *output_bfd,
struct elf32_nios2_link_hash_entry *eh;
bfd_vma relocation;
bfd_vma gp;
- bfd_vma reloc_address;
bfd_reloc_status_type r = bfd_reloc_ok;
const char *name = NULL;
int r_type;
rel, 1, relend, howto, 0, contents);
/* Nothing more to do unless this is a final link. */
- if (info->relocatable)
+ if (bfd_link_relocatable (info))
continue;
- if (sec && sec->output_section)
- reloc_address = (sec->output_section->vma + sec->output_offset
- + rel->r_offset);
- else
- reloc_address = 0;
-
if (howto)
{
switch (howto->type)
/* Turns an absolute address into a gp-relative address. */
if (!nios2_elf_assign_gp (output_bfd, &gp, info))
{
+ bfd_vma reloc_address;
+
+ if (sec && sec->output_section)
+ reloc_address = (sec->output_section->vma
+ + sec->output_offset
+ + rel->r_offset);
+ else
+ reloc_address = 0;
+
format = _("global pointer relative relocation at address "
"0x%08x when _gp not defined\n");
sprintf (msgbuf, format, reloc_address);
else
{
bfd_vma symbol_address = rel->r_addend + relocation;
- relocation = relocation + rel->r_addend - gp;
+ relocation = symbol_address - gp;
rel->r_addend = 0;
if (((signed) relocation < -32768
|| (signed) relocation > 32767)
|| h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak))
{
+ if (h)
+ name = h->root.root.string;
+ /* xgettext:c-format */
format = _("Unable to reach %s (at 0x%08x) from the "
"global pointer (at 0x%08x) because the "
"offset (%d) is out of the allowed range, "
"-32678 to 32767.\n" );
- sprintf (msgbuf, format, name, symbol_address, gp,
+ sprintf (msgbuf, format, name, symbol_address, gp,
(signed)relocation);
msg = msgbuf;
r = bfd_reloc_outofrange;
rel->r_offset, relocation,
rel->r_addend);
}
-
break;
case R_NIOS2_UJMP:
r = nios2_elf32_do_ujmp_relocate (input_bfd, howto,
off = h->got.offset;
BFD_ASSERT (off != (bfd_vma) -1);
dyn = elf_hash_table (info)->dynamic_sections_created;
- if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
- || (info->shared
+ if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
+ bfd_link_pic (info),
+ h)
+ || (bfd_link_pic (info)
&& SYMBOL_REFERENCES_LOCAL (info, h))
|| (ELF_ST_VISIBILITY (h->other)
&& h->root.type == bfd_link_hash_undefweak))
bfd_put_32 (output_bfd, relocation,
sgot->contents + off);
- if (info->shared)
+ if (bfd_link_pic (info))
{
asection *srelgot;
Elf_Internal_Rela outrel;
}
}
- if (use_plt && info->shared)
+ if (use_plt && bfd_link_pic (info))
{
off = ((h->plt.offset - 24) / 12 + 3) * 4;
relocation = (htab->root.sgotplt->output_offset + off
{
/* If we don't know the module number, create a relocation
for it. */
- if (info->shared)
+ if (bfd_link_pic (info))
{
Elf_Internal_Rela outrel;
bfd_byte *loc;
{
bfd_boolean dyn;
dyn = htab->root.dynamic_sections_created;
- if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
- && (!info->shared
+ if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
+ bfd_link_pic (info),
+ h)
+ && (!bfd_link_pic (info)
|| !SYMBOL_REFERENCES_LOCAL (info, h)))
{
unresolved_reloc = FALSE;
now, and emit any relocations. If both an IE GOT and a
GD GOT are necessary, we emit the GD first. */
- 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))
break;
case R_NIOS2_TLS_LE16:
- if (info->shared && !info->pie)
+ if (bfd_link_dll (info))
{
- (*_bfd_error_handler)
+ _bfd_error_handler
+ /* xgettext:c-format */
(_("%B(%A+0x%lx): R_NIOS2_TLS_LE16 relocation not "
"permitted in shared object"),
input_bfd, input_section,
break;
case R_NIOS2_BFD_RELOC_32:
- if (info->shared
+ if (bfd_link_pic (info)
&& (input_section->flags & SEC_ALLOC) != 0
&& (h == NULL
|| ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
memset (&outrel, 0, sizeof outrel);
else if (h != NULL
&& h->dynindx != -1
- && (!info->shared
- || !info->symbolic
+ && (!bfd_link_pic (info)
+ || !SYMBOLIC_BIND (info, h)
|| !h->def_regular))
{
outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
switch (r)
{
case bfd_reloc_overflow:
- r = info->callbacks->reloc_overflow (info, NULL, name,
- howto->name, (bfd_vma) 0,
- input_bfd, input_section,
- rel->r_offset);
+ (*info->callbacks->reloc_overflow) (info, NULL, name,
+ howto->name, (bfd_vma) 0,
+ input_bfd, input_section,
+ rel->r_offset);
break;
case bfd_reloc_undefined:
- r = info->callbacks->undefined_symbol (info, name, input_bfd,
- input_section,
- rel->r_offset, TRUE);
+ (*info->callbacks->undefined_symbol) (info, name, input_bfd,
+ input_section,
+ rel->r_offset, TRUE);
break;
case bfd_reloc_outofrange:
if (msg)
{
- r = info->callbacks->warning
- (info, msg, name, input_bfd, input_section, rel->r_offset);
+ (*info->callbacks->warning) (info, msg, name, input_bfd,
+ input_section, rel->r_offset);
return FALSE;
}
}
htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
if (!htab->sdynbss)
return FALSE;
- if (!info->shared)
+ if (!bfd_link_pic (info))
{
htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
if (!htab->srelbss)
asection *sreloc = NULL;
bfd_signed_vma *local_got_refcounts;
- if (info->relocatable)
+ if (bfd_link_relocatable (info))
return TRUE;
dynobj = elf_hash_table (info)->dynobj;
}
if (srelgot == NULL
- && (h != NULL || info->shared))
+ && (h != NULL || bfd_link_pic (info)))
{
srelgot = htab->root.srelgot;
BFD_ASSERT (srelgot != NULL);
sections have not yet been mapped to output sections.
Tentatively set the flag for now, and correct in
adjust_dynamic_symbol. */
- if (!info->shared)
+ if (!bfd_link_pic (info))
h->non_got_ref = 1;
/* Make sure a plt entry is created for this symbol if it
/* If we are creating a shared library, we need to copy the
reloc into the shared library. */
- if (info->shared
+ if (bfd_link_pic (info)
&& (sec->flags & SEC_ALLOC) != 0
&& (r_type == R_NIOS2_BFD_RELOC_32
|| (h != NULL && ! h->needs_plt
- && (! info->symbolic || ! h->def_regular))))
+ && (! SYMBOLIC_BIND (info, h) || ! h->def_regular))))
{
struct elf32_nios2_dyn_relocs *p;
struct elf32_nios2_dyn_relocs **head;
const Elf_Internal_Rela *rel, *relend;
bfd *dynobj;
- if (info->relocatable)
+ if (bfd_link_relocatable (info))
return TRUE;
elf_section_data (sec)->local_dynrel = NULL;
BFD_ASSERT (splt != NULL && sgotplt != NULL && srela != NULL);
/* Emit the PLT entry. */
- if (info->shared)
+ if (bfd_link_pic (info))
{
nios2_elf32_install_data (splt, nios2_so_plt_entry, h->plt.offset,
3);
The entry in the global offset table will already have been
initialized in the relocate_section function. */
- if (info->shared && SYMBOL_REFERENCES_LOCAL (info, h))
+ if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
{
rela.r_info = ELF32_R_INFO (0, R_NIOS2_RELATIVE);
rela.r_addend = bfd_get_signed_32 (output_bfd,
break;
case DT_PLTGOT:
- s = htab->root.sgot;
- BFD_ASSERT (s != NULL);
- dyn.d_un.d_ptr = s->output_section->vma;
+ s = htab->root.sgotplt;
+ dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
case DT_JMPREL:
s = htab->root.srelplt;
- BFD_ASSERT (s != NULL);
- dyn.d_un.d_ptr = s->output_section->vma;
+ dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
case DT_PLTRELSZ:
s = htab->root.srelplt;
- BFD_ASSERT (s != NULL);
dyn.d_un.d_val = s->size;
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
- case DT_RELASZ:
- /* The procedure linkage table relocs (DT_JMPREL) should
- not be included in the overall relocs (DT_RELA).
- Therefore, we override the DT_RELASZ entry here to
- make it not include the JMPREL relocs. Since the
- linker script arranges for .rela.plt to follow all
- other relocation sections, we don't have to worry
- about changing the DT_RELA entry. */
- s = htab->root.srelplt;
- if (s != NULL)
- dyn.d_un.d_val -= s->size;
- bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
- break;
-
case DT_NIOS2_GP:
- s = htab->root.sgot;
- BFD_ASSERT (s != NULL);
- dyn.d_un.d_ptr = s->output_section->vma + 0x7ff0;
+ s = htab->root.sgotplt;
+ dyn.d_un.d_ptr
+ = s->output_section->vma + s->output_offset + 0x7ff0;
bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
break;
}
{
bfd_vma got_address = (sgotplt->output_section->vma
+ sgotplt->output_offset);
- if (info->shared)
+ if (bfd_link_pic (info))
{
- bfd_vma corrected = got_address - (splt->output_section->vma
- + splt->output_offset + 4);
+ bfd_vma got_pcrel = got_address - (splt->output_section->vma
+ + splt->output_offset);
+ /* Both GOT and PLT must be aligned to a 16-byte boundary
+ for the two loads to share the %hiadj part. The 4-byte
+ offset for nextpc is accounted for in the %lo offsets
+ on the loads. */
+ BFD_ASSERT ((got_pcrel & 0xf) == 0);
nios2_elf32_install_data (splt, nios2_so_plt0_entry, 0, 6);
- nios2_elf32_install_imm16 (splt, 4, hiadj (corrected));
- nios2_elf32_install_imm16 (splt, 12, (corrected & 0xffff) + 4);
- nios2_elf32_install_imm16 (splt, 16, (corrected & 0xffff) + 8);
+ nios2_elf32_install_imm16 (splt, 4, hiadj (got_pcrel));
+ nios2_elf32_install_imm16 (splt, 12, got_pcrel & 0xffff);
+ nios2_elf32_install_imm16 (splt, 16, (got_pcrel + 4) & 0xffff);
}
else
{
6 | ((res_size - (res_offset + 4)) << 6),
splt->contents + res_offset);
+ /* The GOT must be aligned to a 16-byte boundary for the
+ two loads to share the same %hiadj part. */
+ BFD_ASSERT ((got_address & 0xf) == 0);
+
nios2_elf32_install_data (splt, nios2_plt0_entry, res_size, 7);
nios2_elf32_install_imm16 (splt, res_size, hiadj (res_start));
nios2_elf32_install_imm16 (splt, res_size + 4,
nios2_elf32_install_imm16 (splt, res_size + 12,
hiadj (got_address));
nios2_elf32_install_imm16 (splt, res_size + 16,
- (got_address & 0xffff) + 4);
+ (got_address + 4) & 0xffff);
nios2_elf32_install_imm16 (splt, res_size + 20,
- (got_address & 0xffff) + 8);
+ (got_address + 8) & 0xffff);
}
}
}
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 (h->size == 0)
{
- (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
- h->root.root.string);
+ _bfd_error_handler (_("dynamic variable `%s' is zero size"),
+ h->root.root.string);
return TRUE;
}
&& !bfd_elf_link_record_dynamic_symbol (info, h))
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->root.splt;
/* Allocate room for the header. */
if (s->size == 0)
{
- if (info->shared)
+ if (bfd_link_pic (info))
s->size = 24;
else
s->size = 28;
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;
dyn = htab->root.dynamic_sections_created;
indx = 0;
- if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
- && (!info->shared
+ if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
+ && (!bfd_link_pic (info)
|| !SYMBOL_REFERENCES_LOCAL (info, h)))
indx = h->dynindx;
if (tls_type != GOT_NORMAL
- && (info->shared || indx != 0)
+ && (bfd_link_pic (info) || indx != 0)
&& (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|| h->root.type != bfd_link_hash_undefweak))
{
else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|| h->root.type != bfd_link_hash_undefweak)
&& !use_plt
- && (info->shared
+ && (bfd_link_pic (info)
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
htab->root.srelgot->size += sizeof (Elf32_External_Rela);
}
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 || info->symbolic))
+ && (h->forced_local || SYMBOLIC_BIND (info, h)))
{
struct elf32_nios2_dyn_relocs **pp;
if (elf_hash_table (info)->dynamic_sections_created)
{
/* Set the contents of the .interp section to the interpreter. */
- if (info->executable)
+ if (bfd_link_executable (info) && !info->nointerp)
{
s = bfd_get_linker_section (dynobj, ".interp");
BFD_ASSERT (s != NULL);
if (*local_tls_type == GOT_NORMAL)
s->size += 4;
- if (info->shared || *local_tls_type == GOT_TLS_GD)
+ if (bfd_link_pic (info) || *local_tls_type == GOT_TLS_GD)
srel->size += sizeof (Elf32_External_Rela);
}
else
for R_NIOS2_TLS_LDM16 relocations. */
htab->tls_ldm_got.offset = htab->root.sgot->size;
htab->root.sgot->size += 8;
- if (info->shared)
+ if (bfd_link_pic (info))
htab->root.srelgot->size += sizeof (Elf32_External_Rela);
}
else
plt = s->size != 0;
/* Correct for the number of res_N branches. */
- if (plt && !info->shared)
+ if (plt && !bfd_link_pic (info))
{
htab->res_n_size = (s->size-28) / 3;
s->size += htab->res_n_size;
#define add_dynamic_entry(TAG, VAL) \
_bfd_elf_add_dynamic_entry (info, TAG, VAL)
- if (!info->shared && !add_dynamic_entry (DT_DEBUG, 0))
+ if (!bfd_link_pic (info) && !add_dynamic_entry (DT_DEBUG, 0))
return FALSE;
if (got && !add_dynamic_entry (DT_PLTGOT, 0))
|| !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))))
return FALSE;
- if (!info->shared && !add_dynamic_entry (DT_NIOS2_GP, 0))
+ if (!bfd_link_pic (info) && !add_dynamic_entry (DT_NIOS2_GP, 0))
return FALSE;
if ((info->flags & DF_TEXTREL) != 0
bfd *dynobj;
if (sym->st_shndx == SHN_COMMON
- && !info->relocatable
+ && !bfd_link_relocatable (info)
&& sym->st_size <= elf_gp_size (abfd)
&& is_nios2_elf_target (info->output_bfd->xvec))
{
#define elf_backend_plt_readonly 1
#define elf_backend_want_got_plt 1
#define elf_backend_rela_normal 1
+#define elf_backend_dtrel_excludes_plt 1
#define elf_backend_relocate_section nios2_elf32_relocate_section
#define elf_backend_section_flags nios2_elf32_section_flags