[PATCH] sparc64: Check whether the compiler supports -fcall-used-g6
Stian Halseth
stian@itx.no
Thu Nov 5 19:49:09 GMT 2026
The sparc64 Makefile adds -fcall-used-g6 unconditionally. Clang does
not implement -fcall-used-<reg> and rejects the option, so glibc cannot
be built with clang for sparc64.
Pass it only when the compiler accepts it. LLVM never allocates %g6
on SPARC, so a clang build does not need it. As for
-mprefer-vector-width on x86_64, check TEST_CC as well.
Tested on sparc64 with GCC, where the generated code does not change,
with clang, and with GCC and TEST_CC=clang.
Signed-off-by: Stian Halseth <stian@itx.no>
---
Building glibc with clang for sparc64 is tracked in
https://github.com/sparclinux/issues/issues/96; with current LLVM this
is the only change needed to build it.
Makefile.in | 2 +
configure | 2 +
configure.ac | 1 +
.../unix/sysv/linux/sparc/sparc64/Makefile | 2 +-
.../unix/sysv/linux/sparc/sparc64/configure | 59 +++++++++++++++++++
.../sysv/linux/sparc/sparc64/configure.ac | 12 ++++
6 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/Makefile.in b/Makefile.in
index 9fd5468ba8..17f3dc9dc0 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -5,6 +5,7 @@ TEST_CXX = @TEST_CXX@
test-cc-option-wimplicit-fallthrough = @libc_cv_test_cc_wimplicit_fallthrough@
test-config-cflags-mprefer-vector-width = @libc_cv_test_cc_mprefer_vector_width@
test-config-cflags-signaling-nans = @libc_cv_test_cc_signaling_nans@
+test-config-cflags-fcall-used-g6 = @libc_cv_test_cc_fcall_used_g6@
test-cc-option-wfree-labels = @libc_cv_test_cc_wfree_labels@
test-cc-option-wmissing-parameter-name = @libc_cv_test_cc_wmissing_parameter_name@
test-enable-cet = @test_enable_cet@
@@ -27,6 +28,7 @@ check xcheck test:
cc-option-wimplicit-fallthrough="$(test-cc-option-wimplicit-fallthrough)" \
config-cflags-mprefer-vector-width="$(test-config-cflags-mprefer-vector-width)" \
config-cflags-signaling-nans="$(test-config-cflags-signaling-nans)" \
+ config-cflags-fcall-used-g6="$(test-config-cflags-fcall-used-g6)" \
cc-option-wfree-labels="$(test-cc-option-wfree-labels)" \
cc-option-wmissing-parameter-name="$(test-cc-option-wmissing-parameter-name)" \
enable-cet="$(test-enable-cet)" \
diff --git a/configure b/configure
index 604279533a..d97754fce7 100755
--- a/configure
+++ b/configure
@@ -619,6 +619,7 @@ DEFINES
profile
libc_cv_multidir
test_enable_cet
+libc_cv_test_cc_fcall_used_g6
libc_cv_test_cc_mprefer_vector_width
shared
static
@@ -9438,6 +9439,7 @@ fi
+
enable_gsframe=no
if test $use_sframe = yes; then
# SFrame requires to be explicit enabled by the architecture
diff --git a/configure.ac b/configure.ac
index 2fe7980fc9..5244ab299a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2135,6 +2135,7 @@ fi
# Support configure.ac under sysdeps.
AC_SUBST(libc_cv_test_cc_mprefer_vector_width)
+AC_SUBST(libc_cv_test_cc_fcall_used_g6)
AC_SUBST(test_enable_cet)
enable_gsframe=no
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/Makefile b/sysdeps/unix/sysv/linux/sparc/sparc64/Makefile
index 218c246f16..d014246f8b 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/Makefile
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/Makefile
@@ -1,7 +1,7 @@
# See Makeconfig regarding the use of default-abi.
default-abi := 64
-sysdep-CFLAGS += -fcall-used-g6
+sysdep-CFLAGS += $(config-cflags-fcall-used-g6)
LD += -melf64_sparc
ifeq ($(subdir),stdlib)
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/configure b/sysdeps/unix/sysv/linux/sparc/sparc64/configure
index f09553588c..b3e6b01421 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/configure
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/configure
@@ -14,3 +14,62 @@ case "$prefix" in
;;
esac
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -fcall-used-g6" >&5
+printf %s "checking for -fcall-used-g6... " >&6; }
+if test ${libc_cv_cc_fcall_used_g6+y}
+then :
+ printf %s "(cached) " >&6
+else case e in #(
+ e) if { ac_try='${CC-cc} -Werror -fcall-used-g6 -xc /dev/null -S -o /dev/null'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }
+then :
+ libc_cv_cc_fcall_used_g6=-fcall-used-g6
+else case e in #(
+ e) libc_cv_cc_fcall_used_g6= ;;
+esac
+fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_fcall_used_g6" >&5
+printf "%s\n" "$libc_cv_cc_fcall_used_g6" >&6; }
+if test "$TEST_CC" = "$CC"; then
+ libc_cv_test_cc_fcall_used_g6=$libc_cv_cc_fcall_used_g6
+else
+
+saved_CC="$CC"
+CC="$TEST_CC"
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -fcall-used-g6 in testing" >&5
+printf %s "checking for -fcall-used-g6 in testing... " >&6; }
+if test ${libc_cv_test_cc_fcall_used_g6+y}
+then :
+ printf %s "(cached) " >&6
+else case e in #(
+ e) if { ac_try='${CC-cc} -Werror -fcall-used-g6 -xc /dev/null -S -o /dev/null'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }
+then :
+ libc_cv_test_cc_fcall_used_g6=-fcall-used-g6
+else case e in #(
+ e) libc_cv_test_cc_fcall_used_g6= ;;
+esac
+fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_cc_fcall_used_g6" >&5
+printf "%s\n" "$libc_cv_test_cc_fcall_used_g6" >&6; }
+
+CC="$saved_CC"
+
+fi
+
+config_vars="$config_vars
+config-cflags-fcall-used-g6 = $libc_cv_cc_fcall_used_g6"
+
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/configure.ac b/sysdeps/unix/sysv/linux/sparc/sparc64/configure.ac
index 979bb8d923..3dbc510025 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/configure.ac
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/configure.ac
@@ -2,3 +2,15 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
# Local configure fragment for sysdeps/unix/sysv/linux/sparc/sparc64.
LIBC_SLIBDIR_RTLDDIR([lib64], [lib64])
+
+dnl Clang does not support -fcall-used-<reg>.
+LIBC_TRY_CC_AND_TEST_CC_OPTION([for -fcall-used-g6],
+ [-Werror -fcall-used-g6],
+ libc_cv_cc_fcall_used_g6,
+ [libc_cv_cc_fcall_used_g6=-fcall-used-g6],
+ [libc_cv_cc_fcall_used_g6=],
+ libc_cv_test_cc_fcall_used_g6,
+ [libc_cv_test_cc_fcall_used_g6=-fcall-used-g6],
+ [libc_cv_test_cc_fcall_used_g6=])
+LIBC_CONFIG_VAR([config-cflags-fcall-used-g6],
+ [$libc_cv_cc_fcall_used_g6])
--
2.43.0
More information about the Libc-alpha
mailing list