History

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.

Jonathan Wright committed 6 years ago

Commit 08b47161 parent 6f04cf53 files · +38 −0Browse files

Unified · Split

3 files
  1. libavcodec/aarch64/fft_neon.S +4 −0
  2. libavcodec/aarch64/h264idct_neon.S +4 −0
  3. libavutil/aarch64/asm.S +30 −0
libavcodec/aarch64/fft_neon.S+4−0
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636
3737
3838 function fft4_neon
39+ AARCH64_VALID_JUMP_TARGET
3940 ld1 {v0.2s,v1.2s,v2.2s,v3.2s}, [x0]
4041
4142 fadd v4.2s, v0.2s, v1.2s // r0+r1,i0+i1
@@ -58,6 +59,7 @@ function fft4_neon · 16 unmodified lines
5859 endfunc
5960
6061 function fft8_neon
62+ AARCH64_VALID_JUMP_TARGET
6163 mov x1, x0
6264 ld1 {v0.2s, v1.2s, v2.2s, v3.2s}, [x0], #32
6365 ld1 {v16.2s,v17.2s,v18.2s,v19.2s}, [x0]
@@ -108,6 +110,7 @@ function fft8_neon · 44 unmodified lines
108110 endfunc
109111
110112 function fft16_neon
113+ AARCH64_VALID_JUMP_TARGET
111114 mov x1, x0
112115 ld1 {v0.2s, v1.2s, v2.2s, v3.2s}, [x0], #32
113116 ld1 {v16.2s,v17.2s,v18.2s,v19.2s}, [x0], #32
@@ -337,6 +340,7 @@ endfunc · 223 unmodified lines
337340
338341 .macro def_fft n, n2, n4
339342 function fft\n\()_neon, align=6
343+ AARCH64_VALID_JUMP_TARGET
340344 sub sp, sp, #16
341345 stp x28, x30, [sp]
342346 add x28, x0, #\n4*2*8
libavcodec/aarch64/h264idct_neon.S+4−0
@@ -24,6 +24,7 @@ · 23 unmodified lines
2424
2525 function ff_h264_idct_add_neon, export=1
2626 .L_ff_h264_idct_add_neon:
27+ AARCH64_VALID_CALL_TARGET
2728 ld1 {v0.4H, v1.4H, v2.4H, v3.4H}, [x1]
2829 sxtw x2, w2
2930 movi v30.8H, #0
@@ -79,6 +80,7 @@ endfunc · 49 unmodified lines
7980
8081 function ff_h264_idct_dc_add_neon, export=1
8182 .L_ff_h264_idct_dc_add_neon:
83+ AARCH64_VALID_CALL_TARGET
8284 sxtw x2, w2
8385 mov w3, #0
8486 ld1r {v2.8H}, [x1]
@@ -266,6 +268,7 @@ endfunc · 181 unmodified lines
266268
267269 function ff_h264_idct8_add_neon, export=1
268270 .L_ff_h264_idct8_add_neon:
271+ AARCH64_VALID_CALL_TARGET
269272 movi v19.8H, #0
270273 sxtw x2, w2
271274 ld1 {v24.8H, v25.8H}, [x1]
@@ -330,6 +333,7 @@ endfunc · 58 unmodified lines
330333
331334 function ff_h264_idct8_dc_add_neon, export=1
332335 .L_ff_h264_idct8_dc_add_neon:
336+ AARCH64_VALID_CALL_TARGET
333337 mov w3, #0
334338 sxtw x2, w2
335339 ld1r {v31.8H}, [x1]
libavutil/aarch64/asm.S+30−0
@@ -36,6 +36,35 @@ · 35 unmodified lines
3636 # define __has_feature(x) 0
3737 #endif
3838
39+/* Support macros for the Armv8.5-A Branch Target Identification feature which
40+ * requires emitting a .note.gnu.property section with the appropriate
41+ * architecture-dependent feature bits set.
42+ * Read more: "ELF for the Arm® 64-bit Architecture"
43+ */
44+#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
45+# define GNU_PROPERTY_AARCH64_BTI (1 << 0) // Has BTI
46+# define AARCH64_VALID_CALL_TARGET hint #34 // BTI 'c'
47+# define AARCH64_VALID_JUMP_TARGET hint #38 // BTI 'j'
48+#else
49+# define GNU_PROPERTY_AARCH64_BTI 0 // No BTI
50+# define AARCH64_VALID_CALL_TARGET
51+# define AARCH64_VALID_JUMP_TARGET
52+#endif
53+
54+#if (GNU_PROPERTY_AARCH64_BTI != 0)
55+ .pushsection .note.gnu.property, "a"
56+ .balign 8
57+ .long 4
58+ .long 0x10
59+ .long 0x5
60+ .asciz "GNU"
61+ .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
62+ .long 4
63+ .long GNU_PROPERTY_AARCH64_BTI
64+ .long 0
65+ .popsection
66+#endif
67+
3968 .macro function name, export=0, align=2
4069 .macro endfunc
4170 ELF .size \name, . - \name
@@ -49,6 +78,7 @@ FUNC .endfunc · 7 unmodified lines
4978 ELF .type EXTERN_ASM\name, %function
5079 FUNC .func EXTERN_ASM\name
5180 EXTERN_ASM\name:
81+ AARCH64_VALID_CALL_TARGET
5282 .else
5383 ELF .type \name, %function
5484 FUNC .func \name

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t