This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Building old GCC with new GCC: stage1 32-bit libstdc++ fails to build after building 64-bit libstdc++


Hello,

I was recently trying to build an older multilib bootstrap GCC
(version 4.8.3) using a newer GCC (version 8.1), and I ran into an
issue where after building the 64-bit libstdc++ for the target, while
building the 32-bit libstdc++, I would get the following error[1]:

/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/./gcc/cc1plus:
/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/src/.libs/libstdc++.so.6:
version `CXXABI_1.3.9' not found (required by
/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/./gcc/cc1plus)

What I think is happening is that the stage1 host GCC executable
cc1plus depends on the build libstdc++,

# objdump -p /builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/./gcc/cc1plus
| tail -n 17 | head -n 5
Version References:
  required from libstdc++.so.6:
    0x0bafd179 0x00 11 CXXABI_1.3.9
    0x08922974 0x00 10 GLIBCXX_3.4
    0x056bafd3 0x00 07 CXXABI_1.3

which defines CXXABI_1.3.9, among other things. However, the older
libstdc++ does not define CXXABI_1.3.9,

# objdump -p /builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/src/.libs/libstdc++.so
| grep 'CXXABI_1\.3\.9'

so after the target libstdc++ is built, because BASE_TARGET_EXPORTS
exports LD_LIBRARY_PATH which gives preference to the target
libraries, cc1plus fails to load.

There are also some other stage1 host GCC executables such as cc1 and
lto1 which also depend on CXXABI_1.3.9 from the build libstdc++. The
final, post-stage1 host GCC binaries cc1plus etc. do not depend on
libstdc++.so.6 at all, however, since they are linked using
-static-libstdc++.

To allow me to continue to build, I changed the BASE_TARGET_EXPORTS to
only export LD_LIBRARY_PATH with the target libraries excluding the
target libstdc++ so that the stage1 host programs would continue to
use the build libstdc++. Then in post-stage1, the target libstdc++
path is prepended to LD_LIBRARY_PATH.

I've attached two patches here: the first,
gcc48-libstdc++v3-CXXABI_1.3.9.patch, is the one that allowed me to
build[2] GCC 4.8.3 using GCC 8.1. The second,
gcc81-libstdc++v3-CXXABI_1.3.9.patch, is an analogous patch but for
GCC 8.1, which might allow future versions of GCC to build GCC 8.1
(not tested).

Now I also haven't tested what is the typical use case of building new
compilers with old ones with this patch, but it seems to me that it
makes sense for the stage1 host programs to use the build libstdc++ in
either case since they will depend on the build libstdc++ in either
case. This issue I had wouldn't show up when building new compilers
because presumably the new libstdc++ will define the versions required
by host programs from the old, build libstdc++.

Does this seem like a reasonable change in the general case, or have I
overlooked something?

Best,
Matthew Krupcale

[1] https://copr-be.cloud.fedoraproject.org/results/mkrupcale/gcc/fedora-28-x86_64/00789265-gcc/build.log.gz
[2] https://copr.fedorainfracloud.org/coprs/mkrupcale/gcc/build/789678/
diff --git a/Makefile.in b/Makefile.in
index bfbaf0341..9fb6ef128 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -291,7 +291,7 @@ BASE_TARGET_EXPORTS = \
 	WINDRES="$(WINDRES_FOR_TARGET)"; export WINDRES; \
 	WINDMC="$(WINDMC_FOR_TARGET)"; export WINDMC; \
 @if gcc-bootstrap
-	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
+	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH_BUILD_LIBSTDC++)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
 @endif gcc-bootstrap
 	$(RPATH_ENVVAR)=`echo "$(HOST_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
 	TARGET_CONFIGDIRS="$(TARGET_CONFIGDIRS)"; export TARGET_CONFIGDIRS;
@@ -305,6 +305,18 @@ NORMAL_TARGET_EXPORTS = \
 	$(BASE_TARGET_EXPORTS) \
 	CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX;
 
+# Use the target libstdc++ only after stage1 since the build libstdc++ is
+# required by some stage1 host modules (e.g. cc1, cc1plus, lto1) for
+# CXXABI_1.3.9
+POSTSTAGE1_RPATH_EXPORT = \
+@if target-libstdc++-v3-bootstrap
+	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH_libstdc++-v3)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR);
+@endif target-libstdc++-v3-bootstrap
+
+# Similar, for later GCC stages.
+POSTSTAGE1_TARGET_EXPORTS = \
+	$(POSTSTAGE1_RPATH_EXPORT)
+
 # Where to find GMP
 HOST_GMPLIBS = @gmplibs@
 HOST_GMPINC = @gmpinc@
