On 2/8/24 12:55, Paolo Bonzini wrote:
On 2/8/24 18:16, Jason Merrill wrote:
Hmm. In stage 1, when we build with the system gcc, I'd think we
want the just-built gnat1 to find the system libgcc.
In stage 2, when we build with the stage 1 gcc, we want the
just-built gnat1 to find the stage 1 libgcc.
In neither case do we want it to find the libgcc from the current stage.
So it seems to me that what we want is for stage2+ LD_LIBRARY_PATH to
include the TARGET_LIB_PATH from the previous stage. Something like
the below, on top of the earlier patch.
Does this make sense? Does it work on Darwin?
Oops, that was broken, please consider this one instead:
Yes, this one makes sense (and the current code would not work since it
lacks the prev- prefix on TARGET_LIB_PATH).
Indeed, that seems like evidence that the only element of
TARGET_LIB_PATH that has been useful in HOST_EXPORTS is the prev- part
of HOST_LIB_PATH_gcc.
So, here's another patch that just includes that for post-stage1:
From 3709ba23e4e3f5f6b2b6af709179ea5e471e2a55 Mon Sep 17 00:00:00 2001
From: Jason Merrill <ja...@redhat.com>
Date: Wed, 24 Jan 2024 07:47:26 -0500
Subject: [PATCH] build: drop target libs from LD_LIBRARY_PATH [PR105688]
To: gcc-patches@gcc.gnu.org
The patch for PR22340 (r104978) moved the adding of TARGET_LIB_PATH to
RPATH_ENVVAR from POSTSTAGE1_HOST_EXPORTS to HOST_EXPORTS, but didn't
mention that in the ChangeLog; it also wasn't part of the patch that was
sent to gcc-patches. I suspect it was included accidentally?
It also causes PR105688 when rebuilding stage1: once the stage1 libstdc++
has been built, if calling the system gcc to build host code involves
invoking any tool that links against libstdc++.so (gold, ccache) they get
the just-built library instead of the system library they expect.
Reverting that hunk of the change fixed my problem with bubblestrapping GCC
12 with ccache on a host with a newer system libstdc++.
But I believe that adding TARGET_LIB_PATH to RPATH_ENVVAR is not needed for
post-stage1 either. Including TARGET_LIB_PATH goes back to r37545, with the
stated rationale of getting other C++ library configury to succeed, but that
seems like a rationale for having it in TARGET_EXPORTS, not HOST_.
And when building stage2+, looking for current stage target libraries isn't
what we want anyway; we would have wanted the previous stage target
libraries, and we haven't been looking for them, except for the previous
stage libgcc that we get from HOST_LIB_PATH_gcc.
So, for stage2+, let's add just prev-gcc.
PR bootstrap/105688
ChangeLog:
* Makefile.tpl (HOST_EXPORTS): Don't add TARGET_LIB_PATH to
RPATH_ENVVAR.
(POSTSTAGE1_HOST_EXPORTS): Add PREV_HOST_LIB_PATH_gcc.
(PREV_HOST_LIB_PATH_gcc): Split out from HOST_LIB_PATH_gcc.
* Makefile.in: Regenerate.
---
Makefile.in | 7 +++----
Makefile.tpl | 7 +++----
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/Makefile.in b/Makefile.in
index edb0c8a9a42..c248003ee36 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -242,9 +242,6 @@ HOST_EXPORTS = \
ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
ISLINC="$(HOST_ISLINC)"; export ISLINC; \
XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export XGCC_FLAGS_FOR_TARGET; \
-@if gcc-bootstrap
- $(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(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);
POSTSTAGE1_CXX_EXPORT = \
@@ -269,6 +266,7 @@ POSTSTAGE1_CXX_EXPORT = \
# Similar, for later GCC stages.
POSTSTAGE1_HOST_EXPORTS = \
$(HOST_EXPORTS) \
+ $(RPATH_ENVVAR)=`echo "$(HOST_PREV_LIB_PATH_gcc)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
CC="$(STAGE_CC_WRAPPER) $$r/$(HOST_SUBDIR)/prev-gcc/xgcc$(exeext) \
-B$$r/$(HOST_SUBDIR)/prev-gcc/ -B$(build_tooldir)/bin/ \
$(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CC; \
@@ -775,7 +773,8 @@ HOST_LIB_PATH = $(HOST_LIB_PATH_gmp)$(HOST_LIB_PATH_mpfr)$(HOST_LIB_PATH_mpc)$(H
# Define HOST_LIB_PATH_gcc here, for the sake of TARGET_LIB_PATH, ouch
@if gcc
-HOST_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/gcc$(GCC_SHLIB_SUBDIR):$$r/$(HOST_SUBDIR)/prev-gcc$(GCC_SHLIB_SUBDIR):
+HOST_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/gcc$(GCC_SHLIB_SUBDIR):
+HOST_PREV_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/prev-gcc$(GCC_SHLIB_SUBDIR):
@endif gcc
diff --git a/Makefile.tpl b/Makefile.tpl
index adbcbdd1d57..844b9e8f63a 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -245,9 +245,6 @@ HOST_EXPORTS = \
ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
ISLINC="$(HOST_ISLINC)"; export ISLINC; \
XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export XGCC_FLAGS_FOR_TARGET; \
-@if gcc-bootstrap
- $(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(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);
POSTSTAGE1_CXX_EXPORT = \
@@ -272,6 +269,7 @@ POSTSTAGE1_CXX_EXPORT = \
# Similar, for later GCC stages.
POSTSTAGE1_HOST_EXPORTS = \
$(HOST_EXPORTS) \
+ $(RPATH_ENVVAR)=`echo "$(PREV_HOST_LIB_PATH_gcc)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
CC="$(STAGE_CC_WRAPPER) $$r/$(HOST_SUBDIR)/prev-gcc/xgcc$(exeext) \
-B$$r/$(HOST_SUBDIR)/prev-gcc/ -B$(build_tooldir)/bin/ \
$(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CC; \
@@ -670,7 +668,8 @@ HOST_LIB_PATH = [+ FOR host_modules +][+
# Define HOST_LIB_PATH_gcc here, for the sake of TARGET_LIB_PATH, ouch
@if gcc
-HOST_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/gcc$(GCC_SHLIB_SUBDIR):$$r/$(HOST_SUBDIR)/prev-gcc$(GCC_SHLIB_SUBDIR):
+HOST_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/gcc$(GCC_SHLIB_SUBDIR):
+PREV_HOST_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/prev-gcc$(GCC_SHLIB_SUBDIR):
@endif gcc
[+ FOR host_modules +][+ IF lib_path +]
--
2.43.0