On 30/07/2026 16:06, Andreas Schwab wrote:
On Mai 21 2026, Muhammad Kamran wrote:
@@ -92,14 +91,39 @@
.word 0; \
.previous
+#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_PAC); \
+ .aeabi_attribute Tag_Feature_PAC, 1; \
+ .else; \
+ .aeabi_attribute Tag_Feature_PAC, 0; \
+ .endif; \
+ .if ((value) & FEATURE_1_GCS); \
+ .aeabi_attribute Tag_Feature_GCS, 1; \
+ .else; \
+ .aeabi_attribute Tag_Feature_GCS, 0; \
+ .endif; \
+ .previous
This does not work. The .previous directive will not undo the
.aeabi_subsection switch, instead it will switch to the .note.GNU-stack
section ...
+#else
+/* Add a NT_GNU_PROPERTY_TYPE_0 note. */
+# define FEATURE_1_AND_MARK(value) GNU_PROPERTY (FEATURE_1_AND, value)
+#endif
+
#if defined(__linux__) || defined(__FreeBSD__)
/* Do not require executable stack. */
.section .note.GNU-stack, "", %progbits
.previous
... which was temporarily entered here. Thus all the rest of the code
will end up there instead of .text.
Thanks, you're right. I incorrectly treated .aeabi_subsection like a
normal .section switch that could be undone with .previous. I'll drop
the .previous from the __ARM_BUILDATTR64_FV FEATURE_1_AND_MARK
definition and leave section restoration only in the GNU_PROPERTY path,
where it matches the explicit .section switch.
Thanks,
Kamran
-/* Add GNU property note if built with branch protection. */
+/* Add marking if built with branch protection. */
# if (BTI_FLAG|PAC_FLAG|GCS_FLAG) != 0
-GNU_PROPERTY (FEATURE_1_AND, BTI_FLAG|PAC_FLAG|GCS_FLAG)
+FEATURE_1_AND_MARK (BTI_FLAG|PAC_FLAG|GCS_FLAG)
# endif
#endif