diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-07-08 14:03:53 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-07-08 14:04:40 -0700 |
commit | cce64d8d01ba1558f9fc93775b9d96b40a019199 (patch) | |
tree | 4d61a3528a44b3f2e351fd2ed4ceb0086ad7b16e | |
parent | 26672a41ea554bee2346143f889483615779320d (diff) | |
download | fsf-binutils-gdb-cce64d8d01ba1558f9fc93775b9d96b40a019199.zip fsf-binutils-gdb-cce64d8d01ba1558f9fc93775b9d96b40a019199.tar.gz fsf-binutils-gdb-cce64d8d01ba1558f9fc93775b9d96b40a019199.tar.bz2 |
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.
(cherry picked from commit 661b504df9bfb8d7c5d669091720e1dc0079c05e)
-rw-r--r-- | bfd/ChangeLog | 6 | ||||
-rw-r--r-- | bfd/elf64-x86-64.c | 7 | ||||
-rw-r--r-- | ld/ChangeLog | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/pie3.d | 11 |
4 files changed, 17 insertions, 12 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 14d159b..9566e41 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2021-07-08 H.J. Lu <hongjiu.lu@intel.com> + + PR ld/21782 + * elf64-x86-64.c (elf_x86_64_relocate_section): Disallow PC + relocations against weak undefined symbols in PIE. + 2021-07-08 Nick Clifton <nickc@redhat.com> * po/pt.po: Updated Portuguese translation. diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 98fb881..4b6489b 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -3160,6 +3160,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; @@ -3173,8 +3175,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)) diff --git a/ld/ChangeLog b/ld/ChangeLog index fa8cd35..40b4e58 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2021-07-08 H.J. Lu <hongjiu.lu@intel.com> + + PR ld/21782 + * testsuite/ld-x86-64/pie3.d: Expect linker error. + 2021-07-07 Michael Matz <matz@suse.de> PR ld/28021 diff --git a/ld/testsuite/ld-x86-64/pie3.d b/ld/testsuite/ld-x86-64/pie3.d index b943837..a20029c 100644 --- a/ld/testsuite/ld-x86-64/pie3.d +++ b/ld/testsuite/ld-x86-64/pie3.d @@ -1,12 +1,3 @@ #as: --64 #ld: -pie -melf_x86_64 --hash-style=sysv -z max-page-size=0x200000 -z noseparate-code -#objdump: -dw - -.*: +file format .* - - -Disassembly of section .text: - -0+191 <_start>: - +191: 48 8d 05 68 fe ff ff lea -0x198\(%rip\),%rax # 0 <_start-0x191> -#pass +#error: .*relocation R_X86_64_PC32 against undefined symbol `foo' can not be used when making a PIE object; recompile with -fPIE |