PATCH: Move some STT_GNU_IFUNC support to generic ELF linker
H.J. Lu
hjl.tools@gmail.com
Tue Jun 16 17:34:00 GMT 2009
On Tue, Jun 16, 2009 at 8:51 AM, H.J. Lu<hjl.tools@gmail.com> wrote:
> On Tue, Jun 16, 2009 at 4:56 AM, Nick Clifton<nickc@redhat.com> wrote:
>> Hi H.J.
>>
>>> Here is the first patch. OK for trunk?
>>
>>> 2009-06-15 H.J. Lu <hongjiu.lu@intel.com>
>>>
>>> * configure.in (elf): Add elf-ifunc.lo.
>>>
>>> * configure: Regenerated.
>>> * Makefile.in: Likewise.
>>>
>>> * elf-bfd.h (elf_link_hash_table): Add sgot, sgotplt,
>>> srelgot, splt, srelplt, igotplt, iplt, irelplt and irelifunc.
>>>
>>> * elf32-i386.c (elf_i386_link_hash_table): Remove sgot,
>>> sgotplt, srelgot, splt, srelplt, igotplt, iplt, irelplt and
>>> irelifunc.
>>> (elf_i386_link_hash_table_create): Likewise.
>>> (elf_i386_create_dynamic_sections): Likewise.
>>> (elf_i386_check_relocs): Likewise.
>>> (elf_i386_allocate_dynrelocs): Likewise.
>>> (elf_i386_size_dynamic_sections): Likewise.
>>> (elf_i386_relocate_section): Likewise.
>>> (elf_i386_finish_dynamic_symbol): Likewise.
>>> (elf_i386_finish_dynamic_sections): Likewise.
>>> (elf_i386_create_got_section): Removed.
>>>
>>> * elf64-x86-64.c (elf64_x86_64_link_hash_table): Remove sgot,
>>> sgotplt, srelgot, splt, srelplt, igotplt, iplt, irelplt and
>>> irelifunc.
>>> (elf64_x86_64_compute_jump_table_size): Updated.
>>> (elf64_x86_64_link_hash_table_create): Likewise.
>>> (elf64_x86_64_create_dynamic_sections): Likewise.
>>> (elf64_x86_64_check_relocs): Likewise.
>>> (elf64_x86_64_allocate_dynrelocs): Likewise.
>>> (elf64_x86_64_size_dynamic_sections): Likewise.
>>> (elf64_x86_64_relocate_section): Likewise.
>>> (elf64_x86_64_finish_dynamic_symbol): Likewise.
>>> (elf64_x86_64_finish_dynamic_sections): Likewise.
>>> (elf64_x86_64_create_got_section): Removed.
>>>
>>> * elflink.c (_bfd_elf_create_got_section): Use log_file_align
>>> for pointer alignment. Set up section pointers.
>>> (_bfd_elf_create_dynamic_sections): Likewise.
>>> (_bfd_elf_create_ifunc_sections): Moved to ...
>>> * elf-ifunc.c: Here. New.
>>>
>>> * Makefile.am (BFD32_BACKENDS): Add elf-ifunc.lo.
>>> (BFD32_BACKENDS_CFILES): Add elf-ifunc.c.
>>> Run "make dep-am".
>>
>> Approved - please apply.
>>
>> Cheers
>> Nick
>>
>
> IA64 needs this patch to fix linker failures. I will check it in as an
> obvious fix. Please let me know if other backends need similar
> patches.
>
> Thanks.
>
>
> H.J.
> ---
> 2009-06-16 H.J. Lu <hongjiu.lu@intel.com>
>
> * elfxx-ia64.c (elfNN_ia64_link_hash_table): Remove got_sec,
> rel_got_sec and plt_sec.
> (elfNN_ia64_relax_section): Updated.
> (elfNN_ia64_create_dynamic_sections): Likewise.
> (get_got): Likewise.
> (allocate_dynrel_entries): Likewise.
> (elfNN_ia64_size_dynamic_sections): Likewise.
> (set_got_entry): Likewise.
> (elfNN_ia64_choose_gp): Likewise.
> (elfNN_ia64_relocate_section): Likewise.
> (elfNN_ia64_finish_dynamic_symbol): Likewise.
> (elfNN_ia64_finish_dynamic_sections): Likewise.
>
I think ARM needs the patch below, which is pretty much
mechanical. I tested it with a cross linker. Here is the
complete list of files which may need update.
M elf32-lm32.c
M elf32-ppc.c
M elf32-hppa.c
M elf64-ppc.c
M elf32-frv.c
M elfxx-sparc.h
M elf64-hppa.c
M elf32-sh.c
M elf32-s390.c
M elfxx-mips.c
M elf32-m32r.c
M elf32-xtensa.c
M elf64-s390.c
M elf32-arm.c
M elf32-bfin.c
I don't have access to those hardwares. I can only test
with a cross linker. Please let me know if I should go
ahead to make those changes.
Thanks.
--
H.J.
----
2009-06-16 H.J. Lu <hongjiu.lu@intel.com>
* elf32-arm.c (elf32_arm_link_hash_table): Remove sgot,
sgotplt, srelgot, splt and srelplt.
(create_got_section): Likewise.
(elf32_arm_create_dynamic_sections): Likewise.
(elf32_arm_link_hash_table_create): Likewise.
(arm_type_of_stub): Likewise.
(elf32_arm_size_stubs): Likewise.
(bfd_elf32_arm_process_before_allocation): Likewise.
(elf32_arm_final_link_relocate): Likewise.
(elf32_arm_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
(elf32_arm_size_dynamic_sections): Likewise.
(elf32_arm_output_arch_local_syms): Likewise.
-------------- next part --------------
2009-06-16 H.J. Lu <hongjiu.lu@intel.com>
* elf32-arm.c (elf32_arm_link_hash_table): Remove sgot,
sgotplt, srelgot, splt and srelplt.
(create_got_section): Likewise.
(elf32_arm_create_dynamic_sections): Likewise.
(elf32_arm_link_hash_table_create): Likewise.
(arm_type_of_stub): Likewise.
(elf32_arm_size_stubs): Likewise.
(bfd_elf32_arm_process_before_allocation): Likewise.
(elf32_arm_final_link_relocate): Likewise.
(elf32_arm_check_relocs): Likewise.
(allocate_dynrelocs): Likewise.
(elf32_arm_size_dynamic_sections): Likewise.
(elf32_arm_output_arch_local_syms): Likewise.
Index: elf32-arm.c
===================================================================
--- elf32-arm.c (revision 6150)
+++ elf32-arm.c (working copy)
@@ -2600,11 +2600,6 @@ struct elf32_arm_link_hash_table
int use_rel;
/* Short-cuts to get to dynamic linker sections. */
- asection *sgot;
- asection *sgotplt;
- asection *srelgot;
- asection *splt;
- asection *srelplt;
asection *sdynbss;
asection *srelbss;
@@ -2740,25 +2735,7 @@ create_got_section (bfd *dynobj, struct
if (htab->symbian_p)
return TRUE;
- if (! _bfd_elf_create_got_section (dynobj, info))
- return FALSE;
-
- htab->sgot = bfd_get_section_by_name (dynobj, ".got");
- htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
- if (!htab->sgot || !htab->sgotplt)
- abort ();
-
- htab->srelgot = bfd_make_section_with_flags (dynobj,
- RELOC_SECTION (htab, ".got"),
- (SEC_ALLOC | SEC_LOAD
- | SEC_HAS_CONTENTS
- | SEC_IN_MEMORY
- | SEC_LINKER_CREATED
- | SEC_READONLY));
- if (htab->srelgot == NULL
- || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
- return FALSE;
- return TRUE;
+ return _bfd_elf_create_got_section (dynobj, info);
}
/* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
@@ -2771,15 +2748,9 @@ elf32_arm_create_dynamic_sections (bfd *
struct elf32_arm_link_hash_table *htab;
htab = elf32_arm_hash_table (info);
- if (!htab->sgot && !create_got_section (dynobj, info))
- return FALSE;
-
if (!_bfd_elf_create_dynamic_sections (dynobj, info))
return FALSE;
- htab->splt = bfd_get_section_by_name (dynobj, ".plt");
- htab->srelplt = bfd_get_section_by_name (dynobj,
- RELOC_SECTION (htab, ".plt"));
htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
if (!info->shared)
htab->srelbss = bfd_get_section_by_name (dynobj,
@@ -2805,9 +2776,7 @@ elf32_arm_create_dynamic_sections (bfd *
}
}
- if (!htab->splt
- || !htab->srelplt
- || !htab->sdynbss
+ if (!htab->sdynbss
|| (!info->shared && !htab->srelbss))
abort ();
@@ -2895,11 +2864,6 @@ elf32_arm_link_hash_table_create (bfd *a
return NULL;
}
- ret->sgot = NULL;
- ret->sgotplt = NULL;
- ret->srelgot = NULL;
- ret->splt = NULL;
- ret->srelplt = NULL;
ret->sdynbss = NULL;
ret->srelbss = NULL;
ret->srelplt2 = NULL;
@@ -3051,7 +3015,7 @@ arm_type_of_stub (struct bfd_link_info *
r_type = ELF32_R_TYPE (rel->r_info);
/* Keep a simpler condition, for the sake of clarity. */
- if (globals->splt != NULL && hash != NULL && hash->root.plt.offset != (bfd_vma) -1)
+ if (globals->root.splt != NULL && hash != NULL && hash->root.plt.offset != (bfd_vma) -1)
{
use_plt = 1;
/* Note when dealing with PLT entries: the main PLT stub is in
@@ -4383,10 +4347,10 @@ elf32_arm_size_stubs (bfd *output_bfd,
struct elf32_arm_link_hash_table *globals =
elf32_arm_hash_table (info);
- if (globals->splt != NULL && hash != NULL
+ if (globals->root.splt != NULL && hash != NULL
&& hash->root.plt.offset != (bfd_vma) -1)
{
- sym_sec = globals->splt;
+ sym_sec = globals->root.splt;
sym_value = hash->root.plt.offset;
if (sym_sec->output_section != NULL)
destination = (sym_value
@@ -5361,7 +5325,7 @@ bfd_elf32_arm_process_before_allocation
/* If the call will go through a PLT entry then we do not need
glue. */
- if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
+ if (globals->root.splt != NULL && h->plt.offset != (bfd_vma) -1)
continue;
switch (r_type)
@@ -7728,7 +7692,7 @@ elf32_arm_final_link_relocate (reloc_how
{
bfd_vma off;
- if (globals->sgot == NULL)
+ if (globals->root.sgot == NULL)
abort ();
off = globals->tls_ldm_got.offset;
@@ -7744,29 +7708,29 @@ elf32_arm_final_link_relocate (reloc_how
Elf_Internal_Rela outrel;
bfd_byte *loc;
- if (globals->srelgot == NULL)
+ if (globals->root.srelgot == NULL)
abort ();
outrel.r_addend = 0;
- outrel.r_offset = (globals->sgot->output_section->vma
- + globals->sgot->output_offset + off);
+ outrel.r_offset = (globals->root.sgot->output_section->vma
+ + globals->root.sgot->output_offset + off);
outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
if (globals->use_rel)
bfd_put_32 (output_bfd, outrel.r_addend,
- globals->sgot->contents + off);
+ globals->root.sgot->contents + off);
- loc = globals->srelgot->contents;
- loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
+ loc = globals->root.srelgot->contents;
+ loc += globals->root.srelgot->reloc_count++ * RELOC_SIZE (globals);
SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
}
else
- bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
+ bfd_put_32 (output_bfd, 1, globals->root.sgot->contents + off);
globals->tls_ldm_got.offset |= 1;
}
- value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
+ value = globals->root.sgot->output_section->vma + globals->root.sgot->output_offset + off
- (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
return _bfd_final_link_relocate (howto, input_bfd, input_section,
@@ -7781,7 +7745,7 @@ elf32_arm_final_link_relocate (reloc_how
int indx;
char tls_type;
- if (globals->sgot == NULL)
+ if (globals->root.sgot == NULL)
abort ();
indx = 0;
@@ -7829,10 +7793,10 @@ elf32_arm_final_link_relocate (reloc_how
|| h->root.type != bfd_link_hash_undefweak))
{
need_relocs = TRUE;
- if (globals->srelgot == NULL)
+ if (globals->root.srelgot == NULL)
abort ();
- loc = globals->srelgot->contents;
- loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
+ loc = globals->root.srelgot->contents;
+ loc += globals->root.srelgot->reloc_count * RELOC_SIZE (globals);
}
if (tls_type & GOT_TLS_GD)
@@ -7840,22 +7804,22 @@ elf32_arm_final_link_relocate (reloc_how
if (need_relocs)
{
outrel.r_addend = 0;
- outrel.r_offset = (globals->sgot->output_section->vma
- + globals->sgot->output_offset
+ outrel.r_offset = (globals->root.sgot->output_section->vma
+ + globals->root.sgot->output_offset
+ cur_off);
outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
if (globals->use_rel)
bfd_put_32 (output_bfd, outrel.r_addend,
- globals->sgot->contents + cur_off);
+ globals->root.sgot->contents + cur_off);
SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
- globals->srelgot->reloc_count++;
+ globals->root.srelgot->reloc_count++;
loc += RELOC_SIZE (globals);
if (indx == 0)
bfd_put_32 (output_bfd, value - dtpoff_base (info),
- globals->sgot->contents + cur_off + 4);
+ globals->root.sgot->contents + cur_off + 4);
else
{
outrel.r_addend = 0;
@@ -7865,11 +7829,11 @@ elf32_arm_final_link_relocate (reloc_how
if (globals->use_rel)
bfd_put_32 (output_bfd, outrel.r_addend,
- globals->sgot->contents + cur_off + 4);
+ globals->root.sgot->contents + cur_off + 4);
SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
- globals->srelgot->reloc_count++;
+ globals->root.srelgot->reloc_count++;
loc += RELOC_SIZE (globals);
}
}
@@ -7881,9 +7845,9 @@ elf32_arm_final_link_relocate (reloc_how
symbol binding locally. Mark it as belonging
to module 1, the executable. */
bfd_put_32 (output_bfd, 1,
- globals->sgot->contents + cur_off);
+ globals->root.sgot->contents + cur_off);
bfd_put_32 (output_bfd, value - dtpoff_base (info),
- globals->sgot->contents + cur_off + 4);
+ globals->root.sgot->contents + cur_off + 4);
}
cur_off += 8;
@@ -7897,22 +7861,22 @@ elf32_arm_final_link_relocate (reloc_how
outrel.r_addend = value - dtpoff_base (info);
else
outrel.r_addend = 0;
- outrel.r_offset = (globals->sgot->output_section->vma
- + globals->sgot->output_offset
+ outrel.r_offset = (globals->root.sgot->output_section->vma
+ + globals->root.sgot->output_offset
+ cur_off);
outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
if (globals->use_rel)
bfd_put_32 (output_bfd, outrel.r_addend,
- globals->sgot->contents + cur_off);
+ globals->root.sgot->contents + cur_off);
SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
- globals->srelgot->reloc_count++;
+ globals->root.srelgot->reloc_count++;
loc += RELOC_SIZE (globals);
}
else
bfd_put_32 (output_bfd, tpoff (info, value),
- globals->sgot->contents + cur_off);
+ globals->root.sgot->contents + cur_off);
cur_off += 4;
}
@@ -7924,7 +7888,7 @@ elf32_arm_final_link_relocate (reloc_how
if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
off += 8;
- value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
+ value = globals->root.sgot->output_section->vma + globals->root.sgot->output_offset + off
- (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
return _bfd_final_link_relocate (howto, input_bfd, input_section,
@@ -10702,7 +10666,7 @@ elf32_arm_check_relocs (bfd *abfd, struc
case R_ARM_GOTOFF32:
case R_ARM_GOTPC:
- if (htab->sgot == NULL)
+ if (htab->root.sgot == NULL)
{
if (htab->root.dynobj == NULL)
htab->root.dynobj = abfd;
@@ -11249,7 +11213,7 @@ allocate_dynrelocs (struct elf_link_hash
if (info->shared
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
{
- asection *s = htab->splt;
+ asection *s = htab->root.splt;
/* If this is the first .plt entry, make room for the special
first entry. */
@@ -11295,12 +11259,12 @@ allocate_dynrelocs (struct elf_link_hash
{
/* We also need to make an entry in the .got.plt section, which
will be placed in the .got section by the linker script. */
- eh->plt_got_offset = htab->sgotplt->size;
- htab->sgotplt->size += 4;
+ eh->plt_got_offset = htab->root.sgotplt->size;
+ htab->root.sgotplt->size += 4;
}
/* We also need to make an entry in the .rel(a).plt section. */
- htab->srelplt->size += RELOC_SIZE (htab);
+ htab->root.srelplt->size += RELOC_SIZE (htab);
/* VxWorks executables have a second set of relocations for
each PLT entry. They go in a separate relocation section,
@@ -11348,7 +11312,7 @@ allocate_dynrelocs (struct elf_link_hash
if (!htab->symbian_p)
{
- s = htab->sgot;
+ s = htab->root.sgot;
h->got.offset = s->size;
if (tls_type == GOT_UNKNOWN)
@@ -11381,19 +11345,19 @@ allocate_dynrelocs (struct elf_link_hash
|| h->root.type != bfd_link_hash_undefweak))
{
if (tls_type & GOT_TLS_IE)
- htab->srelgot->size += RELOC_SIZE (htab);
+ htab->root.srelgot->size += RELOC_SIZE (htab);
if (tls_type & GOT_TLS_GD)
- htab->srelgot->size += RELOC_SIZE (htab);
+ htab->root.srelgot->size += RELOC_SIZE (htab);
if ((tls_type & GOT_TLS_GD) && indx != 0)
- htab->srelgot->size += RELOC_SIZE (htab);
+ htab->root.srelgot->size += RELOC_SIZE (htab);
}
else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|| h->root.type != bfd_link_hash_undefweak)
&& (info->shared
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
- htab->srelgot->size += RELOC_SIZE (htab);
+ htab->root.srelgot->size += RELOC_SIZE (htab);
}
}
else
@@ -11670,8 +11634,8 @@ elf32_arm_size_dynamic_sections (bfd * o
locsymcount = symtab_hdr->sh_info;
end_local_got = local_got + locsymcount;
local_tls_type = elf32_arm_local_got_tls_type (ibfd);
- s = htab->sgot;
- srel = htab->srelgot;
+ s = htab->root.sgot;
+ srel = htab->root.srelgot;
for (; local_got < end_local_got; ++local_got, ++local_tls_type)
{
if (*local_got > 0)
@@ -11697,10 +11661,10 @@ elf32_arm_size_dynamic_sections (bfd * o
{
/* Allocate two GOT entries and one dynamic relocation (if necessary)
for R_ARM_TLS_LDM32 relocations. */
- htab->tls_ldm_got.offset = htab->sgot->size;
- htab->sgot->size += 8;
+ htab->tls_ldm_got.offset = htab->root.sgot->size;
+ htab->root.sgot->size += 8;
if (info->shared)
- htab->srelgot->size += RELOC_SIZE (htab);
+ htab->root.srelgot->size += RELOC_SIZE (htab);
}
else
htab->tls_ldm_got.offset = -1;
@@ -11755,7 +11719,7 @@ elf32_arm_size_dynamic_sections (bfd * o
{
/* Remember whether there are any reloc sections other
than .rel(a).plt and .rela.plt.unloaded. */
- if (s != htab->srelplt && s != htab->srelplt2)
+ if (s != htab->root.srelplt && s != htab->srelplt2)
relocs = TRUE;
/* We use the reloc_count field as a counter if we need
@@ -11946,7 +11910,7 @@ elf32_arm_finish_dynamic_symbol (bfd * o
+ splt->output_offset
+ h->plt.offset);
- ptr = htab->splt->contents + h->plt.offset;
+ ptr = htab->root.splt->contents + h->plt.offset;
if (htab->vxworks_p && info->shared)
{
unsigned int i;
@@ -12396,14 +12360,14 @@ elf32_arm_finish_dynamic_sections (bfd *
if (splt->output_section->owner == output_bfd)
elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
- if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
+ if (htab->vxworks_p && !info->shared && htab->root.splt->size > 0)
{
/* Correct the .rel(a).plt.unloaded relocations. They will have
incorrect symbol indexes. */
int num_plts;
unsigned char *p;
- num_plts = ((htab->splt->size - htab->plt_header_size)
+ num_plts = ((htab->root.splt->size - htab->plt_header_size)
/ htab->plt_entry_size);
p = htab->srelplt2->contents + RELOC_SIZE (htab);
@@ -13005,12 +12969,12 @@ elf32_arm_output_arch_local_syms (bfd *o
}
/* Finally, output mapping symbols for the PLT. */
- if (!htab->splt || htab->splt->size == 0)
+ if (!htab->root.splt || htab->root.splt->size == 0)
return TRUE;
osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
- htab->splt->output_section);
- osi.sec = htab->splt;
+ htab->root.splt->output_section);
+ osi.sec = htab->root.splt;
/* Output mapping symbols for the plt header. SymbianOS does not have a
plt header. */
if (htab->vxworks_p)
More information about the Binutils
mailing list