https://gcc.gnu.org/g:94c5f47d21aa5f144a690189222cc08b86a00505

commit r17-1618-g94c5f47d21aa5f144a690189222cc08b86a00505
Author: Muhammad Kamran <[email protected]>
Date:   Wed Jun 17 13:25:31 2026 +0000

    libffi: Mark AArch64 BTI and PAC with build attributes
    
    This is an adapted backport of the BTI/PAC parts of upstream libffi commit
    547449d705258ea490aa8787dc084c5b38dbe722, which emits AArch64 feature build
    attributes when assembler support is available and keeps the existing GNU
    property note as the fallback.
    
    GCC's current libffi copy does not include the upstream GCS support, so
    this backport only covers the existing BTI and PAC feature marking.
    
    libffi/ChangeLog:
    
            * src/aarch64/internal.h (AARCH64_POINTER_AUTH): Rename from
            GNU_PROPERTY_AARCH64_POINTER_AUTH.
            * src/aarch64/sysv.S (AARCH64_BTI): Rename from
            GNU_PROPERTY_AARCH64_BTI.
            (GNU_PROPERTY): New macro.
            (FEATURE_1_AND_MARK): Likewise.
            Emit BTI and PAC feature build attributes when
            __ARM_BUILDATTR64_FV is defined.

Diff:
---
 libffi/src/aarch64/internal.h |  6 +++---
 libffi/src/aarch64/sysv.S     | 48 ++++++++++++++++++++++++++++++-------------
 2 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/libffi/src/aarch64/internal.h b/libffi/src/aarch64/internal.h
index 591b9f5c087e..2f76eb370194 100644
--- a/libffi/src/aarch64/internal.h
+++ b/libffi/src/aarch64/internal.h
@@ -91,10 +91,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
   #define SIGN_LR_LINUX_ONLY
   #define BRANCH_TO_REG braaz
   #define PAC_CFI_WINDOW_SAVE
-  #define GNU_PROPERTY_AARCH64_POINTER_AUTH 0
+  #define AARCH64_POINTER_AUTH 0
   /* Linux PAC Support */
   #elif defined(__ARM_FEATURE_PAC_DEFAULT)
-    #define GNU_PROPERTY_AARCH64_POINTER_AUTH (1 << 1)
+    #define AARCH64_POINTER_AUTH (1 << 1)
     #define PAC_CFI_WINDOW_SAVE cfi_window_save
     #define TMP_REG x9
     #define BRANCH_TO_REG br
@@ -141,6 +141,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
     #define SIGN_LR_LINUX_ONLY
     #define BRANCH_TO_REG br
     #define PAC_CFI_WINDOW_SAVE
-    #define GNU_PROPERTY_AARCH64_POINTER_AUTH 0
+    #define AARCH64_POINTER_AUTH 0
   #endif /* HAVE_ARM64E_PTRAUTH */
 #endif /* LIBFFI_ASM */
diff --git a/libffi/src/aarch64/sysv.S b/libffi/src/aarch64/sysv.S
index 81d33f2ef0a5..df932c9d4bb0 100644
--- a/libffi/src/aarch64/sysv.S
+++ b/libffi/src/aarch64/sysv.S
@@ -70,7 +70,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
  * The ELF Notes section needs to indicate if BTI is supported, as the first 
ELF loaded that doesn't
  * declare this support disables it for memory region containing the loaded 
library.
  */
-# define GNU_PROPERTY_AARCH64_BTI (1 << 0)         /* Has Branch Target 
Identification */
+# define AARCH64_BTI (1 << 0)         /* Has Branch Target Identification */
        .text
        .align 4
 
@@ -681,19 +681,39 @@ CNAME(ffi_go_closure_SYSV):
 #endif /* FFI_CLOSURES */
 #endif /* __arm64__ */
 
+#define GNU_PROPERTY(value)                                            \
+       .pushsection .note.gnu.property, "a";                           \
+       .balign 8;                                                      \
+       .long 4;                                                        \
+       .long 0x10;                                                     \
+       .long 0x5;                                                      \
+       .asciz "GNU";                                                   \
+       .long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */      \
+       .long 4;                                                        \
+       .long value;                                                    \
+       .long 0;                                                        \
+       .popsection;
+
+#ifdef __ARM_BUILDATTR64_FV
+/* Add AArch64 feature bits build attributes.  */
+# define FEATURE_1_AND_MARK(value)                                     \
+    .aeabi_subsection aeabi_feature_and_bits, optional, ULEB128;       \
+    .if ((value) & AARCH64_BTI);                                       \
+    .aeabi_attribute Tag_Feature_BTI, 1;                               \
+    .else;                                                             \
+    .aeabi_attribute Tag_Feature_BTI, 0;                               \
+    .endif;                                                            \
+    .if ((value) & AARCH64_POINTER_AUTH);                              \
+    .aeabi_attribute Tag_Feature_PAC, 1;                               \
+    .else;                                                             \
+    .aeabi_attribute Tag_Feature_PAC, 0;                               \
+    .endif;
+#else
+/* Add a NT_GNU_PROPERTY_TYPE_0 note.  */
+# define FEATURE_1_AND_MARK(value) GNU_PROPERTY (value)
+#endif /* __ARM_BUILDATTR64_FV */
+
 #if defined __ELF__ && defined __linux__
        .section .note.GNU-stack,"",%progbits
-
-       .pushsection .note.gnu.property, "a";
-       .balign 8;
-       .long 4;
-       .long 0x10;
-       .long 0x5;
-       .asciz "GNU";
-       .long 0xc0000000; /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
-       .long 4;
-       .long GNU_PROPERTY_AARCH64_BTI | GNU_PROPERTY_AARCH64_POINTER_AUTH;
-       .long 0;
-       .popsection;
+FEATURE_1_AND_MARK(AARCH64_BTI | AARCH64_POINTER_AUTH)
 #endif
-

Reply via email to