config.patch

From: Sebastian Sumpf <sebastian.sumpf@genode-labs.com>
---
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 7af8e028..3c87dfb0 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1184,7 +1184,7 @@ arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems* | arm*-*-fuchsia*)
 	case ${target} in
 	arm*-*-eabi*)
 	  tm_file="$tm_file newlib-stdint.h"
-	  tmake_file="${tmake_file} arm/t-bpabi"
+	  tmake_file="${tmake_file} arm/t-bpabi t-slibgcc"
 	  use_gcc_stdint=wrap
 	  ;;
 	arm*-*-fuchsia*)
diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index 942bb4ca..c36b8eea 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -668,11 +668,11 @@ extern int arm_arch_cmse;
 #define MAX_FIXED_MODE_SIZE 64
 
 #ifndef SIZE_TYPE
-#define SIZE_TYPE (TARGET_AAPCS_BASED ? "unsigned int" : "long unsigned int")
+#define SIZE_TYPE (TARGET_AAPCS_BASED ? "long unsigned int" : "long unsigned int")
 #endif
 
 #ifndef PTRDIFF_TYPE
-#define PTRDIFF_TYPE (TARGET_AAPCS_BASED ? "int" : "long int")
+#define PTRDIFF_TYPE (TARGET_AAPCS_BASED ? "long int" : "long int")
 #endif
 
 /* AAPCS requires that structure alignment is affected by bitfields.  */
diff --git a/gcc/config/arm/unknown-elf.h b/gcc/config/arm/unknown-elf.h
index 12dd0931..ec0a72e7 100644
--- a/gcc/config/arm/unknown-elf.h
+++ b/gcc/config/arm/unknown-elf.h
@@ -94,3 +94,19 @@
    which will depend on abort, which is defined in libc.  */ 
 #undef LINK_GCC_C_SEQUENCE_SPEC
 #define LINK_GCC_C_SEQUENCE_SPEC "--start-group %G %L --end-group"
+
+/* genode.h */
+
+/*
+ * The 'LINK_SPEC' define comprises the rules of how the GCC frontend invokes
+ * the linker.
+ */
+
+#undef LINK_SPEC
+#define LINK_SPEC \
+  "%(shared:-shared) \
+   %{!static:--eh-frame-hdr}"
+
+/* Don't assume anything about the header files.  */
+/* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57699 */
+#define NO_IMPLICIT_EXTERN_C
diff --git a/gcc/config/i386/x86-64.h b/gcc/config/i386/x86-64.h
index e2a8306c..1c5e2e15 100644
--- a/gcc/config/i386/x86-64.h
+++ b/gcc/config/i386/x86-64.h
@@ -37,10 +37,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define MCOUNT_NAME "mcount"
 
 #undef SIZE_TYPE
-#define SIZE_TYPE (TARGET_LP64 ? "long unsigned int" : "unsigned int")
+#define SIZE_TYPE (TARGET_LP64 ? "long unsigned int" : "long unsigned int")
 
 #undef PTRDIFF_TYPE
-#define PTRDIFF_TYPE (TARGET_LP64 ? "long int" : "int")
+#define PTRDIFF_TYPE (TARGET_LP64 ? "long int" : "long int")
 
 #undef WCHAR_TYPE
 #define WCHAR_TYPE "int"
@@ -106,3 +106,22 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #undef TARGET_SECTION_TYPE_FLAGS
 #define TARGET_SECTION_TYPE_FLAGS  x86_64_elf_section_type_flags
+
+/* genode64.h */
+
+/*
+ * The 'LINK_SPEC' macro expresses the policy of how the GCC
+ * frontend invokes 'ld' on multiarch platforms. I.e., on x86, we need to pass
+ * '-melf_i386' to 'ld' when building in '-m32' mode.
+ */
+
+#undef LINK_SPEC
+#define LINK_SPEC \
+  "%{!m32:-m elf_x86_64} \
+   %{m32:-m elf_i386} \
+   %{shared:-shared} \
+   %{!static:--eh-frame-hdr}"
+
+/* Don't assume anything about the header files.  */
+/* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57699 */
+#define NO_IMPLICIT_EXTERN_C
diff --git a/gcc/config/riscv/elf.h b/gcc/config/riscv/elf.h
index a8357bb6..cd33bb28 100644
--- a/gcc/config/riscv/elf.h
+++ b/gcc/config/riscv/elf.h
@@ -17,10 +17,12 @@ 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 LINK_SPEC
 #define LINK_SPEC "\
 -melf" XLEN_SPEC "lriscv \
 %{mno-relax:--no-relax} \
 %{shared}"
