From: H.J. Lu Date: Sat, 30 Jan 2016 22:11:03 +0000 (-0800) Subject: Check reloc against IFUNC symbol only with dynamic symbols X-Git-Tag: users/ARM/embedded-gdb-2_26-branch-2016q1~6^2~75 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=17248591dadd061eb26d1b5f8ef048c1bb24b42e;p=thirdparty%2Fbinutils-gdb.git Check reloc against IFUNC symbol only with dynamic symbols There is no need to check relocation IFUNC symbol if there are no dynamic symbols. Backport from master bfd/ PR ld/19539 * elf32-i386.c (elf_i386_reloc_type_class): Check relocation against STT_GNU_IFUNC symbol only with dynamic symbols. * elf64-x86-64.c (elf_x86_64_reloc_type_class): Likewise. ld/ PR ld/19539 * testsuite/ld-elf/pr19539.d: Skip cris*-*-* targets. * testsuite/ld-elf/pr19539.d: New file. * testsuite/ld-elf/pr19539.s: Likewise. * testsuite/ld-elf/pr19539.t: Likewise. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 44b70d4978c..59e49fab34f 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,13 @@ +2016-03-15 H.J. Lu + + Backport from master + 2016-01-30 H.J. Lu + + PR ld/19539 + * elf32-i386.c (elf_i386_reloc_type_class): Check relocation + against STT_GNU_IFUNC symbol only with dynamic symbols. + * elf64-x86-64.c (elf_x86_64_reloc_type_class): Likewise. + 2016-03-15 Nick Clifton Backport from master: diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 5d07c773f4f..0b7615397ce 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -5359,19 +5359,23 @@ elf_i386_reloc_type_class (const struct bfd_link_info *info, bfd *abfd = info->output_bfd; const struct elf_backend_data *bed = get_elf_backend_data (abfd); struct elf_link_hash_table *htab = elf_hash_table (info); - unsigned long r_symndx = ELF32_R_SYM (rela->r_info); - Elf_Internal_Sym sym; - - if (htab->dynsym == NULL - || !bed->s->swap_symbol_in (abfd, - (htab->dynsym->contents - + r_symndx * sizeof (Elf32_External_Sym)), - 0, &sym)) - abort (); - /* Check relocation against STT_GNU_IFUNC symbol. */ - if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) - return reloc_class_ifunc; + if (htab->dynsym != NULL + && htab->dynsym->contents != NULL) + { + /* Check relocation against STT_GNU_IFUNC symbol if there are + dynamic symbols. */ + unsigned long r_symndx = ELF32_R_SYM (rela->r_info); + Elf_Internal_Sym sym; + if (!bed->s->swap_symbol_in (abfd, + (htab->dynsym->contents + + r_symndx * sizeof (Elf32_External_Sym)), + 0, &sym)) + abort (); + + if (ELF32_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) + return reloc_class_ifunc; + } switch (ELF32_R_TYPE (rela->r_info)) { diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index bddcfe1eed6..8c98ceac213 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -5738,19 +5738,23 @@ elf_x86_64_reloc_type_class (const struct bfd_link_info *info, bfd *abfd = info->output_bfd; const struct elf_backend_data *bed = get_elf_backend_data (abfd); struct elf_x86_64_link_hash_table *htab = elf_x86_64_hash_table (info); - unsigned long r_symndx = htab->r_sym (rela->r_info); - Elf_Internal_Sym sym; - - if (htab->elf.dynsym == NULL - || !bed->s->swap_symbol_in (abfd, - (htab->elf.dynsym->contents - + r_symndx * bed->s->sizeof_sym), - 0, &sym)) - abort (); - /* Check relocation against STT_GNU_IFUNC symbol. */ - if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) - return reloc_class_ifunc; + if (htab->elf.dynsym != NULL + && htab->elf.dynsym->contents != NULL) + { + /* Check relocation against STT_GNU_IFUNC symbol if there are + dynamic symbols. */ + unsigned long r_symndx = htab->r_sym (rela->r_info); + Elf_Internal_Sym sym; + if (!bed->s->swap_symbol_in (abfd, + (htab->elf.dynsym->contents + + r_symndx * bed->s->sizeof_sym), + 0, &sym)) + abort (); + + if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) + return reloc_class_ifunc; + } switch ((int) ELF32_R_TYPE (rela->r_info)) { diff --git a/ld/ChangeLog b/ld/ChangeLog index edbf9f2f9ea..7cd6599a64c 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,17 @@ +2016-03-15 H.J. Lu + + Backport from master + 2016-02-20 H.J. Lu + + * testsuite/ld-elf/pr19539.d: Skip cris*-*-* targets. + + 2016-01-30 H.J. Lu + + PR ld/19539 + * testsuite/ld-elf/pr19539.d: New file. + * testsuite/ld-elf/pr19539.s: Likewise. + * testsuite/ld-elf/pr19539.t: Likewise. + 2016-03-14 H.J. Lu Backport from master diff --git a/ld/testsuite/ld-elf/pr19539.d b/ld/testsuite/ld-elf/pr19539.d new file mode 100644 index 00000000000..87c2b1b4379 --- /dev/null +++ b/ld/testsuite/ld-elf/pr19539.d @@ -0,0 +1,9 @@ +#source: start.s +#source: pr19539.s +#ld: -pie -T pr19539.t +#readelf : --dyn-syms --wide +#target: *-*-linux* *-*-gnu* *-*-solaris* +#notarget: cris*-*-* + +Symbol table '\.dynsym' contains [0-9]+ entries: +#pass diff --git a/ld/testsuite/ld-elf/pr19539.s b/ld/testsuite/ld-elf/pr19539.s new file mode 100644 index 00000000000..0f55d3f7aaa --- /dev/null +++ b/ld/testsuite/ld-elf/pr19539.s @@ -0,0 +1,2 @@ + .section .prefix,"a",%progbits + .dc.a foo diff --git a/ld/testsuite/ld-elf/pr19539.t b/ld/testsuite/ld-elf/pr19539.t new file mode 100644 index 00000000000..b6b48e71d3c --- /dev/null +++ b/ld/testsuite/ld-elf/pr19539.t @@ -0,0 +1 @@ +HIDDEN (foo = .);