[PATCH 0/3] MR10184: compiler-rt: Import aarch64 chkstk.S.
This fixes a problem with Wine build revealed by https://github.com/llvm/llvm-project/pull/179812. With that LLVM change, the compiler emits references to `__chkstk_arm64ec` from exit thunks. While these references are typically resolved by ntdll in user-mode, ntoskrnl does not provide this symbol, leading to undefined reference errors when building kernel-mode test modules. Although ARM64EC kernel modules obviously don't make much sense by themselves, there is no reason to prohibit compiler builtins in these modules regardless of the EC aspect. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10184
From: Jacek Caban <jacek@codeweavers.com> --- libs/compiler-rt/lib/builtins/assembly.h | 31 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/libs/compiler-rt/lib/builtins/assembly.h b/libs/compiler-rt/lib/builtins/assembly.h index 3f5e59b2544..b1f16491ede 100644 --- a/libs/compiler-rt/lib/builtins/assembly.h +++ b/libs/compiler-rt/lib/builtins/assembly.h @@ -57,7 +57,7 @@ #define LOCAL_LABEL(name) .L ## name #define FILE_LEVEL_DIRECTIVE #define SYMBOL_IS_FUNC(name) \ - .def name SEPARATOR \ + .def FUNC_SYMBOL(name) SEPARATOR \ .scl 2 SEPARATOR \ .type 32 SEPARATOR \ .endef @@ -135,9 +135,20 @@ #define DEFINE_CODE_STATE #endif -#define GLUE2(a, b) a##b -#define GLUE(a, b) GLUE2(a, b) +#define GLUE2_(a, b) a##b +#define GLUE(a, b) GLUE2_(a, b) +#define GLUE2(a, b) GLUE2_(a, b) #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name) +#ifndef __arm64ec__ +#define FUNC_SYMBOL(name) name +#else +// On ARM64EC, function names and calls (but not address-taking or data symbol +// references) use symbols prefixed with "#". +#define QUOTE(a) #a +#define STR(a) QUOTE(a) +#define HASH # +#define FUNC_SYMBOL(name) STR(GLUE2(HASH, name)) +#endif #ifdef VISIBILITY_HIDDEN #define DECLARE_SYMBOL_VISIBILITY(name) \ @@ -149,16 +160,16 @@ #define DEFINE_COMPILERRT_FUNCTION(name) \ DEFINE_CODE_STATE \ FILE_LEVEL_DIRECTIVE SEPARATOR \ - .globl SYMBOL_NAME(name) SEPARATOR \ + .globl FUNC_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ DECLARE_SYMBOL_VISIBILITY(name) \ DECLARE_FUNC_ENCODING \ - SYMBOL_NAME(name): + FUNC_SYMBOL(SYMBOL_NAME(name)): #define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \ DEFINE_CODE_STATE \ FILE_LEVEL_DIRECTIVE SEPARATOR \ - .globl SYMBOL_NAME(name) SEPARATOR \ + .globl FUNC_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \ .thumb_func SEPARATOR \ @@ -167,11 +178,11 @@ #define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \ DEFINE_CODE_STATE \ FILE_LEVEL_DIRECTIVE SEPARATOR \ - .globl SYMBOL_NAME(name) SEPARATOR \ + .globl FUNC_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ HIDDEN(SYMBOL_NAME(name)) SEPARATOR \ DECLARE_FUNC_ENCODING \ - SYMBOL_NAME(name): + FUNC_SYMBOL(SYMBOL_NAME(name)): #define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \ DEFINE_CODE_STATE \ @@ -182,10 +193,10 @@ name: #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \ - .globl SYMBOL_NAME(name) SEPARATOR \ + .globl FUNC_SYMBOL(SYMBOL_NAME(name)) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \ - .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR + .set FUNC_SYMBOL(SYMBOL_NAME(name)), FUNC_SYMBOL(SYMBOL_NAME(target)) SEPARATOR #if defined(__ARM_EABI__) #define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10184
From: Jacek Caban <jacek@codeweavers.com> --- libs/compiler-rt/Makefile.in | 1 + .../compiler-rt/lib/builtins/aarch64/chkstk.S | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 libs/compiler-rt/lib/builtins/aarch64/chkstk.S diff --git a/libs/compiler-rt/Makefile.in b/libs/compiler-rt/Makefile.in index 85757c21a47..48f6762158f 100644 --- a/libs/compiler-rt/Makefile.in +++ b/libs/compiler-rt/Makefile.in @@ -1,6 +1,7 @@ STATICLIB = libcompiler-rt.a SOURCES = \ + lib/builtins/aarch64/chkstk.S \ lib/builtins/arm/aeabi_idivmod.S \ lib/builtins/arm/aeabi_ldivmod.S \ lib/builtins/arm/aeabi_uidivmod.S \ diff --git a/libs/compiler-rt/lib/builtins/aarch64/chkstk.S b/libs/compiler-rt/lib/builtins/aarch64/chkstk.S new file mode 100644 index 00000000000..0a92e3057d0 --- /dev/null +++ b/libs/compiler-rt/lib/builtins/aarch64/chkstk.S @@ -0,0 +1,40 @@ +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. + +#include "../assembly.h" + +// __chkstk routine +// This routine is windows specific. +// http://msdn.microsoft.com/en-us/library/ms648426.aspx + +// This clobbers registers x16 and x17. +// Does not modify any memory or the stack pointer. + +// mov x15, #256 // Number of bytes of stack, in units of 16 byte +// bl __chkstk +// sub sp, sp, x15, lsl #4 + +#if defined(__aarch64__) || defined(__arm64ec__) + +#ifdef __arm64ec__ +#define CHKSTK_FUNC __chkstk_arm64ec +#else +#define CHKSTK_FUNC __chkstk +#endif + +#define PAGE_SIZE 4096 + + .p2align 2 +DEFINE_COMPILERRT_FUNCTION(CHKSTK_FUNC) + lsl x16, x15, #4 + mov x17, sp +1: + sub x17, x17, #PAGE_SIZE + subs x16, x16, #PAGE_SIZE + ldr xzr, [x17] + b.gt 1b + + ret +END_COMPILERRT_FUNCTION(CHKSTK_FUNC) + +#endif // defined(__aarch64__) || defined(__arm64ec__) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10184
From: Jacek Caban <jacek@codeweavers.com> --- tools/makedep.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/makedep.c b/tools/makedep.c index 05345e1b064..8b79718940a 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -2333,8 +2333,7 @@ static struct strarray get_default_imports( const struct makefile *make, struct if (nodefaultlibs) { - STRARRAY_FOR_EACH( imp, &imports ) if (!strcmp( imp, "winecrt0" )) return ret; - strarray_add( &ret, "winecrt0" ); + if (!strarray_exists( ret, "winecrt0" )) strarray_add( &ret, "winecrt0" ); if (compiler_rt) strarray_add( &ret, compiler_rt ); return ret; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10184
participants (2)
-
Jacek Caban -
Jacek Caban (@jacek)