[PATCH] support: Link links-dso-program-c with libgcc_s only if available

Florian Weimer fweimer@redhat.com
Fri Mar 21 18:18:21 GMT 2025


Add a configure check to detect bootstrapping builds that do not
have libgcc_s.

Fixes commit 3e2be87832781a29ed67f38f87c1ce3dd4c1b866 ("support: Link
links-dso-program-c against libgcc_s").

---
 configure        | 40 ++++++++++++++++++++++++++++++++++++++++
 configure.ac     | 12 ++++++++++++
 support/Makefile |  5 ++++-
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 674d1d7e4a..d11dcf97c5 100755
--- a/configure
+++ b/configure
@@ -9135,6 +9135,46 @@ fi
 config_vars="$config_vars
 enable-static-pie = $libc_cv_static_pie"
 
+# Check if we can link support functionality against libgcc_s.
+# Must not be used for linking installed binaries, to produce the
+# same binaries for bootstrapped and bootstrapping builds (the latter
+# with a GCC that does not build libgcc_s).
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC can link against -lgcc_s" >&5
+printf %s "checking whether $CC can link against -lgcc_s... " >&6; }
+if test ${libc_cv_have_libgcc_s+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e)   old_LIBS="$LIBS"
+  LIBS="$LIBS -lgcc_s"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"
+then :
+  libc_cv_have_libgcc_s=yes
+else case e in #(
+  e) libc_cv_have_libgcc_s=no ;;
+esac
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam \
+    conftest$ac_exeext conftest.$ac_ext
+  LIBS="$old_LIBS" ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_have_libgcc_s" >&5
+printf "%s\n" "$libc_cv_have_libgcc_s" >&6; }
+config_vars="$config_vars
+have-libgcc_s = $libc_cv_have_libgcc_s"
+
 # Support configure.ac under sysdeps.
 
 
diff --git a/configure.ac b/configure.ac
index 57cd24c87d..d068bb5082 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2061,6 +2061,18 @@ if test "$libc_cv_static_pie" = "yes"; then
 fi
 LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie])
 
+# Check if we can link support functionality against libgcc_s.
+# Must not be used for linking installed binaries, to produce the
+# same binaries for bootstrapped and bootstrapping builds (the latter
+# with a GCC that does not build libgcc_s).
+AC_CACHE_CHECK([whether $CC can link against -lgcc_s], libc_cv_have_libgcc_s, [dnl
+  old_LIBS="$LIBS"
+  LIBS="$LIBS -lgcc_s"
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+		 [libc_cv_have_libgcc_s=yes], [libc_cv_have_libgcc_s=no])
+  LIBS="$old_LIBS"])
+LIBC_CONFIG_VAR([have-libgcc_s], [$libc_cv_have_libgcc_s])
+
 # Support configure.ac under sysdeps.
 AC_SUBST(libc_cv_test_cc_mprefer_vector_width)
 AC_SUBST(test_enable_cet)
diff --git a/support/Makefile b/support/Makefile
index 0c670555ae..ea7b4cd4a0 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -282,7 +282,10 @@ CFLAGS-temp_file.c += -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
 ifeq (,$(CXX))
 LINKS_DSO_PROGRAM = links-dso-program-c
 CFLAGS-links-dso-program-c.c += -fexceptions
-LDLIBS-links-dso-program-c = -lgcc -lgcc_s $(libunwind)
+LDLIBS-links-dso-program-c = -lgcc
+ifeq ($(have-libgcc_s),yes)
+LDLIBS-links-dso-program-c += -lgcc_s $(libunwind)
+endif
 else
 LINKS_DSO_PROGRAM = links-dso-program
 LDLIBS-links-dso-program = -lstdc++ -lgcc -lgcc_s $(libunwind)

base-commit: 333b9ae8684d0d4c008e78d2820e3afc2e09f674



More information about the Libc-alpha mailing list