@@ -576,6 +588,8 @@ all:
 # This is the list of directories that may be needed in RPATH_ENVVAR
 # so that programs built for the target machine work.
 TARGET_LIB_PATH = $(TARGET_LIB_PATH_libstdc++-v3)$(TARGET_LIB_PATH_libmudflap)$(TARGET_LIB_PATH_libsanitizer)$(TARGET_LIB_PATH_libssp)$(TARGET_LIB_PATH_libgomp)$(TARGET_LIB_PATH_libitm)$(TARGET_LIB_PATH_libatomic)$(HOST_LIB_PATH_gcc)
+# Use the build rather than the target libstdc++
+TARGET_LIB_PATH_BUILD_LIBSTDC++ = $(TARGET_LIB_PATH_libmudflap)$(TARGET_LIB_PATH_libsanitizer)$(TARGET_LIB_PATH_libssp)$(TARGET_LIB_PATH_libgomp)$(TARGET_LIB_PATH_libitm)$(TARGET_LIB_PATH_libatomic)$(HOST_LIB_PATH_gcc)
 
 @if target-libstdc++-v3
 TARGET_LIB_PATH_libstdc++-v3 = $$r/$(TARGET_SUBDIR)/libstdc++-v3/src/.libs:
@@ -30858,7 +30872,7 @@ configure-stage2-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -30903,7 +30917,7 @@ configure-stage3-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -30948,7 +30962,7 @@ configure-stage4-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -30993,7 +31007,7 @@ configure-stageprofile-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -31038,7 +31052,7 @@ configure-stagefeedback-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -32289,7 +32303,7 @@ configure-stage2-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -32334,7 +32348,7 @@ configure-stage3-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -32379,7 +32393,7 @@ configure-stage4-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -32424,7 +32438,7 @@ configure-stageprofile-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -32469,7 +32483,7 @@ configure-stagefeedback-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -34177,7 +34191,7 @@ configure-stage2-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -34222,7 +34236,7 @@ configure-stage3-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -34267,7 +34281,7 @@ configure-stage4-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -34312,7 +34326,7 @@ configure-stageprofile-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -34357,7 +34371,7 @@ configure-stagefeedback-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41464,7 +41478,7 @@ configure-stage2-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41509,7 +41523,7 @@ configure-stage3-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41554,7 +41568,7 @@ configure-stage4-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41599,7 +41613,7 @@ configure-stageprofile-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41644,7 +41658,7 @@ configure-stagefeedback-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
diff --git a/Makefile.tpl b/Makefile.tpl
index 3233a788d..0636445d1 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -294,7 +294,7 @@ BASE_TARGET_EXPORTS = \
 	WINDRES="$(WINDRES_FOR_TARGET)"; export WINDRES; \
 	WINDMC="$(WINDMC_FOR_TARGET)"; export WINDMC; \
 @if gcc-bootstrap
