configure: Repurpose have-cc-with-libunwind for clang support

The `have-cc-with-libunwind` check (and its corresponding macro
HAVE_CC_WITH_LIBUNWIND) was historically specific to IA64, intended
to supplement libgcc with libunwind.  Since this logic is unused in
current GCC configurations, this patch repurposes it to support
clang-based toolchains that utilize LLVM's libunwind instead of
libgcc_s.

The configure script now detects if the compiler natively supports
unwinding via `-lunwind`.

Additionally, when this mode is enabled, `-lclang_rt.builtins` is
explicitly added to the `libgcc_eh` definition.  This is necessary
because `links-dso-program` otherwise fails to link due to a missing
`__gcc_personality_v0` symbol.  It appears that clang does not
automatically link the builtins providing this personality routine
when `rlink-path` is actively used during the build.

Reviewed-by: Sam James <sam@gentoo.org>
This commit is contained in:
Adhemerval Zanella
2026-03-12 13:52:50 -03:00
parent 79942df7c5
commit 570c46d36b
6 changed files with 18 additions and 14 deletions
+4 -2
View File
@@ -711,10 +711,12 @@ link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnuli
ifndef gnulib
ifneq ($(have-cc-with-libunwind),yes)
libunwind =
libgcc_s = -lgcc_s
else
libunwind = -lunwind
libunwind = -lunwind $(libgcc-name)
libgcc_s = $(libunwind)
endif
libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
libgcc_eh := -Wl,--as-needed $(libgcc_s) -Wl,--no-as-needed
gnulib-arch =
gnulib = $(libgcc-name) $(gnulib-arch)
gnulib-tests := $(libgcc-name) $(libgcc_eh)
+2 -1
View File
@@ -565,7 +565,8 @@ $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
-B$(csu-objpfx) $(load-map-file) \
$(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
$(link-test-modules-rpath-link) \
-L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
-L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
$(libgcc_eh)
endef
# This macro is similar to build-shlib but it does not define a soname
-1
View File
@@ -69,7 +69,6 @@ no-fortify-source = @no_fortify_source@
have-selinux = @have_selinux@
have-libaudit = @have_libaudit@
have-libcap = @have_libcap@
have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
bind-now = @bindnow@
have-cxx-thread_local = @libc_cv_cxx_thread_local@
have-loop-to-function = @libc_cv_cc_loop_to_function@
Vendored
+6 -5
View File
@@ -7069,18 +7069,17 @@ if test $libc_cv_have_sdata_section = yes; then
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libunwind-support in compiler" >&5
printf %s "checking for libunwind-support in compiler... " >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler links with libunwind" >&5
printf %s "checking whether the compiler links with libunwind... " >&6; }
if test ${libc_cv_cc_with_libunwind+y}
then :
printf %s "(cached) " >&6
else case e in #(
e)
cat > conftest.c <<EOF
e) cat > conftest.c <<EOF
int main (void) { return 0; }
EOF
if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static -o conftest \
conftest.c -v 2>&1 >/dev/null | grep ' -lunwind ' >/dev/null; then
conftest.c -v 2>&1 >/dev/null | grep 'libunwind.a' >/dev/null; then
libc_cv_cc_with_libunwind=yes
else
libc_cv_cc_with_libunwind=no
@@ -7095,6 +7094,8 @@ if test $libc_cv_cc_with_libunwind = yes; then
printf "%s\n" "#define HAVE_CC_WITH_LIBUNWIND 1" >>confdefs.h
fi
config_vars="$config_vars
have-cc-with-libunwind = $libc_cv_cc_with_libunwind"
ASFLAGS_config=
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether --noexecstack is desirable for .S files" >&5
+5 -4
View File
@@ -1289,13 +1289,13 @@ if test $libc_cv_have_sdata_section = yes; then
AC_DEFINE(HAVE_SDATA_SECTION)
fi
AC_CACHE_CHECK(for libunwind-support in compiler,
libc_cv_cc_with_libunwind, [
cat > conftest.c <<EOF
AC_CACHE_CHECK(whether the compiler links with libunwind,
libc_cv_cc_with_libunwind, [dnl
cat > conftest.c <<EOF
int main (void) { return 0; }
EOF
if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static -o conftest \
conftest.c -v 2>&1 >/dev/null | grep ' -lunwind ' >/dev/null; then
conftest.c -v 2>&1 >/dev/null | grep 'libunwind.a' >/dev/null; then
libc_cv_cc_with_libunwind=yes
else
libc_cv_cc_with_libunwind=no
@@ -1305,6 +1305,7 @@ AC_SUBST(libc_cv_cc_with_libunwind)
if test $libc_cv_cc_with_libunwind = yes; then
AC_DEFINE(HAVE_CC_WITH_LIBUNWIND)
fi
LIBC_CONFIG_VAR([have-cc-with-libunwind], [$libc_cv_cc_with_libunwind])
ASFLAGS_config=
AC_CACHE_CHECK(whether --noexecstack is desirable for .S files,
+1 -1
View File
@@ -319,7 +319,7 @@ LINKS_DSO_PROGRAM = links-dso-program-c
LDLIBS-links-dso-program-c = $(gnulib)
ifeq ($(have-libgcc_s),yes)
CFLAGS-links-dso-program-c.c += -fexceptions
LDLIBS-links-dso-program-c += -lgcc_s $(libunwind)
LDLIBS-links-dso-program-c += $(libgcc_s) $(libunwind)
endif
else
LINKS_DSO_PROGRAM = links-dso-program