+#endif
 
 /* Link against Newlib libraries, because the ELF backend assumes Newlib.
    Handle the circular dependence between libc and libgloss. */
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 62279ff2..fdf77645 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -819,10 +819,10 @@ while (0)
 #define ASM_COMMENT_START "#"
 
 #undef SIZE_TYPE
-#define SIZE_TYPE (POINTER_SIZE == 64 ? "long unsigned int" : "unsigned int")
+#define SIZE_TYPE (POINTER_SIZE == 64 ? "long unsigned int" : "long unsigned int")
 
 #undef PTRDIFF_TYPE
-#define PTRDIFF_TYPE (POINTER_SIZE == 64 ? "long int" : "int")
+#define PTRDIFF_TYPE (POINTER_SIZE == 64 ? "long int" : "long int")
 
 /* The maximum number of bytes copied by one iteration of a movmemsi loop.  */
 
@@ -902,4 +902,17 @@ extern unsigned riscv_stack_boundary;
 #define SWSP_REACH (4LL << C_SxSP_BITS)
 #define SDSP_REACH (8LL << C_SxSP_BITS)
 
+ /* genode.h */
+
+/*
+ * The 'LINK_SPEC' define comprises the rules of how the GCC frontend invokes
+ * the linker
+ */
+#undef LINK_SPEC
+#define LINK_SPEC " \
+-melf" XLEN_SPEC "lriscv \
+  %{mno-relax:--no-relax} \
+  %(shared:-shared) \
+     %{!static:--eh-frame-hdr}"
+
 #endif /* ! GCC_RISCV_H */
diff --git a/libgcc/config.host b/libgcc/config.host
index 11b4acaf..5e9cfa86 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -312,7 +312,7 @@ case ${host} in
   tmake_file=t-vxworks
   ;;
 *-*-elf)
-  extra_parts="crtbegin.o crtend.o"
+  extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o"
   ;;
 esac
 
@@ -449,8 +449,12 @@ arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems*)
 	tm_file="$tm_file arm/bpabi-lib.h"
 	case ${host} in
 	arm*-*-eabi* | arm*-*-rtems*)
+	  # The 't-slibgcc' tmake file is needed to have libgcc_eh.a built.
+	  # The 't-eh-dw2-dip' tmake file is needed to let the tool chain use 'unwind-dw2-fde-dip.c',
+	  # needed for the exception handling on Genode in the presence of shared libraries.
+	  tmake_file="${tmake_file} t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver"
 	  tmake_file="${tmake_file} arm/t-bpabi t-crtfm"
-	  extra_parts="crtbegin.o crtend.o crti.o crtn.o"
+	  extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o"
 	  ;;
 	arm*-*-symbianelf*)
 	  tmake_file="${tmake_file} arm/t-symbian t-slibgcc-nolc-override"
@@ -610,6 +614,10 @@ i[34567]86-*-elf*)
 	tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
 	;;
 x86_64-*-elf* | x86_64-*-rtems*)
+	# The 't-slibgcc' tmake file is needed to have libgcc_eh.a built.
+	# The 't-eh-dw2-dip' tmake file is needed to let the tool chain use 'unwind-dw2-fde-dip.c',
+	# needed for the exception handling on Genode in the presence of shared libraries.
+	tmake_file="$tmake_file t-eh-dw2-dip t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver"
 	tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
 	;;
 x86_64-*-fuchsia*)
@@ -1133,8 +1141,8 @@ riscv*-*-freebsd*)
 	extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o crtendS.o crtbeginT.o"
 	;;
 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"
+	tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address} t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver"
+	extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o"
 	;;
 rs6000-ibm-aix4.[3456789]* | powerpc-ibm-aix4.[3456789]*)
 	md_unwind_header=rs6000/aix-unwind.h