-	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
+	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH_BUILD_LIBSTDC++)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
 @endif gcc-bootstrap
 	$(RPATH_ENVVAR)=`echo "$(HOST_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
 	TARGET_CONFIGDIRS="$(TARGET_CONFIGDIRS)"; export TARGET_CONFIGDIRS;
@@ -308,6 +308,18 @@ NORMAL_TARGET_EXPORTS = \
 	$(BASE_TARGET_EXPORTS) \
 	CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX;
 
+# Use the target libstdc++ only after stage1 since the build libstdc++ is
+# required by some stage1 host modules (e.g. cc1, cc1plus, lto1) for
+# CXXABI_1.3.9
+POSTSTAGE1_RPATH_EXPORT = \
+@if target-libstdc++-v3-bootstrap
+	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH_libstdc++-v3)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR);
+@endif target-libstdc++-v3-bootstrap
+
+# Similar, for later GCC stages.
+POSTSTAGE1_TARGET_EXPORTS = \
+	$(POSTSTAGE1_RPATH_EXPORT)
+
 # Where to find GMP
 HOST_GMPLIBS = @gmplibs@
 HOST_GMPINC = @gmpinc@
@@ -531,6 +543,10 @@ all:
 TARGET_LIB_PATH = [+ FOR target_modules +][+
   IF lib_path +]$(TARGET_LIB_PATH_[+module+])[+ ENDIF lib_path +][+
   ENDFOR target_modules +]$(HOST_LIB_PATH_gcc)
+# Use the build rather than the target libstdc++
+TARGET_LIB_PATH_BUILD_LIBSTDC++ = [+ FOR target_modules +][+
+  IF lib_path +][+ IF (not (= (get "module") "libstdc++-v3")) +]$(TARGET_LIB_PATH_[+module+])[+ ENDIF +][+ ENDIF lib_path +][+
+  ENDFOR target_modules +]$(HOST_LIB_PATH_gcc)
 [+ FOR target_modules +][+ IF lib_path +]
 @if target-[+module+]
 TARGET_LIB_PATH_[+module+] = $$r/$(TARGET_SUBDIR)/[+module+]/[+lib_path+]:
@@ -1275,6 +1291,7 @@ maybe-[+make_target+]-[+module+]: [+make_target+]-[+module+]
 [+ configure prefix="target-" subdir="$(TARGET_SUBDIR)"
 	     check_multilibs=true
 	     exports="$(RAW_CXX_TARGET_EXPORTS)"
+	     poststage1_exports="$(POSTSTAGE1_TARGET_EXPORTS)"
 	     host_alias=(get "host" "${target_alias}")
 	     target_alias=(get "target" "${target_alias}")
 	     args="$(TARGET_CONFIGARGS)" no-config-site=true +]
@@ -1286,6 +1303,7 @@ maybe-[+make_target+]-[+module+]: [+make_target+]-[+module+]
 [+ configure prefix="target-" subdir="$(TARGET_SUBDIR)"
 	     check_multilibs=true
 	     exports="$(NORMAL_TARGET_EXPORTS)"
+	     poststage1_exports="$(POSTSTAGE1_TARGET_EXPORTS)"
 	     host_alias=(get "host" "${target_alias}")
 	     target_alias=(get "target" "${target_alias}")
 	     args="$(TARGET_CONFIGARGS)" no-config-site=true +]
diff --git a/Makefile.in b/Makefile.in
index 38774f542..593a4fdb7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -291,7 +291,7 @@ BASE_TARGET_EXPORTS = \
 	WINDRES="$(WINDRES_FOR_TARGET)"; export WINDRES; \
 	WINDMC="$(WINDMC_FOR_TARGET)"; export WINDMC; \
 @if gcc-bootstrap
-	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
+	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH_BUILD_LIBSTDC++)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
 @endif gcc-bootstrap
 	$(RPATH_ENVVAR)=`echo "$(HOST_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
 	TARGET_CONFIGDIRS="$(TARGET_CONFIGDIRS)"; export TARGET_CONFIGDIRS;
@@ -305,6 +305,18 @@ NORMAL_TARGET_EXPORTS = \
 	$(BASE_TARGET_EXPORTS) \
 	CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX;
 
+# Use the target libstdc++ only after stage1 since the build libstdc++ is
+# required by some stage1 host modules (e.g. cc1, cc1plus, lto1) for
+# CXXABI_1.3.9
+POSTSTAGE1_RPATH_EXPORT = \
+@if target-libstdc++-v3-bootstrap
+	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH_libstdc++-v3)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR);
+@endif target-libstdc++-v3-bootstrap
+
+# Similar, for later GCC stages.
+POSTSTAGE1_TARGET_EXPORTS = \
+	$(POSTSTAGE1_RPATH_EXPORT)
+
 # Where to find GMP
 HOST_GMPLIBS = @gmplibs@
 HOST_GMPINC = @gmpinc@
@@ -613,6 +625,8 @@ all:
 # This is the list of directories that may be needed in RPATH_ENVVAR
 # so that programs built for the target machine work.
 TARGET_LIB_PATH = $(TARGET_LIB_PATH_libstdc++-v3)$(TARGET_LIB_PATH_libsanitizer)$(TARGET_LIB_PATH_libmpx)$(TARGET_LIB_PATH_libvtv)$(TARGET_LIB_PATH_liboffloadmic)$(TARGET_LIB_PATH_libssp)$(TARGET_LIB_PATH_libgomp)$(TARGET_LIB_PATH_libitm)$(TARGET_LIB_PATH_libatomic)$(HOST_LIB_PATH_gcc)
