aarch64: Add assembly support for -fsanitize=hwaddress tagged globals.
[libav.git] / libavutil / aarch64 / asm.S
1 /*
2 * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
3 *
4 * This file is part of Libav.
5 *
6 * Libav 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.
10 *
11 * Libav 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.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "config.h"
22
23 #ifdef __ELF__
24 # define ELF
25 #else
26 # define ELF #
27 #endif
28
29 #if HAVE_AS_FUNC
30 # define FUNC
31 #else
32 # define FUNC #
33 #endif
34
35 #ifndef __has_feature
36 # define __has_feature(x) 0
37 #endif
38
39 .macro function name, export=0, align=2
40 .macro endfunc
41 ELF .size \name, . - \name
42 FUNC .endfunc
43 .purgem endfunc
44 .endm
45 .text
46 .align \align
47 .if \export
48 .global EXTERN_ASM\name
49 ELF .type EXTERN_ASM\name, %function
50 FUNC .func EXTERN_ASM\name
51 EXTERN_ASM\name:
52 .else
53 ELF .type \name, %function
54 FUNC .func \name
55 \name:
56 .endif
57 .endm
58
59 .macro const name, align=2, relocate=0
60 .macro endconst
61 ELF .size \name, . - \name
62 .purgem endconst
63 .endm
64 #if HAVE_SECTION_DATA_REL_RO
65 .if \relocate
66 .section .data.rel.ro
67 .else
68 .section .rodata
69 .endif
70 #elif defined(_WIN32)
71 .section .rdata
72 #elif !defined(__MACH__)
73 .section .rodata
74 #else
75 .const_data
76 #endif
77 .align \align
78 \name:
79 .endm
80
81 .macro movrel rd, val, offset=0
82 #if CONFIG_PIC && defined(__APPLE__)
83 .if \offset < 0
84 adrp \rd, \val@PAGE
85 add \rd, \rd, \val@PAGEOFF
86 sub \rd, \rd, -(\offset)
87 .else
88 adrp \rd, \val+(\offset)@PAGE
89 add \rd, \rd, \val+(\offset)@PAGEOFF
90 .endif
91 #elif CONFIG_PIC && defined(_WIN32)
92 .if \offset < 0
93 adrp \rd, \val
94 add \rd, \rd, :lo12:\val
95 sub \rd, \rd, -(\offset)
96 .else
97 adrp \rd, \val+(\offset)
98 add \rd, \rd, :lo12:\val+(\offset)
99 .endif
100 #elif CONFIG_PIC
101 # if __has_feature(hwaddress_sanitizer)
102 adrp \rd, :pg_hi21_nc:\val+(\offset)
103 # else
104 adrp \rd, \val+(\offset)
105 # endif
106 add \rd, \rd, :lo12:\val+(\offset)
107 #else
108 ldr \rd, =\val+\offset
109 #endif
110 .endm
111
112 #define GLUE(a, b) a ## b
113 #define JOIN(a, b) GLUE(a, b)
114 #define X(s) JOIN(EXTERN_ASM, s)