[PATCH v2 1/4] Makeconfig: Add libgcc directory to rtld-prefix search path

Andreas K. Huettel dilfridge@gentoo.org
Mon Jul 21 17:27:25 GMT 2025


> > > @@ -709,6 +714,7 @@ libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
> > >  gnulib-arch =
> > >  gnulib = -lgcc $(gnulib-arch)
> > >  gnulib-tests := -lgcc $(libgcc_eh)
> > > +gnulib-extralibdir := $(shell dirname $$($(CC) -print-file-name=libgcc_s.so$(libgcc_s.so-version)))
> >
> > This does not return a workable path on a Ubuntu installation, it seems
> > that the internal $(libgcc_s.so-version) is not evaluated correctly:
> >
> > $ arm-linux-gnueabihf-gcc -print-file-name=libgcc_s.so.1
> > /usr/lib/gcc-cross/arm-linux-gnueabihf/13/../../../../arm-linux-gnueabihf/lib/libgcc_s.so.1
> >
> > But I am seeing '/usr/lib/gcc-cross/arm-linux-gnueabihf/13' which is
> > -print-file-name for 'libgcc_s.so.1'.
> >
> > The:
> >
> >   gnulib-extralibdir = $(shell $(CC) -print-file-name=libgcc_s.so$(libgcc_s.so-version) | sed 's#/[^/]*$$##')
> 
> Though this looks like it is causing some issues with some shells. The
> `##` causes the reset of the line to be ignored and I get the
> following error message:
> ../Makeconfig:721: *** unterminated call to function 'shell': missing ')'. Stop.
> 

Eh, if picking # as the separator in the sed s command is a problem, the easiest solution is
to just pick another character that make does not treat special, e.g., maybe this?

sed 's_/[^/]*$$__'

(After verifying that the command line does what we need, I didn't bother digging into what
the problem with the original dirname was.)

> 
> Thanks,
> Andrew Pinski
> 
> 
> >
> > evaluates to a correct path.  With this change I only see a failure,
> > and only without --enable-hardcoded-path-in-tests:
> >
> > FAIL: elf/tst-pathopt
> >
> > Because the test issues the loader through a shell script without
> > the $(gnulib-extralibdir).  The following change fixes it:
> >
> > diff --git a/elf/Makefile b/elf/Makefile
> > index 1ea0e7037e..f0c4bed8ce 100644
> > --- a/elf/Makefile
> > +++ b/elf/Makefile
> > @@ -1869,7 +1869,7 @@ $(objpfx)lateglobal.out: $(objpfx)ltglobmod1.so $(objpfx)ltglobmod2.so
> >  $(objpfx)tst-pathopt.out: tst-pathopt.sh $(objpfx)tst-pathopt \
> >                           $(objpfx)pathoptobj.so
> >         $(SHELL) $< $(common-objpfx) '$(test-wrapper-env)' \
> > -                '$(run-program-env)'; \
> > +                '$(run-program-env)' '$(gnulib-extralibdir)'; \
> >         $(evaluate-test)
> >
> >  $(objpfx)tst-rtld-load-self.out: tst-rtld-load-self.sh $(objpfx)ld.so
> > diff --git a/elf/tst-pathopt.sh b/elf/tst-pathopt.sh
> > index b1539c8ee9..e5b124ea65 100755
> > --- a/elf/tst-pathopt.sh
> > +++ b/elf/tst-pathopt.sh
> > @@ -22,6 +22,7 @@ set -e
> >  common_objpfx=$1
> >  test_wrapper_env=$2
> >  run_program_env=$3
> > +gnulib_extralibdir=$4
> >
> >  test -e ${common_objpfx}elf/will-be-empty &&
> >    rm -fr ${common_objpfx}elf/will-be-empty
> > @@ -32,7 +33,7 @@ cp ${common_objpfx}elf/pathoptobj.so ${common_objpfx}elf/for-renamed/renamed.so
> >
> >  ${test_wrapper_env} \
> >  ${run_program_env} \
> > -LD_LIBRARY_PATH=${common_objpfx}elf/will-be-empty:${common_objpfx}elf/for-renamed:${common_objpfx}.:${common_objpfx}dlfcn \
> > +LD_LIBRARY_PATH=${common_objpfx}elf/will-be-empty:${common_objpfx}elf/for-renamed:${common_objpfx}.:${common_objpfx}dlfcn:${gnulib_extralibdir} \
> >    ${common_objpfx}elf/ld.so ${common_objpfx}elf/tst-pathopt \
> >      > ${common_objpfx}elf/tst-pathopt.out
> >
> >
> > >  static-gnulib-arch =
> > >  # By default, elf/static-stubs.o, instead of -lgcc_eh, is used to
> > >  # statically link programs.  When --disable-shared is used, we use
> > > @@ -781,10 +787,12 @@ endif
> > >
> > >  # How to run a program we just linked with our library.
> > >  # The program binary is assumed to be $(word 2,$^).
> > > +# We may require additional libraries from gcc (e.g. libgcc_s.so for exception
> > > +# handling), which unfortunately somewhat breaks the isolation.
> > >  built-program-file = $(dir $(word 2,$^))$(notdir $(word 2,$^))
> > >  rtld-prefix = $(elf-objpfx)$(rtld-installed-name)                          \
> > >             --library-path                                                  \
> > > -           $(rpath-link)$(patsubst %,:%,$(sysdep-library-path))
> > > +           $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)):$(gnulib-extralibdir)
> > >  ifeq (yes,$(build-shared))
> > >  comma = ,
> > >  sysdep-library-path = \
> >
> 


-- 
Andreas K. Hüttel
dilfridge@gentoo.org
Gentoo Linux developer 
(council, comrel, toolchain, base-system, perl, libreoffice)
https://wiki.gentoo.org/wiki/User:Dilfridge
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250721/8a1ad31d/attachment.sig>


More information about the Libc-alpha mailing list