On Fri, 12 Nov 2021, Jonathan Wright wrote:


This patch adds 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.

Regression tested in in a BTI-enabled environment - no issues. Could
someone take a look and merge?

diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
index d1fa72b3c6..f78942eb86 100644
--- a/libavutil/aarch64/asm.S
+++ b/libavutil/aarch64/asm.S
@@ -36,6 +36,35 @@
 #   define __has_feature(x) 0

+/* 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"
+ */
+#   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'
+#   define GNU_PROPERTY_AARCH64_BTI 0          // No BTI
+    .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 0
+    .popsection

The trailing semicolons here are superfluous. They'd be needed if stacking all of it on one single line, but as it's split over multiple lines (which I like), it's not needed, so I'd suggest removing them.

Also, I'd prefer to have these directives indented in the same way as the rest of main directives in the file, i.e. with 8 leading spaces.

 .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

I'd also prefer to have this aligned one step deeper, along with the .size/.type/.func above.

I can make these hopefully innocent changes before pushing, if that's ok with you. If you want to try out the modifications, my version, ready to be pushed, is available at https://github.com/mstorsjo/FFmpeg/commits/aarch64-bti.

// Martin

ffmpeg-devel mailing list

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to