elf/x86-64: Adjust R_AMD64_DIR64/R_AMD64_DIR32 for PE/x86-64 inputs

Subtract the value of the section contents for R_AMD64_DIR64 and
R_AMD64_DIR32 relocations when generating ELF output from PE/x86-64
inputs.

bfd/

	PR ld/27171
	* reloc.c (bfd_perform_relocation): Adjust R_AMD64_DIR64 and
	R_AMD64_DIR32 relocations for PE/x86-64 inputs.

ld/

	PR ld/27171
	* testsuite/ld-x86-64/pe-x86-64-5.obj.bz2: New file.
	* testsuite/ld-x86-64/pe-x86-64-5.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-5.rd: Likewise.
	* testsuite/ld-x86-64/pe-x86-64.exp: Run PR ld/27171 test.
This commit is contained in:
H.J. Lu
2021-01-12 05:10:58 -08:00
parent 6d104cac0a
commit c2e9a4a3ed
7 changed files with 84 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2021-01-12 H.J. Lu <hongjiu.lu@intel.com>
PR ld/27171
* reloc.c (bfd_perform_relocation): Adjust R_AMD64_DIR64 and
R_AMD64_DIR32 relocations for PE/x86-64 inputs.
2021-01-11 H.J. Lu <hongjiu.lu@intel.com> 2021-01-11 H.J. Lu <hongjiu.lu@intel.com>
PR ld/27173 PR ld/27173

View File

@ -921,6 +921,13 @@ space consuming. For each target:
if (howto->type >= R_AMD64_PCRLONG_1 if (howto->type >= R_AMD64_PCRLONG_1
&& howto->type <= R_AMD64_PCRLONG_5) && howto->type <= R_AMD64_PCRLONG_5)
relocation -= (bfd_vma)(howto->type - R_AMD64_PCRLONG); relocation -= (bfd_vma)(howto->type - R_AMD64_PCRLONG);
else if (howto->type == R_AMD64_DIR64
|| howto->type == R_AMD64_DIR32)
{
bfd_vma val = read_reloc (abfd, (bfd_byte *) data + octets,
howto);
relocation -= val & howto->src_mask;
}
} }
/* FIXME: This overflow checking is incomplete, because the value /* FIXME: This overflow checking is incomplete, because the value

View File

@ -1,3 +1,11 @@
2021-01-12 H.J. Lu <hongjiu.lu@intel.com>
PR ld/27171
* testsuite/ld-x86-64/pe-x86-64-5.obj.bz2: New file.
* testsuite/ld-x86-64/pe-x86-64-5.od: Likewise.
* testsuite/ld-x86-64/pe-x86-64-5.rd: Likewise.
* testsuite/ld-x86-64/pe-x86-64.exp: Run PR ld/27171 test.
2021-01-11 H.J. Lu <hongjiu.lu@intel.com> 2021-01-11 H.J. Lu <hongjiu.lu@intel.com>
PR ld/27173 PR ld/27173

Binary file not shown.

View File

@ -0,0 +1,34 @@
.*: +file format .*
SYMBOL TABLE:
0+402014 g .bss 0000000000000000 non_initdummy
0+402010 g .data 0000000000000000 initdummy
0+401000 g .text\$mn 0000000000000000 begin
0+402012 g .bss 0000000000000000 __bss_start
0+402000 g .data 0000000000000000 Struct
0+402011 g .data 0000000000000000 initializedVar
0+402012 g .data 0000000000000000 _edata
0+402018 g .bss 0000000000000000 _end
0+402015 g .bss 0000000000000000 non_initialVar
Disassembly of section .text\$mn:
0+401000 <begin>:
+[a-f0-9]+: 66 90 xchg %ax,%ax
+[a-f0-9]+: cc int3
+[a-f0-9]+: 48 8d 05 07 10 00 00 lea 0x1007\(%rip\),%rax # 402011 <initializedVar>
+[a-f0-9]+: 48 3b 05 ef 0f 00 00 cmp 0xfef\(%rip\),%rax # 402000 <Struct>
+[a-f0-9]+: 74 01 je 401014 <begin\+0x14>
+[a-f0-9]+: cc int3
+[a-f0-9]+: 48 8d 05 fa 0f 00 00 lea 0xffa\(%rip\),%rax # 402015 <non_initialVar>
+[a-f0-9]+: 48 3b 05 e6 0f 00 00 cmp 0xfe6\(%rip\),%rax # 402008 <Struct\+0x8>
+[a-f0-9]+: 74 01 je 401025 <begin\+0x25>
+[a-f0-9]+: cc int3
+[a-f0-9]+: 66 ba 80 00 mov \$0x80,%dx
+[a-f0-9]+: b0 12 mov \$0x12,%al
+[a-f0-9]+: ee out %al,\(%dx\)
+[a-f0-9]+: c3 ret
#pass

View File

@ -0,0 +1,19 @@
Symbol table '.symtab' contains 10 entries:
Num: Value Size Type Bind Vis Ndx Name
+[a-f0-9]+: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
+[a-f0-9]+: 0000000000402014 0 NOTYPE GLOBAL DEFAULT 3 non_initdummy
+[a-f0-9]+: 0000000000402010 0 NOTYPE GLOBAL DEFAULT 2 initdummy
+[a-f0-9]+: 0000000000401000 0 NOTYPE GLOBAL DEFAULT 1 begin
+[a-f0-9]+: 0000000000402012 0 NOTYPE GLOBAL DEFAULT 3 __bss_start
+[a-f0-9]+: 0000000000402000 0 NOTYPE GLOBAL DEFAULT 2 Struct
+[a-f0-9]+: 0000000000402011 0 NOTYPE GLOBAL DEFAULT 2 initializedVar
+[a-f0-9]+: 0000000000402012 0 NOTYPE GLOBAL DEFAULT 2 _edata
+[a-f0-9]+: 0000000000402018 0 NOTYPE GLOBAL DEFAULT 3 _end
+[a-f0-9]+: 0000000000402015 0 NOTYPE GLOBAL DEFAULT 3 non_initialVar
Hex dump of section '.data':
0x00402000 11204000 00000000 15204000 00000000 . @...... @.....
0x00402010 aa55 .U
#pass

View File

@ -63,4 +63,14 @@ run_ld_link_tests [list \
{{objdump {-dw --sym} pe-x86-64-4.od}} \ {{objdump {-dw --sym} pe-x86-64-4.od}} \
"pe-x86-64-4" \ "pe-x86-64-4" \
] \ ] \
[list \
"Build pe-x86-64-5" \
"-m elf_x86_64 --entry=begin" \
"" \
"" \
{pe-x86-64-5.obj.bz2 } \
{{objdump {-dw --sym} pe-x86-64-5.od} \
{readelf {-s -x .data} pe-x86-64-5.rd}} \
"pe-x86-64-5" \
] \
] ]