aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorMark Harmstone <mark@harmstone.com>2023-01-05 02:36:32 +0000
committerMark Harmstone <mark@harmstone.com>2023-01-10 23:30:49 +0000
commit16fea92ccd993fce6b5b0efebe059d542cad9932 (patch)
tree59a1531c16963593e8b5d07f89b2525a0d00df3a /ld
parent528e4f463f511b11ad414bc91bcf89c4fb53c352 (diff)
downloadgdb-16fea92ccd993fce6b5b0efebe059d542cad9932.zip
gdb-16fea92ccd993fce6b5b0efebe059d542cad9932.tar.gz
gdb-16fea92ccd993fce6b5b0efebe059d542cad9932.tar.bz2
Add aarch64-w64-mingw32 target
This adds a mingw target for aarch64, including windres and dlltool. Note that the old value of jmp_aarch64_bytes was wrong, and this does the same thing as MSVC does.
Diffstat (limited to 'ld')
-rw-r--r--ld/configure.tgt4
-rw-r--r--ld/emultempl/pep.em11
-rw-r--r--ld/pe-dll.c12
-rw-r--r--ld/testsuite/ld-pe/pe-aarch64.d13
-rw-r--r--ld/testsuite/ld-pe/pe.exp2
-rw-r--r--ld/testsuite/ld-scripts/weak.exp1
6 files changed, 28 insertions, 15 deletions
diff --git a/ld/configure.tgt b/ld/configure.tgt
index aa74d25..4f9a61f 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -118,10 +118,10 @@ aarch64-*-linux*) targ_emul=aarch64linux
aarch64-*-haiku*) targ_emul=aarch64haiku
targ_extra_emuls="aarch64elf aarch64elf32 aarch64elf32b aarch64elfb armelf armelfb armelf_haiku $targ_extra_libpath"
;;
-aarch64-*-pe*)
+aarch64-*-pe* | aarch64-*-mingw*)
targ_emul=aarch64pe
targ_extra_emuls="arm64pe"
- targ_extra_ofiles="deffilep.o pep-dll-aarch64.o"
+ targ_extra_ofiles="deffilep.o pep-dll-aarch64.o pe-dll.o"
;;
alpha*-*-freebsd* | alpha*-*-kfreebsd*-gnu)
targ_emul=elf64alpha_fbsd
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 6ac70f9..f0e678b 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -121,7 +121,7 @@ fragment <<EOF
#define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
#endif
-#ifdef TARGET_IS_i386pep
+#if defined(TARGET_IS_i386pep) || defined(COFF_WITH_peAArch64)
#define DLL_SUPPORT
#endif
@@ -130,7 +130,7 @@ fragment <<EOF
| IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA \
| IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)
-#if defined(TARGET_IS_i386pep) || ! defined(DLL_SUPPORT)
+#if defined(TARGET_IS_i386pep) || defined(COFF_WITH_peAArch64) || ! defined(DLL_SUPPORT)
#define PE_DEF_SUBSYSTEM 3
#undef NT_EXE_IMAGE_BASE
#define NT_EXE_IMAGE_BASE \
@@ -1222,6 +1222,7 @@ make_import_fixup (arelent *rel, asection *s, char *name, const char *symname)
else if (suc)
_addend = bfd_get_16 (s->owner, addend);
break;
+ case 26:
case 32:
suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 4);
if (suc && rel->howto->pc_relative)
@@ -1577,14 +1578,14 @@ gld${EMULATION_NAME}_after_open (void)
if (pep_enable_stdcall_fixup) /* -1=warn or 1=enable */
pep_fixup_stdcalls ();
-#ifndef TARGET_IS_i386pep
+#if !defined(TARGET_IS_i386pep) && !defined(COFF_WITH_peAArch64)
if (bfd_link_pic (&link_info))
#else
if (!bfd_link_relocatable (&link_info))
#endif
pep_dll_build_sections (link_info.output_bfd, &link_info);
-#ifndef TARGET_IS_i386pep
+#if !defined(TARGET_IS_i386pep) && !defined(COFF_WITH_peAArch64)
else
pep_exe_build_sections (link_info.output_bfd, &link_info);
#endif
@@ -1880,6 +1881,8 @@ gld${EMULATION_NAME}_recognized_file (lang_input_statement_type *entry ATTRIBUTE
#ifdef DLL_SUPPORT
#ifdef TARGET_IS_i386pep
pep_dll_id_target ("pei-x86-64");
+#elif defined(COFF_WITH_peAArch64)
+ pep_dll_id_target ("pei-aarch64-little");
#endif
if (pep_bfd_is_dll (entry->the_bfd))
return pep_implied_import_dll (entry->filename);
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index de876ca..a2584c3 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -2257,13 +2257,12 @@ static const unsigned char jmp_ix86_bytes[] =
0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90
};
-/* _function:
- b <__imp_function>
- nop */
static const unsigned char jmp_aarch64_bytes[] =
{
- 0x00, 0x00, 0x00, 0x14,
- 0x1f, 0x20, 0x03, 0xD5
+ 0x10, 0x00, 0x00, 0x90, /* adrp x16, 0 */
+ 0x10, 0x02, 0x00, 0x91, /* add x16, x16, #0x0 */
+ 0x10, 0x02, 0x40, 0xf9, /* ldr x16, [x16] */
+ 0x00, 0x02, 0x1f, 0xd6 /* br x16 */
};
/* _function:
@@ -2431,7 +2430,8 @@ make_one (def_file_export *exp, bfd *parent, bool include_jmp_stub)
quick_reloc (abfd, 8, BFD_RELOC_32, 2);
break;
case PE_ARCH_aarch64:
- quick_reloc (abfd, 0, BFD_RELOC_AARCH64_JUMP26, 2);
+ quick_reloc (abfd, 0, BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL, 2);
+ quick_reloc (abfd, 4, BFD_RELOC_AARCH64_ADD_LO12, 2);
break;
default:
abort ();
diff --git a/ld/testsuite/ld-pe/pe-aarch64.d b/ld/testsuite/ld-pe/pe-aarch64.d
index fac02b5..ab6370f 100644
--- a/ld/testsuite/ld-pe/pe-aarch64.d
+++ b/ld/testsuite/ld-pe/pe-aarch64.d
@@ -6,11 +6,20 @@
Disassembly of section .text:
-0000000140001000 <__rt_psrelocs_end>:
+0000000140001000 <___crt_xc_end__>:
140001000: d2800281 mov x1, #0x14 // #20
140001004: 14000001 b 140001008 <foo>
0000000140001008 <foo>:
140001008: d65f03c0 ret
14000100c: 00000000 udf #0
-#...
+
+0000000140001010 <__CTOR_LIST__>:
+ 140001010: ffffffff .inst 0xffffffff ; undefined
+ 140001014: ffffffff .inst 0xffffffff ; undefined
+ ...
+
+0000000140001020 <__DTOR_LIST__>:
+ 140001020: ffffffff .inst 0xffffffff ; undefined
+ 140001024: ffffffff .inst 0xffffffff ; undefined
+ ...
diff --git a/ld/testsuite/ld-pe/pe.exp b/ld/testsuite/ld-pe/pe.exp
index dae8c34..c4d48bb 100644
--- a/ld/testsuite/ld-pe/pe.exp
+++ b/ld/testsuite/ld-pe/pe.exp
@@ -78,7 +78,7 @@ if {[istarget i*86-*-cygwin*]
run_ld_link_tests $pe_tests
}
-if {[istarget "aarch64-*-pe*"]} {
+if {[istarget "aarch64-*-pe*"] || [istarget "aarch64-*-mingw*"]} {
run_dump_test "pe-aarch64"
set pe_tests {
diff --git a/ld/testsuite/ld-scripts/weak.exp b/ld/testsuite/ld-scripts/weak.exp
index 78d0616..bf6f886 100644
--- a/ld/testsuite/ld-scripts/weak.exp
+++ b/ld/testsuite/ld-scripts/weak.exp
@@ -31,6 +31,7 @@ if {! [is_elf_format] && ! [is_pecoff_format]} {
# Weak symbols are broken for most PE targets.
if {! [istarget i?86-*-*] && ! [istarget sh-*-*]} {
setup_xfail *-*-pe*
+ setup_xfail *-*-mingw*
}
# hppa64 is incredibly broken