Date: Sun, 2 Aug 2020 18:07:16 +0000 (UTC) From: Dimitry Andric <dim@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r363773 - projects/clang1100-import/contrib/llvm-project/compiler-rt/lib/builtins Message-ID: <202008021807.072I7GM9059504@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dim Date: Sun Aug 2 18:07:16 2020 New Revision: 363773 URL: https://svnweb.freebsd.org/changeset/base/363773 Log: Reapply r230021, r276851 and a few other commits to compiler-rt Reapply r230021 (by ed): Add a workaround to prevent endless recursion in compiler-rt. SPARC and MIPS CPUs don't have special instructions to count leading/trailing zeroes. The compiler-rt library provides fallback rountines for these. The 64-bit routines, __clzdi2 and __ctzdi2, are implemented as simple wrappers around the compiler built-in __builtin_clz(), assuming these will expand to either 32-bit CPU instructions or calls to __clzsi2 and __ctzsi2. Unfortunately, our GCC 4.2 probably thinks that because the operand is stored in a 64-bit register, it might just be a better idea to invoke its 64-bit equivalent, simply resulting into endless recursion. Fix this by defining __builtin_clz and __builtin_ctz to __clzsi2 and __ctzsi2 explicitly. Reapply r276851: Update compiler-rt to trunk r224034. This brings a number of new builtins, and also the various sanitizers. Support for these will be added in a later commit. Modified: projects/clang1100-import/contrib/llvm-project/compiler-rt/lib/builtins/int_lib.h Modified: projects/clang1100-import/contrib/llvm-project/compiler-rt/lib/builtins/int_lib.h ============================================================================== --- projects/clang1100-import/contrib/llvm-project/compiler-rt/lib/builtins/int_lib.h Sun Aug 2 16:59:14 2020 (r363772) +++ projects/clang1100-import/contrib/llvm-project/compiler-rt/lib/builtins/int_lib.h Sun Aug 2 18:07:16 2020 (r363773) @@ -21,7 +21,9 @@ // ABI macro definitions #if __ARM_EABI__ -#ifdef COMPILER_RT_ARMHF_TARGET +#if defined(COMPILER_RT_ARMHF_TARGET) || (!defined(__clang__) && \ + defined(__GNUC__) && (__GNUC__ < 4 || __GNUC__ == 4 && __GNUC_MINOR__ < 5)) +// The pcs attribute was introduced in GCC 4.5.0 #define COMPILER_RT_ABI #else #define COMPILER_RT_ABI __attribute__((__pcs__("aapcs"))) @@ -91,6 +93,29 @@ // Include internal utility function declarations. #include "int_util.h" + +/* + * Workaround for LLVM bug 11663. Prevent endless recursion in + * __c?zdi2(), where calls to __builtin_c?z() are expanded to + * __c?zdi2() instead of __c?zsi2(). + * + * Instead of placing this workaround in c?zdi2.c, put it in this + * global header to prevent other C files from making the detour + * through __c?zdi2() as well. + * + * This problem has been observed on FreeBSD for sparc64 and + * mips64 with GCC 4.2.1, and for riscv with GCC 5.2.0. + * Presumably it's any version of GCC, and targeting an arch that + * does not have dedicated bit counting instructions. + */ +#if defined(__FreeBSD__) && (defined(__sparc64__) || \ + defined(__mips_n32) || defined(__mips_n64) || defined(__mips_o64) || \ + defined(__riscv)) +si_int __clzsi2(si_int); +si_int __ctzsi2(si_int); +#define __builtin_clz __clzsi2 +#define __builtin_ctz __ctzsi2 +#endif /* FreeBSD && (sparc64 || mips_n32 || mips_n64 || mips_o64 || riscv) */ COMPILER_RT_ABI int __paritysi2(si_int a); COMPILER_RT_ABI int __paritydi2(di_int a);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202008021807.072I7GM9059504>