Skip to content

Commit 3a9b136

Browse files
brooniewilldeacon
authored andcommitted
arm64: asm: Provide a mechanism for generating ELF note for BTI
ELF files built for BTI should have a program property note section which identifies them as such. The linker expects to find this note in all object files it is linking into a BTI annotated output, the compiler will ensure that this happens for C files but for assembler files we need to do this in the source so provide a macro which can be used for this purpose. To support likely future requirements for additional notes we split the defininition of the flags to set for BTI code from the macro that creates the note itself. This is mainly for use in the vDSO which should be a normal ELF shared library and should therefore include BTI annotations when built for BTI. Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 97fed77 commit 3a9b136

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

arch/arm64/include/asm/assembler.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,4 +736,54 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU
736736
.Lyield_out_\@ :
737737
.endm
738738

739+
/*
740+
* This macro emits a program property note section identifying
741+
* architecture features which require special handling, mainly for
742+
* use in assembly files included in the VDSO.
743+
*/
744+
745+
#define NT_GNU_PROPERTY_TYPE_0 5
746+
#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
747+
748+
#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0)
749+
#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1)
750+
751+
#ifdef CONFIG_ARM64_BTI_KERNEL
752+
#define GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT \
753+
((GNU_PROPERTY_AARCH64_FEATURE_1_BTI | \
754+
GNU_PROPERTY_AARCH64_FEATURE_1_PAC))
755+
#endif
756+
757+
#ifdef GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT
758+
.macro emit_aarch64_feature_1_and, feat=GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT
759+
.pushsection .note.gnu.property, "a"
760+
.align 3
761+
.long 2f - 1f
762+
.long 6f - 3f
763+
.long NT_GNU_PROPERTY_TYPE_0
764+
1: .string "GNU"
765+
2:
766+
.align 3
767+
3: .long GNU_PROPERTY_AARCH64_FEATURE_1_AND
768+
.long 5f - 4f
769+
4:
770+
/*
771+
* This is described with an array of char in the Linux API
772+
* spec but the text and all other usage (including binutils,
773+
* clang and GCC) treat this as a 32 bit value so no swizzling
774+
* is required for big endian.
775+
*/
776+
.long \feat
777+
5:
778+
.align 3
779+
6:
780+
.popsection
781+
.endm
782+
783+
#else
784+
.macro emit_aarch64_feature_1_and, feat=0
785+
.endm
786+
787+
#endif /* GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT */
788+
739789
#endif /* __ASM_ASSEMBLER_H */

0 commit comments

Comments
 (0)