x86: Only allow S + A relocations against absolute symbol
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 1 Apr 2020 21:31:47 +0000 (14:31 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 1 Apr 2020 21:31:47 +0000 (14:31 -0700)
commit382aae06322799a25ea52fe61b243cbca4db8d66
treebc60e7b2d1d5acc2622c393933788146f8b1c291
parent6b4a335bf7b7996e904e895b3fdc35443c40cfca
x86: Only allow S + A relocations against absolute symbol

Since value of non-preemptible absolute symbol (SHN_ABS) won't change,
only relocations, which can be resolved as absolute value + addend, and
GOTPCREL relocations, where absolute value + addend is stored in the GOT
slot, against non-preemptible absolute symbol are allowed in PIE and
shared library.

Also convert load relocation to R_386_32, R_X86_64_32S or R_X86_64_32 for
relocation against non-preemptible absolute symbol.  Don't convert to
R_X86_64_32S nor R_X86_64_32 for non-preemptible absolute symbol if they
overflow.

bfd/

PR ld/25749
PR ld/25754
* elf32-i386.c (elf_i386_convert_load_reloc): Convert load
relocation to R_386_32 for relocation against non-preemptible
absolute symbol.
(elf_i386_check_relocs): Call _bfd_elf_x86_valid_reloc_p.  Don't
allocate dynamic relocation for non-preemptible absolute symbol.
(elf_i386_relocate_section): Pass sec to
GENERATE_DYNAMIC_RELOCATION_P.
* elf64-x86-64.c (R_X86_64_converted_reloc_bit): Moved.
(elf_x86_64_convert_load_reloc): Covert load relocation to
R_X86_64_32S or R_X86_64_32 for relocation against non-preemptible
absolute symbol.  Don't convert to R_X86_64_32S nor R_X86_64_32
for non-preemptible absolute symbol if they overflow.
(elf_x86_64_check_relocs): Call _bfd_elf_x86_valid_reloc_p.  Set
tls_type for GOT slot to GOT_ABS for non-preemptible absolute
symbol.  Don't allocate dynamic relocation for non-preemptible
absolute symbol.
(elf_x86_64_relocate_section): Don't generate relative relocation
for GOTPCREL relocations aganst local absolute symbol.  Pass sec
to GENERATE_DYNAMIC_RELOCATION_P.
* elfxx-x86.c (elf_x86_allocate_dynrelocs): No dynamic relocation
against non-preemptible absolute symbol.
(_bfd_elf_x86_valid_reloc_p): New function.
(_bfd_x86_elf_size_dynamic_sections): No dynamic relocation for
GOT_ABS GOT slot.
* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): Add an SEC
argument.  Don't generate dynamic relocation against
non-preemptible absolute symbol.
(ABS_SYMBOL_P): New.
(GENERATE_RELATIVE_RELOC_P): Don't generate relative relocation
against non-preemptible absolute symbol.
(GOT_ABS): New.
(R_X86_64_converted_reloc_bit): New.  Moved from elf64-x86-64.c.
(_bfd_elf_x86_valid_reloc_p): New.

ld/

PR ld/25749
PR ld/25754
* testsuite/ld-elf/linux-x86.exp: Run ld/25749 tests.
* testsuite/ld-elf/pr25749-1.c: New file.
* testsuite/ld-elf/pr25749-1a.c: Likewise.
* testsuite/ld-elf/pr25749-1b.c: Likewise.
* testsuite/ld-elf/pr25749-1b.err: Likewise.
* testsuite/ld-elf/pr25749-1c.c: Likewise.
* testsuite/ld-elf/pr25749-1d.c: Likewise.
* testsuite/ld-elf/pr25749-2.c: Likewise.
* testsuite/ld-elf/pr25749-2a.s: Likewise.
* testsuite/ld-elf/pr25749-2b.s: Likewise.
* testsuite/ld-elf/pr25749.rd: Likewise.
* testsuite/ld-elf/pr25754-1a.c: Likewise.
* testsuite/ld-elf/pr25754-1b.s: Likewise.
* testsuite/ld-elf/pr25754-2a.c: Likewise.
* testsuite/ld-elf/pr25754-2b.err: Likewise.
* testsuite/ld-elf/pr25754-2b.s: Likewise.
* testsuite/ld-elf/pr25754-3a.c: Likewise.
* testsuite/ld-elf/pr25754-3b.s: Likewise.
* testsuite/ld-elf/pr25754-4a.c: Likewise.
* testsuite/ld-elf/pr25754-4b.s: Likewise.
* testsuite/ld-elf/pr25754-4c.s: Likewise.
* testsuite/ld-elf/pr25754-5a.c: Likewise.
* testsuite/ld-elf/pr25754-5b.s: Likewise.
* testsuite/ld-elf/pr25754-5c.s: Likewise.
* testsuite/ld-elf/pr25754-6a.c: Likewise.
* testsuite/ld-elf/pr25754-6b.s: Likewise.
* testsuite/ld-x86-64/pr19609-6a.d: Don't expect linker error.
32 files changed:
bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf64-x86-64.c
bfd/elfxx-x86.c
bfd/elfxx-x86.h
ld/ChangeLog
ld/testsuite/ld-elf/linux-x86.exp
ld/testsuite/ld-elf/pr25749-1.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25749-1a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25749-1b.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25749-1b.err [new file with mode: 0644]
ld/testsuite/ld-elf/pr25749-1c.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25749-1d.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25749-2.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25749-2a.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr25749-2b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr25749.rd [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-1a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-1b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-2a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-2b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-3a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-3b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-4a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-4b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-4c.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-5a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-5b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-5c.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-6a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr25754-6b.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr19609-6a.d
This page took 0.026795 seconds and 4 git commands to generate.