[glibc] aarch64: Use build attributes for asm feature marking

Adhemerval Zanella via Glibc-cvs <[email protected]> Fri, 29 May 2026 17:00:44 +0000 (GMT)
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b9e893b60ef6bfe3f0add02e9125e1aae58f012c

commit b9e893b60ef6bfe3f0add02e9125e1aae58f012c
Author: Muhammad Kamran <[email protected]>
Date:   Thu May 28 09:29:33 2026 +0000

    aarch64: Use build attributes for asm feature marking
    
    When the compiler defines __ARM_BUILDATTR64_FV, emit AArch64
    feature-and-bits build attributes for BTI, PAC, and GCS from sysdep.h
    instead of a GNU property note.  Keep the GNU property note as the
    fallback for older toolchains.
    
    Mirror the same marking logic in elf/tst-asm-helper.h so custom test
    DSOs and assembly tests that cannot include sysdep.h get consistent
    feature marking.
    
    Reviewed-by: Adhemerval Zanella  <[email protected]>

Diff:
---
 elf/tst-asm-helper.h     | 37 ++++++++++++++++++++++++++++++-------
 sysdeps/aarch64/sysdep.h | 32 ++++++++++++++++++++++++++++----
 2 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/elf/tst-asm-helper.h b/elf/tst-asm-helper.h
index 51d079b94e..aa565dc1c7 100644
--- a/elf/tst-asm-helper.h
+++ b/elf/tst-asm-helper.h
@@ -1,6 +1,5 @@
-/* Test header that defines macros for GNU properties that need to be
-   used in some test assembly files where sysdep.h cannot be included
-   for some reason.
+/* Test header that defines feature-marking macros used in some test
+   assembly files where sysdep.h cannot be included for some reason.
    Copyright (C) 2024-2026 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -27,7 +26,6 @@
 #define FEATURE_1_PAC 2
 #define FEATURE_1_GCS 4
 
-/* Add a NT_GNU_PROPERTY_TYPE_0 note.  */
 #define GNU_PROPERTY(type, value)	\
   .section .note.gnu.property, "a";	\
   .p2align 3;				\
@@ -41,7 +39,32 @@
   .word 0;				\
   .text
 
-/* Add GNU property note with the supported features to all asm code
-   where sysdep.h is included.  */
-GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC|FEATURE_1_GCS)
+#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) & FEATURE_1_BTI);					\
+    .aeabi_attribute Tag_Feature_BTI, 1;				\
+    .else;								\
+    .aeabi_attribute Tag_Feature_BTI, 0;				\
+    .endif;								\
+    .if ((value) & FEATURE_1_GCS);					\
+    .aeabi_attribute Tag_Feature_GCS, 1;				\
+    .else;								\
+    .aeabi_attribute Tag_Feature_GCS, 0;				\
+    .endif;								\
+    .if ((value) & FEATURE_1_PAC);					\
+    .aeabi_attribute Tag_Feature_PAC, 1;				\
+    .else;								\
+    .aeabi_attribute Tag_Feature_PAC, 0;				\
+    .endif;								\
+    .text
+#else
+/* Add a NT_GNU_PROPERTY_TYPE_0 note.  */
+# define FEATURE_1_AND_MARK(value) GNU_PROPERTY (FEATURE_1_AND, value)
+#endif /* __ARM_BUILDATTR64_FV */
+
+/* Add marking with the supported features to all asm code where this header
+   is included.  */
+FEATURE_1_AND_MARK (FEATURE_1_BTI | FEATURE_1_PAC | FEATURE_1_GCS)
 #endif
diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h
index da4b7f3fd3..77e6564d97 100644
--- a/sysdeps/aarch64/sysdep.h
+++ b/sysdeps/aarch64/sysdep.h
@@ -43,7 +43,6 @@
 #define FEATURE_1_PAC 2
 #define FEATURE_1_GCS 4
 
-/* Add a NT_GNU_PROPERTY_TYPE_0 note.  */
 #define GNU_PROPERTY(type, value)	\
   .section .note.gnu.property, "a";	\
   .p2align 3;				\
@@ -57,9 +56,34 @@
   .word 0;				\
   .text
 
-/* Add GNU property note with the supported features to all asm code
-   where sysdep.h is included.  */
-GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC|FEATURE_1_GCS)
+#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) & FEATURE_1_BTI);					\
+    .aeabi_attribute Tag_Feature_BTI, 1;				\
+    .else;								\
+    .aeabi_attribute Tag_Feature_BTI, 0;				\
+    .endif;								\
+    .if ((value) & FEATURE_1_GCS);					\
+    .aeabi_attribute Tag_Feature_GCS, 1;				\
+    .else;								\
+    .aeabi_attribute Tag_Feature_GCS, 0;				\
+    .endif;								\
+    .if ((value) & FEATURE_1_PAC);					\
+    .aeabi_attribute Tag_Feature_PAC, 1;				\
+    .else;								\
+    .aeabi_attribute Tag_Feature_PAC, 0;				\
+    .endif;								\
+    .text
+#else
+/* Add a NT_GNU_PROPERTY_TYPE_0 note.  */
+# define FEATURE_1_AND_MARK(value) GNU_PROPERTY (FEATURE_1_AND, value)
+#endif /* __ARM_BUILDATTR64_FV */
+
+/* Add marking with the supported features to all asm code where sysdep.h
+   is included.  */
+FEATURE_1_AND_MARK (FEATURE_1_BTI | FEATURE_1_PAC | FEATURE_1_GCS)
 
 /* Define an entry point visible from C.  */
 #define ENTRY(name)						\