2 * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36 # define __has_feature(x) 0
39 #if HAVE_AS_ARCH_DIRECTIVE
43 #if HAVE_AS_ARCHEXT_DOTPROD_DIRECTIVE
44 #define ENABLE_DOTPROD .arch_extension dotprod
45 #define DISABLE_DOTPROD .arch_extension nodotprod
47 #define ENABLE_DOTPROD
48 #define DISABLE_DOTPROD
51 #if HAVE_AS_ARCHEXT_I8MM_DIRECTIVE
52 #define ENABLE_I8MM .arch_extension i8mm
53 #define DISABLE_I8MM .arch_extension noi8mm
64 * - Armv8.3-A Pointer Authentication and
65 * - Armv8.5-A Branch Target Identification
66 * features which require emitting a .note.gnu.property section with the
67 * appropriate architecture-dependent feature bits set.
69 * |AARCH64_SIGN_LINK_REGISTER| and |AARCH64_VALIDATE_LINK_REGISTER| expand to
70 * PACIxSP and AUTIxSP, respectively. |AARCH64_SIGN_LINK_REGISTER| should be
71 * used immediately before saving the LR register (x30) to the stack.
72 * |AARCH64_VALIDATE_LINK_REGISTER| should be used immediately after restoring
73 * it. Note |AARCH64_SIGN_LINK_REGISTER|'s modifications to LR must be undone
74 * with |AARCH64_VALIDATE_LINK_REGISTER| before RET. The SP register must also
75 * have the same value at the two points. For example:
79 * AARCH64_SIGN_LINK_REGISTER
80 * stp x29, x30, [sp, #-96]!
83 * ldp x29, x30, [sp], #96
84 * AARCH64_VALIDATE_LINK_REGISTER
87 * |AARCH64_VALID_CALL_TARGET| expands to BTI 'c'. Either it, or
88 * |AARCH64_SIGN_LINK_REGISTER|, must be used at every point that may be an
89 * indirect call target. In particular, all symbols exported from a file must
90 * begin with one of these macros. For example, a leaf function that does not
91 * save LR can instead use |AARCH64_VALID_CALL_TARGET|:
95 * AARCH64_VALID_CALL_TARGET
99 * A non-leaf function which does not immediately save LR may need both macros
100 * because |AARCH64_SIGN_LINK_REGISTER| appears late. For example, the function
101 * may jump to an alternate implementation before setting up the stack:
103 * .globl with_early_jump
105 * AARCH64_VALID_CALL_TARGET
107 * b.lt .Lwith_early_jump_128
108 * AARCH64_SIGN_LINK_REGISTER
109 * stp x29, x30, [sp, #-96]!
112 * ldp x29, x30, [sp], #96
113 * AARCH64_VALIDATE_LINK_REGISTER
116 * .Lwith_early_jump_128:
120 * These annotations are only required with indirect calls. Private symbols that
121 * are only the target of direct calls do not require annotations. Also note
122 * that |AARCH64_VALID_CALL_TARGET| is only valid for indirect calls (BLR), not
123 * indirect jumps (BR). Indirect jumps in assembly are supported through
124 * |AARCH64_VALID_JUMP_TARGET|. Landing Pads which shall serve for jumps and
125 * calls can be created using |AARCH64_VALID_JUMP_CALL_TARGET|.
127 * Although not necessary, it is safe to use these macros in 32-bit ARM
128 * assembly. This may be used to simplify dual 32-bit and 64-bit files.
131 * - "ELF for the ArmĀ® 64-bit Architecture"
132 * https: *github.com/ARM-software/abi-aa/blob/master/aaelf64/aaelf64.rst
133 * - "Providing protection for complex software"
134 * https://developer.arm.com/architectures/learn-the-architecture/providing-protection-for-complex-software
136 #if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
137 # define GNU_PROPERTY_AARCH64_BTI (1 << 0) // Has BTI
138 # define AARCH64_VALID_CALL_TARGET hint #34 // BTI 'c'
139 # define AARCH64_VALID_JUMP_TARGET hint #38 // BTI 'j'
141 # define GNU_PROPERTY_AARCH64_BTI 0 // No BTI
142 # define AARCH64_VALID_CALL_TARGET
143 # define AARCH64_VALID_JUMP_TARGET
146 #if defined(__ARM_FEATURE_PAC_DEFAULT)
147 # if ((__ARM_FEATURE_PAC_DEFAULT & (1 << 0)) != 0) // authentication using key A
148 # define AARCH64_SIGN_LINK_REGISTER paciasp
149 # define AARCH64_VALIDATE_LINK_REGISTER autiasp
150 # elif ((__ARM_FEATURE_PAC_DEFAULT & (1 << 1)) != 0) // authentication using key B
151 # define AARCH64_SIGN_LINK_REGISTER pacibsp
152 # define AARCH64_VALIDATE_LINK_REGISTER autibsp
154 # error Pointer authentication defines no valid key!
156 # if ((__ARM_FEATURE_PAC_DEFAULT & (1 << 2)) != 0)
157 # error Authentication of leaf functions is enabled but not supported in FFmpeg!
159 # define GNU_PROPERTY_AARCH64_PAC (1 << 1)
161 # define GNU_PROPERTY_AARCH64_PAC 0
162 # define AARCH64_SIGN_LINK_REGISTER
163 # define AARCH64_VALIDATE_LINK_REGISTER
167 #if (GNU_PROPERTY_AARCH64_BTI != 0 || GNU_PROPERTY_AARCH64_PAC != 0) && defined(__ELF__)
168 .pushsection .note.gnu.property, "a"
174 .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
176 .long (GNU_PROPERTY_AARCH64_BTI | GNU_PROPERTY_AARCH64_PAC)
181 .macro function name, export=0, align=2
183 ELF .size \name, . - \name
190 .global EXTERN_ASM\name
191 ELF .type EXTERN_ASM\name, %function
192 FUNC .func EXTERN_ASM\name
194 AARCH64_VALID_CALL_TARGET
196 ELF .type \name, %function
202 .macro const name, align=2, relocate=0
204 ELF .size \name, . - \name
207 #if HAVE_SECTION_DATA_REL_RO
209 .section .data.rel.ro
213 #elif defined(_WIN32)
215 #elif !defined(__MACH__)
224 .macro movrel rd, val, offset=0
225 #if CONFIG_PIC && defined(__APPLE__)
228 add \rd, \rd, \val@PAGEOFF
229 sub \rd, \rd, -(\offset)
231 adrp \rd, \val+(\offset)@PAGE
232 add \rd, \rd, \val+(\offset)@PAGEOFF
234 #elif CONFIG_PIC && defined(_WIN32)
237 add \rd, \rd, :lo12:\val
238 sub \rd, \rd, -(\offset)
240 adrp \rd, \val+(\offset)
241 add \rd, \rd, :lo12:\val+(\offset)
244 # if __has_feature(hwaddress_sanitizer)
245 adrp \rd, :pg_hi21_nc:\val+(\offset)
247 adrp \rd, \val+(\offset)
249 add \rd, \rd, :lo12:\val+(\offset)
251 ldr \rd, =\val+\offset
255 #define GLUE(a, b) a ## b
256 #define JOIN(a, b) GLUE(a, b)
257 #define X(s) JOIN(EXTERN_ASM, s)
259 #define x18 do_not_use_x18
260 #define w18 do_not_use_w18