[PATCH v2 1/4] aarch64: add configure checks for BTI support
Yury Khrustalev
yury.khrustalev@arm.com
Wed Nov 19 16:35:18 GMT 2025
---
aclocal.m4 | 14 ++++++
configure | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 27 +++++++++++
3 files changed, 167 insertions(+)
diff --git a/aclocal.m4 b/aclocal.m4
index cfe9c0b538..31f13a2f46 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -497,3 +497,17 @@ LIBC_CHECK_TEST_CXX(
[LIBC_TRY_CXX_OPTION([$2], [$4], [$5])])
)
])
+
+dnl Check if a CC compiler defines a macro.
+dnl LIBC_CHECK_CC_MACRO([message], [macro],
+dnl [CC-cache-id], [CC-action-if-true], [CC-action-if-false])
+AC_DEFUN([LIBC_CHECK_CC_MACRO],
+[
+AC_CACHE_CHECK([$1], $3, [dnl
+ if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -dM -E - < /dev/null | grep -wF "$2" 1>&AS_MESSAGE_LOG_FD])
+ then
+ [$4]
+ else
+ [$5]
+ fi])
+])
diff --git a/configure b/configure
index 1999d12f44..a1708a0104 100755
--- a/configure
+++ b/configure
@@ -9148,6 +9148,132 @@ printf "%s\n" "$libc_linker_feature" >&6; }
config_vars="$config_vars
load-address-ldflag = $libc_cv_load_address_ldflag"
+# Check if compilers support BTI in branch protection:
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler supports -mbranch-protection=bti" >&5
+printf %s "checking if compiler supports -mbranch-protection=bti... " >&6; }
+if test ${libc_cv_cc_bti+y}
+then :
+ printf %s "(cached) " >&6
+else case e in #(
+ e) if { ac_try='${CC-cc} -Werror -mbranch-protection=bti -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_bti=yes
+else case e in #(
+ e) libc_cv_cc_bti=no ;;
+esac
+fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_bti" >&5
+printf "%s\n" "$libc_cv_cc_bti" >&6; }
+if test "$TEST_CC" = "$CC"; then
+ libc_cv_test_cc_bti=$libc_cv_cc_bti
+else
+
+saved_CC="$CC"
+CC="$TEST_CC"
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler supports -mbranch-protection=bti in testing" >&5
+printf %s "checking if compiler supports -mbranch-protection=bti in testing... " >&6; }
+if test ${libc_cv_test_cc_bti+y}
+then :
+ printf %s "(cached) " >&6
+else case e in #(
+ e) if { ac_try='${CC-cc} -Werror -mbranch-protection=bti -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_bti=yes
+else case e in #(
+ e) libc_cv_test_cc_bti=no ;;
+esac
+fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_cc_bti" >&5
+printf "%s\n" "$libc_cv_test_cc_bti" >&6; }
+
+CC="$saved_CC"
+
+fi
+
+config_vars="$config_vars
+have-cc-bti = $libc_cv_cc_bti"
+config_vars="$config_vars
+have-test-cc-bti = $libc_cv_test_cc_bti"
+
+# Check if linker supports BTI marking
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for linker that supports -z force-bti" >&5
+printf %s "checking for linker that supports -z force-bti... " >&6; }
+libc_linker_feature=no
+cat > conftest.c <<EOF
+int _start (void) { return 42; }
+EOF
+if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp
+ -Wl,-z,force-bti -nostdlib -nostartfiles
+ -fPIC -shared -o conftest.so conftest.c
+ 1>&5'
+ { { 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
+ if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $no_ssp -Wl,-z,force-bti -nostdlib \
+ -nostartfiles -fPIC -shared -o conftest.so conftest.c 2>&1 \
+ | grep "warning: -z force-bti ignored" > /dev/null 2>&1; then
+ true
+ else
+ libc_linker_feature=yes
+ fi
+fi
+rm -f conftest*
+if test $libc_linker_feature = yes; then
+ libc_cv_ld_bti=yes
+else
+ libc_cv_ld_bti=no
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
+printf "%s\n" "$libc_linker_feature" >&6; }
+config_vars="$config_vars
+have-ld-bti = $libc_cv_ld_bti"
+
+# Check if branch protection is enabled
+
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if BTI branch protection is enabled" >&5
+printf %s "checking if BTI branch protection is enabled... " >&6; }
+if test ${libc_cv_cc_bti_enabled+y}
+then :
+ printf %s "(cached) " >&6
+else case e in #(
+ e) if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -dM -E - < /dev/null | grep -wF "__ARM_FEATURE_BTI_DEFAULT" 1>&5'
+ { { 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_bti_enabled=yes
+ else
+ libc_cv_cc_bti_enabled=no
+
+ fi ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_bti_enabled" >&5
+printf "%s\n" "$libc_cv_cc_bti_enabled" >&6; }
+
+config_vars="$config_vars
+have-cc-bti-enabled = $libc_cv_cc_bti_enabled"
+
# Check if compilers support GCS in branch protection:
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler supports -mbranch-protection=gcs" >&5
diff --git a/configure.ac b/configure.ac
index 46a354dfbc..852004407f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2049,6 +2049,33 @@ LIBC_LINKER_FEATURE([-Ttext-segment=$libc_cv_pde_load_address],
[libc_cv_load_address_ldflag=])
LIBC_CONFIG_VAR([load-address-ldflag], [$libc_cv_load_address_ldflag])
+# Check if compilers support BTI in branch protection:
+LIBC_TRY_CC_AND_TEST_CC_OPTION([if compiler supports -mbranch-protection=bti],
+ [-Werror -mbranch-protection=bti],
+ libc_cv_cc_bti,
+ [libc_cv_cc_bti=yes],
+ [libc_cv_cc_bti=no],
+ libc_cv_test_cc_bti,
+ [libc_cv_test_cc_bti=yes],
+ [libc_cv_test_cc_bti=no])
+LIBC_CONFIG_VAR([have-cc-bti], [$libc_cv_cc_bti])
+LIBC_CONFIG_VAR([have-test-cc-bti], [$libc_cv_test_cc_bti])
+
+# Check if linker supports BTI marking
+LIBC_LINKER_FEATURE([-z force-bti], [-Wl,-z,force-bti],
+ [libc_cv_ld_bti=yes], [libc_cv_ld_bti=no])
+LIBC_CONFIG_VAR([have-ld-bti], [$libc_cv_ld_bti])
+
+# Check if branch protection is enabled
+LIBC_CHECK_CC_MACRO(
+ [if BTI branch protection is enabled],
+ [__ARM_FEATURE_BTI_DEFAULT],
+ libc_cv_cc_bti_enabled,
+ [libc_cv_cc_bti_enabled=yes],
+ [libc_cv_cc_bti_enabled=no]
+)
+LIBC_CONFIG_VAR([have-cc-bti-enabled], [$libc_cv_cc_bti_enabled])
+
# Check if compilers support GCS in branch protection:
LIBC_TRY_CC_AND_TEST_CC_OPTION([if compiler supports -mbranch-protection=gcs],
[-Werror -mbranch-protection=gcs],
--
2.47.3
More information about the Libc-alpha
mailing list