From 6521e4d2021bc047ef78c5360b9277a699117a0e Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Sat, 25 Mar 2023 17:32:15 +0100 Subject: [PATCH] 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 Reviewed-by: Leif Lindholm Reviewed-by: Oliver Smith-Denny --- MdePkg/Include/AArch64/ProcessorBind.h | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/MdePkg/Include/AArch64/ProcessorBind.h b/MdePkg/Include/AArch64/ProcessorBind.h index abe2571245..c03594d924 100644 --- a/MdePkg/Include/AArch64/ProcessorBind.h +++ b/MdePkg/Include/AArch64/ProcessorBind.h @@ -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 /**