]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
aarch64: Use build attributes for asm feature marking
authorMuhammad Kamran <muhammad.kamran@arm.com>
Thu, 28 May 2026 09:29:33 +0000 (09:29 +0000)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 29 May 2026 16:58:58 +0000 (13:58 -0300)
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 <adhemerval.zanella@linaro.org>
elf/tst-asm-helper.h
sysdeps/aarch64/sysdep.h

index 51d079b94ec01efee7dc9878c586b98fe0365fb1..aa565dc1c7af5f4361c30750a3c2a4ea892748ec 100644 (file)
@@ -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;                          \
   .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
index da4b7f3fd32c4fbd62ce777d1857baeda279dcbb..77e6564d97bb5473bc915dde142522f7ee938914 100644 (file)
@@ -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;                          \
   .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)                                            \