https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123396

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:8a99fdb70493df1294b53406913e5ea1fc971c13

commit r16-6736-g8a99fdb70493df1294b53406913e5ea1fc971c13
Author: Jakub Jelinek <[email protected]>
Date:   Tue Jan 13 10:06:47 2026 +0100

    Use -latomic_asneeded or -lgcc_s_asneeded to workaround libtool issues
[PR123396]

    On Mon, Jan 12, 2026 at 12:13:35PM +0100, Florian Weimer wrote:
    > One way to work around the libtool problem would be to stick the
    > as-needed into an existing .so linker script, or create a new one under
    > a different name (say libatomic_optional.so) that has AS_NEEDED in it,
    > and link with -latomic_optional.  Then libtool would not have to be
    > taught about --push-state/--pop-state etc.

    That seems to work.

    So far bootstrapped (c,c++,fortran,lto only) and make install tested
    on x86_64-linux, tested on a small program without need to libatomic and
    struct S { char a[25]; };
    _Atomic struct S s;

    int main () { struct S t = s; s = t; }
    which does at -O0.
    Before this patch I got
    for i in `find x86_64-pc-linux-gnu/ -name lib\*.so.\*.\*`; do ldd -u $i
2>&1 | grep -q libatomic.so.1 && echo $i; done
    x86_64-pc-linux-gnu/libsanitizer/ubsan/.libs/libubsan.so.1.0.0
    x86_64-pc-linux-gnu/libsanitizer/asan/.libs/libasan.so.8.0.0
    x86_64-pc-linux-gnu/libsanitizer/hwasan/.libs/libhwasan.so.0.0.0
    x86_64-pc-linux-gnu/libsanitizer/lsan/.libs/liblsan.so.0.0.0
    x86_64-pc-linux-gnu/libsanitizer/tsan/.libs/libtsan.so.2.0.0
    x86_64-pc-linux-gnu/32/libsanitizer/ubsan/.libs/libubsan.so.1.0.0
    x86_64-pc-linux-gnu/32/libsanitizer/asan/.libs/libasan.so.8.0.0
    x86_64-pc-linux-gnu/32/libstdc++-v3/src/.libs/libstdc++.so.6.0.35
    x86_64-pc-linux-gnu/libgcobol/.libs/libgcobol.so.2.0.0
    x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.35
    With this patch it prints nothing.

    2026-01-13  Jakub Jelinek  <[email protected]>

            PR libstdc++/123396
    gcc/
            * configure.ac (gcc_cv_ld_use_as_needed_ldscript): New test.
            (USE_LD_AS_NEEDED_LDSCRIPT): New AC_DEFINE.
            * gcc.cc (LINK_LIBATOMIC_SPEC): Use "-latomic_asneeded" instead
            of LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION
            if USE_LD_AS_NEEDED_LDSCRIPT is defined.
            (init_gcc_specs): Use "-lgcc_s_asneeded" instead of
            LD_AS_NEEDED_OPTION " -lgcc_s " LD_NO_AS_NEEDED_OPTION
            if USE_LD_AS_NEEDED_LDSCRIPT is defined.
            * config.in: Regenerate.
            * configure: Regenerate.
    libatomic/
            * acinclude.m4 (LIBAT_BUILD_ASNEEDED_SOLINK): New AM_CONDITIONAL.
            * libatomic_asneeded.so: New file.
            * libatomic_asneeded.a: New file.
            * Makefile.am (toolexeclib_DATA): Set if
LIBAT_BUILD_ASNEEDED_SOLINK.
            (all-local): Install those files into gcc subdir.
            * Makefile.in: Regenerate.
            * configure: Regenerate.
    libgcc/
            * config/t-slibgcc (SHLIB_ASNEEDED_SOLINK,
            SHLIB_MAKE_ASNEEDED_SOLINK, SHLIB_INSTALL_ASNEEDED_SOLINK): New
            vars.
            (SHLIB_LINK): Include $(SHLIB_MAKE_ASNEEDED_SOLINK).
            (SHLIB_INSTALL): Include $(SHLIB_INSTALL_ASNEEDED_SOLINK).

Reply via email to