+# Use the build rather than the target libstdc++
+TARGET_LIB_PATH_BUILD_LIBSTDC++ = $(TARGET_LIB_PATH_libsanitizer)$(TARGET_LIB_PATH_libmpx)$(TARGET_LIB_PATH_libvtv)$(TARGET_LIB_PATH_liboffloadmic)$(TARGET_LIB_PATH_libssp)$(TARGET_LIB_PATH_libgomp)$(TARGET_LIB_PATH_libitm)$(TARGET_LIB_PATH_libatomic)$(HOST_LIB_PATH_gcc)
 
 @if target-libstdc++-v3
 TARGET_LIB_PATH_libstdc++-v3 = $$r/$(TARGET_SUBDIR)/libstdc++-v3/src/.libs:
@@ -37982,7 +37996,7 @@ configure-stage2-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -38027,7 +38041,7 @@ configure-stage3-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -38072,7 +38086,7 @@ configure-stage4-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -38117,7 +38131,7 @@ configure-stageprofile-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -38162,7 +38176,7 @@ configure-stagetrain-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -38207,7 +38221,7 @@ configure-stagefeedback-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -38252,7 +38266,7 @@ configure-stageautoprofile-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -38297,7 +38311,7 @@ configure-stageautofeedback-target-libstdc++-v3:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libstdc++-v3/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -39225,7 +39239,7 @@ configure-stage2-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -39270,7 +39284,7 @@ configure-stage3-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -39315,7 +39329,7 @@ configure-stage4-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -39360,7 +39374,7 @@ configure-stageprofile-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -39405,7 +39419,7 @@ configure-stagetrain-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -39450,7 +39464,7 @@ configure-stagefeedback-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -39495,7 +39509,7 @@ configure-stageautoprofile-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -39540,7 +39554,7 @@ configure-stageautofeedback-target-libsanitizer:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libsanitizer/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -40468,7 +40482,7 @@ configure-stage2-target-libmpx:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libmpx/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -40513,7 +40527,7 @@ configure-stage3-target-libmpx:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libmpx/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -40558,7 +40572,7 @@ configure-stage4-target-libmpx:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libmpx/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -40603,7 +40617,7 @@ configure-stageprofile-target-libmpx:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libmpx/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -40648,7 +40662,7 @@ configure-stagetrain-target-libmpx:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libmpx/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -40693,7 +40707,7 @@ configure-stagefeedback-target-libmpx:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libmpx/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -40738,7 +40752,7 @@ configure-stageautoprofile-target-libmpx:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libmpx/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -40783,7 +40797,7 @@ configure-stageautofeedback-target-libmpx:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libmpx/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41711,7 +41725,7 @@ configure-stage2-target-libvtv:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libvtv/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41756,7 +41770,7 @@ configure-stage3-target-libvtv:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libvtv/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41801,7 +41815,7 @@ configure-stage4-target-libvtv:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libvtv/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41846,7 +41860,7 @@ configure-stageprofile-target-libvtv:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libvtv/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41891,7 +41905,7 @@ configure-stagetrain-target-libvtv:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libvtv/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41936,7 +41950,7 @@ configure-stagefeedback-target-libvtv:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libvtv/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -41981,7 +41995,7 @@ configure-stageautoprofile-target-libvtv:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libvtv/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -42026,7 +42040,7 @@ configure-stageautofeedback-target-libvtv:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libvtv/Makefile || exit 0; \
 	$(RAW_CXX_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -44328,7 +44342,7 @@ configure-stage2-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -44373,7 +44387,7 @@ configure-stage3-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -44418,7 +44432,7 @@ configure-stage4-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -44463,7 +44477,7 @@ configure-stageprofile-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -44508,7 +44522,7 @@ configure-stagetrain-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -44553,7 +44567,7 @@ configure-stagefeedback-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -44598,7 +44612,7 @@ configure-stageautoprofile-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -44643,7 +44657,7 @@ configure-stageautofeedback-target-libgcc:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgcc/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -51440,7 +51454,7 @@ configure-stage2-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -51485,7 +51499,7 @@ configure-stage3-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -51530,7 +51544,7 @@ configure-stage4-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -51575,7 +51589,7 @@ configure-stageprofile-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -51620,7 +51634,7 @@ configure-stagetrain-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -51665,7 +51679,7 @@ configure-stagefeedback-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -51710,7 +51724,7 @@ configure-stageautoprofile-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
@@ -51755,7 +51769,7 @@ configure-stageautofeedback-target-libgomp:
 	fi; \
 	test ! -f $(TARGET_SUBDIR)/libgomp/Makefile || exit 0; \
 	$(NORMAL_TARGET_EXPORTS) \
-	 \
+	$(POSTSTAGE1_TARGET_EXPORTS) \
 	CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \
 	CXXFLAGS="$(CXXFLAGS_FOR_TARGET)"; export CXXFLAGS; \
 	LIBCFLAGS="$(LIBCFLAGS_FOR_TARGET)"; export LIBCFLAGS;  \
diff --git a/Makefile.tpl b/Makefile.tpl
index 1f23b79b4..39a36336a 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -294,7 +294,7 @@ BASE_TARGET_EXPORTS = \
 	WINDRES="$(WINDRES_FOR_TARGET)"; export WINDRES; \
 	WINDMC="$(WINDMC_FOR_TARGET)"; export WINDMC; \
 @if gcc-bootstrap
-	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
+	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH_BUILD_LIBSTDC++)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
 @endif gcc-bootstrap
 	$(RPATH_ENVVAR)=`echo "$(HOST_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
 	TARGET_CONFIGDIRS="$(TARGET_CONFIGDIRS)"; export TARGET_CONFIGDIRS;
@@ -308,6 +308,18 @@ NORMAL_TARGET_EXPORTS = \
 	$(BASE_TARGET_EXPORTS) \
 	CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX;
 
+# Use the target libstdc++ only after stage1 since the build libstdc++ is
+# required by some stage1 host modules (e.g. cc1, cc1plus, lto1) for
+# CXXABI_1.3.9
+POSTSTAGE1_RPATH_EXPORT = \
+@if target-libstdc++-v3-bootstrap
+	$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH_libstdc++-v3)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR);
+@endif target-libstdc++-v3-bootstrap
+
+# Similar, for later GCC stages.
+POSTSTAGE1_TARGET_EXPORTS = \
+	$(POSTSTAGE1_RPATH_EXPORT)
+
 # Where to find GMP
 HOST_GMPLIBS = @gmplibs@
 HOST_GMPINC = @gmpinc@
@@ -538,6 +550,10 @@ all:
 TARGET_LIB_PATH = [+ FOR target_modules +][+
   IF lib_path +]$(TARGET_LIB_PATH_[+module+])[+ ENDIF lib_path +][+
   ENDFOR target_modules +]$(HOST_LIB_PATH_gcc)
+# Use the build rather than the target libstdc++
+TARGET_LIB_PATH_BUILD_LIBSTDC++ = [+ FOR target_modules +][+
+  IF lib_path +][+ IF (not (= (get "module") "libstdc++-v3")) +]$(TARGET_LIB_PATH_[+module+])[+ ENDIF +][+ ENDIF lib_path +][+
+  ENDFOR target_modules +]$(HOST_LIB_PATH_gcc)
 [+ FOR target_modules +][+ IF lib_path +]
 @if target-[+module+]
 TARGET_LIB_PATH_[+module+] = $$r/$(TARGET_SUBDIR)/[+module+]/[+lib_path+]:
@@ -1326,6 +1342,7 @@ maybe-[+make_target+]-[+module+]: [+make_target+]-[+module+]
 [+ configure prefix="target-" subdir="$(TARGET_SUBDIR)"
 	     check_multilibs=true
 	     exports="$(RAW_CXX_TARGET_EXPORTS)"
+	     poststage1_exports="$(POSTSTAGE1_TARGET_EXPORTS)"
 	     host_alias=(get "host" "${target_alias}")
 	     target_alias=(get "target" "${target_alias}")
 	     args="$(TARGET_CONFIGARGS)" no-config-site=true +]
@@ -1337,6 +1354,7 @@ maybe-[+make_target+]-[+module+]: [+make_target+]-[+module+]
 [+ configure prefix="target-" subdir="$(TARGET_SUBDIR)"
 	     check_multilibs=true
 	     exports="$(NORMAL_TARGET_EXPORTS)"
+	     poststage1_exports="$(POSTSTAGE1_TARGET_EXPORTS)"
 	     host_alias=(get "host" "${target_alias}")
 	     target_alias=(get "target" "${target_alias}")
 	     args="$(TARGET_CONFIGARGS)" no-config-site=true +]

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]