summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorJonathan Wright <jonathan.wright@arm.com>2020-09-28 13:35:51 +0100
committerMartin Storsjö <martin@martin.st>2021-11-16 13:43:56 +0200
commit08b4716a9ed277afb4af69b07b751c9bd046aa70 (patch)
tree541be310256c907c799c49a4aea070629e13a173 /libavutil
parent6f04cf54f532ad5695072303d74cddaa591f9aa1 (diff)
aarch64: Add Armv8.5-A BTI support
Add Branch Target Identifiers (BTIs) to all functions defined in AArch64 assembly files. Most of the BTI landing pads are added automatically by the 'function' macro. BTI support is turned on or off at compile time based on the presence of the __ARM_FEATURE_BTI_DEFAULT feature macro. A binary compiled with BTI support can be executed on an Armv8-A processor without BTI support because the instructions are defined in NOP space. Signed-off-by: Jonathan Wright <jonathan.wright@arm.com> Signed-off-by: Elijah Ahmad <elijah.ahmad@arm.com> Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/aarch64/asm.S30
1 files changed, 30 insertions, 0 deletions
diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
index d1fa72b3c6..bee91d59c3 100644
--- a/libavutil/aarch64/asm.S
+++ b/libavutil/aarch64/asm.S
@@ -36,6 +36,35 @@
# define __has_feature(x) 0
#endif
+/* Support macros for the Armv8.5-A Branch Target Identification feature which
+ * requires emitting a .note.gnu.property section with the appropriate
+ * architecture-dependent feature bits set.
+ * Read more: "ELF for the Arm® 64-bit Architecture"
+ */
+#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
+# define GNU_PROPERTY_AARCH64_BTI (1 << 0) // Has BTI
+# define AARCH64_VALID_CALL_TARGET hint #34 // BTI 'c'
+# define AARCH64_VALID_JUMP_TARGET hint #38 // BTI 'j'
+#else
+# define GNU_PROPERTY_AARCH64_BTI 0 // No BTI
+# define AARCH64_VALID_CALL_TARGET
+# define AARCH64_VALID_JUMP_TARGET
+#endif
+
+#if (GNU_PROPERTY_AARCH64_BTI != 0)
+ .pushsection .note.gnu.property, "a"
+ .balign 8
+ .long 4
+ .long 0x10
+ .long 0x5
+ .asciz "GNU"
+ .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
+ .long 4
+ .long GNU_PROPERTY_AARCH64_BTI
+ .long 0
+ .popsection
+#endif
+
.macro function name, export=0, align=2
.macro endfunc
ELF .size \name, . - \name
@@ -49,6 +78,7 @@ FUNC .endfunc
ELF .type EXTERN_ASM\name, %function
FUNC .func EXTERN_ASM\name
EXTERN_ASM\name:
+ AARCH64_VALID_CALL_TARGET
.else
ELF .type \name, %function
FUNC .func \name