aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/aarch64/sysdep.h
diff options
context:
space:
mode:
authorSudakshina Das <sudi.das@arm.com>2020-03-17 15:44:18 +0000
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2020-07-08 15:02:37 +0100
commit91181954f94917b1e1ae591c60cbadf0321d35af (patch)
tree8496a8e4cb39e210eea7f8ed9e5bb208ff8556bc /sysdeps/aarch64/sysdep.h
parent2a4c2dde4918c2c4e443e8328eab97db2c26e327 (diff)
downloadglibc-91181954f94917b1e1ae591c60cbadf0321d35af.zip
glibc-91181954f94917b1e1ae591c60cbadf0321d35af.tar.gz
glibc-91181954f94917b1e1ae591c60cbadf0321d35af.tar.bz2
aarch64: Add BTI support to assembly files
To enable building glibc with branch protection, assembly code needs BTI landing pads and ELF object file markings in the form of a GNU property note. The landing pads are unconditionally added to all functions that may be indirectly called. When the code segment is not mapped with PROT_BTI these instructions are nops. They are kept in the code when BTI is not supported so that the layout of performance critical code is unchanged across configurations. The GNU property notes are only added when there is support for BTI in the toolchain, because old binutils does not handle the notes right. (Does not know how to merge them nor to put them in PT_GNU_PROPERTY segment instead of PT_NOTE, and some versions of binutils emit warnings about the unknown GNU property. In such cases the produced libc binaries would not have valid ELF marking so BTI would not be enabled.) Note: functions using ENTRY or ENTRY_ALIGN now start with an additional BTI c, so alignment of the following code changes, but ENTRY_ALIGN_AND_PAD was fixed so there is no change to the existing code layout. Some string functions may need to be tuned for optimal performance after this commit. Co-authored-by: Szabolcs Nagy <szabolcs.nagy@arm.com> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/aarch64/sysdep.h')
-rw-r--r--sysdeps/aarch64/sysdep.h34
1 files changed, 33 insertions, 1 deletions
diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h
index 604c489..0eeb0bb 100644
--- a/sysdeps/aarch64/sysdep.h
+++ b/sysdeps/aarch64/sysdep.h
@@ -41,6 +41,35 @@
#define ASM_SIZE_DIRECTIVE(name) .size name,.-name
+/* Branch Target Identitication support. */
+#define BTI_C hint 34
+#define BTI_J hint 36
+
+/* 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; \
+ .text
+
+/* Add GNU property note with the supported features to all asm code
+ where sysdep.h is included. */
+#if HAVE_AARCH64_BTI
+GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI)
+#endif
+
/* Define an entry point visible from C. */
#define ENTRY(name) \
.globl C_SYMBOL_NAME(name); \
@@ -48,6 +77,7 @@
.align 4; \
C_LABEL(name) \
cfi_startproc; \
+ BTI_C; \
CALL_MCOUNT
/* Define an entry point visible from C. */
@@ -57,6 +87,7 @@
.p2align align; \
C_LABEL(name) \
cfi_startproc; \
+ BTI_C; \
CALL_MCOUNT
/* Define an entry point visible from C with a specified alignment and
@@ -68,11 +99,12 @@
.globl C_SYMBOL_NAME(name); \
.type C_SYMBOL_NAME(name),%function; \
.p2align align; \
- .rep padding; \
+ .rep padding - 1; /* -1 for bti c. */ \
nop; \
.endr; \
C_LABEL(name) \
cfi_startproc; \
+ BTI_C; \
CALL_MCOUNT
#undef END