[v2,1/1] aarch64: Use build attributes for asm feature marking

Message ID 20260518104714.19292-2-muhammad.kamran@arm.com (mailing list archive)
State Superseded
Headers
Series aarch64: Use build attributes for feature marking |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

Muhammad Kamran May 18, 2026, 10:47 a.m. UTC
  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.
---
 elf/tst-asm-helper.h     | 61 +++++++++++++++++++++++++++-------------
 sysdeps/aarch64/sysdep.h | 56 +++++++++++++++++++++++++-----------
 2 files changed, 82 insertions(+), 35 deletions(-)
  

Comments

Adhemerval Zanella Netto May 27, 2026, 5:19 p.m. UTC | #1
On 18/05/26 07:47, Muhammad Kamran wrote:
> 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.
> ---
>  elf/tst-asm-helper.h     | 61 +++++++++++++++++++++++++++-------------
>  sysdeps/aarch64/sysdep.h | 56 +++++++++++++++++++++++++-----------
>  2 files changed, 82 insertions(+), 35 deletions(-)
> 
> diff --git a/elf/tst-asm-helper.h b/elf/tst-asm-helper.h
> index 51d079b94e..b4be9a37df 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,21 +26,45 @@
>  #define FEATURE_1_PAC 2
>  #define FEATURE_1_GCS 4
>  
> +#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 GNU_PROPERTY(type, value)	\
> -  .section .note.gnu.property, "a";	\
> -  .p2align 3;				\
> -  .word 4;				\
> -  .word 16;				\
> -  .word 5;				\
> -  .asciz "GNU";				\
> -  .word type;				\
> -  .word 4;				\
> -  .word value;				\
> -  .word 0;				\
> -  .text
> -

Please keep the same indentation for the internal fields, it helps to the git
history since the idea of this patch is to add the .aeabi_attribute support.

The patch itself looks ok to me.

