On 2/14/24 18:33, Iain Sandoe wrote:

On 14 Feb 2024, at 22:59, Iain Sandoe <idsan...@googlemail.com> wrote:

On 12 Feb 2024, at 19:59, Jason Merrill <ja...@redhat.com> wrote:

On 2/10/24 07:30, Iain Sandoe wrote:
On 10 Feb 2024, at 12:07, Jason Merrill <ja...@redhat.com> wrote:

On 2/10/24 05:46, Iain Sandoe wrote:
On 9 Feb 2024, at 23:21, Iain Sandoe <idsan...@googlemail.com> wrote:



On 9 Feb 2024, at 10:56, Iain Sandoe <idsan...@googlemail.com> wrote:
On 8 Feb 2024, at 21:44, Jason Merrill <ja...@redhat.com> wrote:

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:
<0001-build-drop-target-libs-from-LD_LIBRARY_PATH-PR105688.patch>

Hmm this still fails for me with gnat1 being unable to find libgcc_s.
It seems I have to add the PREV_HOST_LIB_PATH_gcc to HOST_LIB_PATH for it to 
succeed so,
presumably, the post stage1 exports are not being forwarded to that build.  
I’ll try to analyze what
exactly is failing.

The fail is occurring in the target libada build; so, I suppose, one might say 
it’s reasonable that it
requires this host path to be added to the target exports since it’s a host 
library used during target
builds (or do folks expect the host exports to be made for target lib builds as 
well?)

Appending the prev-gcc dirctory to the HOST_LIB_PATH fixes this
Hmm this is still not right, in this case, I think it should actually be the 
“just built” directory;
- if we have a tool that depends on host libraries (that happen to be also 
target ones),
  then those libraries have to be built before the tool so that they can be 
linked to it.
  (we specially copy libgcc* and the CRTs to gcc/ to allow for this case)
- there is no prev-gcc in cross and —disable-bootstrap builds, but the tool 
will still be
   linked to the just-built host libraries (which will also be installed).
So, I think we have to add HOST_LIB_PATH_gcc to HOST_LIB_PATH
and HOST_PREV_LIB_PATH_gcc to POSTSTAGE1_HOST_EXPORTS (as per this patch).

I don't follow.  In a cross build, host libraries are a different architecture 
from target libraries, and certainly can't be linked into host binaries.

In a disable-bootstrap build, even before my change TARGET_LIB_PATH isn't added 
to RPATH_ENVVAR, since that has been guarded with @if gcc-bootstrap.

So in a bootstrap build, it shouldn't be needed for stage1 either.  And for 
stage2, the one we need is from stage1, that matches the compiler we're 
building host tools with.

What am I missing?
nothing, I was off on a tangent about the cross/non-bootstrap, sorry about that.
However, when doing target builds (the previous point) it seems we do have to 
make provision for gnat1 to find libgcc_s, and, at present, it seems that only 
the target exports are active.

Ah, I see: When building target libraries in stage2, we run the stage2 compiler 
that needs the stage1 libgcc_s, but we don't have the HOST_EXPORTS because 
we're building target code, so we also need to get the libgcc path into 
TARGET_EXPORTS.

Since TARGET_LIB_PATH is only added when gcc-bootstrap, I guess the previous 
libgcc is the only piece needed in TARGET_EXPORTS as well.  So, how about this 
version of the patch?

I tested this one on an affected platform version with and without 
—enable-host-shared and for all languages (less go which is not yet supported). 
 It works for me, thanks,
Iain

Incidentally, during my investigations I was looking into various parts of this 
and it seems that actually TARGET_LIB_PATH might well be effectively dead code 
now.

Good point.  Could you test this version as well?


From 6cd188de23ba5b7ac38a7902580fd861af03d3aa 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.  We do want them for
running testcases, but the testsuite handles that in target-libpath.exp.

So, for stage2+, let's add just prev- libgcc.  We do this in both HOST_ and
TARGET_EXPORTS; when building stage2 host tools with the stage1 compiler, if
the stage1 compiler was built with the system gcc, it will load the stage1
libgcc instead of the system libgcc--but that also happens without this
change.  If that turns out to be a problem, we could arrange to only add it
to HOST_EXPORTS for stage3+ in a later patch.

With this change nothing is using TARGET_LIB_PATH, so let's remove it.

Many thanks to Iain Sandoe, who tested this on Darwin systems both with and
without system libstdc++, and reports it working.

	PR bootstrap/105688

ChangeLog:

	* Makefile.tpl (HOST_EXPORTS, BASE_TARGET_EXPORTS): Don't add
	TARGET_LIB_PATH to RPATH_ENVVAR.
	(TARGET_LIB_PATH): Remove.
	(HOST_LIB_PATH): Add HOST_LIB_PATH_gcc.
	(HOST_LIB_PATH_gcc): In prev-gcc, and only when bootstrapping.
	* Makefile.in: Regenerate.
