]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
x86-64: Estimate output section layout before sizing dynamic sections
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 30 Jan 2025 00:48:45 +0000 (08:48 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 6 Feb 2025 22:02:05 +0000 (06:02 +0800)
commit73ab3b9825d232f0f3a4ad811e88697f9b9ab162
tree959ef0f7ba4adc984652da2ddc6f49bab1c24992
parent9a7ed136a9b405408ab20e01f2cab415e7a39b5b
x86-64: Estimate output section layout before sizing dynamic sections

When sizing dynamic sections, elf_x86_64_scan_relocs converts GOTPCREL
relocations to R_X86_64_PC32, R_X86_64_32S or R_X86_64_32 for local
symbols.  But at that time, since the output section layout is unknown,
the local symbol values can't be determined.  Later linker issues an
error if the converted relocation overflows when resolving relocations
against these local symbols.  Update the x86-64 ELF linker to estimate
output section layout before sizing dynamic sections and use the
preliminary output section layout info to skip the GOTPCREL relocation
conversion if the converted relocation overflows.

bfd/

PR ld/32591
* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Add an input
section argument.  Use the lowest-addressed section to estimate
the __ehdr_start symbol value.  Don't convert relocation if the
converted relocation will overflow.

ld/

PR ld/32591
* emultempl/elf-x86.em (elf_x86_64_before_allocation):
New.  Defined for x86-64.
(LDEMUL_BEFORE_ALLOCATION): Likewise.
* testsuite/ld-x86-64/pr19609-2a.d: Don't fail.
* testsuite/ld-x86-64/pr19609-2b.d: Likewise.
* testsuite/ld-x86-64/pr19609-4a.d: Likewise.
* testsuite/ld-x86-64/pr19609-5d.d: Likewise.
* testsuite/ld-x86-64/pr19609-7a.d: Likewise.
* testsuite/ld-x86-64/pr19609-7c.d: Likewise.
* testsuite/ld-x86-64/pr32591-1.s: New file.
* testsuite/ld-x86-64/pr32591-1a-x32.d: Likewise.
* testsuite/ld-x86-64/pr32591-1a.d: Likewise.
* testsuite/ld-x86-64/pr32591-1a.t: Likewise.
* testsuite/ld-x86-64/pr32591-1b-x32.d: Likewise.
* testsuite/ld-x86-64/pr32591-1b.d: Likewise.
* testsuite/ld-x86-64/pr32591-1b.t: Likewise.
* testsuite/ld-x86-64/pr32591-1c-x32.d: Likewise.
* testsuite/ld-x86-64/pr32591-1c.d: Likewise.
* testsuite/ld-x86-64/pr32591-1c.t: Likewise.
* testsuite/ld-x86-64/pr32591-1d-x32.d: Likewise.
* testsuite/ld-x86-64/pr32591-1d.d: Likewise.
* testsuite/ld-x86-64/pr32591-1d.t: Likewise.
* testsuite/ld-x86-64/pr32591-2.s: Likewise.
* testsuite/ld-x86-64/pr32591-2-x32.d: Likewise.
* testsuite/ld-x86-64/pr32591-2.d: Likewise.
* testsuite/ld-x86-64/pr32591-2.t: Likewise.
* testsuite/ld-x86-64/pr32591-3.s: Likewise.
* testsuite/ld-x86-64/pr32591-3-x32.d: Likewise.
* testsuite/ld-x86-64/pr32591-3.d: Likewise.
* testsuite/ld-x86-64/pr32591-3.t: Likewise.
* testsuite/ld-x86-64/pr32591-4.s: Likewise.
* testsuite/ld-x86-64/pr32591-4-x32.d: Likewise.
* testsuite/ld-x86-64/pr32591-4.d: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/32591 tests.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
33 files changed:
bfd/elf64-x86-64.c
ld/emultempl/elf-x86.em
ld/testsuite/ld-x86-64/pr19609-2a.d
ld/testsuite/ld-x86-64/pr19609-2b.d
ld/testsuite/ld-x86-64/pr19609-4a.d
ld/testsuite/ld-x86-64/pr19609-5d.d
ld/testsuite/ld-x86-64/pr19609-7a.d
ld/testsuite/ld-x86-64/pr19609-7c.d
ld/testsuite/ld-x86-64/pr32591-1.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1a-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1a.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1a.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1b-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1b.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1b.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1c-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1c.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1c.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1d-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1d.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-1d.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-2-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-2.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-2.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-2.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-3-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-3.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-3.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-3.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-4-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-4.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr32591-4.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp