diff options
author | Max Filippov <jcmvbkbc@gmail.com> | 2018-07-02 11:12:44 -0700 |
---|---|---|
committer | Max Filippov <jcmvbkbc@gmail.com> | 2018-07-11 09:41:15 -0700 |
commit | 82f32155837415d3f84ceb9c9ffa36495f7211ae (patch) | |
tree | d3dab71ef491345aac6fd2d580c4ffb1426245fc | |
parent | 8e188148c46deb563b5d0c220f01d5f929d2010f (diff) | |
download | fsf-binutils-gdb-82f32155837415d3f84ceb9c9ffa36495f7211ae.zip fsf-binutils-gdb-82f32155837415d3f84ceb9c9ffa36495f7211ae.tar.gz fsf-binutils-gdb-82f32155837415d3f84ceb9c9ffa36495f7211ae.tar.bz2 |
xtensa: don't emit dynamic relocation for weak undefined symbol
Resolved reference to a weak undefined symbol in PIE must not have
a dynamic relative relocation against itself, otherwise the value of a
reference will be changed from 0 to the base of executable, breaking
code like the following:
void weak_function (void);
if (weak_function)
weak_function ();
This fixes tests for PR ld/22269 and a number of PIE tests in xtensa gcc
testsuite.
bfd/
2018-07-11 Max Filippov <jcmvbkbc@gmail.com>
* elf32-xtensa.c (elf_xtensa_allocate_dynrelocs): Don't allocate
space for dynamic relocation for undefined weak symbol.
(elf_xtensa_relocate_section): Don't emit R_XTENSA_RELATIVE
relocation for undefined weak symbols.
(shrink_dynamic_reloc_sections): Don't shrink dynamic relocation
section for relocations against undefined weak symbols.
(cherry picked from commit c451bb34ae8bd2d0669bd563366883cfbcf0de9b)
-rw-r--r-- | bfd/ChangeLog | 9 | ||||
-rw-r--r-- | bfd/elf32-xtensa.c | 13 |
2 files changed, 20 insertions, 2 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index f643c80..0f298d7 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2018-07-11 Max Filippov <jcmvbkbc@gmail.com> + + * elf32-xtensa.c (elf_xtensa_allocate_dynrelocs): Don't allocate + space for dynamic relocation for undefined weak symbol. + (elf_xtensa_relocate_section): Don't emit R_XTENSA_RELATIVE + relocation for undefined weak symbols. + (shrink_dynamic_reloc_sections): Don't shrink dynamic relocation + section for relocations against undefined weak symbols. + 2018-07-10 Maciej W. Rozycki <macro@mips.com> * elflink.c (bfd_elf_final_link): Rename `remove' local variable diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index 44c1074..f7f569d 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -1437,6 +1437,10 @@ elf_xtensa_allocate_dynrelocs (struct elf_link_hash_entry *h, void *arg) if (! elf_xtensa_dynamic_symbol_p (h, info)) elf_xtensa_make_sym_local (info, h); + if (! elf_xtensa_dynamic_symbol_p (h, info) + && h->root.type == bfd_link_hash_undefweak) + return TRUE; + if (h->plt.refcount > 0) htab->elf.srelplt->size += (h->plt.refcount * sizeof (Elf32_External_Rela)); @@ -2777,12 +2781,16 @@ elf_xtensa_relocate_section (bfd *output_bfd, } unresolved_reloc = FALSE; } - else + else if (!is_weak_undef) { /* Generate a RELATIVE relocation. */ outrel.r_info = ELF32_R_INFO (0, R_XTENSA_RELATIVE); outrel.r_addend = 0; } + else + { + continue; + } } loc = (srel->contents @@ -10013,7 +10021,8 @@ shrink_dynamic_reloc_sections (struct bfd_link_info *info, if ((r_type == R_XTENSA_32 || r_type == R_XTENSA_PLT) && (input_section->flags & SEC_ALLOC) != 0 - && (dynamic_symbol || bfd_link_pic (info))) + && (dynamic_symbol || bfd_link_pic (info)) + && (!h || h->root.type != bfd_link_hash_undefweak)) { asection *srel; bfd_boolean is_plt = FALSE; |