Skip to content

Commit

Permalink
[compiler-rt][AArch64] Allow platform-specific mangling of SME routin…
Browse files Browse the repository at this point in the history
…es. (llvm#119864)

Support platform-specific mangling to avoid the compiler emitting a call
to a function that is mangled differently than the definition in the
runtime library.
  • Loading branch information
sdesmalen-arm authored Dec 16, 2024
1 parent 92a4f4d commit e0fb3ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
26 changes: 14 additions & 12 deletions compiler-rt/lib/builtins/aarch64/sme-abi.S
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ DEFINE_COMPILERRT_PRIVATE_FUNCTION(do_abort)
.cfi_offset w30, -24
.cfi_offset w29, -32
.cfi_offset 46, -16
bl __arm_sme_state
bl SYMBOL_NAME(__arm_sme_state)
tbz x0, #0, 2f
1:
smstop sm
Expand All @@ -54,7 +54,7 @@ END_COMPILERRT_FUNCTION(do_abort)
// __arm_sme_state fills the result registers based on a local
// that is set as part of the compiler-rt startup code.
// __aarch64_has_sme_and_tpidr2_el0
DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_sme_state)
DEFINE_COMPILERRT_FUNCTION(__arm_sme_state)
.variant_pcs __arm_sme_state
BTI_C
mov x0, xzr
Expand All @@ -70,9 +70,9 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_sme_state)
mrs x1, TPIDR2_EL0
1:
ret
END_COMPILERRT_OUTLINE_FUNCTION(__arm_sme_state)
END_COMPILERRT_FUNCTION(__arm_sme_state)

DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_restore)
DEFINE_COMPILERRT_FUNCTION(__arm_tpidr2_restore)
.variant_pcs __arm_tpidr2_restore
BTI_C
// If TPIDR2_EL0 is nonnull, the subroutine aborts in some platform-specific
Expand Down Expand Up @@ -106,9 +106,9 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_restore)
ret
2:
b SYMBOL_NAME(do_abort)
END_COMPILERRT_OUTLINE_FUNCTION(__arm_tpidr2_restore)
END_COMPILERRT_FUNCTION(__arm_tpidr2_restore)

DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_save)
DEFINE_COMPILERRT_FUNCTION(__arm_tpidr2_save)
.variant_pcs __arm_tpidr2_save
BTI_C
// If the current thread does not have access to TPIDR2_EL0, the subroutine
Expand Down Expand Up @@ -147,9 +147,10 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_tpidr2_save)
ret
2:
b SYMBOL_NAME(do_abort)
END_COMPILERRT_OUTLINE_FUNCTION(__arm_tpidr2_save)
END_COMPILERRT_FUNCTION(__arm_tpidr2_save)

DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_za_disable)
DEFINE_COMPILERRT_FUNCTION(__arm_za_disable)
.cfi_startproc
.variant_pcs __arm_za_disable
BTI_C
// If the current thread does not have access to SME, the subroutine does
Expand All @@ -166,7 +167,7 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_za_disable)
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
bl __arm_tpidr2_save
bl SYMBOL_NAME(__arm_tpidr2_save)

// * Set TPIDR2_EL0 to null.
msr TPIDR2_EL0, xzr
Expand All @@ -181,9 +182,10 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_za_disable)
.cfi_restore w29
0:
ret
END_COMPILERRT_OUTLINE_FUNCTION(__arm_za_disable)
.cfi_endproc
END_COMPILERRT_FUNCTION(__arm_za_disable)

DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_get_current_vg)
DEFINE_COMPILERRT_FUNCTION(__arm_get_current_vg)
.variant_pcs __arm_get_current_vg
BTI_C

Expand All @@ -200,7 +202,7 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_get_current_vg)
2:
mov x0, xzr
ret
END_COMPILERRT_OUTLINE_FUNCTION(__arm_get_current_vg)
END_COMPILERRT_FUNCTION(__arm_get_current_vg)

NO_EXEC_STACK_DIRECTIVE

Expand Down
8 changes: 4 additions & 4 deletions compiler-rt/lib/builtins/aarch64/sme-libc-mem-routines.S
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
The loop tail is handled by always copying 64 bytes from the end.
*/

DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_sc_memcpy)
DEFINE_COMPILERRT_FUNCTION(__arm_sc_memcpy)
add srcend1, src, count
add dstend1, dstin, count
cmp count, 128
Expand Down Expand Up @@ -232,7 +232,7 @@ L(copy64_from_start):
stp B_l, B_h, [dstin, 16]
stp C_l, C_h, [dstin]
ret
END_COMPILERRT_OUTLINE_FUNCTION(__arm_sc_memcpy)
END_COMPILERRT_FUNCTION(__arm_sc_memcpy)

DEFINE_COMPILERRT_FUNCTION_ALIAS(__arm_sc_memmove, __arm_sc_memcpy)

Expand All @@ -250,7 +250,7 @@ DEFINE_COMPILERRT_FUNCTION_ALIAS(__arm_sc_memmove, __arm_sc_memcpy)
#define dstend2 x4
#define zva_val x5

DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(__arm_sc_memset)
DEFINE_COMPILERRT_FUNCTION(__arm_sc_memset)
#ifdef __ARM_FEATURE_SVE
mov z0.b, valw
#else
Expand Down Expand Up @@ -346,6 +346,6 @@ L(no_zva_loop):
stp q0, q0, [dstend2, -64]
stp q0, q0, [dstend2, -32]
ret
END_COMPILERRT_OUTLINE_FUNCTION(__arm_sc_memset)
END_COMPILERRT_FUNCTION(__arm_sc_memset)

#endif // __aarch64__

0 comments on commit e0fb3ac

Please sign in to comment.