MdePkg/ProcessorBind AARCH64: Add asm macro to emit GNU BTI note

Implement a CPP macro that can be called from .S files to emit the .note
section carrying the annotation that informs the linker that the object
file is compatible with BTI control flow integrity checks.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com>
Reviewed-by: Oliver Smith-Denny <osd@smith-denny.com>
This commit is contained in:
Mikhail Krichanov 2023-04-28 16:51:15 +03:00
parent f3d158c6a0
commit bef3e16d5d

View File

@ -186,6 +186,40 @@ typedef INT64 INTN;
#define GCC_ASM_IMPORT(func__) \
.extern _CONCATENATE (__USER_LABEL_PREFIX__, func__)
#if defined (__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1
#define AARCH64_BTI_NOTE() \
.ifndef .Lgnu_bti_notesize ;\
.pushsection .note.gnu.property, "a" ;\
.set NT_GNU_PROPERTY_TYPE_0, 0x5 ;\
.set GNU_PROPERTY_AARCH64_FEATURE_1_AND, 0xc0000000 ;\
.set GNU_PROPERTY_AARCH64_FEATURE_1_BTI, 0x1 ;\
.align 3 ;\
.long .Lnamesize ;\
.long .Lgnu_bti_notesize ;\
.long NT_GNU_PROPERTY_TYPE_0 ;\
0: .asciz "GNU" ;\
.set .Lnamesize, . - 0b ;\
.align 3 ;\
1: .long GNU_PROPERTY_AARCH64_FEATURE_1_AND ;\
.long .Lvalsize ;\
2: .long GNU_PROPERTY_AARCH64_FEATURE_1_BTI ;\
.set .Lvalsize, . - 2b ;\
.align 3 ;\
.set .Lgnu_bti_notesize, . - 1b ;\
.popsection ;\
.endif
#define AARCH64_BTI(__type) \
AARCH64_BTI_NOTE() ;\
bti __type
#endif
#endif
#ifndef AARCH64_BTI
#define AARCH64_BTI_NOTE()
#define AARCH64_BTI(__type)
#endif
/**