From: Szabolcs Nagy Date: Thu, 2 Jul 2020 16:11:56 +0000 (+0100) Subject: aarch64: Fix BTI support in libgcc [PR96001] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f0f62fa0320762119446893c67cb52934bc5a05e;p=gcc.git aarch64: Fix BTI support in libgcc [PR96001] lse.S did not have the GNU property note markup and the BTI c instructions that are necessary when it is built with branch protection. The notes are only added when libgcc is built with branch protection, because old linkers mishandle the note (merge them incorrectly or emit warnings), the BTI instructions are added unconditionally. Note: BTI c is only necessary at function entry if the function may be called indirectly, currently lse functions are not called indirectly, but BTI is added for ABI reasons e.g. to allow linkers later to emit stub code with indirect jump. 2020-07-09 Szabolcs Nagy libgcc/ChangeLog: PR target/96001 * config/aarch64/lse.S: Add BTI marking and related definitions, and add BTI c to function entries. --- diff --git a/libgcc/config/aarch64/lse.S b/libgcc/config/aarch64/lse.S index 9e2acae806b..64691c601c1 100644 --- a/libgcc/config/aarch64/lse.S +++ b/libgcc/config/aarch64/lse.S @@ -136,6 +136,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define tmp1 17 #define tmp2 15 +#define BTI_C hint 34 + /* Start and end a function. */ .macro STARTFN name .text @@ -145,6 +147,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see .type \name, %function .cfi_startproc \name: + BTI_C .endm .macro ENDFN name @@ -275,6 +278,29 @@ STARTFN NAME(LDNM) ENDFN NAME(LDNM) #endif +/* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ +#define FEATURE_1_AND 0xc0000000 +#define FEATURE_1_BTI 1 +#define FEATURE_1_PAC 2 + +/* Add a NT_GNU_PROPERTY_TYPE_0 note. */ +#define GNU_PROPERTY(type, value) \ + .section .note.gnu.property, "a"; \ + .p2align 3; \ + .word 4; \ + .word 16; \ + .word 5; \ + .asciz "GNU"; \ + .word type; \ + .word 4; \ + .word value; \ + .word 0; + #if defined(__linux__) || defined(__FreeBSD__) .section .note.GNU-stack, "", %progbits + +/* Add GNU property note if built with branch protection. */ +# ifdef __ARM_FEATURE_BTI_DEFAULT +GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI) +# endif #endif