[PATCH v2 3/6] configure: Repurpose have-cc-with-libunwind for clang support
Adhemerval Zanella
adhemerval.zanella@linaro.org
Wed Feb 25 18:31:14 GMT 2026
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.
---
Makeconfig | 6 ++++--
Makerules | 3 ++-
config.make.in | 1 -
configure | 11 ++++++-----
configure.ac | 9 +++++----
support/Makefile | 2 +-
6 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/Makeconfig b/Makeconfig
index 6a05e1d973..ea509dd3bc 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -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)
diff --git a/Makerules b/Makerules
index 30c3559a28..180cbee251 100644
--- a/Makerules
+++ b/Makerules
@@ -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
diff --git a/config.make.in b/config.make.in
index fca75ab5d3..42889716e4 100644
--- a/config.make.in
+++ b/config.make.in
@@ -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@
diff --git a/configure b/configure
index 672b1abad8..d156912063 100755
--- a/configure
+++ b/configure
@@ -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
diff --git a/configure.ac b/configure.ac
index aa50f28e60..776695486a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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,
diff --git a/support/Makefile b/support/Makefile
index b83350180c..1dae2802cf 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -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
--
2.43.0
More information about the Libc-alpha
mailing list