binutils-gdb/ld/testsuite/ld-x86-64/pe-x86-64-5.od
H.J. Lu 8c0546e928 elf/x86-64: Subtract __ImageBase for R_AMD64_IMAGEBASE
When linking Windows x86-64 relocatable object files to generate x86-64
ELF executable, we need to subtract __ImageBase, aka __executable_start,
for R_AMD64_IMAGEBASE relocation:

1. Add link_info to struct output_elf_obj_tdata to store linker info and
_bfd_get_link_info() to retrieve it.
2. Add ldelf_set_output_arch to set up link_info.
3. Add pex64_link_add_symbols to create an indirect reference to
__executable_start for __ImageBase to support R_AMD64_IMAGEBASE relocation
when adding symbols from Windows x86-64 relocatable object files to
generate x86-64 ELF executable.
4. Also subtract __ImageBase for R_AMD64_IMAGEBASE when generating x86-64
ELF executable.

bfd/

	PR ld/27425
	PR ld/27432
	* bfd.c (_bfd_get_link_info): New function.
	* elf-bfd.h (output_elf_obj_tdata): Add link_info.
	(elf_link_info): New.
	* libbfd-in.h (_bfd_get_link_info): New prototype.
	* coff-x86_64.c (coff_amd64_reloc): Also subtract __ImageBase for
	R_AMD64_IMAGEBASE when generating x86-64 ELF executable.
	* pe-x86_64.c: Include "coff/internal.h" and "libcoff.h".
	(pex64_link_add_symbols): New function.
	(coff_bfd_link_add_symbols): New macro.
	* libbfd.h: Regenerated.

ld/

	PR ld/27425
	PR ld/27432
	* ldelf.c (ldelf_set_output_arch): New function.
	* ldelf.h (ldelf_set_output_arch): New prototype.
	* emultempl/elf.em (LDEMUL_SET_OUTPUT_ARCH): Default to
	ldelf_set_output_arch.
	* ld-x86-64/pe-x86-64-1.od: Expect __executable_start.
	* testsuite/ld-x86-64/pe-x86-64-2.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-3.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-4.od: Likewise.
	* 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-6.obj.bz2: New file.
	* testsuite/ld-x86-64/pe-x86-64-6.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64.exp: Run ld/27425 test.
2021-03-05 18:25:06 -08:00

36 lines
1.5 KiB
Plaintext

.*: +file format .*
SYMBOL TABLE:
0+402014 g .bss 0000000000000000 non_initdummy
0+402010 g .data 0000000000000000 initdummy
0+400000 g .text\$mn 0000000000000000 __executable_start
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