On Mon, 19 Jan 2026, Jakub Jelinek wrote:

> Hi!
> 
> So, apparently I've tripped over not just one linker bug with the
> libatomic/libgcc_s asneeded workaround for libtool bug, but two.
> One is that mold doesn't parse INPUT ( AS_NEEDED ( -latomic ) )
> or INPUT ( AS_NEEDED ( -lgcc_s ) ) correctly, I think that just
> should be fixed in mold.
> 
> Another one is that ld.bfd doesn't handle correctly INPUT ( libatomic.a )
> when doing static linking with -flto.  While that bug should be fixed too
> in the linker, the reason to install a linker script for a static library
> has been just my laziness, a symbolic link is more efficient, and even on
> hosts without symbolic link for a very small library like libatomic.a
> we can live with a cp -pR copy of it.
> 
> Furthermore, when I was checking in the last patch (i.e. r16-6736 PR123396),
> git was loudly complaining about libatomic_asneeded.a being checked
> into repository when *.a is in .gitignored.
> 
> So, the following patch revamps the libatomic_asneeded* handling.
> libatomic_asneeded.so is rewritten in the way that libgcc_s_asneeded.so
> is done and libatomic_asneeded.a installed using $(LN_S).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, and make install
> DESTDIR=... tested in both cases too.
> 
> Ok for trunk?

OK.

Thanks,
Richard.

