From: Maotong Zhang <zmtong1988@gmail.com> Commit 8d8d871b switched mingw from -lgcc to compiler-rt. This breaks i386 builds with ccache: Capstone fails to link (AArch64/ARM disassemblers) due to an undefined __ctzdi2 symbol. --- libs/compiler-rt/Makefile.in | 1 + libs/compiler-rt/lib/builtins/ctzdi2.c | 40 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 libs/compiler-rt/lib/builtins/ctzdi2.c diff --git a/libs/compiler-rt/Makefile.in b/libs/compiler-rt/Makefile.in index d0cc171ccbd..85757c21a47 100644 --- a/libs/compiler-rt/Makefile.in +++ b/libs/compiler-rt/Makefile.in @@ -7,6 +7,7 @@ SOURCES = \ lib/builtins/arm/aeabi_uldivmod.S \ lib/builtins/arm/divmodsi4.S \ lib/builtins/arm/udivmodsi4.S \ + lib/builtins/ctzdi2.c \ lib/builtins/divdi3.c \ lib/builtins/divmoddi4.c \ lib/builtins/divmodsi4.c \ diff --git a/libs/compiler-rt/lib/builtins/ctzdi2.c b/libs/compiler-rt/lib/builtins/ctzdi2.c new file mode 100644 index 00000000000..ef6d7fea136 --- /dev/null +++ b/libs/compiler-rt/lib/builtins/ctzdi2.c @@ -0,0 +1,40 @@ +/* ===-- ctzdi2.c - Implement __ctzdi2 -------------------------------------=== + * + * The LLVM Compiler Infrastructure + * + * This file is dual licensed under the MIT and the University of Illinois Open + * Source Licenses. See LICENSE.TXT for details. + * + * ===----------------------------------------------------------------------=== + * + * This file implements __ctzdi2 for the compiler_rt library. + * + * ===----------------------------------------------------------------------=== + */ + +#include "int_lib.h" + +/* Returns: the number of trailing 0-bits */ + +#if !defined(__clang__) && \ + ((defined(__sparc__) && defined(__arch64__)) || \ + defined(__mips64) || \ + (defined(__riscv) && __SIZEOF_POINTER__ >= 8)) +/* On 64-bit architectures with neither a native clz instruction nor a native + * ctz instruction, gcc resolves __builtin_ctz to __ctzdi2 rather than + * __ctzsi2, leading to infinite recursion. */ +#define __builtin_ctz(a) __ctzsi2(a) +extern si_int __ctzsi2(si_int); +#endif + +/* Precondition: a != 0 */ + +COMPILER_RT_ABI si_int +__ctzdi2(di_int a) +{ + dwords x; + x.all = a; + const si_int f = -(x.s.low == 0); + return __builtin_ctz((x.s.high & f) | (x.s.low & ~f)) + + (f & ((si_int)(sizeof(si_int) * CHAR_BIT))); +} -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10178