summaryrefslogtreecommitdiff
path: root/bfd/elf64-x86-64.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-07-08 13:49:17 -0700
committerH.J. Lu <hjl.tools@gmail.com>2021-07-08 13:57:52 -0700
commit661b504df9bfb8d7c5d669091720e1dc0079c05e (patch)
treecfa4e84297a9a3156071b6ab3970989f0af2c292 /bfd/elf64-x86-64.c
parenta8dde0a2114f87bcdc19946aeab26788f5eae1b7 (diff)
downloadbinutils-gdb-661b504df9bfb8d7c5d669091720e1dc0079c05e.tar.gz
x86-64: Disallow PC reloc against weak undefined symbols in PIE
Disallow PC relocations against weak undefined symbols in PIE since they can lead to non-zero address at run-time. bfd/ PR ld/21782 * elf64-x86-64.c (elf_x86_64_relocate_section): Disallow PC relocations against weak undefined symbols in PIE. ld/ PR ld/21782 * testsuite/ld-x86-64/pie3.d: Expect linker error.
Diffstat (limited to 'bfd/elf64-x86-64.c')
-rw-r--r--bfd/elf64-x86-64.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 4c55c5999c3..8deb62dba5c 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -3161,6 +3161,8 @@ elf_x86_64_relocate_section (bfd *output_bfd,
|| (no_copyreloc_p
&& h->def_dynamic
&& !(h->root.u.def.section->flags & SEC_CODE))))
+ || (bfd_link_pie (info)
+ && h->root.type == bfd_link_hash_undefweak)
|| bfd_link_dll (info)))
{
bool fail = false;
@@ -3174,8 +3176,9 @@ elf_x86_64_relocate_section (bfd *output_bfd,
{
/* We can only use PC-relative relocations in PIE
from non-code sections. */
- if (h->type == STT_FUNC
- && (sec->flags & SEC_CODE) != 0)
+ if (h->root.type == bfd_link_hash_undefweak
+ || (h->type == STT_FUNC
+ && (sec->flags & SEC_CODE) != 0))
fail = true;
}
else if (no_copyreloc_p || bfd_link_dll (info))