> -----Original Message----- > From: Joseph Myers <[email protected]> > Sent: 11 October 2025 01:41 > To: Matthew Malcomson <[email protected]> > Cc: Prathamesh Kulkarni <[email protected]>; Jonathan Wakely > <[email protected]>; [email protected]; Thomas Schwinge > <[email protected]>; Sam James <[email protected]> > Subject: Re: libstdc++ DT_NEEDED on libatomic after PR81358 > > External email: Use caution opening links or attachments > > > On Fri, 10 Oct 2025, Matthew Malcomson wrote: > > > Questions for others: > > 1) We'd like to double-check that this sounds like a problem before > > trying to change it. > > 2) Does this trigger thoughts of anything else to look out for? > > 3) Would the best solution be to add some `--as-needed` push/pop > state > > arguments into the link line? > > Yes, I'd expect libstdc++ to be linked (DT_NEEDED) with libatomic only > if it actually has undefined references that libatomic resolves. Hi Joseph, Apologies for getting back late on this. >From what I see, the issue with pseudo dependency on libatomic.so (DT_NEEDED) >probably comes from libatomic.so being placed in gcc subdir, which is where toplevel libtool.m4 seems to pick it up from: for p in `eval "$output_verbose_link_cmd"`; do case $p in -L* | -R* | -l*) # Some compilers place space between "-{L,R}" and the path. # Remove the space. if test $p = "-L" || test $p = "-R"; then prev=$p continue else prev= fi if test "$pre_test_object_deps_done" = no; then case $p in -L* | -R*) # Internal compiler library paths should come after those # provided the user. The postdeps already come after the # user supplied libs so there is no need to process them. if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}" else _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}" fi ;; # The "-l" case would never come before the object being # linked, so don't bother handling this case. esac else if test -z "$_LT_TAGVAR(postdeps, $1)"; then _LT_TAGVAR(postdeps, $1)="${prev}${p}" else _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}" fi fi ;; For eg, the generated libtool for libstdc++v3 shows: # The directories searched by this compiler when creating a shared library. compiler_lib_search_dirs="/home/prathameshk/gcc/stage1-build/aarch64-linux-gnu/libstdc++-v3/src /home/prathameshk/gcc/stage1-build/aarch64-linux-gnu/libstdc++-v3/src/.libs /home/prathameshk/gcc/stage1-build/aarch64-linux-gnu/libstdc++-v3/libsupc++/.libs /home/prathameshk/gcc/stage1-build/./gcc /lib/aarch64-linux-gnu /usr/lib/aarch64-linux-gnu /lib /usr/lib" # Dependencies to place before and after the objects being linked to # create a shared library. predep_objects="/lib/aarch64-linux-gnu/crti.o /home/prathameshk/gcc/stage1-build/./gcc/crtbeginS.o" postdep_objects="/home/prathameshk/gcc/stage1-build/./gcc/crtendS.o /lib/aarch64-linux-gnu/crtn.o" predeps="" postdeps=" -lgcc_s -latomic -lc -lgcc_s " I was wondering if we could modify libtool.m4 to wrap the options around --as-needed/--no-as-needed but I assume that'd only work for GNU ld (or a linker that supports these options), so it may perhaps not be the the right approach ? The following workaround seems to work to remove dependency of libatomic.so on libstdc++.so: diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 339e7bb17a4..d5a5ef53e69 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -157,6 +157,9 @@ pic_mode='default' # Eliminate -lstdc++ addition to postdeps for cross compiles. postdeps_CXX=`echo " $postdeps_CXX " | sed 's, -lstdc++ ,,g'` +# Eliminate -latomic addition to postdeps since the library doesn't depend on libatomic +postdeps_CXX=`echo " $postdeps_CXX " | sed 's, -latomic , ,g'` + # Possibly disable most of the library. ## TODO: Consider skipping unncessary tests altogether in this case, rather ## than just ignoring the results. Faster /and/ more correct, win win. With the patch, readelf --dynamic libstdc++.so no longer shows libatomic.so as dependency: 0x0000000000000001 (NEEDED) Shared library: [libm.so.6] 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] 0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1] 0x000000000000000e (SONAME) Library soname: [libstdc++.so.6] But I am not sure if this approach is entirely correct ? If we choose to proceed with it, I will post a patch to similarly filter out -latomic for other target libraries that don't depend on libatomic.so but have the dependency introduced. If this doesn't look correct, could you please suggest how to proceed ? Signed-off-by: Prathamesh Kulkarni <[email protected]> Thanks, Prathamesh > > -- > Joseph S. Myers > [email protected]
