--- gcc/config/dragonfly.h.orig
+++ gcc/config/dragonfly.h
@@ -84,7 +84,7 @@
    } \
    %{static:-Bstatic} \
   } \
-  %{!static:--hash-style=gnu} \
+  %{!static:--hash-style=gnu -rpath @PREFIX@/@GCCAUX@/lib} \
   %{symbolic:-Bsymbolic}"
 
 #undef  LINK_SPEC
--- gcc/config/i386/freebsd.h.orig
+++ gcc/config/i386/freebsd.h
@@ -77,6 +77,12 @@
    When the -shared link option is used a final link is not being
    done.  */
 
+#if FBSD_MAJOR < 10
+#define ELF_HASH_STYLE "--hash-style=both "
+#else
+#define ELF_HASH_STYLE "--hash-style=gnu "
+#endif
+
 #undef	LINK_SPEC
 #define LINK_SPEC "\
   %{p:%nconsider using '-pg' instead of '-p' with gprof(1)} \
@@ -88,6 +94,7 @@
         %{rdynamic:-export-dynamic} \
         -dynamic-linker %(fbsd_dynamic_linker) } \
     %{static:-Bstatic}} \
+  %{!static:" ELF_HASH_STYLE "-rpath @PREFIX@/@GCCAUX@/lib} \
   %{symbolic:-Bsymbolic}"
 
 /* A C statement to output to the stdio stream FILE an assembler
--- gcc/config/i386/freebsd64.h.orig
+++ gcc/config/i386/freebsd64.h
@@ -41,4 +41,5 @@
         %{rdynamic:-export-dynamic} \
 	-dynamic-linker %(fbsd_dynamic_linker) } \
     %{static:-Bstatic}} \
+  %{!static:" ELF_HASH_STYLE "-rpath @PREFIX@/@GCCAUX@/lib} \
   %{symbolic:-Bsymbolic}"
--- gcc/config/netbsd-elf.h.orig
+++ gcc/config/netbsd-elf.h
@@ -71,6 +71,7 @@
   "%{assert*} %{R*} %{rpath*} \
    %{shared:-shared} \
    %{symbolic:-Bsymbolic} \
+   %{!static:-rpath @PREFIX@/@GCCAUX@/lib} \
    %{!shared: \
      -dc -dp \
      %{!nostdlib: \
@@ -85,3 +86,10 @@
 #ifdef HAVE_LD_AS_NEEDED
 #define USE_LD_AS_NEEDED 1
 #endif
+
+/* Define this to be nonzero if static stack checking is supported. */
+#define STACK_CHECK_STATIC_BUILTIN 1
+
+#if defined(HAVE_LD_EH_FRAME_HDR)
+#define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+#endif
--- gcc/config.gcc.orig
+++ gcc/config.gcc
@@ -1445,12 +1445,16 @@
 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ${fbsd_tm_file} i386/x86-64.h i386/freebsd.h i386/freebsd64.h"
 	;;
 i[34567]86-*-netbsdelf*)
-	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/netbsd-elf.h"
+	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/netbsd-elf.h freebsd-stdint.h"
 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+	tmake_file="${tmake_file} i386/t-crtstuff"
+	use_gcc_stdint=wrap
 	;;
 x86_64-*-netbsd*)
-	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/x86-64.h i386/netbsd64.h"
+	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/x86-64.h i386/netbsd64.h freebsd-stdint.h"
 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+	tmake_file="${tmake_file} i386/t-crtstuff"
+	use_gcc_stdint=wrap
 	;;
 i[34567]86-*-openbsd2.*|i[34567]86-*openbsd3.[0123])
 	tm_file="i386/i386.h i386/unix.h i386/bsd.h i386/gas.h i386/gstabs.h openbsd-oldgas.h openbsd.h i386/openbsd.h"
--- gcc/configure.orig
+++ gcc/configure
@@ -28658,6 +28658,13 @@
   *-linux-musl*)
     gcc_cv_target_dl_iterate_phdr=yes
     ;;
+  *-*-netbsd*)
+    if grep dl_iterate_phdr $target_header_dir/link_elf.h > /dev/null 2>&1; then
+      gcc_cv_target_dl_iterate_phdr=yes
+    else
+      gcc_cv_target_dl_iterate_phdr=no
+    fi
+    ;;
 esac
 
 if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
--- libgcc/crtstuff.c.orig
+++ libgcc/crtstuff.c
@@ -81,7 +81,7 @@
 #endif
 
 #if defined(TARGET_DL_ITERATE_PHDR) && \
-   (defined(__DragonFly__) || defined(__FreeBSD__))
+   (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__))
 #define BSD_DL_ITERATE_PHDR_AVAILABLE
 #endif
  
--- libgcc/unwind-dw2-fde-dip.c.orig
+++ libgcc/unwind-dw2-fde-dip.c
@@ -71,6 +71,12 @@
 #endif
 
 #if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+    && defined(TARGET_DL_ITERATE_PHDR) && defined(__NetBSD__)