> 2026-01-19  Jakub Jelinek  <[email protected]>
> 
>       PR libgcc/123650
>       * Makefile.am (toolexeclib_DATA): Remove.
>       (all-local): For LIBAT_BUILD_ASNEEDED_SOLINK instead of installing
>       libatomic_asneeded.{so,a} from top_srcdir cd into the destination
>       directory, use echo to write libatomic_asneeded.so and $(LN_S) to
>       symlink libatomic_asneeded.a to libatomic.a.
>       (install-data-am): For LIBAT_BUILD_ASNEEDED_SOLINK depend on
>       install-asneeded.
>       (install-asneeded): New goal.
>       * libatomic_asneeded.so: Remove.
>       * libatomic_asneeded.a: Remove.
>       * Makefile.in: Regenerate.
> 
> --- libatomic/Makefile.am.jj  2026-01-13 23:02:05.061762633 +0100
> +++ libatomic/Makefile.am     2026-01-18 19:36:57.511524053 +0100
> @@ -40,9 +40,6 @@ AM_CCASFLAGS = $(XCFLAGS)
>  AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
>  
>  toolexeclib_LTLIBRARIES = libatomic.la
> -if LIBAT_BUILD_ASNEEDED_SOLINK
> -toolexeclib_DATA = libatomic_asneeded.so libatomic_asneeded.a
> -endif
>  noinst_LTLIBRARIES = libatomic_convenience.la
>  
>  if LIBAT_BUILD_VERSIONED_SHLIB
> @@ -187,11 +184,30 @@ gcc_objdir = `pwd`/$(MULTIBUILDTOP)../..
>  all-local: libatomic.la
>       $(LIBTOOL) --mode=install $(INSTALL_DATA) libatomic.la 
> $(gcc_objdir)$(MULTISUBDIR)/
>  if LIBAT_BUILD_ASNEEDED_SOLINK
> -     $(INSTALL_DATA) $(top_srcdir)/libatomic_asneeded.so 
> $(gcc_objdir)$(MULTISUBDIR)/
> -     $(INSTALL_DATA) $(top_srcdir)/libatomic_asneeded.a 
> $(gcc_objdir)$(MULTISUBDIR)/
> +     cd $(gcc_objdir)$(MULTISUBDIR) || exit 1; \
> +     (echo "/* GNU ld script"; \
> +      echo "   Add DT_NEEDED entry for -latomic only if needed.  */"; \
> +      echo "INPUT ( AS_NEEDED ( -latomic ) )" \
> +     ) > libatomic_asneeded.so; \
> +     rm -f libatomic_asneeded.a; \
> +     $(LN_S) libatomic.a libatomic_asneeded.a
>  endif
>       rm $(gcc_objdir)$(MULTISUBDIR)/libatomic.la
>  
> +if LIBAT_BUILD_ASNEEDED_SOLINK
> +install-data-am: install-asneeded
> +
> +install-asneeded: install-toolexeclibLTLIBRARIES
> +     $(MKDIR_P) "$(DESTDIR)$(toolexeclibdir)" || exit 1; \
> +     cd "$(DESTDIR)$(toolexeclibdir)" || exit 1; \
> +     (echo "/* GNU ld script"; \
> +      echo "   Add DT_NEEDED entry for -latomic only if needed.  */"; \
> +      echo "INPUT ( AS_NEEDED ( -latomic ) )" \
> +     ) > libatomic_asneeded.so; \
> +     rm -f libatomic_asneeded.a; \
> +     $(LN_S) libatomic.a libatomic_asneeded.a
> +endif
> +
>  # target overrides
>  -include $(tmake_file)
>  
> --- libatomic/libatomic_asneeded.so.jj        2026-01-13 23:02:05.063762598 
> +0100
> +++ libatomic/libatomic_asneeded.so   2026-01-18 19:28:08.822507919 +0100
> @@ -1,3 +0,0 @@
> -/* GNU ld script
> -   Add DT_NEEDED entry for -latomic only if needed.  */
> -INPUT ( AS_NEEDED ( -latomic ) )
> --- libatomic/libatomic_asneeded.a.jj 2026-01-13 23:02:05.063762598 +0100
> +++ libatomic/libatomic_asneeded.a    2026-01-18 19:28:10.553478504 +0100
> @@ -1,3 +0,0 @@
> -/* GNU ld script
> -   Just link in libatomic.a.  */
> -INPUT ( libatomic.a )
> --- libatomic/Makefile.in.jj  2026-01-13 23:02:05.061762633 +0100
> +++ libatomic/Makefile.in     2026-01-18 19:37:06.180098342 +0100
> @@ -14,7 +14,6 @@
>  
>  @SET_MAKE@
>  
> -
>  VPATH = @srcdir@
>  am__is_gnu_make = { \
>    if test -z '$(MAKELEVEL)'; then \
> @@ -159,8 +158,7 @@ am__uninstall_files_from_dir = { \
>      || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
>           $(am__cd) "$$dir" && rm -f $$files; }; \
>    }
> -am__installdirs = "$(DESTDIR)$(toolexeclibdir)" \
> -     "$(DESTDIR)$(toolexeclibdir)"
> +am__installdirs = "$(DESTDIR)$(toolexeclibdir)"
>  LTLIBRARIES = $(noinst_LTLIBRARIES) $(toolexeclib_LTLIBRARIES)
>  @ARCH_AARCH64_LINUX_TRUE@@PARTIAL_VXWORKS_FALSE@am__objects_1 =  \
>  @ARCH_AARCH64_LINUX_TRUE@@PARTIAL_VXWORKS_FALSE@     atomic_16.lo
> @@ -246,7 +244,6 @@ am__can_run_installinfo = \
>      n|no|NO) false;; \
>      *) (install-info --version) >/dev/null 2>&1;; \
>    esac
> -DATA = $(toolexeclib_DATA)
>  RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive      \
>    distclean-recursive maintainer-clean-recursive
>  am__recursive_targets = \
> @@ -425,7 +422,6 @@ AM_CFLAGS = $(XCFLAGS)
>  AM_CCASFLAGS = $(XCFLAGS)
>  AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
>  toolexeclib_LTLIBRARIES = libatomic.la
> -@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@toolexeclib_DATA = libatomic_asneeded.so 
> libatomic_asneeded.a
>  noinst_LTLIBRARIES = libatomic_convenience.la
>  @LIBAT_BUILD_VERSIONED_SHLIB_FALSE@libatomic_version_script = 
>  
> @LIBAT_BUILD_VERSIONED_SHLIB_GNU_TRUE@@LIBAT_BUILD_VERSIONED_SHLIB_TRUE@libatomic_version_script
>  = -Wl,--version-script,$(top_srcdir)/libatomic.map
> @@ -671,27 +667,6 @@ clean-libtool:
>  
>  distclean-libtool:
>       -rm -f libtool config.lt
> -install-toolexeclibDATA: $(toolexeclib_DATA)
> -     @$(NORMAL_INSTALL)
> -     @list='$(toolexeclib_DATA)'; test -n "$(toolexeclibdir)" || list=; \
> -     if test -n "$$list"; then \
> -       echo " $(MKDIR_P) '$(DESTDIR)$(toolexeclibdir)'"; \
> -       $(MKDIR_P) "$(DESTDIR)$(toolexeclibdir)" || exit 1; \
> -     fi; \
> -     for p in $$list; do \
> -       if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
> -       echo "$$d$$p"; \
> -     done | $(am__base_list) | \
> -     while read files; do \
> -       echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(toolexeclibdir)'"; \
> -       $(INSTALL_DATA) $$files "$(DESTDIR)$(toolexeclibdir)" || exit $$?; \
> -     done
> -
> -uninstall-toolexeclibDATA:
> -     @$(NORMAL_UNINSTALL)
> -     @list='$(toolexeclib_DATA)'; test -n "$(toolexeclibdir)" || list=; \
> -     files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
> -     dir='$(DESTDIR)$(toolexeclibdir)'; $(am__uninstall_files_from_dir)
>  
>  # This directory's subdirectories are mostly independent; you can cd
>  # into them and run 'make' without going through this Makefile.
> @@ -800,10 +775,10 @@ distclean-tags:
>       -rm -f cscope.out cscope.in.out cscope.po.out cscope.files
>  check-am: all-am
>  check: check-recursive
> -all-am: Makefile $(LTLIBRARIES) $(DATA) auto-config.h all-local
> +all-am: Makefile $(LTLIBRARIES) auto-config.h all-local
>  installdirs: installdirs-recursive
>  installdirs-am:
> -     for dir in "$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(toolexeclibdir)"; 
> do \
> +     for dir in "$(DESTDIR)$(toolexeclibdir)"; do \
>         test -z "$$dir" || $(MKDIR_P) "$$dir"; \
>       done
>  install: install-recursive
> @@ -861,14 +836,13 @@ info: info-recursive
>  
>  info-am:
>  
> -install-data-am:
> +@LIBAT_BUILD_ASNEEDED_SOLINK_FALSE@install-data-am:
>  
>  install-dvi: install-dvi-recursive
>  
>  install-dvi-am:
>  
> -install-exec-am: install-exec-local install-toolexeclibDATA \
> -     install-toolexeclibLTLIBRARIES
> +install-exec-am: install-exec-local install-toolexeclibLTLIBRARIES
>  
>  install-html: install-html-recursive
>  
> @@ -911,8 +885,7 @@ ps: ps-recursive
>  
>  ps-am:
>  
> -uninstall-am: uninstall-toolexeclibDATA \
> -     uninstall-toolexeclibLTLIBRARIES
> +uninstall-am: uninstall-toolexeclibLTLIBRARIES
>  
>  .MAKE: $(am__recursive_targets) all install-am install-strip
>  
> @@ -927,14 +900,12 @@ uninstall-am: uninstall-toolexeclibDATA
>       install-exec install-exec-am install-exec-local install-html \
>       install-html-am install-info install-info-am install-man \
>       install-pdf install-pdf-am install-ps install-ps-am \
> -     install-strip install-toolexeclibDATA \
> -     install-toolexeclibLTLIBRARIES installcheck installcheck-am \
> -     installdirs installdirs-am maintainer-clean \
> +     install-strip install-toolexeclibLTLIBRARIES installcheck \
> +     installcheck-am installdirs installdirs-am maintainer-clean \
>       maintainer-clean-generic maintainer-clean-local mostlyclean \
>       mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
>       mostlyclean-local pdf pdf-am ps ps-am tags tags-am uninstall \
> -     uninstall-am uninstall-toolexeclibDATA \
> -     uninstall-toolexeclibLTLIBRARIES
> +     uninstall-am uninstall-toolexeclibLTLIBRARIES
>  
>  .PRECIOUS: Makefile
>  
> @@ -960,10 +931,27 @@ vpath % $(strip $(search_path))
>  all-multi: $(libatomic_la_LIBADD)
>  all-local: libatomic.la
>       $(LIBTOOL) --mode=install $(INSTALL_DATA) libatomic.la 
> $(gcc_objdir)$(MULTISUBDIR)/
> -@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   $(INSTALL_DATA) 
> $(top_srcdir)/libatomic_asneeded.so $(gcc_objdir)$(MULTISUBDIR)/
> -@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   $(INSTALL_DATA) 
> $(top_srcdir)/libatomic_asneeded.a $(gcc_objdir)$(MULTISUBDIR)/
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   cd $(gcc_objdir)$(MULTISUBDIR) || exit 
> 1; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   (echo "/* GNU ld script"; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@    echo "   Add DT_NEEDED entry for 
> -latomic only if needed.  */"; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@    echo "INPUT ( AS_NEEDED ( -latomic ) 
> )" \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   ) > libatomic_asneeded.so; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   rm -f libatomic_asneeded.a; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   $(LN_S) libatomic.a libatomic_asneeded.a
>       rm $(gcc_objdir)$(MULTISUBDIR)/libatomic.la
>  
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@install-data-am: install-asneeded
> +
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@install-asneeded: 
> install-toolexeclibLTLIBRARIES
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   $(MKDIR_P) 
> "$(DESTDIR)$(toolexeclibdir)" || exit 1; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   cd "$(DESTDIR)$(toolexeclibdir)" || 
> exit 1; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   (echo "/* GNU ld script"; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@    echo "   Add DT_NEEDED entry for 
> -latomic only if needed.  */"; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@    echo "INPUT ( AS_NEEDED ( -latomic ) 
> )" \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   ) > libatomic_asneeded.so; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   rm -f libatomic_asneeded.a; \
> +@LIBAT_BUILD_ASNEEDED_SOLINK_TRUE@   $(LN_S) libatomic.a libatomic_asneeded.a
> +
>  # target overrides
>  -include $(tmake_file)
>  
> 
>       Jakub
> 
> 

-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

Reply via email to