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

Muhammad Kamran muhammad.kamran@arm.com
Mon May 18 10:51:28 GMT 2026


Hi,

The patch has an issue of not emitting a feature in build attributes if 
it is disabled. v2 of the patch fixes it by emitting the feature with 
value 0 and can be found at:
https://inbox.sourceware.org/libc-alpha/20260518104714.19292-1-muhammad.kamran@arm.com/T/#t

Thanks,
Kamran

On 18/05/2026 10:43, 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     | 55 ++++++++++++++++++++++++++--------------
>   sysdeps/aarch64/sysdep.h | 50 ++++++++++++++++++++++++------------
>   2 files changed, 70 insertions(+), 35 deletions(-)
> 
> diff --git a/elf/tst-asm-helper.h b/elf/tst-asm-helper.h
> index 51d079b94e..3a1bf1a8ec 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,39 @@
>   #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;				\
> +    .endif;								\
> +    .if ((value) & FEATURE_1_GCS);					\
> +    .aeabi_attribute Tag_Feature_GCS, 1;				\
> +    .endif;								\
> +    .if ((value) & FEATURE_1_PAC);					\
> +    .aeabi_attribute Tag_Feature_PAC, 1;				\
> +    .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..6cb2752b20 100644
> --- a/sysdeps/aarch64/sysdep.h
> +++ b/sysdeps/aarch64/sysdep.h
> @@ -43,23 +43,41 @@
>   #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;				\
> +    .endif;								\
> +    .if ((value) & FEATURE_1_GCS);					\
> +    .aeabi_attribute Tag_Feature_GCS, 1;				\
> +    .endif;								\
> +    .if ((value) & FEATURE_1_PAC);					\
> +    .aeabi_attribute Tag_Feature_PAC, 1;				\
> +    .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)						\



More information about the Libc-alpha mailing list