0004-arm-pr22269.diff 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. From: Szabolcs Nagy <[email protected]>
  2. Date: Thu, 9 Jan 2020 17:20:56 +0000 (+0000)
  3. Subject: [PR ld/22269] arm: Avoid dynamic relocs for undefweak symbols in static PIE
  4. X-Git-Url: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff_plain;h=6fbcfe4762c3732339cffd82426d00d35382b858;hp=c06868784d819a45c43947180c69e168aecaf368
  5. [PR ld/22269] arm: Avoid dynamic relocs for undefweak symbols in static PIE
  6. With static PIE linking undefined weak symbols are resolved to 0, so no
  7. dynamic relocation is needed for them. The UNDEFWEAK_NO_DYNAMIC_RELOC
  8. macro was introduced so this case can be handled easily, but it was not
  9. applied consistently in the first attempt to fix ld/22269 for arm:
  10. commit 95b03e4ad68e7a90f5096b47df595636344b783a
  11. arm: Check UNDEFWEAK_NO_DYNAMIC_RELOC
  12. This patch fixes spurious relative relocs in static PIE binaries against
  13. GOT entries created for undefined weak symbols on arm*-*, this fixes
  14. FAIL: pr22269-1 (static pie undefined weak)
  15. bfd/ChangeLog:
  16. Backported from master
  17. 2020-01-10 Szabolcs Nagy <[email protected]>
  18. PR ld/22269
  19. * elf32-arm.c (elf32_arm_final_link_relocate): Use
  20. UNDEFWEAK_NO_DYNAMIC_RELOC.
  21. (allocate_dynrelocs_for_symbol): Likewise.
  22. ---
  23. diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
  24. index cce796d..21cf4b0 100644
  25. --- a/bfd/elf32-arm.c
  26. +++ b/bfd/elf32-arm.c
  27. @@ -11572,8 +11572,7 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto,
  28. if (dynreloc_st_type == STT_GNU_IFUNC)
  29. outrel.r_info = ELF32_R_INFO (0, R_ARM_IRELATIVE);
  30. else if (bfd_link_pic (info)
  31. - && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  32. - || h->root.type != bfd_link_hash_undefweak))
  33. + && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
  34. outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
  35. else
  36. {
  37. @@ -16527,8 +16526,7 @@ allocate_dynrelocs_for_symbol (struct elf_link_hash_entry *h, void * inf)
  38. GOT entry's R_ARM_IRELATIVE relocation. */
  39. elf32_arm_allocate_irelocs (info, htab->root.srelgot, 1);
  40. else if (bfd_link_pic (info)
  41. - && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  42. - || h->root.type != bfd_link_hash_undefweak))
  43. + && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
  44. /* Reserve room for the GOT entry's R_ARM_RELATIVE relocation. */
  45. elf32_arm_allocate_dynrelocs (info, htab->root.srelgot, 1);
  46. else if (htab->fdpic_p && tls_type == GOT_NORMAL)