From 5056ba1d4df19006b873bc8e752f85fcc712b65b Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 14 Oct 2017 11:02:20 -0700 Subject: [PATCH] m68k: Check UNDEFWEAK_NO_DYNAMIC_RELOC Don't generate dynamic relocation against weak undefined symbol if it is resolved to zero. FIXME: UNDEFWEAK_NO_DYNAMIC_RELOC may need to be checked in more places. PR ld/22269 * elf32-m68k.c (elf_m68k_check_relocs): Don't allocate dynamic relocations if UNDEFWEAK_NO_DYNAMIC_RELOC is true. (elf_m68k_adjust_dynamic_symbol): Don't make symbol dynamic if UNDEFWEAK_NO_DYNAMIC_RELOC is true. (elf_m68k_relocate_section): Don't generate dynamic relocation if UNDEFWEAK_NO_DYNAMIC_RELOC is true. --- bfd/ChangeLog | 10 ++++++++++ bfd/elf32-m68k.c | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 34dde75c1d8..90a85a751ea 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,13 @@ +2017-10-14 H.J. Lu + + PR ld/22269 + * elf32-m68k.c (elf_m68k_check_relocs): Don't allocate dynamic + relocations if UNDEFWEAK_NO_DYNAMIC_RELOC is true. + (elf_m68k_adjust_dynamic_symbol): Don't make symbol dynamic if + UNDEFWEAK_NO_DYNAMIC_RELOC is true. + (elf_m68k_relocate_section): Don't generate dynamic relocation + if UNDEFWEAK_NO_DYNAMIC_RELOC is true. + 2017-10-14 H.J. Lu PR ld/22269 diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c index 21bff66ab40..501190db12e 100644 --- a/bfd/elf32-m68k.c +++ b/bfd/elf32-m68k.c @@ -2773,7 +2773,9 @@ elf_m68k_check_relocs (bfd *abfd, /* If we are creating a shared library, we need to copy the reloc into the shared library. */ - if (bfd_link_pic (info)) + if (bfd_link_pic (info) + && (h == NULL + || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))) { /* When creating a shared object, we must copy these reloc types into the output file. We create a reloc @@ -3095,7 +3097,8 @@ elf_m68k_adjust_dynamic_symbol (struct bfd_link_info *info, { if ((h->plt.refcount <= 0 || SYMBOL_CALLS_LOCAL (info, h) - || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT + || ((ELF_ST_VISIBILITY (h->other) != STV_DEFAULT + || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) && h->root.type == bfd_link_hash_undefweak)) /* We must always create the plt entry if it was referenced by a PLTxxO relocation. In this case we already recorded @@ -3622,6 +3625,7 @@ elf_m68k_relocate_section (bfd *output_bfd, bfd_vma relocation; bfd_boolean unresolved_reloc; bfd_reloc_status_type r; + bfd_boolean resolved_to_zero; r_type = ELF32_R_TYPE (rel->r_info); if (r_type < 0 || r_type >= (int) R_68K_max) @@ -3661,6 +3665,9 @@ elf_m68k_relocate_section (bfd *output_bfd, if (bfd_link_relocatable (info)) continue; + resolved_to_zero = (h != NULL + && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); + switch (r_type) { case R_68K_GOT8: @@ -3785,7 +3792,8 @@ elf_m68k_relocate_section (bfd *output_bfd, h) || (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h)) - || (ELF_ST_VISIBILITY (h->other) + || ((ELF_ST_VISIBILITY (h->other) + || resolved_to_zero) && h->root.type == bfd_link_hash_undefweak)) { /* This is actually a static link, or it is a @@ -3954,7 +3962,8 @@ elf_m68k_relocate_section (bfd *output_bfd, && r_symndx != STN_UNDEF && (input_section->flags & SEC_ALLOC) != 0 && (h == NULL - || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + && !resolved_to_zero) || h->root.type != bfd_link_hash_undefweak) && ((r_type != R_68K_PC8 && r_type != R_68K_PC16 -- 2.30.2