From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andreas Kling <awesomekling@gmail.com>
Date: Mon, 16 May 2022 15:01:06 +0200
Subject: [PATCH] libgcc: Build for Minerva
This patch enables building gcc's own C runtime files, and sets up
exception handling support.
Co-Authored-By: Gunnar Beutner <gbeutner@serenityos.org>
Co-Authored-By: Itamar <itamar8910@gmail.com>
Co-Authored-By: Nico Weber <thakis@chromium.org>
Co-Authored-By: Andrew Kaster <andrewdkaster@gmail.com>
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
Co-Authored-By: Philip Herron <herron.philip@googlemail.com>
Co-Authored-By: Shannon Booth <shannon@serenityos.org>
---
gcc/configure | 3 +++
libgcc/config.host | 18 ++++++++++++++++++
libgcc/unwind-dw2-fde-dip.c | 6 ++++++
3 files changed, 27 insertions(+)
diff --git a/gcc/configure b/gcc/configure
index 16965953f05160ea4572957144f305cc0cce4e18..63fbeab1be55e2a9bf6718f8a6d826bb7ecf7d27 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -33648,6 +33648,9 @@ case "$target" in
*-linux-musl*)
gcc_cv_target_dl_iterate_phdr=yes
;;
+ *-minerva*)
+ gcc_cv_target_dl_iterate_phdr=yes
+ ;;
esac
if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
diff --git a/libgcc/config.host b/libgcc/config.host
index 6a88ee5a2dd0b1386b2a5f2fbb579953f8ce9441..5fc80843a52ba80469df05fd5162964c8d7ae322 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1358,6 +1358,11 @@ riscv*-*-freebsd*)
tmake_file="${tmake_file} riscv/t-crtstuff riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address} t-slibgcc-libgcc"
extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o crtendS.o crtbeginT.o"
;;
+riscv64-*-minerva*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtbeginS.o crtend.o crtendS.o crtn.o"
+ tmake_file="$tmake_file riscv/t-softfp64 t-softfp riscv/t-elf riscv/t-elf64 t-slibgcc-libgcc t-eh-dw2-dip"
+ tmake_file="$tmake_file riscv/t-crtstuff t-crtstuff-pic t-libgcc-pic t-slibgcc t-slibgcc-gld-nover"
+ ;;
riscv*-*-*)
tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address}"
extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o"
@@ -1571,6 +1576,19 @@ nvptx-*)
tmake_file="$tmake_file nvptx/t-nvptx"
extra_parts="crt0.o"
;;
+x86_64-*-minerva*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtbeginS.o crtend.o crtendS.o crtn.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic t-slibgcc t-eh-dw2-dip"
+ ;;
+aarch64-*-minerva*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtbeginS.o crtend.o crtendS.o crtn.o"
+ extra_parts="$extra_parts crtfastmath.o"
+ tmake_file="$tmake_file ${cpu_type}/t-aarch64"
+ tmake_file="$tmake_file ${cpu_type}/t-lse t-slibgcc t-slibgcc-libgcc t-slibgcc-gld-nover"
+ tmake_file="$tmake_file ${cpu_type}/t-softfp t-softfp t-crtfm"
+ md_unwind_def_header=aarch64/aarch64-unwind-def.h
+ md_unwind_header=aarch64/aarch64-unwind.h
+ ;;
*)
echo "*** Configuration ${host} not supported" 1>&2
exit 1
diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c
index 5c19838e0a3c34ea3b0420c552c0100276e5aab4..01138feee2a1c2c69a931c785a6f6614b7239c0f 100644
--- a/libgcc/unwind-dw2-fde-dip.c
+++ b/libgcc/unwind-dw2-fde-dip.c
@@ -57,6 +57,12 @@
# define USE_PT_GNU_EH_FRAME
#endif
+#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+ && defined(TARGET_DL_ITERATE_PHDR) \
+ && defined(__minerva__)
+# define USE_PT_GNU_EH_FRAME
+#endif
+
#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
&& defined(TARGET_DL_ITERATE_PHDR) \
&& defined(__linux__)