#include "elf/common.h"
#include "elf/internal.h"
-struct tilepro_elf_link_hash_table
-{
- struct elf_link_hash_table elf;
-
- /* Small local sym to section mapping cache. */
- struct sym_cache sym_cache;
-};
-
/* Get the Tilepro ELF linker hash table from a link_info structure. */
#define tilepro_elf_hash_table(p) \
- (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
- == TILEPRO_ELF_DATA \
- ? ((struct tilepro_elf_link_hash_table *) ((p)->hash)) : NULL)
+ ((is_elf_hash_table ((p)->hash) \
+ && elf_hash_table_id (elf_hash_table (p)) == TILEPRO_ELF_DATA) \
+ ? (struct elf_link_hash_table *) (p)->hash : NULL)
static reloc_howto_type *
tilepro_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
static struct bfd_link_hash_table *
tilepro_elf_link_hash_table_create (bfd *abfd)
{
- struct tilepro_elf_link_hash_table *ret;
- size_t amt = sizeof (struct tilepro_elf_link_hash_table);
+ struct elf_link_hash_table *ret;
+ size_t amt = sizeof (struct elf_link_hash_table);
- ret = (struct tilepro_elf_link_hash_table *) bfd_zmalloc (amt);
+ ret = (struct elf_link_hash_table *) bfd_zmalloc (amt);
if (ret == NULL)
return NULL;
- if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
+ if (!_bfd_elf_link_hash_table_init (ret, abfd, link_hash_newfunc,
sizeof (struct tilepro_elf_link_hash_entry),
TILEPRO_ELF_DATA))
{
return NULL;
}
- return &ret->elf.root;
+ return &ret->root;
}
/* Create the .got section. */
tilepro_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
asection *sec, const Elf_Internal_Rela *relocs)
{
- struct tilepro_elf_link_hash_table *htab;
+ struct elf_link_hash_table *htab;
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
const Elf_Internal_Rela *rel;
BFD_ASSERT (is_tilepro_elf (abfd) || num_relocs == 0);
- if (htab->elf.dynobj == NULL)
- htab->elf.dynobj = abfd;
+ if (htab->dynobj == NULL)
+ htab->dynobj = abfd;
rel_end = relocs + num_relocs;
for (rel = relocs; rel < rel_end; rel++)
}
}
- if (htab->elf.sgot == NULL)
+ if (htab->sgot == NULL)
{
- if (!tilepro_elf_create_got_section (htab->elf.dynobj, info))
+ if (!tilepro_elf_create_got_section (htab->dynobj, info))
return FALSE;
}
break;
if (sreloc == NULL)
{
sreloc = _bfd_elf_make_dynamic_reloc_section
- (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE);
+ (sec, htab->dynobj, 2, abfd, /*rela?*/ TRUE);
if (sreloc == NULL)
return FALSE;
{
size_t amt = sizeof *p;
p = ((struct elf_dyn_relocs *)
- bfd_alloc (htab->elf.dynobj, amt));
+ bfd_alloc (htab->dynobj, amt));
if (p == NULL)
return FALSE;
p->next = *head;
tilepro_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
struct elf_link_hash_entry *h)
{
- struct tilepro_elf_link_hash_table *htab;
+ struct elf_link_hash_table *htab;
asection *s, *srel;
htab = tilepro_elf_hash_table (info);
BFD_ASSERT (htab != NULL);
/* Make sure we know what is going on here. */
- BFD_ASSERT (htab->elf.dynobj != NULL
+ BFD_ASSERT (htab->dynobj != NULL
&& (h->needs_plt
|| h->is_weakalias
|| (h->def_dynamic
.rel.bss section we are going to use. */
if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
{
- s = htab->elf.sdynrelro;
- srel = htab->elf.sreldynrelro;
+ s = htab->sdynrelro;
+ srel = htab->sreldynrelro;
}
else
{
- s = htab->elf.sdynbss;
- srel = htab->elf.srelbss;
+ s = htab->sdynbss;
+ srel = htab->srelbss;
}
if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
{
allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
{
struct bfd_link_info *info;
- struct tilepro_elf_link_hash_table *htab;
+ struct elf_link_hash_table *htab;
struct elf_dyn_relocs *p;
if (h->root.type == bfd_link_hash_indirect)
htab = tilepro_elf_hash_table (info);
BFD_ASSERT (htab != NULL);
- if (htab->elf.dynamic_sections_created
+ if (htab->dynamic_sections_created
&& h->plt.refcount > 0)
{
/* Make sure this symbol is output as a dynamic symbol.
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
{
- asection *s = htab->elf.splt;
+ asection *s = htab->splt;
/* Allocate room for the header. */
if (s->size == 0)
s->size += PLT_ENTRY_SIZE;
/* We also need to make an entry in the .got.plt section. */
- htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
+ htab->sgotplt->size += GOT_ENTRY_SIZE;
/* We also need to make an entry in the .rela.plt section. */
- htab->elf.srelplt->size += TILEPRO_ELF_RELA_BYTES;
+ htab->srelplt->size += TILEPRO_ELF_RELA_BYTES;
}
else
{
return FALSE;
}
- s = htab->elf.sgot;
+ s = htab->sgot;
h->got.offset = s->size;
s->size += TILEPRO_BYTES_PER_WORD;
/* R_TILEPRO_IMM16_Xn_TLS_GD entries need 2 consecutive GOT slots. */
if (tls_type == GOT_TLS_GD)
s->size += TILEPRO_BYTES_PER_WORD;
- dyn = htab->elf.dynamic_sections_created;
+ dyn = htab->dynamic_sections_created;
/* R_TILEPRO_IMM16_Xn_TLS_IE_xxx needs one dynamic relocation,
R_TILEPRO_IMM16_Xn_TLS_GD_xxx needs two if local symbol and two if
global. */
if (tls_type == GOT_TLS_GD || tls_type == GOT_TLS_IE)
- htab->elf.srelgot->size += 2 * TILEPRO_ELF_RELA_BYTES;
+ htab->srelgot->size += 2 * TILEPRO_ELF_RELA_BYTES;
else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
bfd_link_pic (info),
h))
- htab->elf.srelgot->size += TILEPRO_ELF_RELA_BYTES;
+ htab->srelgot->size += TILEPRO_ELF_RELA_BYTES;
}
else
h->got.offset = (bfd_vma) -1;
if (!h->non_got_ref
&& ((h->def_dynamic
&& !h->def_regular)
- || (htab->elf.dynamic_sections_created
+ || (htab->dynamic_sections_created
&& (h->root.type == bfd_link_hash_undefweak
|| h->root.type == bfd_link_hash_undefined))))
{
{
(void)output_bfd;
- struct tilepro_elf_link_hash_table *htab;
+ struct elf_link_hash_table *htab;
bfd *dynobj;
asection *s;
bfd *ibfd;
htab = tilepro_elf_hash_table (info);
BFD_ASSERT (htab != NULL);
- dynobj = htab->elf.dynobj;
+ dynobj = htab->dynobj;
BFD_ASSERT (dynobj != NULL);
if (elf_hash_table (info)->dynamic_sections_created)
locsymcount = symtab_hdr->sh_info;
end_local_got = local_got + locsymcount;
local_tls_type = _bfd_tilepro_elf_local_got_tls_type (ibfd);
- s = htab->elf.sgot;
- srel = htab->elf.srelgot;
+ s = htab->sgot;
+ srel = htab->srelgot;
for (; local_got < end_local_got; ++local_got, ++local_tls_type)
{
if (*local_got > 0)
/* Allocate global sym .plt and .got entries, and space for global
sym dynamic relocs. */
- elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
+ elf_link_hash_traverse (htab, allocate_dynrelocs, info);
if (elf_hash_table (info)->dynamic_sections_created)
{
/* If the .got section is more than 0x8000 bytes, we add
0x8000 to the value of _GLOBAL_OFFSET_TABLE_, so that 16
bit relocations have a greater chance of working. */
- if (htab->elf.sgot->size >= 0x8000
+ if (htab->sgot->size >= 0x8000
&& elf_hash_table (info)->hgot->root.u.def.value == 0)
elf_hash_table (info)->hgot->root.u.def.value = 0x8000;
}
- if (htab->elf.sgotplt)
+ if (htab->sgotplt)
{
struct elf_link_hash_entry *got;
got = elf_link_hash_lookup (elf_hash_table (info),
entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
if ((got == NULL
|| !got->ref_regular_nonweak)
- && (htab->elf.sgotplt->size
+ && (htab->sgotplt->size
== GOTPLT_HEADER_SIZE)
- && (htab->elf.splt == NULL
- || htab->elf.splt->size == 0)
- && (htab->elf.sgot == NULL
- || (htab->elf.sgot->size
+ && (htab->splt == NULL
+ || htab->splt->size == 0)
+ && (htab->sgot == NULL
+ || (htab->sgot->size
== get_elf_backend_data (output_bfd)->got_header_size)))
- htab->elf.sgotplt->size = 0;
+ htab->sgotplt->size = 0;
}
/* The check_relocs and adjust_dynamic_symbol entry points have
if ((s->flags & SEC_LINKER_CREATED) == 0)
continue;
- if (s == htab->elf.splt
- || s == htab->elf.sgot
- || s == htab->elf.sgotplt
- || s == htab->elf.sdynbss
- || s == htab->elf.sdynrelro)
+ if (s == htab->splt
+ || s == htab->sgot
+ || s == htab->sgotplt
+ || s == htab->sdynbss
+ || s == htab->sdynrelro)
{
/* Strip this section if we don't need it; see the
comment below. */
return FALSE;
}
- if (elf_hash_table (info)->dynamic_sections_created)
- {
- /* Add some entries to the .dynamic section. We fill in the
- values later, in tilepro_elf_finish_dynamic_sections, but we
- must add the entries now so that we get the correct size for
- the .dynamic section. The DT_DEBUG entry is filled in by the
- dynamic linker and used by the debugger. */
-#define add_dynamic_entry(TAG, VAL) \
- _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
- if (bfd_link_executable (info))
- {
- if (!add_dynamic_entry (DT_DEBUG, 0))
- return FALSE;
- }
-
- if (htab->elf.srelplt->size != 0)
- {
- if (!add_dynamic_entry (DT_PLTGOT, 0)
- || !add_dynamic_entry (DT_PLTRELSZ, 0)
- || !add_dynamic_entry (DT_PLTREL, DT_RELA)
- || !add_dynamic_entry (DT_JMPREL, 0))
- return FALSE;
- }
-
- if (!add_dynamic_entry (DT_RELA, 0)
- || !add_dynamic_entry (DT_RELASZ, 0)
- || !add_dynamic_entry (DT_RELAENT, TILEPRO_ELF_RELA_BYTES))
- return FALSE;
-
- /* If any dynamic relocs apply to a read-only section,
- then we need a DT_TEXTREL entry. */
- if ((info->flags & DF_TEXTREL) == 0)
- elf_link_hash_traverse (&htab->elf,
- _bfd_elf_maybe_set_textrel, info);
-
- if (info->flags & DF_TEXTREL)
- {
- if (!add_dynamic_entry (DT_TEXTREL, 0))
- return FALSE;
- }
- }
-#undef add_dynamic_entry
-
- return TRUE;
+ return _bfd_elf_add_dynamic_tags (output_bfd, info, TRUE);
}
\f
/* Return the base VMA address which should be subtracted from real addresses
Elf_Internal_Sym *local_syms,
asection **local_sections)
{
- struct tilepro_elf_link_hash_table *htab;
+ struct elf_link_hash_table *htab;
Elf_Internal_Shdr *symtab_hdr;
struct elf_link_hash_entry **sym_hashes;
bfd_vma *local_got_offsets;
case R_TILEPRO_IMM16_X1_GOT_HA:
/* Relocation is to the entry for this symbol in the global
offset table. */
- if (htab->elf.sgot == NULL)
+ if (htab->sgot == NULL)
abort ();
if (h != NULL)
else
{
bfd_put_32 (output_bfd, relocation,
- htab->elf.sgot->contents + off);
+ htab->sgot->contents + off);
h->got.offset |= 1;
}
}
/* We need to generate a R_TILEPRO_RELATIVE reloc
for the dynamic linker. */
- s = htab->elf.srelgot;
+ s = htab->srelgot;
BFD_ASSERT (s != NULL);
- outrel.r_offset = (htab->elf.sgot->output_section->vma
- + htab->elf.sgot->output_offset
+ outrel.r_offset = (htab->sgot->output_section->vma
+ + htab->sgot->output_offset
+ off);
outrel.r_info = ELF32_R_INFO (0, R_TILEPRO_RELATIVE);
outrel.r_addend = relocation;
}
bfd_put_32 (output_bfd, relocation,
- htab->elf.sgot->contents + off);
+ htab->sgot->contents + off);
local_got_offsets[r_symndx] |= 1;
}
}
procedure linkage table. */
BFD_ASSERT (h != NULL);
- if (h->plt.offset == (bfd_vma) -1 || htab->elf.splt == NULL)
+ if (h->plt.offset == (bfd_vma) -1 || htab->splt == NULL)
{
/* We didn't make a PLT entry for this symbol. This
happens when statically linking PIC code, or when
break;
}
- relocation = (htab->elf.splt->output_section->vma
- + htab->elf.splt->output_offset
+ relocation = (htab->splt->output_section->vma
+ + htab->splt->output_offset
+ h->plt.offset);
unresolved_reloc = FALSE;
break;
outrel.r_addend = relocation + rel->r_addend;
if (is_plt)
- sec = htab->elf.splt;
+ sec = htab->splt;
if (bfd_is_abs_section (sec))
indx = 0;
if (indx == 0)
{
- osec = htab->elf.text_index_section;
+ osec = htab->text_index_section;
indx = elf_section_data (osec)->dynindx;
}
local_got_offsets[r_symndx] |= 1;
}
- if (htab->elf.sgot == NULL)
+ if (htab->sgot == NULL)
abort ();
if ((off & 1) != 0)
int indx = 0;
bfd_boolean need_relocs = FALSE;
- if (htab->elf.srelgot == NULL)
+ if (htab->srelgot == NULL)
abort ();
if (h != NULL)
{
bfd_boolean dyn;
- dyn = htab->elf.dynamic_sections_created;
+ dyn = htab->dynamic_sections_created;
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
bfd_link_pic (info),
case R_TILEPRO_IMM16_X0_TLS_IE_HA:
case R_TILEPRO_IMM16_X1_TLS_IE_HA:
if (need_relocs) {
- bfd_put_32 (output_bfd, 0, htab->elf.sgot->contents + off);
- outrel.r_offset = (htab->elf.sgot->output_section->vma
- + htab->elf.sgot->output_offset + off);
+ bfd_put_32 (output_bfd, 0, htab->sgot->contents + off);
+ outrel.r_offset = (htab->sgot->output_section->vma
+ + htab->sgot->output_offset + off);
outrel.r_addend = 0;
if (indx == 0)
outrel.r_addend = relocation - dtpoff_base (info);
outrel.r_info = ELF32_R_INFO (indx, R_TILEPRO_TLS_TPOFF32);
- tilepro_elf_append_rela_32 (output_bfd, htab->elf.srelgot,
+ tilepro_elf_append_rela_32 (output_bfd, htab->srelgot,
&outrel);
} else {
bfd_put_32 (output_bfd, tpoff (info, relocation),
- htab->elf.sgot->contents + off);
+ htab->sgot->contents + off);
}
break;
case R_TILEPRO_IMM16_X0_TLS_GD_HA:
case R_TILEPRO_IMM16_X1_TLS_GD_HA:
if (need_relocs) {
- outrel.r_offset = (htab->elf.sgot->output_section->vma
- + htab->elf.sgot->output_offset + off);
+ outrel.r_offset = (htab->sgot->output_section->vma
+ + htab->sgot->output_offset + off);
outrel.r_addend = 0;
outrel.r_info = ELF32_R_INFO (indx, R_TILEPRO_TLS_DTPMOD32);
- bfd_put_32 (output_bfd, 0, htab->elf.sgot->contents + off);
- tilepro_elf_append_rela_32 (output_bfd, htab->elf.srelgot,
+ bfd_put_32 (output_bfd, 0, htab->sgot->contents + off);
+ tilepro_elf_append_rela_32 (output_bfd, htab->srelgot,
&outrel);
if (indx == 0)
{
BFD_ASSERT (! unresolved_reloc);
bfd_put_32 (output_bfd,
relocation - dtpoff_base (info),
- (htab->elf.sgot->contents + off +
+ (htab->sgot->contents + off +
TILEPRO_BYTES_PER_WORD));
}
else
{
bfd_put_32 (output_bfd, 0,
- (htab->elf.sgot->contents + off +
+ (htab->sgot->contents + off +
TILEPRO_BYTES_PER_WORD));
outrel.r_info = ELF32_R_INFO (indx,
R_TILEPRO_TLS_DTPOFF32);
outrel.r_offset += TILEPRO_BYTES_PER_WORD;
tilepro_elf_append_rela_32 (output_bfd,
- htab->elf.srelgot, &outrel);
+ htab->srelgot, &outrel);
}
}
symbol binding locally. Mark it as belonging
to module 1, the executable. */
bfd_put_32 (output_bfd, 1,
- htab->elf.sgot->contents + off );
+ htab->sgot->contents + off );
bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
- htab->elf.sgot->contents + off +
+ htab->sgot->contents + off +
TILEPRO_BYTES_PER_WORD);
}
break;
struct elf_link_hash_entry *h,
Elf_Internal_Sym *sym)
{
- struct tilepro_elf_link_hash_table *htab;
+ struct elf_link_hash_table *htab;
htab = tilepro_elf_hash_table (info);
BFD_ASSERT (htab != NULL);
BFD_ASSERT (h->dynindx != -1);
- splt = htab->elf.splt;
- srela = htab->elf.srelplt;
- sgotplt = htab->elf.sgotplt;
+ splt = htab->splt;
+ srela = htab->srelplt;
+ sgotplt = htab->sgotplt;
if (splt == NULL || srela == NULL)
abort ();
/* This symbol has an entry in the GOT. Set it up. */
- sgot = htab->elf.sgot;
- srela = htab->elf.srelgot;
+ sgot = htab->sgot;
+ srela = htab->srelgot;
BFD_ASSERT (sgot != NULL && srela != NULL);
rela.r_offset = (sgot->output_section->vma
+ h->root.u.def.section->output_offset);
rela.r_info = ELF32_R_INFO (h->dynindx, R_TILEPRO_COPY);
rela.r_addend = 0;
- if (h->root.u.def.section == htab->elf.sdynrelro)
- s = htab->elf.sreldynrelro;
+ if (h->root.u.def.section == htab->sdynrelro)
+ s = htab->sreldynrelro;
else
- s = htab->elf.srelbss;
+ s = htab->srelbss;
tilepro_elf_append_rela_32 (output_bfd, s, &rela);
}
/* Mark some specially defined symbols as absolute. */
- if (h == htab->elf.hdynamic
- || (h == htab->elf.hgot || h == htab->elf.hplt))
+ if (h == htab->hdynamic
+ || (h == htab->hgot || h == htab->hplt))
sym->st_shndx = SHN_ABS;
return TRUE;
asection *splt ATTRIBUTE_UNUSED)
{
Elf32_External_Dyn *dyncon, *dynconend;
- struct tilepro_elf_link_hash_table *htab;
+ struct elf_link_hash_table *htab;
htab = tilepro_elf_hash_table (info);
BFD_ASSERT (htab != NULL);
switch (dyn.d_tag)
{
case DT_PLTGOT:
- s = htab->elf.sgotplt;
+ s = htab->sgotplt;
dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
break;
case DT_JMPREL:
- s = htab->elf.srelplt;
+ s = htab->srelplt;
dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
break;
case DT_PLTRELSZ:
- s = htab->elf.srelplt;
+ s = htab->srelplt;
dyn.d_un.d_val = s->size;
break;
default:
{
bfd *dynobj;
asection *sdyn;
- struct tilepro_elf_link_hash_table *htab;
+ struct elf_link_hash_table *htab;
htab = tilepro_elf_hash_table (info);
BFD_ASSERT (htab != NULL);
- dynobj = htab->elf.dynobj;
+ dynobj = htab->dynobj;
sdyn = bfd_get_linker_section (dynobj, ".dynamic");
asection *splt;
bfd_boolean ret;
- splt = htab->elf.splt;
+ splt = htab->splt;
BFD_ASSERT (splt != NULL && sdyn != NULL);
ret = tilepro_finish_dyn (output_bfd, info, dynobj, sdyn, splt);
= PLT_ENTRY_SIZE;
}
- if (htab->elf.sgotplt)
+ if (htab->sgotplt)
{
- if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
+ if (bfd_is_abs_section (htab->sgotplt->output_section))
{
_bfd_error_handler
- (_("discarded output section: `%pA'"), htab->elf.sgotplt);
+ (_("discarded output section: `%pA'"), htab->sgotplt);
return FALSE;
}
- if (htab->elf.sgotplt->size > 0)
+ if (htab->sgotplt->size > 0)
{
/* Write the first two entries in .got.plt, needed for the dynamic
linker. */
bfd_put_32 (output_bfd, (bfd_vma) -1,
- htab->elf.sgotplt->contents);
+ htab->sgotplt->contents);
bfd_put_32 (output_bfd, (bfd_vma) 0,
- htab->elf.sgotplt->contents + GOT_ENTRY_SIZE);
+ htab->sgotplt->contents + GOT_ENTRY_SIZE);
}
- elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize
+ elf_section_data (htab->sgotplt->output_section)->this_hdr.sh_entsize
= GOT_ENTRY_SIZE;
}
- if (htab->elf.sgot)
+ if (htab->sgot)
{
- if (htab->elf.sgot->size > 0)
+ if (htab->sgot->size > 0)
{
/* Set the first entry in the global offset table to the address of
the dynamic section. */
bfd_vma val = (sdyn ?
sdyn->output_section->vma + sdyn->output_offset :
0);
- bfd_put_32 (output_bfd, val, htab->elf.sgot->contents);
+ bfd_put_32 (output_bfd, val, htab->sgot->contents);
}
- elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
+ elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize
= GOT_ENTRY_SIZE;
}