+# define ElfW(type) Elf_##type
+# define USE_PT_GNU_EH_FRAME
+#endif
+
+#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
     && defined(__OpenBSD__)
 # define ElfW(type) Elf_##type
 # define USE_PT_GNU_EH_FRAME
--- libgcc/config.host.orig
+++ libgcc/config.host
@@ -242,7 +242,8 @@
   extra_parts="crtbegin.o crtbeginS.o crtend.o crtendS.o"
   ;;
 *-*-netbsd*)
-  tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver"
+  tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip"
+  tmake_file="$tmake_file t-slibgcc t-slibgcc-gld t-slibgcc-elf-ver"
   # NetBSD 1.7 and later are set up to use GCC's crtstuff for
   # ELF configurations.  We will clear extra_parts in the
   # a.out configurations.
@@ -597,9 +598,12 @@
 	md_unwind_header=i386/freebsd-unwind.h
 	;;
 i[34567]86-*-netbsdelf*)
+	tmake_file="${tmake_file} i386/t-crtstuff"
+	#md_unwind_header=i386/netbsd-unwind.h
 	;;
 x86_64-*-netbsd*)
 	tmake_file="${tmake_file} i386/t-crtstuff"
+	#md_unwind_header=i386/netbsd-unwind.h
 	;;
 i[34567]86-*-openbsd2.*|i[34567]86-*openbsd3.[0123])
 	;;
--- gcc/Makefile.in.orig
+++ gcc/Makefile.in
@@ -1185,7 +1185,6 @@
 	insn-emit.o \
 	insn-extract.o \
 	insn-latencytab.o \
-	insn-modes.o \
 	insn-opinit.o \
 	insn-output.o \
 	insn-peep.o \
@@ -1557,6 +1556,7 @@
   $(OBJS-libcommon-target) main.o c-family/cppspec.o \
   $(COLLECT2_OBJS) $(EXTRA_GCC_OBJS) $(GCOV_OBJS) $(GCOV_DUMP_OBJS) \
   $(GCOV_TOOL_OBJS) $(GENGTYPE_OBJS) gcc-ar.o gcc-nm.o gcc-ranlib.o \
+  insn-modes.o insn-modes-ada.o \
   lto-wrapper.o collect-utils.o
 
 # This lists all host object files, whether they are included in this
@@ -1564,6 +1564,11 @@
 ALL_HOST_OBJS = $(ALL_HOST_FRONTEND_OBJS) $(ALL_HOST_BACKEND_OBJS)
 
 BACKEND = libbackend.a main.o libcommon-target.a libcommon.a \
+	insn-modes.o \
+	$(CPPLIB) $(LIBDECNUMBER)
+
+BACKEND2 = libbackend.a main.o libcommon-target.a libcommon.a \
+	insn-modes-ada.o \
 	$(CPPLIB) $(LIBDECNUMBER)
 
 # This is defined to "yes" if Tree checking is enabled, which roughly means
@@ -2218,6 +2223,7 @@
 
 insn-modes.c: s-modes; @true
 insn-modes.h: s-modes-h; @true
+insn-modes-ada.c: s-modes-ada; @true
 min-insn-modes.c: s-modes-m; @true
 
 s-modes: build/genmodes$(build_exeext)
@@ -2235,6 +2241,12 @@
 	$(SHELL) $(srcdir)/../move-if-change tmp-min-modes.c min-insn-modes.c
 	$(STAMP) s-modes-m
 
+s-modes-ada: s-modes
+	$(shell sed -e 's/: TARGET_96_ROUND_53_LONG_DOUBLE \? &ieee_extended_intel_96_round_53_format //'  \
+		< insn-modes.c > tmp-modes-ada.c)
+	$(SHELL) $(srcdir)/../move-if-change tmp-modes-ada.c insn-modes-ada.c
+	$(STAMP) s-modes-ada
+
 insn-preds.c: s-preds; @true
 tm-preds.h: s-preds-h; @true
 tm-constrs.h: s-constrs-h; @true
@@ -3420,6 +3432,9 @@
 	    ( cd $(DESTDIR)$(bindir) && \
 	      $(LN) $(GCC_INSTALL_NAME)$(exeext) $(FULL_DRIVER_NAME) ); \
 	  fi; \
+	  if [ -f gnat1$(exeext) ] ; then \
+	    ( cd $(DESTDIR)$(bindir) && $(LN) $(GCC_INSTALL_NAME)$(exeext) ada$(exeext) ) \
+	  fi; \
 	  if [ ! -f gcc-cross$(exeext) ] \
 	      && [ "$(GCC_INSTALL_NAME)" != "$(GCC_TARGET_INSTALL_NAME)" ]; then \
 	    rm -f $(DESTDIR)$(bindir)/$(target_noncanonical)-gcc-tmp$(exeext); \