> -/* 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)
> +# define GNU_PROPERTY(type, value)	\
> +    .section .note.gnu.property, "a";	\
> +    .p2align 3;				\
> +    .word 4;				\
> +    .word 16;				\
> +    .word 5;				\
> +    .asciz "GNU";			\
> +    .word type;				\
> +    .word 4;				\
> +    .word value;			\
> +    .word 0;				\
> +    .text
> +
> +# 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..6bf2f4fe0e 100644
> --- a/sysdeps/aarch64/sysdep.h
> +++ b/sysdeps/aarch64/sysdep.h
> @@ -43,23 +43,47 @@
>  #define FEATURE_1_PAC 2
>  #define FEATURE_1_GCS 4
>  
> +#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 GNU_PROPERTY(type, value)	\
> -  .section .note.gnu.property, "a";	\
> -  .p2align 3;				\
> -  .word 4;				\
> -  .word 16;				\
> -  .word 5;				\
> -  .asciz "GNU";				\
> -  .word type;				\
> -  .word 4;				\
> -  .word value;				\
> -  .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)
> +# define GNU_PROPERTY(type, value)	\
> +    .section .note.gnu.property, "a";	\
> +    .p2align 3;				\
> +    .word 4;				\
> +    .word 16;				\
> +    .word 5;				\
> +    .asciz "GNU";			\
> +    .word type;				\
> +    .word 4;				\
> +    .word value;			\
> +    .word 0;				\
> +    .text
> +
> +# 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)						\
  
Muhammad Kamran May 28, 2026, 9:32 a.m. UTC | #2
On 27/05/2026 18:19, Adhemerval Zanella Netto wrote:
> 
> 
> On 18/05/26 07:47, Muhammad Kamran wrote:
>> 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.
>> ---
>>   elf/tst-asm-helper.h     | 61 +++++++++++++++++++++++++++-------------
>>   sysdeps/aarch64/sysdep.h | 56 +++++++++++++++++++++++++-----------
>>   2 files changed, 82 insertions(+), 35 deletions(-)
>>
>> diff --git a/elf/tst-asm-helper.h b/elf/tst-asm-helper.h
>> index 51d079b94e..b4be9a37df 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,21 +26,45 @@
>>   #define FEATURE_1_PAC 2
>>   #define FEATURE_1_GCS 4
>>   
>> +#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 GNU_PROPERTY(type, value)	\
>> -  .section .note.gnu.property, "a";	\
>> -  .p2align 3;				\
>> -  .word 4;				\
>> -  .word 16;				\
>> -  .word 5;				\
>> -  .asciz "GNU";				\
>> -  .word type;				\
>> -  .word 4;				\
>> -  .word value;				\
>> -  .word 0;				\
>> -  .text
>> -
> 
> Please keep the same indentation for the internal fields, it helps to the git
> history since the idea of this patch is to add the .aeabi_attribute support.
> 
> The patch itself looks ok to me.
> 

Thanks for the review. I have posted v3 with the requested change: the 
existing GNU_PROPERTY macro indentation is now kept unchanged, so the 
diff is focused on adding the .aeabi_attribute support.

Thanks,
Kamran

>> -/* 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)
>> +# define GNU_PROPERTY(type, value)	\
>> +    .section .note.gnu.property, "a";	\
>> +    .p2align 3;				\
>> +    .word 4;				\
>> +    .word 16;				\
>> +    .word 5;				\
>> +    .asciz "GNU";			\
>> +    .word type;				\
>> +    .word 4;				\
>> +    .word value;			\
>> +    .word 0;				\
>> +    .text
>> +
>> +# 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..6bf2f4fe0e 100644
>> --- a/sysdeps/aarch64/sysdep.h
>> +++ b/sysdeps/aarch64/sysdep.h
>> @@ -43,23 +43,47 @@
>>   #define FEATURE_1_PAC 2
>>   #define FEATURE_1_GCS 4
>>   
>> +#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 GNU_PROPERTY(type, value)	\
>> -  .section .note.gnu.property, "a";	\
>> -  .p2align 3;				\
>> -  .word 4;				\
>> -  .word 16;				\
>> -  .word 5;				\
>> -  .asciz "GNU";				\
>> -  .word type;				\
>> -  .word 4;				\
>> -  .word value;				\
>> -  .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)
>> +# define GNU_PROPERTY(type, value)	\
>> +    .section .note.gnu.property, "a";	\
>> +    .p2align 3;				\
>> +    .word 4;				\
>> +    .word 16;				\
>> +    .word 5;				\
>> +    .asciz "GNU";			\
>> +    .word type;				\
>> +    .word 4;				\
>> +    .word value;			\
>> +    .word 0;				\
>> +    .text
>> +
>> +# 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)						\
>
  

Patch

diff --git a/elf/tst-asm-helper.h b/elf/tst-asm-helper.h
index 51d079b94e..b4be9a37df 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,21 +26,45 @@ 
 #define FEATURE_1_PAC 2
 #define FEATURE_1_GCS 4
 
+#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 GNU_PROPERTY(type, value)	\
-  .section .note.gnu.property, "a";	\
-  .p2align 3;				\
-  .word 4;				\
-  .word 16;				\
-  .word 5;				\
-  .asciz "GNU";				\
-  .word type;				\
-  .word 4;				\
-  .word value;				\
-  .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)
+# define GNU_PROPERTY(type, value)	\
+    .section .note.gnu.property, "a";	\
+    .p2align 3;				\
+    .word 4;				\
+    .word 16;				\
+    .word 5;				\
+    .asciz "GNU";			\
+    .word type;				\
+    .word 4;				\
+    .word value;			\
+    .word 0;				\
+    .text
+
+# 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..6bf2f4fe0e 100644
--- a/sysdeps/aarch64/sysdep.h
+++ b/sysdeps/aarch64/sysdep.h
@@ -43,23 +43,47 @@ 
 #define FEATURE_1_PAC 2
 #define FEATURE_1_GCS 4
 
+#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 GNU_PROPERTY(type, value)	\
-  .section .note.gnu.property, "a";	\
-  .p2align 3;				\
-  .word 4;				\
-  .word 16;				\
-  .word 5;				\
-  .asciz "GNU";				\
-  .word type;				\
-  .word 4;				\
-  .word value;				\
-  .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)
+# define GNU_PROPERTY(type, value)	\
+    .section .note.gnu.property, "a";	\
+    .p2align 3;				\
+    .word 4;				\
+    .word 16;				\
+    .word 5;				\
+    .asciz "GNU";			\
+    .word type;				\
+    .word 4;				\
+    .word value;			\
+    .word 0;				\
+    .text
+
+# 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)						\