diff --git a/pkgs/development/compilers/gcc/5/default.nix b/pkgs/development/compilers/gcc/5/default.nix
index 1721eba325b..da4f7a60670 100644
--- a/pkgs/development/compilers/gcc/5/default.nix
+++ b/pkgs/development/compilers/gcc/5/default.nix
@@ -74,7 +74,10 @@ let version = "5.4.0";
# The GNAT Makefiles did not pay attention to CFLAGS_FOR_TARGET for its
# target libraries and tools.
++ optional langAda ../gnat-cflags.patch
- ++ optional langFortran ../gfortran-driving.patch;
+ ++ optional langFortran ../gfortran-driving.patch
+
+ # This could be applied unconditionally but I don't want to cause a full Linux rebuild.
+ ++ optional stdenv.cc.isClang ./libcxx38-and-above.patch;
javaEcj = fetchurl {
# The `$(top_srcdir)/ecj.jar' file is automatically picked up at
diff --git a/pkgs/development/compilers/gcc/5/libcxx38-and-above.patch b/pkgs/development/compilers/gcc/5/libcxx38-and-above.patch
new file mode 100644
index 00000000000..ee48901a6d0
--- /dev/null
+++ b/pkgs/development/compilers/gcc/5/libcxx38-and-above.patch
@@ -0,0 +1,46 @@
+This is a slightly modified version of https://svnweb.freebsd.org/ports/head/lang/gcc5/files/patch-libc%2B%2B?revision=432958&view=co&pathrev=432958,
+which doesn't apply cleanly due to them using a slightly different format of patch from us. I just replaced the .orig file references with a/b paths.
+
+--- a/gcc/auto-profile.c 2015-01-18 02:25:42 UTC
++++ b/gcc/auto-profile.c
+@@ -19,11 +19,9 @@ along with GCC; see the file COPYING3.
+ . */
+
+ #include "config.h"
+-#include "system.h"
+-
+-#include
+ #include