From dc77e7d37904fc9f3170379481fa2ff185e7d555 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sun, 3 Feb 2019 23:36:49 +0100 Subject: [PATCH] [CRT] Use alias names for rot functions when compiling with Clang-CL Clang-CL does not support #pragma function like CL. The alternative to this approach is to disable all intrinsics for this single source file, but that is not trivial to do, as it can only be done by removing a compiler switch, which we have no CMake support for. Therefore this solution is simpler and as good. --- sdk/lib/crt/crt.cmake | 4 ++++ sdk/lib/crt/stdlib/clang-alias.s | 22 ++++++++++++++++++++++ sdk/lib/crt/stdlib/rot.c | 10 ++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 sdk/lib/crt/stdlib/clang-alias.s diff --git a/sdk/lib/crt/crt.cmake b/sdk/lib/crt/crt.cmake index a6a7e5dc137..144a6000976 100644 --- a/sdk/lib/crt/crt.cmake +++ b/sdk/lib/crt/crt.cmake @@ -441,6 +441,10 @@ if(ARCH STREQUAL "i386") list(APPEND CRT_ASM_SOURCE except/i386/cpp.s) endif() + if(USE_CLANG_CL) + list(APPEND CRT_ASM_SOURCE + stdlib/clang-alias.s) + endif() elseif(ARCH STREQUAL "amd64") list(APPEND CRT_ASM_SOURCE except/amd64/seh.s diff --git a/sdk/lib/crt/stdlib/clang-alias.s b/sdk/lib/crt/stdlib/clang-alias.s new file mode 100644 index 00000000000..56550073af8 --- /dev/null +++ b/sdk/lib/crt/stdlib/clang-alias.s @@ -0,0 +1,22 @@ +#include + +.code + +MACRO(DEFINE_ALIAS, alias, orig, type) +EXTERN &orig:&type +ALIAS <&alias> = <&orig> +ENDM + +#ifdef _M_X64 +DEFINE_ALIAS _rotl, __function_rotl +DEFINE_ALIAS _rotr, __function_rotr +DEFINE_ALIAS _lrotl, __function_lrotl +DEFINE_ALIAS _lrotr, __function_lrotr +#else +DEFINE_ALIAS __rotl, ___function_rotl +DEFINE_ALIAS __rotr, ___function_rotr +DEFINE_ALIAS __lrotl, ___function_lrotl +DEFINE_ALIAS __lrotr, ___function_lrotr +#endif + +END diff --git a/sdk/lib/crt/stdlib/rot.c b/sdk/lib/crt/stdlib/rot.c index 7637a5e9b6d..3c4b613a3a6 100644 --- a/sdk/lib/crt/stdlib/rot.c +++ b/sdk/lib/crt/stdlib/rot.c @@ -10,11 +10,18 @@ #include -#ifdef _MSC_VER +#ifdef __clang__ +#define _rotl __function_rotl +#define _rotr __function_rotr +#define _lrotl __function_lrotl +#define _lrotr __function_lrotr +#elif defined(_MSC_VER) #pragma function(_rotr, _rotl, _rotr, _lrotl, _lrotr) #endif unsigned int _rotr( unsigned int value, int shift ); +unsigned long _lrotr(unsigned long value, int shift); + /* * @implemented */ @@ -43,7 +50,6 @@ unsigned int _rotr( unsigned int value, int shift ) return (value >> shift) | (value << (max_bits-shift)); } - /* * @implemented */ -- 2.17.1