---
 Makefile.in  | 59 ++++++----------------------------------------------
 Makefile.tpl | 29 ++++++--------------------
 2 files changed, 12 insertions(+), 76 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index edb0c8a9a42..9d801464251 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 = \
@@ -325,9 +322,6 @@ BASE_TARGET_EXPORTS = \
 	SYSROOT_CFLAGS_FOR_TARGET="$(SYSROOT_CFLAGS_FOR_TARGET)"; export SYSROOT_CFLAGS_FOR_TARGET; \
 	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); \
-@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;
 
@@ -727,56 +721,15 @@ all:
 @host_makefile_frag@
 ###
 
-# 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_libvtv)$(TARGET_LIB_PATH_libssp)$(TARGET_LIB_PATH_libphobos)$(TARGET_LIB_PATH_libgm2)$(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:
-@endif target-libstdc++-v3
-
-@if target-libsanitizer
-TARGET_LIB_PATH_libsanitizer = $$r/$(TARGET_SUBDIR)/libsanitizer/.libs:
-@endif target-libsanitizer
-
-@if target-libvtv
-TARGET_LIB_PATH_libvtv = $$r/$(TARGET_SUBDIR)/libvtv/.libs:
-@endif target-libvtv
-
-@if target-libssp
-TARGET_LIB_PATH_libssp = $$r/$(TARGET_SUBDIR)/libssp/.libs:
-@endif target-libssp
-
-@if target-libphobos
-TARGET_LIB_PATH_libphobos = $$r/$(TARGET_SUBDIR)/libphobos/src/.libs:
-@endif target-libphobos
-
-@if target-libgm2
-TARGET_LIB_PATH_libgm2 = $$r/$(TARGET_SUBDIR)/libgm2/.libs:
-@endif target-libgm2
-
-@if target-libgomp
-TARGET_LIB_PATH_libgomp = $$r/$(TARGET_SUBDIR)/libgomp/.libs:
-@endif target-libgomp
-
-@if target-libitm
-TARGET_LIB_PATH_libitm = $$r/$(TARGET_SUBDIR)/libitm/.libs:
-@endif target-libitm
-
-@if target-libatomic
-TARGET_LIB_PATH_libatomic = $$r/$(TARGET_SUBDIR)/libatomic/.libs:
-@endif target-libatomic
-
-
-
 # This is the list of directories that may be needed in RPATH_ENVVAR
 # so that programs built for the host machine work.
-HOST_LIB_PATH = $(HOST_LIB_PATH_gmp)$(HOST_LIB_PATH_mpfr)$(HOST_LIB_PATH_mpc)$(HOST_LIB_PATH_isl)
+HOST_LIB_PATH = $(HOST_LIB_PATH_gmp)$(HOST_LIB_PATH_mpfr)$(HOST_LIB_PATH_mpc)$(HOST_LIB_PATH_isl)$(HOST_LIB_PATH_gcc)
 
-# 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):
-@endif gcc
+# libgcc is a target library in the current stage and a host library
+# in the previous stage (when bootstrapping).
+@if gcc-bootstrap
+HOST_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/prev-gcc$(GCC_SHLIB_SUBDIR):
+@endif gcc-bootstrap
 
 
 @if gmp
diff --git a/Makefile.tpl b/Makefile.tpl
index adbcbdd1d57..e3de2a7ba3b 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 = \
@@ -328,9 +325,6 @@ BASE_TARGET_EXPORTS = \
 	SYSROOT_CFLAGS_FOR_TARGET="$(SYSROOT_CFLAGS_FOR_TARGET)"; export SYSROOT_CFLAGS_FOR_TARGET; \
 	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); \
-@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;
 
@@ -650,28 +644,17 @@ all:
 @host_makefile_frag@
 ###
 
-# 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 = [+ FOR target_modules +][+
-  IF lib_path +]$(TARGET_LIB_PATH_[+module+])[+ 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+]:
-@endif target-[+module+]
-[+ ENDIF lib_path +][+ ENDFOR target_modules +]
-
-
 # This is the list of directories that may be needed in RPATH_ENVVAR
 # so that programs built for the host machine work.
 HOST_LIB_PATH = [+ FOR host_modules +][+
   IF lib_path +]$(HOST_LIB_PATH_[+module+])[+ ENDIF lib_path +][+
-  ENDFOR host_modules +]
+  ENDFOR host_modules +]$(HOST_LIB_PATH_gcc)
 
-# 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):
-@endif gcc
+# libgcc is a target library in the current stage and a host library
+# in the previous stage (when bootstrapping).
+@if gcc-bootstrap
+HOST_LIB_PATH_gcc = $$r/$(HOST_SUBDIR)/prev-gcc$(GCC_SHLIB_SUBDIR):
+@endif gcc-bootstrap
 
 [+ FOR host_modules +][+ IF lib_path +]
 @if [+module+]
-- 
2.43.0

Reply via email to