0003-libgcc-Add-basic-support-for-aarch64-gnu-GNU-Hurd-on.patch
@@ -0,0 +1,102 @@
+From fa1df4f95659b1b53bfbf82f936a687bf9af3191 Mon Sep 17 00:00:00 2001
+From: Sergey Bugaev <[email protected]>
+Date: Mon, 1 Jan 2024 14:41:35 +0300
+Subject: [PATCH 3/3] libgcc: Add basic support for aarch64-gnu (GNU/Hurd on
+ AArch64)
+
+There is currently no unwinding implementation.
+
+Signed-off-by: Sergey Bugaev <[email protected]>
+---
+ libgcc/config.host | 9 +++++++
+ libgcc/config/aarch64/gnu-unwind.h | 36 +++++++++++++++++++++++++
+ libgcc/config/aarch64/heap-trampoline.c | 4 +--
+ 3 files changed, 47 insertions(+), 2 deletions(-)
+ create mode 100644 libgcc/config/aarch64/gnu-unwind.h
+
+diff --git a/libgcc/config.host b/libgcc/config.host
+index 54d06978a..c5b4df2c5 100644
+--- a/libgcc/config.host
++++ b/libgcc/config.host
+@@ -448,6 +448,15 @@ aarch64*-*-linux*)
+ tmake_file="${tmake_file} t-dfprules"
+ tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline"
+ ;;
++aarch64*-*-gnu*)
++ extra_parts="$extra_parts crtfastmath.o"
++ md_unwind_header=aarch64/gnu-unwind.h
++ tmake_file="${tmake_file} ${cpu_type}/t-aarch64"
++ tmake_file="${tmake_file} ${cpu_type}/t-lse t-slibgcc-libgcc"
++ tmake_file="${tmake_file} ${cpu_type}/t-softfp t-softfp t-crtfm"
++ tmake_file="${tmake_file} t-dfprules"
++ tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline"
++ ;;
+ aarch64*-*-vxworks7*)
+ extra_parts="$extra_parts crtfastmath.o"
+ md_unwind_header=aarch64/aarch64-unwind.h
+diff --git a/libgcc/config/aarch64/gnu-unwind.h b/libgcc/config/aarch64/gnu-unwind.h
+new file mode 100644
+index 000000000..d9e485a18
+--- /dev/null
++++ b/libgcc/config/aarch64/gnu-unwind.h
+@@ -0,0 +1,36 @@
++/* DWARF2 EH unwinding support for GNU Hurd: aarch64.
++ Copyright (C) 2020-2024 Free Software Foundation, Inc.
++
++This file is part of GCC.
++
++GCC 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, or (at your option)
++any later version.
++
++GCC 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.
++
++Under Section 7 of GPL version 3, you are granted additional
++permissions described in the GCC Runtime Library Exception, version
++3.1, as published by the Free Software Foundation.
++
++You should have received a copy of the GNU General Public License and
++a copy of the GCC Runtime Library Exception along with this program;
++see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
++<http://www.gnu.org/licenses/>. */
++
++/* Always include AArch64 unwinder header file. */
++#include "config/aarch64/aarch64-unwind.h"
++
++#ifndef inhibit_libc
++
++#include <signal.h>
++
++/*
++ * TODO: support for aarch64 needs to be implemented.
++ */
++
++#endif /* ifndef inhibit_libc */
+diff --git a/libgcc/config/aarch64/heap-trampoline.c b/libgcc/config/aarch64/heap-trampoline.c
+index f22233987..6565584c7 100644
+--- a/libgcc/config/aarch64/heap-trampoline.c
++++ b/libgcc/config/aarch64/heap-trampoline.c
+@@ -23,7 +23,7 @@ void *allocate_trampoline_page (void);
+ void __builtin_nested_func_ptr_created (void *chain, void *func, void **dst);
+ void __builtin_nested_func_ptr_deleted (void);
+
+-#if defined(__gnu_linux__)
++#if defined(__gnu_linux__) || defined(__gnu_hurd__)
+ static const uint32_t aarch64_trampoline_insns[] = {
+ 0xd503245f, /* hint 34 */
+ 0x580000b1, /* ldr x17, .+20 */
+@@ -76,7 +76,7 @@ allocate_trampoline_page (void)
+ {
+ void *page;
+
+-#if defined(__gnu_linux__)
++#if defined(__gnu_linux__) || defined(__gnu_hurd__)
+ page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC,
+ MAP_ANON | MAP_PRIVATE, 0, 0);
+ #elif __APPLE__
+--
+2.44.0
0001-Move-GNU-Hurd-startfile-spec-from-config-i386-gnu.h-.patch
@@ -0,0 +1,68 @@
+From f7dc70f22093b575f5a37eb811b4f881155d3bc7 Mon Sep 17 00:00:00 2001
+From: Sergey Bugaev <[email protected]>
+Date: Mon, 1 Jan 2024 14:23:41 +0300
+Subject: [PATCH 1/3] Move GNU/Hurd startfile spec from config/i386/gnu.h to
+ config/gnu.h
+
+Since it's not i386-specific; this makes it possible to reuse it for other
+architectures.
+
+Also, add a warning for the case gnu.h is specified before gnu-user.h, which
+would cause gnu-user's version of the spec to override gnu's, and not the other
+way around as it's intended. The i?86-gnu target currently specifies them in
+the right order, but it's easy to accidentally put them in a wrong order.
+
+Signed-off-by: Sergey Bugaev <[email protected]>
+---
+ gcc/config/gnu.h | 16 ++++++++++++++++
+ gcc/config/i386/gnu.h | 11 -----------
+ 2 files changed, 16 insertions(+), 11 deletions(-)
+
+diff --git a/gcc/config/gnu.h b/gcc/config/gnu.h
+index 97baea939..89904cd9b 100644
+--- a/gcc/config/gnu.h
++++ b/gcc/config/gnu.h
+@@ -31,3 +31,19 @@ along with GCC. If not, see <http://www.gnu.org/licenses/>.
+ builtin_assert ("system=unix"); \
+ builtin_assert ("system=posix"); \
+ } while (0)
++
++
++#ifndef GNU_USER_TARGET_STARTFILE_SPEC
++# warning This file should be included after gnu-user.h, to override its STARTFILE_SPEC
++#endif
++
++#undef STARTFILE_SPEC
++#if defined HAVE_LD_PIE
++#define STARTFILE_SPEC \
++ "%{!shared: %{pg|p|profile:%{static-pie:grcrt0.o%s;static:gcrt0.o%s;:gcrt1.o%s};static-pie:rcrt0.o%s;static:crt0.o%s;" PIE_SPEC ":Scrt1.o%s;:crt1.o%s}} \
++ crti.o%s %{static:crtbeginT.o%s;shared|static-pie|" PIE_SPEC ":crtbeginS.o%s;:crtbegin.o%s}"
++#else
++#define STARTFILE_SPEC \
++ "%{!shared: %{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};static:crt0.o%s;:crt1.o%s}} \
++ crti.o%s %{static:crtbeginT.o%s;shared:crtbeginS.o%s;:crtbegin.o%s}"
++#endif
+diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h
+index e776144f9..60244bfc8 100644
+--- a/gcc/config/i386/gnu.h
++++ b/gcc/config/i386/gnu.h
+@@ -24,17 +24,6 @@ along with GCC. If not, see <http://www.gnu.org/licenses/>.
+ #undef GNU_USER_DYNAMIC_LINKER
+ #define GNU_USER_DYNAMIC_LINKER "/lib/ld.so"
+
+-#undef STARTFILE_SPEC
+-#if defined HAVE_LD_PIE
+-#define STARTFILE_SPEC \
+- "%{!shared: %{pg|p|profile:%{static-pie:grcrt0.o%s;static:gcrt0.o%s;:gcrt1.o%s};static-pie:rcrt0.o%s;static:crt0.o%s;" PIE_SPEC ":Scrt1.o%s;:crt1.o%s}} \
+- crti.o%s %{static:crtbeginT.o%s;shared|static-pie|" PIE_SPEC ":crtbeginS.o%s;:crtbegin.o%s}"
+-#else
+-#define STARTFILE_SPEC \
+- "%{!shared: %{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};static:crt0.o%s;:crt1.o%s}} \
+- crti.o%s %{static:crtbeginT.o%s;shared:crtbeginS.o%s;:crtbegin.o%s}"
+-#endif
+-
+ #ifdef TARGET_LIBC_PROVIDES_SSP
+
+ /* i386 glibc provides __stack_chk_guard in %gs:0x14. */
+--
+2.44.0
0002-aarch64-Add-support-for-aarch64-gnu-GNU-Hurd-on-AArc.patch
@@ -0,0 +1,109 @@
+From 72d07d459d1a9a011683c5344e46c9847efec845 Mon Sep 17 00:00:00 2001
+From: Sergey Bugaev <[email protected]>
+Date: Mon, 1 Jan 2024 14:33:44 +0300
+Subject: [PATCH 2/3] aarch64: Add support for aarch64-gnu (GNU/Hurd on
+ AArch64)
+
+Coupled with a corresponding binutils patch, this produces a toolchain that can
+sucessfully build working binaries targeting aarch64-gnu.
+
+Signed-off-by: Sergey Bugaev <[email protected]>
+---
+ gcc/config.gcc | 6 +++
+ gcc/config/aarch64/aarch64-gnu.h | 68 ++++++++++++++++++++++++++++++++
+ 2 files changed, 74 insertions(+)
+ create mode 100644 gcc/config/aarch64/aarch64-gnu.h
+
+diff --git a/gcc/config.gcc b/gcc/config.gcc
+index f0676c830..d8dd127ad 100644
+--- a/gcc/config.gcc
++++ b/gcc/config.gcc
+@@ -1263,6 +1263,12 @@ aarch64*-*-linux*)
+ done
+ TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
+ ;;
++aarch64*-*-gnu*)
++ tm_file="${tm_file} elfos.h gnu-user.h gnu.h glibc-stdint.h"
++ tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-gnu.h"
++ tmake_file="${tmake_file} aarch64/t-aarch64"
++ tm_defines="${tm_defines} TARGET_DEFAULT_ASYNC_UNWIND_TABLES=1"
++ ;;
+ aarch64*-wrs-vxworks*)
+ tm_file="${tm_file} elfos.h aarch64/aarch64-elf.h"
+ tm_file="${tm_file} vx-common.h vxworks.h aarch64/aarch64-vxworks.h"
+diff --git a/gcc/config/aarch64/aarch64-gnu.h b/gcc/config/aarch64/aarch64-gnu.h
+new file mode 100644
+index 000000000..ee5494034
+--- /dev/null
++++ b/gcc/config/aarch64/aarch64-gnu.h
+@@ -0,0 +1,68 @@
++/* Definitions for AArch64 running GNU/Hurd.
++ Copyright (C) 2009-2024 Free Software Foundation, Inc.
++
++ This file is part of GCC.
++
++ GCC 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, or (at your option)
++ any later version.
++
++ GCC 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 GCC; see the file COPYING3. If not see
++ <http://www.gnu.org/licenses/>. */
++
++#ifndef GCC_AARCH64_GNU_H
++#define GCC_AARCH64_GNU_H
++
++#define GNU_USER_DYNAMIC_LINKER "/lib/ld-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
++
++#define CPP_SPEC "%{pthread:-D_REENTRANT}"
++
++#define GNU_TARGET_LINK_SPEC "%{h*} \
++ %{static:-Bstatic} \
++ %{shared:-shared} \
++ %{symbolic:-Bsymbolic} \
++ %{!static:%{!static-pie: \
++ %{rdynamic:-export-dynamic} \
++ %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}} \
++ %{static-pie:-Bstatic -pie --no-dynamic-linker -z text} \
++ -X \
++ %{mbig-endian:-EB} %{mlittle-endian:-EL} \
++ -maarch64gnu%{mabi=ilp32:32}%{mbig-endian:b}"
++
++
++#define LINK_SPEC GNU_TARGET_LINK_SPEC AARCH64_ERRATA_LINK_SPEC
++
++#define GNU_USER_TARGET_MATHFILE_SPEC \
++ "%{Ofast|ffast-math|funsafe-math-optimizations:%{!shared:crtfastmath.o%s}}"
++
++#undef ENDFILE_SPEC
++#define ENDFILE_SPEC \
++ GNU_USER_TARGET_MATHFILE_SPEC " " \
++ GNU_USER_TARGET_ENDFILE_SPEC
++
++#define TARGET_OS_CPP_BUILTINS() \
++ do \
++ { \
++ GNU_USER_TARGET_OS_CPP_BUILTINS(); \
++ } \
++ while (0)
++
++#define TARGET_ASM_FILE_END aarch64_file_end_indicate_exec_stack
++
++/* Uninitialized common symbols in non-PIE executables, even with
++ strong definitions in dependent shared libraries, will resolve
++ to COPY relocated symbol in the executable. See PR65780. */
++#undef TARGET_BINDS_LOCAL_P
++#define TARGET_BINDS_LOCAL_P default_binds_local_p_2
++
++/* Define this to be nonzero if static stack checking is supported. */
++#define STACK_CHECK_STATIC_BUILTIN 1
++
++#endif /* GCC_AARCH64_GNU_H */
+--
+2.44.0