]> xenbits.xensource.com Git - ovmf.git/commitdiff
MdePkg/ProcessorBind AARCH64: Add asm macro to emit GNU BTI note
authorArd Biesheuvel <ardb@kernel.org>
Sat, 25 Mar 2023 16:32:15 +0000 (17:32 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 30 Mar 2023 11:05:22 +0000 (11:05 +0000)
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>
MdePkg/Include/AArch64/ProcessorBind.h

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