mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-16 23:04:21 +08:00
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.
This commit is contained in:
@@ -2771,11 +2771,12 @@ _bfd_x86_elf_finish_dynamic_sections (bfd *output_bfd,
|
||||
break;
|
||||
|
||||
case DT_JMPREL:
|
||||
dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
|
||||
s = htab->elf.srelplt;
|
||||
dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
|
||||
break;
|
||||
|
||||
case DT_PLTRELSZ:
|
||||
s = htab->elf.srelplt->output_section;
|
||||
s = htab->elf.srelplt;
|
||||
dyn.d_un.d_val = s->size;
|
||||
break;
|
||||
|
||||
|
||||
@@ -511,6 +511,7 @@ run_dump_test "dt-relr-1a"
|
||||
run_dump_test "dt-relr-1b"
|
||||
run_dump_test "pr28870"
|
||||
run_dump_test "pr28894"
|
||||
run_dump_test "pr30787"
|
||||
|
||||
if { !([istarget "i?86-*-linux*"]
|
||||
|| [istarget "i?86-*-gnu*"]
|
||||
|
||||
7
ld/testsuite/ld-i386/pr30787.d
Normal file
7
ld/testsuite/ld-i386/pr30787.d
Normal file
@@ -0,0 +1,7 @@
|
||||
#as: --32
|
||||
#ld: -melf_i386 -shared --no-warn-rwx-segments -T pr30787.t
|
||||
#readelf: -d --wide
|
||||
|
||||
#...
|
||||
0x0+2 \(PLTRELSZ\) +8 \(bytes\)
|
||||
#pass
|
||||
6
ld/testsuite/ld-i386/pr30787.s
Normal file
6
ld/testsuite/ld-i386/pr30787.s
Normal file
@@ -0,0 +1,6 @@
|
||||
.text
|
||||
.globl foo
|
||||
foo:
|
||||
jmp bar@PLT
|
||||
leal func@GOT(%ebx), %eax
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
4
ld/testsuite/ld-i386/pr30787.t
Normal file
4
ld/testsuite/ld-i386/pr30787.t
Normal file
@@ -0,0 +1,4 @@
|
||||
SECTIONS
|
||||
{
|
||||
.rel.dyn : { *(.rel.*) }
|
||||
}
|
||||
7
ld/testsuite/ld-x86-64/pr30787.d
Normal file
7
ld/testsuite/ld-x86-64/pr30787.d
Normal file
@@ -0,0 +1,7 @@
|
||||
#as: --64
|
||||
#ld: -melf_x86_64 -shared --no-warn-rwx-segments -T pr30787.t
|
||||
#readelf: -d --wide
|
||||
|
||||
#...
|
||||
0x0+2 \(PLTRELSZ\) +24 \(bytes\)
|
||||
#pass
|
||||
6
ld/testsuite/ld-x86-64/pr30787.s
Normal file
6
ld/testsuite/ld-x86-64/pr30787.s
Normal file
@@ -0,0 +1,6 @@
|
||||
.text
|
||||
.globl foo
|
||||
foo:
|
||||
jmp bar@PLT
|
||||
movq func@GOTPCREL(%rip), %rax
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
4
ld/testsuite/ld-x86-64/pr30787.t
Normal file
4
ld/testsuite/ld-x86-64/pr30787.t
Normal file
@@ -0,0 +1,4 @@
|
||||
SECTIONS
|
||||
{
|
||||
.rela.dyn : { *(.rela.*) }
|
||||
}
|
||||
@@ -505,6 +505,7 @@ run_dump_test "dt-relr-1a"
|
||||
run_dump_test "dt-relr-1a-x32"
|
||||
run_dump_test "dt-relr-1b"
|
||||
run_dump_test "dt-relr-1b-x32"
|
||||
run_dump_test "pr30787"
|
||||
|
||||
if { ![skip_sframe_tests] } {
|
||||
run_dump_test "sframe-simple-1"
|
||||
|
||||
Reference in New Issue
Block a user