aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2016-06-18 09:16:52 -0700
committerH.J. Lu <hjl.tools@gmail.com>2016-06-18 09:17:25 -0700
commit233cc9c13af8e8182d0ce5b306526b59f5b11f37 (patch)
tree6381519cd959d8a585cd640de586e6aab3ca715b /bfd
parent854594f5ce00381eb0ed57e3c7fa08b5971eabec (diff)
downloadgdb-233cc9c13af8e8182d0ce5b306526b59f5b11f37.zip
gdb-233cc9c13af8e8182d0ce5b306526b59f5b11f37.tar.gz
gdb-233cc9c13af8e8182d0ce5b306526b59f5b11f37.tar.bz2
Don't generate PLT for IFUNC GOT/pointer reference
If a backend supports it, PLT entry isn't needed when all references to a STT_GNU_IFUNC symbols are done via GOT or static function pointers. For GOT entries, We generate dynamic R_*_GLOB_DAT relocations for preemptable symbols and R_*_IRELATIVE relocations for non-preemptable symbols to update them with real function address. For static pointer pointers, we generate dynamic pointer relocations and store them in: 1. .rel[a].ifunc section in PIC object. 2. .rel[a].got section in dynamic executable. 3. .rel[a].iplt section in static executable. We don't allocate GOT entry if it isn't used. bfd/ PR ld/20253 * elf-bfd.h (_bfd_elf_allocate_ifunc_dyn_relocs): Add an bfd_boolean argument. * elf-ifunc.c (_bfd_elf_create_ifunc_sections): Replace "shared object" with "PIC object" in comments. (_bfd_elf_allocate_ifunc_dyn_relocs): Updated. Replace "shared object" with "PIC object" in comments. Avoid PLT if requested. Generate dynamic relocations for non-GOT references. Make room for the special first entry in PLT and allocate PLT entry only for PLT and PC-relative references. Store dynamic GOT relocations in .rel[a].iplt section for static executables. If PLT isn't used, always use GOT for symbol value. Don't allocate GOT entry if it isn't used. * elf32-i386.c (elf_i386_check_relocs): Increment PLT reference count only in the code section. Allocate dynamic pointer relocation against STT_GNU_IFUNC symbol in the non-code section. (elf_i386_adjust_dynamic_symbol): Increment PLT reference count only for PC-relative references. (elf_i386_allocate_dynrelocs): Pass TRUE to _bfd_elf_allocate_ifunc_dyn_relocs. (elf_i386_relocate_section): Allow R_386_GOT32/R_386_GOT32X relocations against STT_GNU_IFUNC symbols without PLT. Generate dynamic pointer relocation against STT_GNU_IFUNC symbol in the non-code section and store it in the proper REL section. Don't allow non-pointer relocation against STT_GNU_IFUNC symbol without PLT. (elf_i386_finish_dynamic_symbol): Generate dynamic R_386_IRELATIVE and R_386_GLOB_DAT GOT relocations against STT_GNU_IFUNC symbols without PLT. (elf_i386_finish_dynamic_sections): Don't handle local STT_GNU_IFUNC symbols here. (elf_i386_output_arch_local_syms): Handle local STT_GNU_IFUNC symbols here. (elf_backend_output_arch_local_syms): New. * elf32-x86-64.c (elf_i386_check_relocs): Increment PLT reference count only in the code section. Allocate dynamic pointer relocation against STT_GNU_IFUNC symbol in the non-code section. (elf_x86_64_adjust_dynamic_symbol): Increment PLT reference count only for PC-relative references. (elf_x86_64_allocate_dynrelocs): Pass TRUE to _bfd_elf_allocate_ifunc_dyn_relocs. (elf_x86_64_relocate_section): Allow R_X86_64_GOTPCREL, R_X86_64_GOTPCRELX, R_X86_64_REX_GOTPCRELX and R_X86_64_GOTPCREL64 relocations against STT_GNU_IFUNC symbols without PLT. Generate dynamic pointer relocation against STT_GNU_IFUNC symbol in the non-code section and store it in the proper RELA section. Don't allow non-pointer relocation against STT_GNU_IFUNC symbol without PLT. (elf_x86_64_finish_dynamic_symbol): Generate dynamic R_X86_64_IRELATIVE and R_X86_64_GLOB_DAT GOT relocations against STT_GNU_IFUNC symbols without PLT. (elf_x86_64_finish_dynamic_sections): Don't handle local STT_GNU_IFUNC symbols here. (elf_x86_64_output_arch_local_syms): Handle local STT_GNU_IFUNC symbols here. (elf_backend_output_arch_local_syms): New. * elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs): Pass FALSE to _bfd_elf_allocate_ifunc_dyn_relocs. ld/ PR ld/20253 * testsuite/ld-i386/i386.exp: Run PR ld/20253 tests. * testsuite/ld-i386/no-plt.exp: Likewise. * testsuite/ld-x86-64/no-plt.exp: Likewise. * testsuite/ld-i386/pr13302.d: Remove .rel.plt section. * testsuite/ld-ifunc/ifunc-13-i386.d: Likewise. * testsuite/ld-ifunc/ifunc-13-x86-64.d: Likewise. * testsuite/ld-ifunc/ifunc-15-i386.d: Likewise. * testsuite/ld-ifunc/ifunc-15-x86-64.d: Likewise. * testsuite/ld-x86-64/pr13082-5a.d: Likewise. * testsuite/ld-x86-64/pr13082-5b.d: Likewise. * testsuite/ld-x86-64/pr13082-6a.d: Likewise. * testsuite/ld-x86-64/pr13082-6b.d: Likewise. * testsuite/ld-i386/pr20244-2a.d: Remove .plt section. * testsuite/ld-ifunc/ifunc-21-i386.d: Likewise. * testsuite/ld-ifunc/ifunc-21-x86-64.d: Likewise. * testsuite/ld-ifunc/ifunc-22-i386.d: Likewise. * testsuite/ld-ifunc/ifunc-22-x86-64.d: Likewise. * testsuite/ld-i386/pr20244-2b.d: Updated. * testsuite/ld-i386/pr20244-2c.d: Likewise. * testsuite/ld-ifunc/ifunc-18a-i386.d: Likewise. * testsuite/ld-ifunc/ifunc-18a-x86-64.d: Likewise. * testsuite/ld-ifunc/ifunc-18b-i386.d: Likewise. * testsuite/ld-ifunc/ifunc-18b-x86-64.d: Likewise. * testsuite/ld-i386/pr20253-1a.c: New file. * testsuite/ld-i386/pr20253-1b.S: Likewise. * testsuite/ld-i386/pr20253-1c.S: Likewise. * testsuite/ld-i386/pr20253-1d.S: Likewise. * testsuite/ld-i386/pr20253-2a.c: Likewise. * testsuite/ld-i386/pr20253-2b.S: Likewise. * testsuite/ld-i386/pr20253-2c.S: Likewise. * testsuite/ld-i386/pr20253-2d.S: Likewise. * testsuite/ld-i386/pr20253-3.d: Likewise. * testsuite/ld-i386/pr20253-3.s: Likewise. * testsuite/ld-i386/pr20253-4.s: Likewise. * testsuite/ld-i386/pr20253-4a.d: Likewise. * testsuite/ld-i386/pr20253-4b.d: Likewise. * testsuite/ld-i386/pr20253-4c.d: Likewise. * testsuite/ld-i386/pr20253-5.d: Likewise. * testsuite/ld-i386/pr20253-5.s: Likewise. * testsuite/ld-ifunc/ifunc-23-x86.s: Likewise. * testsuite/ld-ifunc/ifunc-23a-x86.d: Likewise. * testsuite/ld-ifunc/ifunc-23b-x86.d: Likewise. * testsuite/ld-ifunc/ifunc-23c-x86.d: Likewise. * testsuite/ld-ifunc/ifunc-24-x86.s: Likewise. * testsuite/ld-ifunc/ifunc-24a-x86.d: Likewise. * testsuite/ld-ifunc/ifunc-24b-x86.d: Likewise. * testsuite/ld-ifunc/ifunc-24c-x86.d: Likewise. * testsuite/ld-ifunc/ifunc-25-x86.s: Likewise. * testsuite/ld-ifunc/ifunc-25a-x86.d: Likewise. * testsuite/ld-ifunc/ifunc-25b-x86.d: Likewise. * testsuite/ld-ifunc/ifunc-25c-x86.d: Likewise. * testsuite/ld-x86-64/pr20253-1.s: Likewise. * testsuite/ld-x86-64/pr20253-1a.d: Likewise. * testsuite/ld-x86-64/pr20253-1b.d: Likewise. * testsuite/ld-x86-64/pr20253-1c.d: Likewise. * testsuite/ld-x86-64/pr20253-1d.d: Likewise. * testsuite/ld-x86-64/pr20253-1e.d: Likewise. * testsuite/ld-x86-64/pr20253-1f.d: Likewise. * testsuite/ld-x86-64/pr20253-1g.d: Likewise. * testsuite/ld-x86-64/pr20253-1h.d: Likewise. * testsuite/ld-x86-64/pr20253-1i.d: Likewise. * testsuite/ld-x86-64/pr20253-1j.d: Likewise. * testsuite/ld-x86-64/pr20253-1k.d: Likewise. * testsuite/ld-x86-64/pr20253-1l.d: Likewise. * testsuite/ld-x86-64/pr20253-2a.c: Likewise. * testsuite/ld-x86-64/pr20253-2b.S: Likewise. * testsuite/ld-x86-64/pr20253-2c.S: Likewise. * testsuite/ld-x86-64/pr20253-2d.S: Likewise. * testsuite/ld-x86-64/pr20253-3.d: Likewise. * testsuite/ld-x86-64/pr20253-3.s: Likewise. * testsuite/ld-x86-64/pr20253-4.s: Likewise. * testsuite/ld-x86-64/pr20253-4a.d: Likewise. * testsuite/ld-x86-64/pr20253-4b.d: Likewise. * testsuite/ld-x86-64/pr20253-4c.d: Likewise. * testsuite/ld-x86-64/pr20253-4d.d: Likewise. * testsuite/ld-x86-64/pr20253-4e.d: Likewise. * testsuite/ld-x86-64/pr20253-4f.d: Likewise. * testsuite/ld-x86-64/pr20253-5.s: Likewise. * testsuite/ld-x86-64/pr20253-5a.d: Likewise. * testsuite/ld-x86-64/pr20253-5b.d: Likewise. * testsuite/ld-ifunc/ifunc-18a-i386.d: Remove extra IRELATIVE relocation. * testsuite/ld-ifunc/ifunc-18a-x86-64.d: Likewise. * testsuite/ld-ifunc/ifunc-18b-i386.d: Likewise. * testsuite/ld-ifunc/ifunc-18b-x86-64.d: Likewise. * testsuite/ld-ifunc/ifunc-18a.s: Fix a typo. * testsuite/ld-x86-64/x86-64.exp: Run pr20253-1 tests.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog61
-rw-r--r--bfd/elf-bfd.h2
-rw-r--r--bfd/elf-ifunc.c176
-rw-r--r--bfd/elf32-i386.c262
-rw-r--r--bfd/elf64-x86-64.c257
-rw-r--r--bfd/elfnn-aarch64.c3
6 files changed, 534 insertions, 227 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 0e52b95..2173fc9 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,64 @@
+2016-06-18 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/20253
+ * elf-bfd.h (_bfd_elf_allocate_ifunc_dyn_relocs): Add an
+ bfd_boolean argument.
+ * elf-ifunc.c (_bfd_elf_create_ifunc_sections): Replace
+ "shared object" with "PIC object" in comments.
+ (_bfd_elf_allocate_ifunc_dyn_relocs): Updated. Replace
+ "shared object" with "PIC object" in comments. Avoid PLT if
+ requested. Generate dynamic relocations for non-GOT references.
+ Make room for the special first entry in PLT and allocate PLT
+ entry only for PLT and PC-relative references. Store dynamic
+ GOT relocations in .rel[a].iplt section for static executables.
+ If PLT isn't used, always use GOT for symbol value. Don't
+ allocate GOT entry if it isn't used.
+ * elf32-i386.c (elf_i386_check_relocs): Increment PLT reference
+ count only in the code section. Allocate dynamic pointer
+ relocation against STT_GNU_IFUNC symbol in the non-code section.
+ (elf_i386_adjust_dynamic_symbol): Increment PLT reference count
+ only for PC-relative references.
+ (elf_i386_allocate_dynrelocs): Pass TRUE to
+ _bfd_elf_allocate_ifunc_dyn_relocs.
+ (elf_i386_relocate_section): Allow R_386_GOT32/R_386_GOT32X
+ relocations against STT_GNU_IFUNC symbols without PLT. Generate
+ dynamic pointer relocation against STT_GNU_IFUNC symbol in
+ the non-code section and store it in the proper REL section.
+ Don't allow non-pointer relocation against STT_GNU_IFUNC symbol
+ without PLT.
+ (elf_i386_finish_dynamic_symbol): Generate dynamic
+ R_386_IRELATIVE and R_386_GLOB_DAT GOT relocations against
+ STT_GNU_IFUNC symbols without PLT.
+ (elf_i386_finish_dynamic_sections): Don't handle local
+ STT_GNU_IFUNC symbols here.
+ (elf_i386_output_arch_local_syms): Handle local STT_GNU_IFUNC
+ symbols here.
+ (elf_backend_output_arch_local_syms): New.
+ * elf32-x86-64.c (elf_i386_check_relocs): Increment PLT reference
+ count only in the code section. Allocate dynamic pointer
+ relocation against STT_GNU_IFUNC symbol in the non-code section.
+ (elf_x86_64_adjust_dynamic_symbol): Increment PLT reference
+ count only for PC-relative references.
+ (elf_x86_64_allocate_dynrelocs): Pass TRUE to
+ _bfd_elf_allocate_ifunc_dyn_relocs.
+ (elf_x86_64_relocate_section): Allow R_X86_64_GOTPCREL,
+ R_X86_64_GOTPCRELX, R_X86_64_REX_GOTPCRELX and
+ R_X86_64_GOTPCREL64 relocations against STT_GNU_IFUNC symbols
+ without PLT. Generate dynamic pointer relocation against
+ STT_GNU_IFUNC symbol in the non-code section and store it in
+ the proper RELA section. Don't allow non-pointer relocation
+ against STT_GNU_IFUNC symbol without PLT.
+ (elf_x86_64_finish_dynamic_symbol): Generate dynamic
+ R_X86_64_IRELATIVE and R_X86_64_GLOB_DAT GOT relocations against
+ STT_GNU_IFUNC symbols without PLT.
+ (elf_x86_64_finish_dynamic_sections): Don't handle local
+ STT_GNU_IFUNC symbols here.
+ (elf_x86_64_output_arch_local_syms): Handle local STT_GNU_IFUNC
+ symbols here.
+ (elf_backend_output_arch_local_syms): New.
+ * elfnn-aarch64.c (elfNN_aarch64_allocate_ifunc_dynrelocs):
+ Pass FALSE to _bfd_elf_allocate_ifunc_dyn_relocs.
+
2016-06-17 Thomas Preud'homme <thomas.preudhomme@arm.com>
Tony Wang <tony.wang@arm.com>
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 6825530..163ef35 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2521,7 +2521,7 @@ extern bfd_boolean _bfd_elf_create_ifunc_sections
extern bfd_boolean _bfd_elf_allocate_ifunc_dyn_relocs
(struct bfd_link_info *, struct elf_link_hash_entry *,
struct elf_dyn_relocs **, bfd_boolean *, unsigned int,
- unsigned int, unsigned int);
+ unsigned int, unsigned int, bfd_boolean);
extern long _bfd_elf_ifunc_get_synthetic_symtab
(bfd *, long, asymbol **, long, asymbol **, asymbol **, asection *,
bfd_vma *(*) (bfd *, asymbol **, asection *, asection *));
diff --git a/bfd/elf-ifunc.c b/bfd/elf-ifunc.c
index 1377fed..09cbf4a 100644
--- a/bfd/elf-ifunc.c
+++ b/bfd/elf-ifunc.c
@@ -55,7 +55,7 @@ _bfd_elf_create_ifunc_sections (bfd *abfd, struct bfd_link_info *info)
if (bfd_link_pic (info))
{
- /* We need to create .rel[a].ifunc for shared objects. */
+ /* We need to create .rel[a].ifunc for PIC objects. */
const char *rel_sec = (bed->rela_plts_and_copies_p
? ".rela.ifunc" : ".rel.ifunc");
@@ -113,7 +113,8 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
bfd_boolean *readonly_dynrelocs_against_ifunc_p,
unsigned int plt_entry_size,
unsigned int plt_header_size,
- unsigned int got_entry_size)
+ unsigned int got_entry_size,
+ bfd_boolean avoid_plt)
{
asection *plt, *gotplt, *relplt;
struct elf_dyn_relocs *p;
@@ -121,13 +122,17 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
const struct elf_backend_data *bed;
struct elf_link_hash_table *htab;
bfd_boolean readonly_dynrelocs_against_ifunc;
-
- /* When a shared library references a STT_GNU_IFUNC symbol defined
- in executable, the address of the resolved function may be used.
- But in non-shared executable, the address of its .plt slot may
- be used. Pointer equality may not work correctly. PIE should
- be used if pointer equality is required here. */
- if (!bfd_link_pic (info)
+ /* If AVOID_PLT is TRUE, don't use PLT if possible. */
+ bfd_boolean use_plt = !avoid_plt || h->plt.refcount > 0;
+ bfd_boolean need_dynreloc = !use_plt || bfd_link_pic (info);
+
+ /* When a PIC object references a STT_GNU_IFUNC symbol defined
+ in executable or it isn't referenced via PLT, the address of
+ the resolved function may be used. But in non-PIC executable,
+ the address of its .plt slot may be used. Pointer equality may
+ not work correctly. PIE or non-PLT reference should be used if
+ pointer equality is required here. */
+ if (!need_dynreloc
&& (h->dynindx != -1
|| info->export_dynamic)
&& h->pointer_equality_needed)
@@ -144,16 +149,30 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
htab = elf_hash_table (info);
- /* When building shared library, we need to handle the case where it is
- marked with regular reference, but not non-GOT reference since the
- non-GOT reference bit may not be set here. */
- if (bfd_link_pic (info) && !h->non_got_ref && h->ref_regular)
- for (p = *head; p != NULL; p = p->next)
- if (p->count)
- {
- h->non_got_ref = 1;
- goto keep;
- }
+ /* When the symbol is marked with regular reference, if PLT isn't used
+ or we are building a PIC object, we must keep dynamic relocation
+ if there is non-GOT reference and use PLT if there is PC-relative
+ reference. */
+ if (need_dynreloc && h->ref_regular)
+ {
+ bfd_boolean keep = FALSE;
+ for (p = *head; p != NULL; p = p->next)
+ if (p->count)
+ {
+ h->non_got_ref = 1;
+ /* Need dynamic relocations for non-GOT reference. */
+ keep = TRUE;
+ if (p->pc_count)
+ {
+ /* Must use PLT for PC-relative reference. */
+ use_plt = TRUE;
+ need_dynreloc = bfd_link_pic (info);
+ break;
+ }
+ }
+ if (keep)
+ goto keep;
+ }
/* Support garbage collection against STT_GNU_IFUNC symbols. */
if (h->plt.refcount <= 0 && h->got.refcount <= 0)
@@ -165,7 +184,7 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
}
/* Return and discard space for dynamic relocations against it if
- it is never referenced in a non-shared object. */
+ it is never referenced. */
if (!h->ref_regular)
{
if (h->plt.refcount > 0
@@ -192,9 +211,9 @@ keep:
gotplt = htab->sgotplt;
relplt = htab->srelplt;
- /* If this is the first .plt entry, make room for the special
- first entry. */
- if (plt->size == 0)
+ /* If this is the first .plt entry and PLT is used, make room for
+ the special first entry. */
+ if (plt->size == 0 && use_plt)
plt->size += plt_header_size;
}
else
@@ -204,26 +223,31 @@ keep:
relplt = htab->irelplt;
}
- /* Don't update value of STT_GNU_IFUNC symbol to PLT. We need
- the original value for R_*_IRELATIVE. */
- h->plt.offset = plt->size;
+ if (use_plt)
+ {
+ /* Don't update value of STT_GNU_IFUNC symbol to PLT. We need
+ the original value for R_*_IRELATIVE. */
+ h->plt.offset = plt->size;
- /* Make room for this entry in the .plt/.iplt section. */
- plt->size += plt_entry_size;
+ /* Make room for this entry in the .plt/.iplt section. */
+ plt->size += plt_entry_size;
- /* We also need to make an entry in the .got.plt/.got.iplt section,
- which will be placed in the .got section by the linker script. */
- gotplt->size += got_entry_size;
+ /* We also need to make an entry in the .got.plt/.got.iplt section,
+ which will be placed in the .got section by the linker script. */
+ gotplt->size += got_entry_size;
+ }
/* We also need to make an entry in the .rel[a].plt/.rel[a].iplt
- section. */
- relplt->size += sizeof_reloc;
- relplt->reloc_count++;
+ section for GOTPLT relocation if PLT is used. */
+ if (use_plt)
+ {
+ relplt->size += sizeof_reloc;
+ relplt->reloc_count++;
+ }
/* We need dynamic relocation for STT_GNU_IFUNC symbol only when
- there is a non-GOT reference in a shared object. */
- if (!bfd_link_pic (info)
- || !h->non_got_ref)
+ there is a non-GOT reference in a PIC object or PLT isn't used. */
+ if (!need_dynreloc || !h->non_got_ref)
*head = NULL;
readonly_dynrelocs_against_ifunc = FALSE;
@@ -245,7 +269,20 @@ keep:
p = p->next;
}
while (p != NULL);
- htab->irelifunc->size += count * sizeof_reloc;
+
+ /* Dynamic relocations are stored in
+ 1. .rel[a].ifunc section in PIC object.
+ 2. .rel[a].got section in dynamic executable.
+ 3. .rel[a].iplt section in static executable. */
+ if (bfd_link_pic (info))
+ htab->irelifunc->size += count * sizeof_reloc;
+ else if (htab->splt != NULL)
+ htab->srelgot->size += count * sizeof_reloc;
+ else
+ {
+ relplt->size += count * sizeof_reloc;
+ relplt->reloc_count += count;
+ }
}
if (readonly_dynrelocs_against_ifunc_p)
@@ -254,34 +291,65 @@ keep:
/* For STT_GNU_IFUNC symbol, .got.plt has the real function address
and .got has the PLT entry adddress. We will load the GOT entry
with the PLT entry in finish_dynamic_symbol if it is used. For
- branch, it uses .got.plt. For symbol value,
- 1. Use .got.plt in a shared object if it is forced local or not
+ branch, it uses .got.plt. For symbol value, if PLT is used,
+ 1. Use .got.plt in a PIC object if it is forced local or not
dynamic.
- 2. Use .got.plt in a non-shared object if pointer equality isn't
+ 2. Use .got.plt in a non-PIC object if pointer equality isn't
needed.
3. Use .got.plt in PIE.
4. Use .got.plt if .got isn't used.
5. Otherwise use .got so that it can be shared among different
objects at run-time.
- We only need to relocate .got entry in shared object. */
- if (h->got.refcount <= 0
- || (bfd_link_pic (info)
- && (h->dynindx == -1
- || h->forced_local))
- || (!bfd_link_pic (info)
- && !h->pointer_equality_needed)
- || bfd_link_pie (info)
- || htab->sgot == NULL)
+ If PLT isn't used, always use .got for symbol value.
+ We only need to relocate .got entry in PIC object or in dynamic
+ executable without PLT. */
+ if (use_plt
+ && (h->got.refcount <= 0
+ || (bfd_link_pic (info)
+ && (h->dynindx == -1
+ || h->forced_local))
+ || (!bfd_link_pic (info)
+ && !h->pointer_equality_needed)
+ || bfd_link_pie (info)
+ || htab->sgot == NULL))
{
/* Use .got.plt. */
h->got.offset = (bfd_vma) -1;
}
else
{
- h->got.offset = htab->sgot->size;
- htab->sgot->size += got_entry_size;
- if (bfd_link_pic (info))
- htab->srelgot->size += sizeof_reloc;
+ if (!use_plt)
+ {
+ /* PLT isn't used. */
+ h->plt.offset = (bfd_vma) -1;
+ }
+ if (h->got.refcount <= 0)
+ {
+ /* GOT isn't need when there are only relocations for static
+ pointers. */
+ h->got.offset = (bfd_vma) -1;
+ }
+ else
+ {
+ h->got.offset = htab->sgot->size;
+ htab->sgot->size += got_entry_size;
+ /* Need to relocate the GOT entry in a PIC object or PLT isn't
+ used. Otherwise, the GOT entry will be filled with the PLT
+ entry and dynamic GOT relocation isn't needed. */
+ if (need_dynreloc)
+ {
+ /* For non-static executable, dynamic GOT relocation is in
+ .rel[a].got section, but for static executable, it is
+ in .rel[a].iplt section. */
+ if (htab->splt != NULL)
+ htab->srelgot->size += sizeof_reloc;
+ else
+ {
+ relplt->size += sizeof_reloc;
+ relplt->reloc_count++;
+ }
+ }
+ }
}
return TRUE;
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 2b7de33..4179572 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -2164,9 +2164,13 @@ do_relocation:
adjust_dynamic_symbol. */
h->non_got_ref = 1;
- /* We may need a .plt entry if the function this reloc
- refers to is in a shared lib. */
- h->plt.refcount += 1;
+ /* We may need a .plt entry if the symbol is a function
+ defined in a shared lib or is a STT_GNU_IFUNC function
+ referenced from the code or read-only section. */
+ if (!h->def_regular
+ || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
+ h->plt.refcount += 1;
+
if (r_type == R_386_PC32)
{
/* Since something like ".long foo - ." may be used
@@ -2207,7 +2211,10 @@ do_size:
If on the other hand, we are creating an executable, we
may need to keep relocations for symbols satisfied by a
dynamic library if we manage to avoid copy relocs for the
- symbol. */
+ symbol.
+
+ Generate dynamic pointer relocation against STT_GNU_IFUNC
+ symbol in the non-code section. */
if ((bfd_link_pic (info)
&& (r_type != R_386_PC32
|| (h != NULL
@@ -2215,6 +2222,10 @@ do_size:
|| SYMBOLIC_BIND (info, h))
|| h->root.type == bfd_link_hash_defweak
|| !h->def_regular))))
+ || (h != NULL
+ && h->type == STT_GNU_IFUNC
+ && r_type == R_386_32
+ && (sec->flags & SEC_CODE) == 0)
|| (ELIMINATE_COPY_RELOCS
&& !bfd_link_pic (info)
&& h != NULL
@@ -2448,12 +2459,17 @@ elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info,
if (pc_count || count)
{
- h->needs_plt = 1;
h->non_got_ref = 1;
- if (h->plt.refcount <= 0)
- h->plt.refcount = 1;
- else
- h->plt.refcount += 1;
+ if (pc_count)
+ {
+ /* Increment PLT reference count only for PC-relative
+ references. */
+ h->needs_plt = 1;
+ if (h->plt.refcount <= 0)
+ h->plt.refcount = 1;
+ else
+ h->plt.refcount += 1;
+ }
}
}
@@ -2643,7 +2659,7 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
return _bfd_elf_allocate_ifunc_dyn_relocs (info, h, &eh->dyn_relocs,
&htab->readonly_dynrelocs_against_ifunc,
plt_entry_size,
- plt_entry_size, 4);
+ plt_entry_size, 4, TRUE);
/* Don't create the PLT entry if there are only function pointer
relocations which can be resolved at run-time. */
else if (htab->elf.dynamic_sections_created
@@ -3898,8 +3914,6 @@ elf_i386_relocate_section (bfd *output_bfd,
continue;
abort ();
}
- else if (h->plt.offset == (bfd_vma) -1)
- abort ();
/* STT_GNU_IFUNC symbol must go through PLT. */
if (htab->elf.splt != NULL)
@@ -3913,77 +3927,10 @@ elf_i386_relocate_section (bfd *output_bfd,
gotplt = htab->elf.igotplt;
}
- relocation = (plt->output_section->vma
- + plt->output_offset + h->plt.offset);
-
switch (r_type)
{
default:
- if (h->root.root.string)
- name = h->root.root.string;
- else
- name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
- NULL);
- (*_bfd_error_handler)
- (_("%B: relocation %s against STT_GNU_IFUNC "
- "symbol `%s' isn't handled by %s"), input_bfd,
- elf_howto_table[r_type].name,
- name, __FUNCTION__);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
-
- case R_386_32:
- /* Generate dynamic relcoation only when there is a
- non-GOT reference in a shared object. */
- if (bfd_link_pic (info) && h->non_got_ref)
- {
- Elf_Internal_Rela outrel;
- asection *sreloc;
- bfd_vma offset;
-
- /* Need a dynamic relocation to get the real function
- adddress. */
- offset = _bfd_elf_section_offset (output_bfd,
- info,
- input_section,
- rel->r_offset);
- if (offset == (bfd_vma) -1
- || offset == (bfd_vma) -2)
- abort ();
-
- outrel.r_offset = (input_section->output_section->vma
- + input_section->output_offset
- + offset);
-
- if (h->dynindx == -1
- || h->forced_local
- || bfd_link_executable (info))
- {
- /* This symbol is resolved locally. */
- outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
- bfd_put_32 (output_bfd,
- (h->root.u.def.value
- + h->root.u.def.section->output_section->vma
- + h->root.u.def.section->output_offset),
- contents + offset);
- }
- else
- outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
-
- sreloc = htab->elf.irelifunc;
- elf_append_rel (output_bfd, sreloc, &outrel);
-
- /* If this reloc is against an external symbol, we
- do not want to fiddle with the addend. Otherwise,
- we need to include the symbol value so that it
- becomes an addend for the dynamic reloc. For an
- internal symbol, we have updated addend. */
- continue;
- }
- /* FALLTHROUGH */
- case R_386_PC32:
- case R_386_PLT32:
- goto do_relocation;
+ break;
case R_386_GOT32:
case R_386_GOT32X:
@@ -3999,6 +3946,9 @@ elf_i386_relocate_section (bfd *output_bfd,
even just remember the offset, as finish_dynamic_symbol
would use that as offset into .got. */
+ if (h->plt.offset == (bfd_vma) -1)
+ abort ();
+
if (htab->elf.splt != NULL)
{
plt_index = h->plt.offset / plt_entry_size - 1;
@@ -4059,6 +4009,99 @@ elf_i386_relocate_section (bfd *output_bfd,
}
goto do_relocation;
+ }
+
+ if (h->plt.offset == (bfd_vma) -1)
+ {
+ /* Handle static pointers of STT_GNU_IFUNC symbols. */
+ if (r_type == R_386_32
+ && (input_section->flags & SEC_CODE) == 0)
+ goto do_ifunc_pointer;
+ goto bad_ifunc_reloc;
+ }
+
+ relocation = (plt->output_section->vma
+ + plt->output_offset + h->plt.offset);
+
+ switch (r_type)
+ {
+ default:
+bad_ifunc_reloc:
+ if (h->root.root.string)
+ name = h->root.root.string;
+ else
+ name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
+ NULL);
+ (*_bfd_error_handler)
+ (_("%B: relocation %s against STT_GNU_IFUNC "
+ "symbol `%s' isn't supported"), input_bfd,
+ howto->name, name);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+
+ case R_386_32:
+ /* Generate dynamic relcoation only when there is a
+ non-GOT reference in a shared object. */
+ if ((bfd_link_pic (info) && h->non_got_ref)
+ || h->plt.offset == (bfd_vma) -1)
+ {
+ Elf_Internal_Rela outrel;
+ asection *sreloc;
+ bfd_vma offset;
+
+do_ifunc_pointer:
+ /* Need a dynamic relocation to get the real function
+ adddress. */
+ offset = _bfd_elf_section_offset (output_bfd,
+ info,
+ input_section,
+ rel->r_offset);
+ if (offset == (bfd_vma) -1
+ || offset == (bfd_vma) -2)
+ abort ();
+
+ outrel.r_offset = (input_section->output_section->vma
+ + input_section->output_offset
+ + offset);
+
+ if (h->dynindx == -1
+ || h->forced_local
+ || bfd_link_executable (info))
+ {
+ /* This symbol is resolved locally. */
+ outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
+ bfd_put_32 (output_bfd,
+ (h->root.u.def.value
+ + h->root.u.def.section->output_section->vma
+ + h->root.u.def.section->output_offset),
+ contents + offset);
+ }
+ else
+ outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+
+ /* Dynamic relocations are stored in
+ 1. .rel.ifunc section in PIC object.
+ 2. .rel.got section in dynamic executable.
+ 3. .rel.iplt section in static executable. */
+ if (bfd_link_pic (info))
+ sreloc = htab->elf.irelifunc;
+ else if (htab->elf.splt != NULL)
+ sreloc = htab->elf.srelgot;
+ else
+ sreloc = htab->elf.irelplt;
+ elf_append_rel (output_bfd, sreloc, &outrel);
+
+ /* If this reloc is against an external symbol, we
+ do not want to fiddle with the addend. Otherwise,
+ we need to include the symbol value so that it
+ becomes an addend for the dynamic reloc. For an
+ internal symbol, we have updated addend. */
+ continue;
+ }
+ /* FALLTHROUGH */
+ case R_386_PC32:
+ case R_386_PLT32:
+ goto do_relocation;
case R_386_GOTOFF:
relocation -= (gotplt->output_section->vma
@@ -5432,6 +5475,7 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
&& !local_undefweak)
{
Elf_Internal_Rela rel;
+ asection *relgot = htab->elf.srelgot;
/* This symbol has an entry in the global offset table. Set it
up. */
@@ -5451,7 +5495,28 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
if (h->def_regular
&& h->type == STT_GNU_IFUNC)
{
- if (bfd_link_pic (info))
+ if (h->plt.offset == (bfd_vma) -1)
+ {
+ /* STT_GNU_IFUNC is referenced without PLT. */
+ if (htab->elf.splt == NULL)
+ {
+ /* use .rel[a].iplt section to store .got relocations
+ in static executable. */
+ relgot = htab->elf.irelplt;
+ }
+ if (SYMBOL_REFERENCES_LOCAL (info, h))
+ {
+ bfd_put_32 (output_bfd,
+ (h->root.u.def.value
+ + h->root.u.def.section->output_section->vma
+ + h->root.u.def.section->output_offset),
+ htab->elf.sgot->contents + h->got.offset);
+ rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
+ }
+ else
+ goto do_glob_dat;
+ }
+ else if (bfd_link_pic (info))
{
/* Generate R_386_GLOB_DAT. */
goto do_glob_dat;
@@ -5489,7 +5554,7 @@ do_glob_dat:
rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT);
}
- elf_append_rel (output_bfd, htab->elf.srelgot, &rel);
+ elf_append_rel (output_bfd, relgot, &rel);
}
if (h->needs_copy)
@@ -5826,11 +5891,6 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
if (htab->elf.sgot && htab->elf.sgot->size > 0)
elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 4;
- /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
- htab_traverse (htab->loc_hash_table,
- elf_i386_finish_local_dynamic_symbol,
- info);
-
/* Fill PLT entries for undefined weak symbols in PIE. */
if (bfd_link_pie (info))
bfd_hash_traverse (&info->hash->table,
@@ -5840,6 +5900,33 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
return TRUE;
}
+/* Fill PLT/GOT entries and allocate dynamic relocations for local
+ STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
+ It has to be done before elf_link_sort_relocs is called so that
+ dynamic relocations are properly sorted. */
+
+static bfd_boolean
+elf_i386_output_arch_local_syms
+ (bfd *output_bfd ATTRIBUTE_UNUSED,
+ struct bfd_link_info *info,
+ void *flaginfo ATTRIBUTE_UNUSED,
+ int (*func) (void *, const char *,
+ Elf_Internal_Sym *,
+ asection *,
+ struct elf_link_hash_entry *) ATTRIBUTE_UNUSED)
+{
+ struct elf_i386_link_hash_table *htab = elf_i386_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
+ htab_traverse (htab->loc_hash_table,
+ elf_i386_finish_local_dynamic_symbol,
+ info);
+
+ return TRUE;
+}
+
/* Return an array of PLT entry symbol values. */
static bfd_vma *
@@ -5982,6 +6069,7 @@ elf_i386_hash_symbol (struct elf_link_hash_entry *h)
#define elf_backend_fake_sections elf_i386_fake_sections
#define elf_backend_finish_dynamic_sections elf_i386_finish_dynamic_sections
#define elf_backend_finish_dynamic_symbol elf_i386_finish_dynamic_symbol
+#define elf_backend_output_arch_local_syms elf_i386_output_arch_local_syms
#define elf_backend_gc_mark_hook elf_i386_gc_mark_hook
#define elf_backend_grok_prstatus elf_i386_grok_prstatus
#define elf_backend_grok_psinfo elf_i386_grok_psinfo
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 57a3c73..f920208 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2556,9 +2556,13 @@ pointer:
adjust_dynamic_symbol. */
h->non_got_ref = 1;
- /* We may need a .plt entry if the function this reloc
- refers to is in a shared lib. */
- h->plt.refcount += 1;
+ /* We may need a .plt entry if the symbol is a function
+ defined in a shared lib or is a STT_GNU_IFUNC function
+ referenced from the code or read-only section. */
+ if (!h->def_regular
+ || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0)
+ h->plt.refcount += 1;
+
if (r_type == R_X86_64_PC32)
{
/* Since something like ".long foo - ." may be used
@@ -2605,7 +2609,10 @@ do_size:
If on the other hand, we are creating an executable, we
may need to keep relocations for symbols satisfied by a
dynamic library if we manage to avoid copy relocs for the
- symbol. */
+ symbol.
+
+ Generate dynamic pointer relocation against STT_GNU_IFUNC
+ symbol in the non-code section. */
if ((bfd_link_pic (info)
&& (! IS_X86_64_PCREL_TYPE (r_type)
|| (h != NULL
@@ -2613,6 +2620,10 @@ do_size:
|| SYMBOLIC_BIND (info, h))
|| h->root.type == bfd_link_hash_defweak
|| !h->def_regular))))
+ || (h != NULL
+ && h->type == STT_GNU_IFUNC
+ && r_type == htab->pointer_r_type
+ && (sec->flags & SEC_CODE) == 0)
|| (ELIMINATE_COPY_RELOCS
&& !bfd_link_pic (info)
&& h != NULL
@@ -2850,12 +2861,17 @@ elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info,
if (pc_count || count)
{
- h->needs_plt = 1;
h->non_got_ref = 1;
- if (h->plt.refcount <= 0)
- h->plt.refcount = 1;
- else
- h->plt.refcount += 1;
+ if (pc_count)
+ {
+ /* Increment PLT reference count only for PC-relative
+ references. */
+ h->needs_plt = 1;
+ if (h->plt.refcount <= 0)
+ h->plt.refcount = 1;
+ else
+ h->plt.refcount += 1;
+ }
}
}
@@ -3049,7 +3065,7 @@ elf_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
&htab->readonly_dynrelocs_against_ifunc,
plt_entry_size,
plt_entry_size,
- GOT_ENTRY_SIZE))
+ GOT_ENTRY_SIZE, TRUE))
{
asection *s = htab->plt_bnd;
if (h->plt.offset != (bfd_vma) -1 && s != NULL)
@@ -4233,8 +4249,84 @@ elf_x86_64_relocate_section (bfd *output_bfd,
continue;
abort ();
}
- else if (h->plt.offset == (bfd_vma) -1)
- abort ();
+
+ switch (r_type)
+ {
+ default:
+ break;
+
+ case R_X86_64_GOTPCREL:
+ case R_X86_64_GOTPCRELX:
+ case R_X86_64_REX_GOTPCRELX:
+ case R_X86_64_GOTPCREL64:
+ base_got = htab->elf.sgot;
+ off = h->got.offset;
+
+ if (base_got == NULL)
+ abort ();
+
+ if (off == (bfd_vma) -1)
+ {
+ /* We can't use h->got.offset here to save state, or
+ even just remember the offset, as finish_dynamic_symbol
+ would use that as offset into .got. */
+
+ if (h->plt.offset == (bfd_vma) -1)
+ abort ();
+
+ if (htab->elf.splt != NULL)
+ {
+ plt_index = h->plt.offset / plt_entry_size - 1;
+ off = (plt_index + 3) * GOT_ENTRY_SIZE;
+ base_got = htab->elf.sgotplt;
+ }
+ else
+ {
+ plt_index = h->plt.offset / plt_entry_size;
+ off = plt_index * GOT_ENTRY_SIZE;
+ base_got = htab->elf.igotplt;
+ }
+
+ if (h->dynindx == -1
+ || h->forced_local
+ || info->symbolic)
+ {
+ /* This references the local defitionion. We must
+ initialize this entry in the global offset table.
+ Since the offset must always be a multiple of 8,
+ we use the least significant bit to record
+ whether we have initialized it already.
+
+ When doing a dynamic link, we create a .rela.got
+ relocation entry to initialize the value. This
+ is done in the finish_dynamic_symbol routine. */
+ if ((off & 1) != 0)
+ off &= ~1;
+ else
+ {
+ bfd_put_64 (output_bfd, relocation,
+ base_got->contents + off);
+ /* Note that this is harmless for the GOTPLT64
+ case, as -1 | 1 still is -1. */
+ h->got.offset |= 1;
+ }
+ }
+ }
+
+ relocation = (base_got->output_section->vma
+ + base_got->output_offset + off);
+
+ goto do_relocation;
+ }
+
+ if (h->plt.offset == (bfd_vma) -1)
+ {
+ /* Handle static pointers of STT_GNU_IFUNC symbols. */
+ if (r_type == htab->pointer_r_type
+ && (input_section->flags & SEC_CODE) == 0)
+ goto do_ifunc_pointer;
+ goto bad_ifunc_reloc;
+ }
/* STT_GNU_IFUNC symbol must go through PLT. */
if (htab->elf.splt != NULL)
@@ -4262,6 +4354,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
switch (r_type)
{
default:
+bad_ifunc_reloc:
if (h->root.root.string)
name = h->root.root.string;
else
@@ -4269,8 +4362,8 @@ elf_x86_64_relocate_section (bfd *output_bfd,
NULL);
(*_bfd_error_handler)
(_("%B: relocation %s against STT_GNU_IFUNC "
- "symbol `%s' isn't handled by %s"), input_bfd,
- howto->name, name, __FUNCTION__);
+ "symbol `%s' isn't supported"), input_bfd,
+ howto->name, name);
bfd_set_error (bfd_error_bad_value);
return FALSE;
@@ -4284,6 +4377,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
goto do_relocation;
/* FALLTHROUGH */
case R_X86_64_64:
+do_ifunc_pointer:
if (rel->r_addend != 0)
{
if (h->root.root.string)
@@ -4300,8 +4394,10 @@ elf_x86_64_relocate_section (bfd *output_bfd,
}
/* Generate dynamic relcoation only when there is a
- non-GOT reference in a shared object. */
- if (bfd_link_pic (info) && h->non_got_ref)
+ non-GOT reference in a shared object or there is no
+ PLT. */
+ if ((bfd_link_pic (info) && h->non_got_ref)
+ || h->plt.offset == (bfd_vma) -1)
{
Elf_Internal_Rela outrel;
asection *sreloc;
@@ -4335,7 +4431,16 @@ elf_x86_64_relocate_section (bfd *output_bfd,
outrel.r_addend = 0;
}
- sreloc = htab->elf.irelifunc;
+ /* Dynamic relocations are stored in
+ 1. .rela.ifunc section in PIC object.
+ 2. .rela.got section in dynamic executable.
+ 3. .rela.iplt section in static executable. */
+ if (bfd_link_pic (info))
+ sreloc = htab->elf.irelifunc;
+ else if (htab->elf.splt != NULL)
+ sreloc = htab->elf.srelgot;
+ else
+ sreloc = htab->elf.irelplt;
elf_append_rela (output_bfd, sreloc, &outrel);
/* If this reloc is against an external symbol, we
@@ -4352,66 +4457,6 @@ elf_x86_64_relocate_section (bfd *output_bfd,
case R_X86_64_PLT32:
case R_X86_64_PLT32_BND:
goto do_relocation;
-
- case R_X86_64_GOTPCREL:
- case R_X86_64_GOTPCRELX:
- case R_X86_64_REX_GOTPCRELX:
- case R_X86_64_GOTPCREL64:
- base_got = htab->elf.sgot;
- off = h->got.offset;
-
- if (base_got == NULL)
- abort ();
-
- if (off == (bfd_vma) -1)
- {
- /* We can't use h->got.offset here to save state, or
- even just remember the offset, as finish_dynamic_symbol
- would use that as offset into .got. */
-
- if (htab->elf.splt != NULL)
- {
- plt_index = h->plt.offset / plt_entry_size - 1;
- off = (plt_index + 3) * GOT_ENTRY_SIZE;
- base_got = htab->elf.sgotplt;
- }
- else
- {
- plt_index = h->plt.offset / plt_entry_size;
- off = plt_index * GOT_ENTRY_SIZE;
- base_got = htab->elf.igotplt;
- }
-
- if (h->dynindx == -1
- || h->forced_local
- || info->symbolic)
- {
- /* This references the local defitionion. We must
- initialize this entry in the global offset table.
- Since the offset must always be a multiple of 8,
- we use the least significant bit to record
- whether we have initialized it already.
-
- When doing a dynamic link, we create a .rela.got
- relocation entry to initialize the value. This
- is done in the finish_dynamic_symbol routine. */
- if ((off & 1) != 0)
- off &= ~1;
- else
- {
- bfd_put_64 (output_bfd, relocation,
- base_got->contents + off);
- /* Note that this is harmless for the GOTPLT64
- case, as -1 | 1 still is -1. */
- h->got.offset |= 1;
- }
- }
- }
-
- relocation = (base_got->output_section->vma
- + base_got->output_offset + off);
-
- goto do_relocation;
}
}
@@ -5870,6 +5915,7 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
&& !local_undefweak)
{
Elf_Internal_Rela rela;
+ asection *relgot = htab->elf.srelgot;
/* This symbol has an entry in the global offset table. Set it
up. */
@@ -5888,7 +5934,27 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
if (h->def_regular
&& h->type == STT_GNU_IFUNC)
{
- if (bfd_link_pic (info))
+ if (h->plt.offset == (bfd_vma) -1)
+ {
+ /* STT_GNU_IFUNC is referenced without PLT. */
+ if (htab->elf.splt == NULL)
+ {
+ /* use .rel[a].iplt section to store .got relocations
+ in static executable. */
+ relgot = htab->elf.irelplt;
+ }
+ if (SYMBOL_REFERENCES_LOCAL (info, h))
+ {
+ rela.r_info = htab->r_info (0,
+ R_X86_64_IRELATIVE);
+ rela.r_addend = (h->root.u.def.value
+ + h->root.u.def.section->output_section->vma
+ + h->root.u.def.section->output_offset);
+ }
+ else
+ goto do_glob_dat;
+ }
+ else if (bfd_link_pic (info))
{
/* Generate R_X86_64_GLOB_DAT. */
goto do_glob_dat;
@@ -5932,7 +5998,7 @@ do_glob_dat:
rela.r_addend = 0;
}
- elf_append_rela (output_bfd, htab->elf.srelgot, &rela);
+ elf_append_rela (output_bfd, relgot, &rela);
}
if (h->needs_copy)
@@ -6265,11 +6331,6 @@ elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
= GOT_ENTRY_SIZE;
- /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
- htab_traverse (htab->loc_hash_table,
- elf_x86_64_finish_local_dynamic_symbol,
- info);
-
/* Fill PLT entries for undefined weak symbols in PIE. */
if (bfd_link_pie (info))
bfd_hash_traverse (&info->hash->table,
@@ -6279,6 +6340,33 @@ elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
return TRUE;
}
+/* Fill PLT/GOT entries and allocate dynamic relocations for local
+ STT_GNU_IFUNC symbols, which aren't in the ELF linker hash table.
+ It has to be done before elf_link_sort_relocs is called so that
+ dynamic relocations are properly sorted. */
+
+static bfd_boolean
+elf_x86_64_output_arch_local_syms
+ (bfd *output_bfd ATTRIBUTE_UNUSED,
+ struct bfd_link_info *info,
+ void *flaginfo ATTRIBUTE_UNUSED,
+ int (*func) (void *, const char *,
+ Elf_Internal_Sym *,
+ asection *,
+ struct elf_link_hash_entry *) ATTRIBUTE_UNUSED)
+{
+ struct elf_x86_64_link_hash_table *htab = elf_x86_64_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
+ htab_traverse (htab->loc_hash_table,
+ elf_x86_64_finish_local_dynamic_symbol,
+ info);
+
+ return TRUE;
+}
+
/* Return an array of PLT entry symbol values. */
static bfd_vma *
@@ -6641,6 +6729,7 @@ static const struct bfd_elf_special_section
#define elf_backend_create_dynamic_sections elf_x86_64_create_dynamic_sections
#define elf_backend_finish_dynamic_sections elf_x86_64_finish_dynamic_sections
#define elf_backend_finish_dynamic_symbol elf_x86_64_finish_dynamic_symbol
+#define elf_backend_output_arch_local_syms elf_x86_64_output_arch_local_syms
#define elf_backend_gc_mark_hook elf_x86_64_gc_mark_hook
#define elf_backend_grok_prstatus elf_x86_64_grok_prstatus
#define elf_backend_grok_psinfo elf_x86_64_grok_psinfo
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 774364a..fa66b0f 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -8238,7 +8238,8 @@ elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
NULL,
htab->plt_entry_size,
htab->plt_header_size,
- GOT_ENTRY_SIZE);
+ GOT_ENTRY_SIZE,
+ FALSE);
return TRUE;
}