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

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").

Reviewed-by: Sam James <sam@gentoo.org>
This commit is contained in:
Florian Weimer 2025-03-21 21:40:28 +01:00
parent 2f8e8c9cb7
commit 5dfbc3c43e
3 changed files with 56 additions and 1 deletions

40
configure vendored
View File

@ -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.

View File

@ -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)

View File

@ -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)