]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Fix BTI support in libgcc [PR96001]
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 2 Jul 2020 16:11:56 +0000 (17:11 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 16 Jul 2020 12:46:36 +0000 (13:46 +0100)
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  <szabolcs.nagy@arm.com>

libgcc/ChangeLog:

PR target/96001
* config/aarch64/lse.S: Add BTI marking and related definitions,
and add BTI c to function entries.

(cherry picked from commit f0f62fa0320762119446893c67cb52934bc5a05e)

libgcc/config/aarch64/lse.S

index c8a9f1ab0ddd23b41ecf56575b1514f660883d13..69529834390caf7ed3becb0ecedfc83ad8c35152 100644 (file)
@@ -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