[binutils] Add support for the aarch64-gnu target (GNU/Hurd on AArch64)

Message ID 20240101115309.614317-1-bugaevc@gmail.com
State Accepted
Headers
Series [binutils] Add support for the aarch64-gnu target (GNU/Hurd on AArch64) |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Sergey Bugaev Jan. 1, 2024, 11:53 a.m. UTC
  Also recognized are aarch64-*-gnu tagrets, e.g. aarch64-pc-gnu or
aarch64-unknown-gnu.

The ld/emulparams/aarch64gnu.sh file is (for now) identical to aarch64fbsd.sh,
or to aarch64linux.sh with Linux-specific logic removed; and mainly different
from the generic aarch64elf.sh in that it does not set EMBEDDED=yes.

Coupled with a corresponding GCC patch, this produces a toolchain that can
sucessfully build working binaries targeting aarch64-gnu.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 bfd/config.bfd              |  2 +-
 gas/configure.tgt           |  1 +
 ld/configure.tgt            |  5 +++++
 ld/emulparams/aarch64gnu.sh | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 ld/emulparams/aarch64gnu.sh
  

Comments

Nick Clifton Jan. 5, 2024, 3:35 p.m. UTC | #1
Hi Sergey,

> Also recognized are aarch64-*-gnu tagrets, e.g. aarch64-pc-gnu or
> aarch64-unknown-gnu.
> 
> The ld/emulparams/aarch64gnu.sh file is (for now) identical to aarch64fbsd.sh,
> or to aarch64linux.sh with Linux-specific logic removed; and mainly different
> from the generic aarch64elf.sh in that it does not set EMBEDDED=yes.
> 
> Coupled with a corresponding GCC patch, this produces a toolchain that can
> sucessfully build working binaries targeting aarch64-gnu.
  Approved - please apply.

Cheers
   Nick
  
Samuel Thibault Jan. 5, 2024, 10:45 p.m. UTC | #2
Hello,

Nick Clifton, le ven. 05 janv. 2024 15:35:24 +0000, a ecrit:
> Hi Sergey,
> 
> > Also recognized are aarch64-*-gnu tagrets, e.g. aarch64-pc-gnu or
> > aarch64-unknown-gnu.
> > 
> > The ld/emulparams/aarch64gnu.sh file is (for now) identical to aarch64fbsd.sh,
> > or to aarch64linux.sh with Linux-specific logic removed; and mainly different
> > from the generic aarch64elf.sh in that it does not set EMBEDDED=yes.
> > 
> > Coupled with a corresponding GCC patch, this produces a toolchain that can
> > sucessfully build working binaries targeting aarch64-gnu.
>  Approved - please apply.

We don't have commit access, please commit it, thanks ;)

Samuel
  
Nick Clifton Jan. 8, 2024, 9:52 a.m. UTC | #3
Hi Samuel,

>>   Approved - please apply.
> 
> We don't have commit access, please commit it, thanks ;)

Done. :-)

Cheers
   Nick
  

Patch

diff --git a/bfd/config.bfd b/bfd/config.bfd
index 4106924e..9f3d4d46 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -284,7 +284,7 @@  case "${targ}" in
     targ_selvecs="aarch64_elf64_be_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_le_vec arm_elf32_be_vec"
     want64=true
     ;;
-  aarch64-*-linux* | aarch64-*-netbsd* | aarch64-*-nto*)
+  aarch64-*-linux* | aarch64-*-netbsd* | aarch64-*-nto* | aarch64-*-gnu*)
     targ_defvec=aarch64_elf64_le_vec
     targ_selvecs="aarch64_elf64_be_vec aarch64_elf32_le_vec aarch64_elf32_be_vec arm_elf32_le_vec arm_elf32_be_vec aarch64_pei_le_vec aarch64_pe_le_vec"
     want64=true
diff --git a/gas/configure.tgt b/gas/configure.tgt
index 3a582ef4..15c1ed3d 100644
--- a/gas/configure.tgt
+++ b/gas/configure.tgt
@@ -134,6 +134,7 @@  case ${generic_target} in
     case ${cpu}-${os} in
       aarch64*-linux-gnu_ilp32)		arch=aarch64:32 ;;
     esac ;;
+  aarch64*-*-gnu*)			fmt=elf em=gnu ;;
   aarch64*-*-netbsd*)			fmt=elf em=nbsd;;
   aarch64*-*-nto*)			fmt=elf;;
   aarch64*-*-openbsd*)			fmt=elf;;
diff --git a/ld/configure.tgt b/ld/configure.tgt
index afd43032..211a2dee 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -116,6 +116,11 @@  aarch64-*-linux*)	targ_emul=aarch64linux
 			targ_extra_libpath="aarch64linuxb aarch64linux32 aarch64linux32b armelfb_linux_eabi armelf_linux_eabi"
 			targ_extra_emuls="aarch64elf aarch64elf32 aarch64elf32b aarch64elfb armelf armelfb $targ_extra_libpath"
 			;;
+# This has to come after aarch64-*-linux* for aarch64-*-linux-gnu to hit the Linux branch.
+aarch64-*-gnu*)
+			targ_emul=aarch64gnu
+			targ_extra_emuls="aarch64elf aarch64elfb armelf armelfb"
+			;;
 aarch64-*-haiku*)	targ_emul=aarch64haiku
 			targ_extra_emuls="aarch64elf aarch64elf32 aarch64elf32b aarch64elfb armelf armelfb armelf_haiku $targ_extra_libpath"
 			;;
diff --git a/ld/emulparams/aarch64gnu.sh b/ld/emulparams/aarch64gnu.sh
new file mode 100644
index 00000000..0bcab7a4
--- /dev/null
+++ b/ld/emulparams/aarch64gnu.sh
@@ -0,0 +1,37 @@ 
+ARCH=aarch64
+MACHINE=
+NOP=0x1f2003d5
+
+SCRIPT_NAME=elf
+ELFSIZE=64
+OUTPUT_FORMAT="elf64-littleaarch64"
+BIG_OUTPUT_FORMAT="elf64-bigaarch64"
+LITTLE_OUTPUT_FORMAT="elf64-littleaarch64"
+NO_REL_RELOCS=yes
+
+TEMPLATE_NAME=elf
+EXTRA_EM_FILE=aarch64elf
+
+GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
+
+MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
+COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
+SEPARATE_GOTPLT=24
+IREL_IN_PLT=
+
+TEXT_START_ADDR=0x400000
+
+DATA_START_SYMBOLS='PROVIDE (__data_start = .);';
+
+# AArch64 does not support .s* sections.
+NO_SMALL_DATA=yes
+
+OTHER_BSS_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__bss_start__ = .${CREATE_SHLIB+)};"
+OTHER_BSS_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}_bss_end__ = .${CREATE_SHLIB+)}; ${CREATE_SHLIB+PROVIDE (}__bss_end__ = .${CREATE_SHLIB+)};"
+OTHER_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__end__ = .${CREATE_SHLIB+)};"
+
+OTHER_SECTIONS='.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }'
+ATTRS_SECTIONS='.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }'
+# Ensure each PLT entry is aligned to a cache line.
+PLT=".plt          ${RELOCATING-0} : ALIGN(16) { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} }"