From: Wilco Dijkstra Date: Wed, 14 May 2025 16:32:31 +0000 (+0000) Subject: AArch64: Cleanup PAC and BTI X-Git-Tag: glibc-2.42~232 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2c421fc4302ecb729823ca442f9dfab95afba752;p=thirdparty%2Fglibc.git AArch64: Cleanup PAC and BTI Now we finally support modern GCC and binutils, it's time for a cleanup. Use PAC and BTI instructions unconditionally and use proper assembler syntax. Remove the PR target/94791 strip_pac workarounds for buggy GCCs. Remove the PAC/BTI configure checks - always emit GNU property notes on assembly files. Change cfi_window_save to the correct cfi_negate_ra_state unwind directive. Reviewed-by: Matthieu Longo --- diff --git a/config.h.in b/config.h.in index d3575c9845..f8e7d1780d 100644 --- a/config.h.in +++ b/config.h.in @@ -113,12 +113,6 @@ /* AArch64 big endian ABI */ #undef HAVE_AARCH64_BE -/* AArch64 BTI support enabled. */ -#define HAVE_AARCH64_BTI 0 - -/* AArch64 PAC-RET code generation is enabled. */ -#define HAVE_AARCH64_PAC_RET 0 - /* Assembler support ARMv8.2-A SVE. This macro becomes obsolete when glibc increased the minimum required version of GNU 'binutils' to 2.28 or later. */ diff --git a/elf/tst-asm-helper.h b/elf/tst-asm-helper.h index 6f91ac2ddc..ae2e3aae5c 100644 --- a/elf/tst-asm-helper.h +++ b/elf/tst-asm-helper.h @@ -20,6 +20,7 @@ #include +#ifdef __aarch64__ /* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ #define FEATURE_1_AND 0xc0000000 #define FEATURE_1_BTI 1 @@ -42,8 +43,5 @@ /* Add GNU property note with the supported features to all asm code where sysdep.h is included. */ -#if HAVE_AARCH64_BTI && HAVE_AARCH64_PAC_RET GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC|FEATURE_1_GCS) -#elif HAVE_AARCH64_BTI -GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_GCS) #endif diff --git a/sysdeps/aarch64/__arm_za_disable.S b/sysdeps/aarch64/__arm_za_disable.S index 629080372c..92f48145a3 100644 --- a/sysdeps/aarch64/__arm_za_disable.S +++ b/sysdeps/aarch64/__arm_za_disable.S @@ -88,10 +88,8 @@ L(save_loop): L(end): ret L(fail): -#if HAVE_AARCH64_PAC_RET - PACIASP - cfi_window_save -#endif + paciasp + cfi_negate_ra_state stp x29, x30, [sp, -32]! cfi_adjust_cfa_offset (32) cfi_rel_offset (x29, 0) diff --git a/sysdeps/aarch64/__longjmp.S b/sysdeps/aarch64/__longjmp.S index d062e04862..ed5b6b1fba 100644 --- a/sysdeps/aarch64/__longjmp.S +++ b/sysdeps/aarch64/__longjmp.S @@ -27,10 +27,8 @@ ENTRY (__longjmp) #if IS_IN(libc) /* Disable ZA state of SME in libc.a and libc.so, but not in ld.so. */ -# if HAVE_AARCH64_PAC_RET - PACIASP - cfi_window_save -# endif + paciasp + cfi_negate_ra_state stp x29, x30, [sp, -16]! cfi_adjust_cfa_offset (16) cfi_rel_offset (x29, 0) @@ -41,10 +39,8 @@ ENTRY (__longjmp) cfi_adjust_cfa_offset (-16) cfi_restore (x29) cfi_restore (x30) -# if HAVE_AARCH64_PAC_RET - AUTIASP - cfi_window_save -# endif + autiasp + cfi_negate_ra_state #endif cfi_def_cfa (x0, 0) diff --git a/sysdeps/aarch64/configure b/sysdeps/aarch64/configure index 4bd5496a4a..7bddc99d7f 100755 --- a/sysdeps/aarch64/configure +++ b/sysdeps/aarch64/configure @@ -185,93 +185,6 @@ else default-abi = lp64" fi -# Only consider BTI supported if -mbranch-protection=bti is -# on by default in the compiler and the linker produces -# binaries with GNU property notes in PT_GNU_PROPERTY segment. -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BTI support" >&5 -printf %s "checking for BTI support... " >&6; } -if test ${libc_cv_aarch64_bti+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) cat > conftest.c <&5 - (eval $ac_try) 2>&5 - ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; } \ - && { ac_try='$READELF -lW conftest.so | grep -q GNU_PROPERTY' - { { 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; }; } \ - && { ac_try='$READELF -nW conftest.so | grep -q "NT_GNU_PROPERTY_TYPE_0.*AArch64 feature:.* BTI"' - { { 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_aarch64_bti=yes - fi - rm -rf conftest.* ;; -esac -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_aarch64_bti" >&5 -printf "%s\n" "$libc_cv_aarch64_bti" >&6; } -config_vars="$config_vars -aarch64-bti = $libc_cv_aarch64_bti" -if test $libc_cv_aarch64_bti = yes; then - printf "%s\n" "#define HAVE_AARCH64_BTI 1" >>confdefs.h - -fi - -# Check if glibc is built with return address signing, i.e. -# if -mbranch-protection=pac-ret is on. We need this because -# pac-ret relies on unwinder support so it's not safe to use -# it in assembly code unconditionally, but there is no -# feature test macro for it in gcc. -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if pac-ret is enabled" >&5 -printf %s "checking if pac-ret is enabled... " >&6; } -if test ${libc_cv_aarch64_pac_ret+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) cat > conftest.c <&5 - (eval $ac_try) 2>&5 - ac_status=$? - printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; } \ - && { ac_try='grep -q -E '\''(hint( | )+25|paciasp)'\'' conftest.s' - { { 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_aarch64_pac_ret=yes - fi - rm -rf conftest.* ;; -esac -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_aarch64_pac_ret" >&5 -printf "%s\n" "$libc_cv_aarch64_pac_ret" >&6; } -if test $libc_cv_aarch64_pac_ret = yes; then - printf "%s\n" "#define HAVE_AARCH64_PAC_RET 1" >>confdefs.h - -fi - # Check if binutils supports variant PCS symbols. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for variant PCS support" >&5 printf %s "checking for variant PCS support... " >&6; } diff --git a/sysdeps/aarch64/configure.ac b/sysdeps/aarch64/configure.ac index 56d12d661d..633513374a 100644 --- a/sysdeps/aarch64/configure.ac +++ b/sysdeps/aarch64/configure.ac @@ -24,47 +24,6 @@ else LIBC_CONFIG_VAR([default-abi], [lp64]) fi -# Only consider BTI supported if -mbranch-protection=bti is -# on by default in the compiler and the linker produces -# binaries with GNU property notes in PT_GNU_PROPERTY segment. -AC_CACHE_CHECK([for BTI support], [libc_cv_aarch64_bti], [dnl - cat > conftest.c < conftest.c < conftest.S < -#undef BTI_C -#define BTI_C - /* Assumptions: * * ARMv8.2-a, AArch64, unaligned accesses, sve @@ -91,9 +88,6 @@ st1b z7.b, p0, [dst, 7, mul vl] .endm -#undef BTI_C -#define BTI_C - ENTRY (__memcpy_a64fx) cntb vlen diff --git a/sysdeps/aarch64/multiarch/memset_a64fx.S b/sysdeps/aarch64/multiarch/memset_a64fx.S index ea60b78e69..bebc191309 100644 --- a/sysdeps/aarch64/multiarch/memset_a64fx.S +++ b/sysdeps/aarch64/multiarch/memset_a64fx.S @@ -50,10 +50,6 @@ .endif .endm - -#undef BTI_C -#define BTI_C - ENTRY (__memset_a64fx) cntb vector_length diff --git a/sysdeps/aarch64/setjmp.S b/sysdeps/aarch64/setjmp.S index 83d1e342bc..c8a2994f46 100644 --- a/sysdeps/aarch64/setjmp.S +++ b/sysdeps/aarch64/setjmp.S @@ -38,10 +38,8 @@ ENTRY_ALIGN (__sigsetjmp, 2) #if IS_IN(libc) /* Disable ZA state of SME in libc.a and libc.so, but not in ld.so. */ -# if HAVE_AARCH64_PAC_RET - PACIASP - cfi_window_save -# endif + paciasp + cfi_negate_ra_state stp x29, x30, [sp, -16]! cfi_adjust_cfa_offset (16) cfi_rel_offset (x29, 0) @@ -52,10 +50,8 @@ ENTRY_ALIGN (__sigsetjmp, 2) cfi_adjust_cfa_offset (-16) cfi_restore (x29) cfi_restore (x30) -# if HAVE_AARCH64_PAC_RET - AUTIASP - cfi_window_save -# endif + autiasp + cfi_negate_ra_state #endif stp x19, x20, [x0, #JB_X19<<3] @@ -96,7 +92,7 @@ L(gcs_done): #if IS_IN (rtld) /* In ld.so we never save the signal mask */ mov w0, #0 - RET + ret #else b C_SYMBOL_NAME(__sigjmp_save) #endif diff --git a/sysdeps/aarch64/start.S b/sysdeps/aarch64/start.S index 544e397c50..694c338c8b 100644 --- a/sysdeps/aarch64/start.S +++ b/sysdeps/aarch64/start.S @@ -108,7 +108,7 @@ ENTRY(_start) because crt1.o and rcrt1.o share code and the later must avoid the use of GOT relocations before __libc_start_main is called. */ __wrap_main: - BTI_C + bti c b main #endif END(_start) diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h index 942411599d..f5e28cb242 100644 --- a/sysdeps/aarch64/sysdep.h +++ b/sysdeps/aarch64/sysdep.h @@ -21,43 +21,15 @@ #include -#ifndef __ASSEMBLER__ -/* Strip pointer authentication code from pointer p. */ -static inline void * -strip_pac (void *p) -{ - register void *ra asm ("x30") = (p); - asm ("hint 7 // xpaclri" : "+r"(ra)); - return ra; -} - -/* This is needed when glibc is built with -mbranch-protection=pac-ret - with a gcc that is affected by PR target/94891. */ -# if HAVE_AARCH64_PAC_RET -# undef RETURN_ADDRESS -# define RETURN_ADDRESS(n) strip_pac (__builtin_return_address (n)) -# endif -#endif - #ifdef __ASSEMBLER__ +/* CFI directive for return address. */ +#define cfi_negate_ra_state .cfi_negate_ra_state + /* Syntactic details of assembler. */ #define ASM_SIZE_DIRECTIVE(name) .size name,.-name -/* Branch Target Identitication support. */ -#if HAVE_AARCH64_BTI -# define BTI_C hint 34 -# define BTI_J hint 36 -#else -# define BTI_C nop -# define BTI_J nop -#endif - -/* Return address signing support (pac-ret). */ -#define PACIASP hint 25 -#define AUTIASP hint 29 - /* Guarded Control Stack support. */ #define CHKFEAT_X16 hint 40 #define MRS_GCSPR(x) mrs x, s3_3_c2_c5_1 @@ -87,11 +59,7 @@ strip_pac (void *p) /* Add GNU property note with the supported features to all asm code where sysdep.h is included. */ -#if HAVE_AARCH64_BTI && HAVE_AARCH64_PAC_RET GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC|FEATURE_1_GCS) -#elif HAVE_AARCH64_BTI -GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_GCS) -#endif /* Define an entry point visible from C. */ #define ENTRY(name) \ @@ -100,7 +68,7 @@ GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_GCS) .p2align 6; \ C_LABEL(name) \ cfi_startproc; \ - BTI_C; \ + bti c; \ CALL_MCOUNT /* Define an entry point visible from C. */ @@ -110,7 +78,7 @@ GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_GCS) .p2align align; \ C_LABEL(name) \ cfi_startproc; \ - BTI_C; \ + bti c; \ CALL_MCOUNT /* Define an entry point visible from C with a specified alignment and @@ -127,7 +95,7 @@ GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_GCS) .endr; \ C_LABEL(name) \ cfi_startproc; \ - BTI_C; \ + bti c; \ CALL_MCOUNT #undef END diff --git a/sysdeps/unix/sysv/linux/aarch64/setcontext.S b/sysdeps/unix/sysv/linux/aarch64/setcontext.S index 022a263c47..18e4fb7f21 100644 --- a/sysdeps/unix/sysv/linux/aarch64/setcontext.S +++ b/sysdeps/unix/sysv/linux/aarch64/setcontext.S @@ -49,10 +49,8 @@ ENTRY (__setcontext) b C_SYMBOL_NAME (__syscall_error) 1: /* Disable ZA of SME. */ -#if HAVE_AARCH64_PAC_RET - PACIASP - cfi_window_save -#endif + paciasp + cfi_negate_ra_state stp x29, x30, [sp, -16]! cfi_adjust_cfa_offset (16) cfi_rel_offset (x29, 0) @@ -63,10 +61,8 @@ ENTRY (__setcontext) cfi_adjust_cfa_offset (-16) cfi_restore (x29) cfi_restore (x30) -#if HAVE_AARCH64_PAC_RET - AUTIASP - cfi_window_save -#endif + autiasp + cfi_negate_ra_state /* Restore the general purpose registers. */ mov x0, x9 cfi_def_cfa (x0, 0) diff --git a/sysdeps/unix/sysv/linux/aarch64/swapcontext.S b/sysdeps/unix/sysv/linux/aarch64/swapcontext.S index cc41253a13..58ddb95591 100644 --- a/sysdeps/unix/sysv/linux/aarch64/swapcontext.S +++ b/sysdeps/unix/sysv/linux/aarch64/swapcontext.S @@ -119,7 +119,7 @@ L(gcs_done): 2: /* The oucp context is restored here via an indirect branch, x1 must be restored too which has the real return address. */ - BTI_J + bti j mov x30, x1 RET PSEUDO_END (__swapcontext)