commit 3f0b1ef2e5aebf896033ee5f78635d349807fc08
Author: Sebastian Sumpf <sebastian.sumpf@genode-labs.com>
Date:   Wed May 3 14:15:07 2017 +0200

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 263739c..2bc831e 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1123,7 +1123,7 @@ arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems*)
 	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*-*-rtems*)

--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -671,11 +671,11 @@
 #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.  */

@@ -2064,7 +2064,7 @@ riscv*-*-elf*)
 	xyes) tmake_file="${tmake_file} riscv/t-elf-multilib" ;;
 	*) echo "Unknown value for enable_multilib"; exit 1
 	esac
-	tmake_file="${tmake_file} riscv/t-riscv"
+	tmake_file="${tmake_file} riscv/t-riscv t-slibgcc"
 	gnu_ld=yes
 	gas=yes
 	# Force .init_array support.  The configure script cannot always

diff --git a/gcc/config/arm/unknown-elf.h b/gcc/config/arm/unknown-elf.h
index fafe057..8bd23e0 100644
--- a/gcc/config/arm/unknown-elf.h
+++ b/gcc/config/arm/unknown-elf.h
@@ -98,3 +98,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 204f128..8f590fe 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 391e59f..9271e17 100644
--- a/gcc/config/riscv/elf.h
+++ b/gcc/config/riscv/elf.h
@@ -19,7 +19,8 @@ along with GCC; see the file COPYING3.  If not see
 
 #define LINK_SPEC "\
 -melf" XLEN_SPEC "lriscv \
-%{shared}"
+%{shared:-shared} \
+%{!static:--eh-frame-hdr}"
 
 /* Link against Newlib libraries, because the ELF backend assumes Newlib.
    Handle the circular dependence between libc and libgloss. */
diff --git a/libgcc/config.host b/libgcc/config.host
index 40e3038..fd206a4 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
 
@@ -417,8 +417,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"
@@ -588,6 +592,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"
 	;;
 i[34567]86-*-dragonfly*)
@@ -1104,8 +1112,8 @@ riscv*-*-linux*)
 	md_unwind_header=riscv/linux-unwind.h
 	;;
 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
