x86: Fix DT_JMPREL/DT_PLTRELSZ when relocs share a section
authorPeter Edwards <peadar@arista.com>
Tue, 22 Aug 2023 18:57:28 +0000 (19:57 +0100)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 23 Aug 2023 16:10:16 +0000 (09:10 -0700)
commitfa4f2d46f95a1c673b025fab7f292cb864a99020
tree5088fff05a1d5527433ee61f9bba052bf9bd1afa
parentc99853f48cd9132c5a745ad7452d1b0d856f32b8
x86: Fix DT_JMPREL/DT_PLTRELSZ when relocs share a section

If a linker script does not place the PLT relocations and "normal"
relocations in separate ELF sections, `ld` will currently output incorrect
values for DT_JMPREL and DT_PLTRELSZ - they cover the entire ELF section,
rather than just the PLT relocations

Don't ignore the extent of the BFD section - use the size of the srelplt
BFD section and its offset from the output_secttion

bfd/

PR ld/30787
* elfxx-x86.c (_bfd_x86_elf_finish_dynamic_sections): Use input
section for DT_JMPREL and DT_PLTRELSZ.

ld/

PR ld/30787
* testsuite/ld-i386/i386.exp: Run pr30787.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-i386/pr30787.d: New file.
* testsuite/ld-i386/pr30787.s: Likewise.
* testsuite/ld-i386/pr30787.t: Likewise.
* testsuite/ld-x86-64/pr30787.d: Likewise.
* testsuite/ld-x86-64/pr30787.s: Likewise.
* testsuite/ld-x86-64/pr30787.t: Likewise.
bfd/elfxx-x86.c
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr30787.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr30787.s [new file with mode: 0644]
ld/testsuite/ld-i386/pr30787.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr30787.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr30787.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr30787.t [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp