Skip to content

Commit 6ade80c

Browse files
authored
[compiler-rt] Use mangled function names on ARM64EC (#137960)
On ARM64EC, function names and calls (but not address-taking or data symbol references) use symbols prefixed with "#". Since it's an unique behavior, introduce a new `FUNC_SYMBOL` macro instead of reusing something like `SYMBOL_NAME`, which is also used for data symbols. Based on patch by Billy Laws.
1 parent 7948b39 commit 6ade80c

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

compiler-rt/lib/builtins/aarch64/sme-abi.S

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// because the function does not return.
3333
DEFINE_COMPILERRT_PRIVATE_FUNCTION(do_abort)
3434
.cfi_startproc
35-
.variant_pcs SYMBOL_NAME(do_abort)
35+
.variant_pcs FUNC_SYMBOL(SYMBOL_NAME(do_abort))
3636
BTI_C
3737
stp x29, x30, [sp, #-32]!
3838
cntd x0
@@ -42,14 +42,14 @@ DEFINE_COMPILERRT_PRIVATE_FUNCTION(do_abort)
4242
.cfi_offset w30, -24
4343
.cfi_offset w29, -32
4444
.cfi_offset 46, -16
45-
bl SYMBOL_NAME(__arm_sme_state)
45+
bl FUNC_SYMBOL(SYMBOL_NAME(__arm_sme_state))
4646
tbz x0, #0, 2f
4747
1:
4848
smstop sm
4949
2:
5050
// We can't make this into a tail-call because the unwinder would
5151
// need to restore the value of VG.
52-
bl SYMBOL_NAME(abort)
52+
bl FUNC_SYMBOL(SYMBOL_NAME(abort))
5353
.cfi_endproc
5454
END_COMPILERRT_FUNCTION(do_abort)
5555

@@ -107,7 +107,7 @@ DEFINE_COMPILERRT_FUNCTION(__arm_tpidr2_restore)
107107
1:
108108
ret
109109
2:
110-
b SYMBOL_NAME(do_abort)
110+
b FUNC_SYMBOL(SYMBOL_NAME(do_abort))
111111
END_COMPILERRT_FUNCTION(__arm_tpidr2_restore)
112112

113113
DEFINE_COMPILERRT_FUNCTION(__arm_tpidr2_save)
@@ -148,7 +148,7 @@ DEFINE_COMPILERRT_FUNCTION(__arm_tpidr2_save)
148148
1:
149149
ret
150150
2:
151-
b SYMBOL_NAME(do_abort)
151+
b FUNC_SYMBOL(SYMBOL_NAME(do_abort))
152152
END_COMPILERRT_FUNCTION(__arm_tpidr2_save)
153153

154154
DEFINE_COMPILERRT_FUNCTION(__arm_za_disable)
@@ -169,7 +169,7 @@ DEFINE_COMPILERRT_FUNCTION(__arm_za_disable)
169169
.cfi_def_cfa w29, 16
170170
.cfi_offset w30, -8
171171
.cfi_offset w29, -16
172-
bl SYMBOL_NAME(__arm_tpidr2_save)
172+
bl FUNC_SYMBOL(SYMBOL_NAME(__arm_tpidr2_save))
173173

174174
// * Set TPIDR2_EL0 to null.
175175
msr TPIDR2_EL0, xzr
@@ -301,7 +301,7 @@ DEFINE_COMPILERRT_FUNCTION(__arm_sme_save)
301301
ret
302302

303303
3:
304-
b SYMBOL_NAME(do_abort)
304+
b FUNC_SYMBOL(SYMBOL_NAME(do_abort))
305305
END_COMPILERRT_FUNCTION(__arm_sme_save)
306306

307307
DEFINE_COMPILERRT_FUNCTION(__arm_sme_restore)
@@ -365,7 +365,7 @@ DEFINE_COMPILERRT_FUNCTION(__arm_sme_restore)
365365
ret
366366

367367
3:
368-
b SYMBOL_NAME(do_abort)
368+
b FUNC_SYMBOL(SYMBOL_NAME(do_abort))
369369
.cfi_endproc
370370
END_COMPILERRT_FUNCTION(__arm_sme_restore)
371371

compiler-rt/lib/builtins/assembly.h

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#define LOCAL_LABEL(name) .L ## name
6262
#define FILE_LEVEL_DIRECTIVE
6363
#define SYMBOL_IS_FUNC(name) \
64-
.def name SEPARATOR \
64+
.def FUNC_SYMBOL(name) SEPARATOR \
6565
.scl 2 SEPARATOR \
6666
.type 32 SEPARATOR \
6767
.endef
@@ -71,7 +71,7 @@
7171

7272
#endif
7373

74-
#if defined(__arm__) || defined(__aarch64__)
74+
#if defined(__arm__) || defined(__aarch64__) || defined(__arm64ec__)
7575
#define FUNC_ALIGN \
7676
.text SEPARATOR \
7777
.balign 16 SEPARATOR
@@ -208,6 +208,16 @@
208208
#define GLUE4(a, b, c, d) GLUE4_(a, b, c, d)
209209

210210
#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
211+
#ifndef __arm64ec__
212+
#define FUNC_SYMBOL(name) name
213+
#else
214+
// On ARM64EC, function names and calls (but not address-taking or data symbol
215+
// references) use symbols prefixed with "#".
216+
#define QUOTE(a) #a
217+
#define STR(a) QUOTE(a)
218+
#define HASH #
219+
#define FUNC_SYMBOL(name) STR(GLUE2(HASH, name))
220+
#endif
211221

212222
#ifdef VISIBILITY_HIDDEN
213223
#define DECLARE_SYMBOL_VISIBILITY(name) \
@@ -222,54 +232,54 @@
222232
#define DEFINE_COMPILERRT_FUNCTION(name) \
223233
DEFINE_CODE_STATE \
224234
FILE_LEVEL_DIRECTIVE SEPARATOR \
225-
.globl SYMBOL_NAME(name) SEPARATOR \
235+
.globl FUNC_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
226236
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
227237
DECLARE_SYMBOL_VISIBILITY(name) \
228238
DECLARE_FUNC_ENCODING \
229-
SYMBOL_NAME(name):
239+
FUNC_SYMBOL(SYMBOL_NAME(name)):
230240

231241
#define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
232242
DEFINE_CODE_STATE \
233243
FILE_LEVEL_DIRECTIVE SEPARATOR \
234-
.globl SYMBOL_NAME(name) SEPARATOR \
244+
.globl FUNC_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
235245
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
236246
DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
237247
.thumb_func SEPARATOR \
238-
SYMBOL_NAME(name):
248+
FUNC_SYMBOL(SYMBOL_NAME(name)):
239249

240250
#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
241251
DEFINE_CODE_STATE \
242252
FILE_LEVEL_DIRECTIVE SEPARATOR \
243-
.globl SYMBOL_NAME(name) SEPARATOR \
253+
.globl FUNC_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
244254
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
245255
HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
246256
DECLARE_FUNC_ENCODING \
247-
SYMBOL_NAME(name):
257+
FUNC_SYMBOL(SYMBOL_NAME(name)):
248258

249259
#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
250260
DEFINE_CODE_STATE \
251-
.globl name SEPARATOR \
261+
.globl FUNC_SYMBOL(name) SEPARATOR \
252262
SYMBOL_IS_FUNC(name) SEPARATOR \
253263
HIDDEN(name) SEPARATOR \
254264
DECLARE_FUNC_ENCODING \
255-
name:
265+
FUNC_SYMBOL(name):
256266

257267
#define DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(name) \
258268
DEFINE_CODE_STATE \
259269
FUNC_ALIGN \
260-
.globl name SEPARATOR \
270+
.globl FUNC_SYMBOL(name) SEPARATOR \
261271
SYMBOL_IS_FUNC(name) SEPARATOR \
262-
DECLARE_SYMBOL_VISIBILITY_UNMANGLED(name) SEPARATOR \
272+
DECLARE_SYMBOL_VISIBILITY_UNMANGLED(FUNC_SYMBOL(name)) SEPARATOR \
263273
DECLARE_FUNC_ENCODING \
264-
name: \
274+
FUNC_SYMBOL(name): \
265275
SEPARATOR CFI_START \
266276
SEPARATOR BTI_C
267277

268278
#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
269-
.globl SYMBOL_NAME(name) SEPARATOR \
279+
.globl FUNC_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \
270280
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
271281
DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
272-
.set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
282+
.set FUNC_SYMBOL(SYMBOL_NAME(name)), FUNC_SYMBOL(target) SEPARATOR
273283

274284
#if defined(__ARM_EABI__)
275285
#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \

0 commit comments

Comments
 (0)