From: H.J. Lu Date: Wed, 16 Sep 2020 14:11:16 +0000 (-0700) Subject: elf/x86-64: Adjust relocation for PE/x86-64 inputs X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=36068e2fa5460e6cfa1f5f359df6f37c497aab50;p=binutils-gdb.git elf/x86-64: Adjust relocation for PE/x86-64 inputs PE linker calls _bfd_relocate_contents to resolve relocation, instead of bfd_perform_relocation. But ELF linker calls bfd_perform_relocation, not _bfd_relocate_contents. When linking PE/x86-64 inputs to generate ELF output, we need to adjust PE/x86-64 relocations in bfd_perform_relocation. Enable PE/x86-64 in bfd together with PEI/x86-64. Update run_ld_link_tests to handle bzip2 binary inputs. bfd/ PR ld/26583 * config.bfd (targ64_selvecs, targ_selvecs): Add x86_64_pe_vec to x86_64_pei_vec. * reloc.c: Include "coff/internal.h". (bfd_perform_relocation): Adjust relocation for PE/x86-64 inputs. ld/ PR ld/26583 * testsuite/ld-x86-64/pe-x86-64-1.od: New file. * testsuite/ld-x86-64/pe-x86-64-1a.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-1b.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-1c.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-2.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-2a.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-2b.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-2c.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-3.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-3a.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-3b.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-3c.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-3d.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-4.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-4a.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-4b.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-4c.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64-4d.obj.bz2: Likewise. * testsuite/ld-x86-64/pe-x86-64.exp: Likewise. * testsuite/lib/ld-lib.exp (run_ld_link_tests): Handle bz2 binary inputs. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index b01cd958714..75904fe20b2 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2020-09-16 H.J. Lu + + PR ld/26583 + * config.bfd (targ64_selvecs, targ_selvecs): Add x86_64_pe_vec + to x86_64_pei_vec. + * reloc.c: Include "coff/internal.h". + (bfd_perform_relocation): Adjust relocation for PE/x86-64 inputs. + 2020-09-16 Alan Modra * elf-bfd.h (elf_symbol_from): Remove unused ABFD parameter. diff --git a/bfd/config.bfd b/bfd/config.bfd index 6c2919e47eb..49007359584 100644 --- a/bfd/config.bfd +++ b/bfd/config.bfd @@ -564,13 +564,13 @@ case "${targ}" in i[3-7]86-*-solaris2*) targ_defvec=i386_elf32_sol2_vec targ_selvecs="iamcu_elf32_vec i386_coff_vec i386_pei_vec" - targ64_selvecs="x86_64_elf64_sol2_vec l1om_elf64_vec k1om_elf64_vec x86_64_pei_vec" + targ64_selvecs="x86_64_elf64_sol2_vec l1om_elf64_vec k1om_elf64_vec x86_64_pe_vec x86_64_pei_vec" want64=true ;; #ifdef BFD64 x86_64-*-solaris2*) targ_defvec=i386_elf32_sol2_vec - targ_selvecs="x86_64_elf64_sol2_vec l1om_elf64_vec k1om_elf64_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pei_vec" + targ_selvecs="x86_64_elf64_sol2_vec l1om_elf64_vec k1om_elf64_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec" want64=true ;; #endif @@ -609,7 +609,7 @@ case "${targ}" in i[3-7]86-*-freebsd* | i[3-7]86-*-kfreebsd*-gnu) targ_defvec=i386_elf32_fbsd_vec targ_selvecs="i386_elf32_vec iamcu_elf32_vec i386_pei_vec i386_coff_vec" - targ64_selvecs="x86_64_elf64_fbsd_vec x86_64_elf64_vec x86_64_pei_vec l1om_elf64_vec l1om_elf64_fbsd_vec k1om_elf64_vec k1om_elf64_fbsd_vec" + targ64_selvecs="x86_64_elf64_fbsd_vec x86_64_elf64_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec l1om_elf64_fbsd_vec k1om_elf64_vec k1om_elf64_fbsd_vec" # FreeBSD <= 4.0 supports only the old nonstandard way of ABI labelling. case "${targ}" in i[3-7]86-*-freebsd3* | i[3-7]86-*-freebsd4 | i[3-7]86-*-freebsd4.0*) @@ -632,7 +632,7 @@ case "${targ}" in i[3-7]86-*-linux-*) targ_defvec=i386_elf32_vec targ_selvecs="iamcu_elf32_vec i386_pei_vec" - targ64_selvecs="x86_64_elf64_vec x86_64_elf32_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + targ64_selvecs="x86_64_elf64_vec x86_64_elf32_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" ;; i[3-7]86-*-redox*) targ_defvec=i386_elf32_vec @@ -660,7 +660,7 @@ case "${targ}" in targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec l1om_elf64_vec k1om_elf64_vec" case "${targ}" in x86_64-*-rtems*) - targ_selvecs="${targ_selvecs} x86_64_pei_vec" + targ_selvecs="${targ_selvecs} x86_64_pe_vec x86_64_pei_vec" esac want64=true ;; @@ -671,17 +671,17 @@ case "${targ}" in ;; x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu) targ_defvec=x86_64_elf64_fbsd_vec - targ_selvecs="i386_elf32_fbsd_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pei_vec i386_elf32_vec x86_64_elf64_vec l1om_elf64_vec l1om_elf64_fbsd_vec k1om_elf64_vec k1om_elf64_fbsd_vec" + targ_selvecs="i386_elf32_fbsd_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec i386_elf32_vec x86_64_elf64_vec l1om_elf64_vec l1om_elf64_fbsd_vec k1om_elf64_vec k1om_elf64_fbsd_vec" want64=true ;; x86_64-*-netbsd* | x86_64-*-openbsd*) targ_defvec=x86_64_elf64_vec - targ_selvecs="i386_elf32_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + targ_selvecs="i386_elf32_vec iamcu_elf32_vec i386_coff_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" want64=true ;; x86_64-*-linux-*) targ_defvec=x86_64_elf64_vec - targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec i386_pei_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" want64=true ;; x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin) diff --git a/bfd/reloc.c b/bfd/reloc.c index dc923fe39c2..9639ad262ae 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -51,6 +51,7 @@ SECTION #include "bfdlink.h" #include "libbfd.h" #include "bfdver.h" +#include "coff/internal.h" /* DOCDD INODE @@ -904,6 +905,23 @@ space consuming. For each target: } } } + else if (abfd->xvec->flavour == bfd_target_coff_flavour + && (input_section->output_section->owner->xvec->flavour + == bfd_target_elf_flavour) + && strcmp (abfd->xvec->name, "pe-x86-64") == 0 + && strcmp (input_section->output_section->owner->xvec->name, + "elf64-x86-64") == 0) + { + /* NB: bfd_perform_relocation isn't called to generate PE binary. + _bfd_relocate_contents is called instead. When linking PE + object files to generate ELF output, _bfd_relocate_contents + isn't called and bfd_perform_relocation is used. We need to + adjust relocation here. */ + relocation -= reloc_entry->addend; + if (howto->type >= R_AMD64_PCRLONG_1 + && howto->type <= R_AMD64_PCRLONG_5) + relocation -= (bfd_vma)(howto->type - R_AMD64_PCRLONG); + } /* FIXME: This overflow checking is incomplete, because the value might have overflowed before we get here. For a correct check we diff --git a/ld/ChangeLog b/ld/ChangeLog index b61c3fd0db0..81ad2a5ed2c 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,28 @@ +2020-09-16 H.J. Lu + + PR ld/26583 + * testsuite/ld-x86-64/pe-x86-64-1.od: New file. + * testsuite/ld-x86-64/pe-x86-64-1a.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-1b.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-1c.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-2.od: Likewise. + * testsuite/ld-x86-64/pe-x86-64-2a.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-2b.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-2c.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-3.od: Likewise. + * testsuite/ld-x86-64/pe-x86-64-3a.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-3b.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-3c.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-3d.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-4.od: Likewise. + * testsuite/ld-x86-64/pe-x86-64-4a.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-4b.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-4c.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64-4d.obj.bz2: Likewise. + * testsuite/ld-x86-64/pe-x86-64.exp: Likewise. + * testsuite/lib/ld-lib.exp (run_ld_link_tests): Handle bz2 binary + inputs. + 2020-09-16 Alan Modra * plugin.c (asymbol_from_plugin_symbol): Adjust elf_symbol_from diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-1.od b/ld/testsuite/ld-x86-64/pe-x86-64-1.od new file mode 100644 index 00000000000..1ff644ee9c8 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pe-x86-64-1.od @@ -0,0 +1,38 @@ + +.*: +file format .* + +SYMBOL TABLE: +0+401000 l d .text\$mn 0000000000000000 .text\$mn +0+402000 l d .xdata 0000000000000000 .xdata +0+402008 l d .pdata 0000000000000000 .pdata +0+403014 l d .bss 0000000000000000 .bss +0+ l d .debug\$S 0000000000000000 .debug\$S +0+401000 g .text\$mn 0000000000000000 getaddr1 +0+401020 g .text\$mn 0000000000000000 begin +0+403014 g .bss 0000000000000000 __bss_start +0+403014 g .bss 0000000000000000 var +0+401010 g .text\$mn 0000000000000000 getaddr2 +0+403014 g .bss 0000000000000000 _edata +0+403018 g .bss 0000000000000000 _end + + + +Disassembly of section .text\$mn: + +0+401000 : + +[a-f0-9]+: 48 8d 05 0d 20 00 00 lea 0x200d\(%rip\),%rax # 403014 <__bss_start> + +[a-f0-9]+: c3 ret + +[a-f0-9]+: 0f 1f 84 00 00 00 00 00 nopl 0x0\(%rax,%rax,1\) + +0+401010 : + +[a-f0-9]+: 48 8d 05 fd 1f 00 00 lea 0x1ffd\(%rip\),%rax # 403014 <__bss_start> + +[a-f0-9]+: c3 ret + +[a-f0-9]+: 0f 1f 84 00 00 00 00 00 nopl 0x0\(%rax,%rax,1\) + +0+401020 : + +[a-f0-9]+: 48 83 ec 28 sub \$0x28,%rsp + +[a-f0-9]+: e8 d7 ff ff ff call 401000 + +[a-f0-9]+: e8 e2 ff ff ff call 401010 + +[a-f0-9]+: 48 83 c4 28 add \$0x28,%rsp + +[a-f0-9]+: c3 ret +#pass diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-1a.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-1a.obj.bz2 new file mode 100644 index 00000000000..42724277d95 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-1a.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-1b.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-1b.obj.bz2 new file mode 100644 index 00000000000..23b7f67dcf9 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-1b.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-1c.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-1c.obj.bz2 new file mode 100644 index 00000000000..c9a14b02cf2 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-1c.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-2.od b/ld/testsuite/ld-x86-64/pe-x86-64-2.od new file mode 100644 index 00000000000..1ff644ee9c8 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pe-x86-64-2.od @@ -0,0 +1,38 @@ + +.*: +file format .* + +SYMBOL TABLE: +0+401000 l d .text\$mn 0000000000000000 .text\$mn +0+402000 l d .xdata 0000000000000000 .xdata +0+402008 l d .pdata 0000000000000000 .pdata +0+403014 l d .bss 0000000000000000 .bss +0+ l d .debug\$S 0000000000000000 .debug\$S +0+401000 g .text\$mn 0000000000000000 getaddr1 +0+401020 g .text\$mn 0000000000000000 begin +0+403014 g .bss 0000000000000000 __bss_start +0+403014 g .bss 0000000000000000 var +0+401010 g .text\$mn 0000000000000000 getaddr2 +0+403014 g .bss 0000000000000000 _edata +0+403018 g .bss 0000000000000000 _end + + + +Disassembly of section .text\$mn: + +0+401000 : + +[a-f0-9]+: 48 8d 05 0d 20 00 00 lea 0x200d\(%rip\),%rax # 403014 <__bss_start> + +[a-f0-9]+: c3 ret + +[a-f0-9]+: 0f 1f 84 00 00 00 00 00 nopl 0x0\(%rax,%rax,1\) + +0+401010 : + +[a-f0-9]+: 48 8d 05 fd 1f 00 00 lea 0x1ffd\(%rip\),%rax # 403014 <__bss_start> + +[a-f0-9]+: c3 ret + +[a-f0-9]+: 0f 1f 84 00 00 00 00 00 nopl 0x0\(%rax,%rax,1\) + +0+401020 : + +[a-f0-9]+: 48 83 ec 28 sub \$0x28,%rsp + +[a-f0-9]+: e8 d7 ff ff ff call 401000 + +[a-f0-9]+: e8 e2 ff ff ff call 401010 + +[a-f0-9]+: 48 83 c4 28 add \$0x28,%rsp + +[a-f0-9]+: c3 ret +#pass diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-2a.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-2a.obj.bz2 new file mode 100644 index 00000000000..31bd019ea70 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-2a.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-2b.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-2b.obj.bz2 new file mode 100644 index 00000000000..da067fdd242 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-2b.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-2c.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-2c.obj.bz2 new file mode 100644 index 00000000000..153cfdcc484 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-2c.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-3.od b/ld/testsuite/ld-x86-64/pe-x86-64-3.od new file mode 100644 index 00000000000..1ff644ee9c8 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pe-x86-64-3.od @@ -0,0 +1,38 @@ + +.*: +file format .* + +SYMBOL TABLE: +0+401000 l d .text\$mn 0000000000000000 .text\$mn +0+402000 l d .xdata 0000000000000000 .xdata +0+402008 l d .pdata 0000000000000000 .pdata +0+403014 l d .bss 0000000000000000 .bss +0+ l d .debug\$S 0000000000000000 .debug\$S +0+401000 g .text\$mn 0000000000000000 getaddr1 +0+401020 g .text\$mn 0000000000000000 begin +0+403014 g .bss 0000000000000000 __bss_start +0+403014 g .bss 0000000000000000 var +0+401010 g .text\$mn 0000000000000000 getaddr2 +0+403014 g .bss 0000000000000000 _edata +0+403018 g .bss 0000000000000000 _end + + + +Disassembly of section .text\$mn: + +0+401000 : + +[a-f0-9]+: 48 8d 05 0d 20 00 00 lea 0x200d\(%rip\),%rax # 403014 <__bss_start> + +[a-f0-9]+: c3 ret + +[a-f0-9]+: 0f 1f 84 00 00 00 00 00 nopl 0x0\(%rax,%rax,1\) + +0+401010 : + +[a-f0-9]+: 48 8d 05 fd 1f 00 00 lea 0x1ffd\(%rip\),%rax # 403014 <__bss_start> + +[a-f0-9]+: c3 ret + +[a-f0-9]+: 0f 1f 84 00 00 00 00 00 nopl 0x0\(%rax,%rax,1\) + +0+401020 : + +[a-f0-9]+: 48 83 ec 28 sub \$0x28,%rsp + +[a-f0-9]+: e8 d7 ff ff ff call 401000 + +[a-f0-9]+: e8 e2 ff ff ff call 401010 + +[a-f0-9]+: 48 83 c4 28 add \$0x28,%rsp + +[a-f0-9]+: c3 ret +#pass diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-3a.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-3a.obj.bz2 new file mode 100644 index 00000000000..1c3e28d3cff Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-3a.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-3b.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-3b.obj.bz2 new file mode 100644 index 00000000000..2af616598e8 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-3b.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-3c.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-3c.obj.bz2 new file mode 100644 index 00000000000..821c01bde64 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-3c.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-3d.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-3d.obj.bz2 new file mode 100644 index 00000000000..173bb4116ad Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-3d.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-4.od b/ld/testsuite/ld-x86-64/pe-x86-64-4.od new file mode 100644 index 00000000000..e8940ba4fc0 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pe-x86-64-4.od @@ -0,0 +1,67 @@ + +.*: +file format .* + +SYMBOL TABLE: +0+401000 l d .text\$mn 0000000000000000 .text\$mn +0+402000 l d .xdata 0000000000000000 .xdata +0+402008 l d .pdata 0000000000000000 .pdata +0+403018 l d .data 0000000000000000 .data +0+403038 l d .bss 0000000000000000 .bss +0+ l d .debug\$S 0000000000000000 .debug\$S +0+403038 g .bss 0000000000000000 c +0+401000 g .text\$mn 0000000000000000 begin +0+403038 g .bss 0000000000000000 __bss_start +0+403018 g .data 0000000000000000 Struct +0+401020 g .text\$mn 0000000000000000 opti_O1 +0+403038 g .data 0000000000000000 _edata +0+403040 g .bss 0000000000000000 _end +0+401060 g .text\$mn 0000000000000000 opti_Od + + + +Disassembly of section .text\$mn: + +0+401000 : + +[a-f0-9]+: 48 83 ec 28 sub \$0x28,%rsp + +[a-f0-9]+: 48 c7 05 29 20 00 00 01 00 00 00 movq \$0x1,0x2029\(%rip\) # 403038 <__bss_start> + +[a-f0-9]+: e8 4c 00 00 00 call 401060 + +[a-f0-9]+: e8 07 00 00 00 call 401020 + +[a-f0-9]+: 48 83 c4 28 add \$0x28,%rsp + +[a-f0-9]+: c3 ret + +[a-f0-9]+: 66 90 xchg %ax,%ax + +0+401020 : + +[a-f0-9]+: b8 33 22 00 00 mov \$0x2233,%eax + +[a-f0-9]+: c6 05 ec 1f 00 00 12 movb \$0x12,0x1fec\(%rip\) # 403018 + +[a-f0-9]+: 66 89 05 e7 1f 00 00 mov %ax,0x1fe7\(%rip\) # 40301a + +[a-f0-9]+: 48 b8 99 99 99 99 88 88 88 88 movabs \$0x8888888899999999,%rax + +[a-f0-9]+: 48 89 05 dc 1f 00 00 mov %rax,0x1fdc\(%rip\) # 403020 + +[a-f0-9]+: 83 c8 ff or \$0xffffffff,%eax + +[a-f0-9]+: c7 05 cb 1f 00 00 55 55 44 44 movl \$0x44445555,0x1fcb\(%rip\) # 40301c + +[a-f0-9]+: c3 ret + +[a-f0-9]+: 66 2e 0f 1f 84 00 00 00 00 00 nopw %cs:0x0\(%rax,%rax,1\) + +[a-f0-9]+: 0f 1f 40 00 nopl 0x0\(%rax\) + +0+401060 : + +[a-f0-9]+: 48 89 4c 24 08 mov %rcx,0x8\(%rsp\) + +[a-f0-9]+: b8 10 00 00 00 mov \$0x10,%eax + +[a-f0-9]+: 48 6b c0 00 imul \$0x0,%rax,%rax + +[a-f0-9]+: 48 8d 0d a3 1f 00 00 lea 0x1fa3\(%rip\),%rcx # 403018 + +[a-f0-9]+: c6 04 01 11 movb \$0x11,\(%rcx,%rax,1\) + +[a-f0-9]+: b8 10 00 00 00 mov \$0x10,%eax + +[a-f0-9]+: 48 6b c0 00 imul \$0x0,%rax,%rax + +[a-f0-9]+: 48 8d 0d 8f 1f 00 00 lea 0x1f8f\(%rip\),%rcx # 403018 + +[a-f0-9]+: ba 22 22 00 00 mov \$0x2222,%edx + +[a-f0-9]+: 66 89 54 01 02 mov %dx,0x2\(%rcx,%rax,1\) + +[a-f0-9]+: b8 10 00 00 00 mov \$0x10,%eax + +[a-f0-9]+: 48 6b c0 00 imul \$0x0,%rax,%rax + +[a-f0-9]+: 48 8d 0d 75 1f 00 00 lea 0x1f75\(%rip\),%rcx # 403018 + +[a-f0-9]+: c7 44 01 04 44 44 44 44 movl \$0x44444444,0x4\(%rcx,%rax,1\) + +[a-f0-9]+: b8 10 00 00 00 mov \$0x10,%eax + +[a-f0-9]+: 48 6b c0 00 imul \$0x0,%rax,%rax + +[a-f0-9]+: 48 8d 0d 5d 1f 00 00 lea 0x1f5d\(%rip\),%rcx # 403018 + +[a-f0-9]+: 48 ba 88 88 88 88 88 88 88 88 movabs \$0x8888888888888888,%rdx + +[a-f0-9]+: 48 89 54 01 08 mov %rdx,0x8\(%rcx,%rax,1\) + +[a-f0-9]+: b8 ff ff ff ff mov \$0xffffffff,%eax + +[a-f0-9]+: c3 ret +#pass diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-4a.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-4a.obj.bz2 new file mode 100644 index 00000000000..99db1e8ff85 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-4a.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-4b.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-4b.obj.bz2 new file mode 100644 index 00000000000..2284cea3f87 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-4b.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-4c.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-4c.obj.bz2 new file mode 100644 index 00000000000..6b4efca9b56 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-4c.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64-4d.obj.bz2 b/ld/testsuite/ld-x86-64/pe-x86-64-4d.obj.bz2 new file mode 100644 index 00000000000..f2ac9d2d717 Binary files /dev/null and b/ld/testsuite/ld-x86-64/pe-x86-64-4d.obj.bz2 differ diff --git a/ld/testsuite/ld-x86-64/pe-x86-64.exp b/ld/testsuite/ld-x86-64/pe-x86-64.exp new file mode 100644 index 00000000000..74d06e015bb --- /dev/null +++ b/ld/testsuite/ld-x86-64/pe-x86-64.exp @@ -0,0 +1,66 @@ +# Expect script for ELF tests with pe-x86-64 inputs. +# Copyright (C) 2020 Free Software Foundation, Inc. +# +# This file is part of the GNU Binutils. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. +# + +# Only for Linux/x86-64. +if {![istarget "x86_64-*-linux*"] } { + return +} + +run_ld_link_tests [list \ + [list \ + "Build pe-x86-64-1" \ + "-m elf_x86_64 --entry=begin" \ + "" \ + "" \ + {pe-x86-64-1a.obj.bz2 pe-x86-64-1b.obj.bz2 pe-x86-64-1c.obj.bz2} \ + {{objdump {-dw --sym} pe-x86-64-1.od}} \ + "pe-x86-64-1" \ + ] \ + [list \ + "Build pe-x86-64-2" \ + "-m elf_x86_64 --entry=begin" \ + "" \ + "" \ + {pe-x86-64-2a.obj.bz2 pe-x86-64-2b.obj.bz2 pe-x86-64-2c.obj.bz2} \ + {{objdump {-dw --sym} pe-x86-64-2.od}} \ + "pe-x86-64-2" \ + ] \ + [list \ + "Build pe-x86-64-3" \ + "-m elf_x86_64 --entry=begin" \ + "" \ + "" \ + {pe-x86-64-3a.obj.bz2 pe-x86-64-3b.obj.bz2 pe-x86-64-3c.obj.bz2 \ + pe-x86-64-3d.obj.bz2 } \ + {{objdump {-dw --sym} pe-x86-64-3.od}} \ + "pe-x86-64-3" \ + ] \ + [list \ + "Build pe-x86-64-4" \ + "-m elf_x86_64 --entry=begin" \ + "" \ + "" \ + {pe-x86-64-4a.obj.bz2 pe-x86-64-4b.obj.bz2 pe-x86-64-4c.obj.bz2 \ + pe-x86-64-4d.obj.bz2 } \ + {{objdump {-dw --sym} pe-x86-64-4.od}} \ + "pe-x86-64-4" \ + ] \ +] diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp index 7972e8fd33c..e933be781b7 100644 --- a/ld/testsuite/lib/ld-lib.exp +++ b/ld/testsuite/lib/ld-lib.exp @@ -506,22 +506,34 @@ proc run_ld_link_tests { ldtests args } { # Assemble each file in the test. foreach src_file $src_files { set fileroot "[file rootname [file tail $src_file]]" - set objfile "tmpdir/$fileroot.o" - lappend objfiles $objfile - if { [file extension $src_file] == ".c" } { - set as_file "tmpdir/$fileroot.s" - if ![ld_compile "$CC -S $CFLAGS $cflags" $srcdir/$subdir/$src_file $as_file] { + if { [file extension $src_file] == ".bz2" } { + set objfile tmpdir/[file rootname $src_file] + set unbzip2 "system \"bzip2 -dc $srcdir/$subdir/$src_file > $objfile\"" + send_log "$unbzip2\n" + catch "$unbzip2" exec_output + if ![string match "" $exec_output] then { + send_log "$exec_output\n" set is_unresolved 1 break } } else { - set as_file "$srcdir/$subdir/$src_file" - } - if ![ld_assemble $as "$as_options $as_file" $objfile] { - set failed 1 - break + set objfile "tmpdir/$fileroot.o" + if { [file extension $src_file] == ".c" } { + set as_file "tmpdir/$fileroot.s" + if ![ld_compile "$CC -S $CFLAGS $cflags" $srcdir/$subdir/$src_file $as_file] { + set is_unresolved 1 + break + } + } else { + set as_file "$srcdir/$subdir/$src_file" + } + if ![ld_assemble $as "$as_options $as_file" $objfile] { + set failed 1 + break + } } + lappend objfiles $objfile } # Catch assembler errors.