diff options
Diffstat (limited to 'contrib/llvm-project/compiler-rt/lib/builtins')
59 files changed, 289 insertions, 125 deletions
diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/README.txt b/contrib/llvm-project/compiler-rt/lib/builtins/README.txt index 53d656d5086d..5637183cc3b4 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/README.txt +++ b/contrib/llvm-project/compiler-rt/lib/builtins/README.txt @@ -35,13 +35,13 @@ typedef uint64_t du_int; // Integral bit manipulation -di_int __ashldi3(di_int a, si_int b); // a << b -ti_int __ashlti3(ti_int a, si_int b); // a << b +di_int __ashldi3(di_int a, int b); // a << b +ti_int __ashlti3(ti_int a, int b); // a << b -di_int __ashrdi3(di_int a, si_int b); // a >> b arithmetic (sign fill) -ti_int __ashrti3(ti_int a, si_int b); // a >> b arithmetic (sign fill) -di_int __lshrdi3(di_int a, si_int b); // a >> b logical (zero fill) -ti_int __lshrti3(ti_int a, si_int b); // a >> b logical (zero fill) +di_int __ashrdi3(di_int a, int b); // a >> b arithmetic (sign fill) +ti_int __ashrti3(ti_int a, int b); // a >> b arithmetic (sign fill) +di_int __lshrdi3(di_int a, int b); // a >> b logical (zero fill) +ti_int __lshrti3(ti_int a, int b); // a >> b logical (zero fill) int __clzsi2(si_int a); // count leading zeros int __clzdi2(di_int a); // count leading zeros diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/aarch64/lse.S b/contrib/llvm-project/compiler-rt/lib/builtins/aarch64/lse.S index 1fe18f4a4681..5dc0d5320b5a 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/aarch64/lse.S +++ b/contrib/llvm-project/compiler-rt/lib/builtins/aarch64/lse.S @@ -7,7 +7,7 @@ // Out-of-line LSE atomics helpers. Ported from libgcc library. // N = {1, 2, 4, 8} // M = {1, 2, 4, 8, 16} -// ORDER = {'relax', 'acq', 'rel', 'acq_rel', 'sync'} +// ORDER = {'relax', 'acq', 'rel', 'acq_rel'} // Routines implemented: // // iM __aarch64_casM_ORDER(iM expected, iM desired, iM *ptr) @@ -35,8 +35,8 @@ HIDDEN(___aarch64_have_lse_atomics) #endif // Generate mnemonics for -// L_cas: SIZE: 1,2,4,8,16 MODEL: 1,2,3,4,5 -// L_swp L_ldadd L_ldclr L_ldeor L_ldset: SIZE: 1,2,4,8 MODEL: 1,2,3,4,5 +// L_cas: SIZE: 1,2,4,8,16 MODEL: 1,2,3,4 +// L_swp L_ldadd L_ldclr L_ldeor L_ldset: SIZE: 1,2,4,8 MODEL: 1,2,3,4 #if SIZE == 1 #define S b @@ -64,44 +64,24 @@ HIDDEN(___aarch64_have_lse_atomics) #define L #define M 0x000000 #define N 0x000000 -#define BARRIER #elif MODEL == 2 #define SUFF _acq #define A a #define L #define M 0x400000 #define N 0x800000 -#define BARRIER #elif MODEL == 3 #define SUFF _rel #define A #define L l #define M 0x008000 #define N 0x400000 -#define BARRIER #elif MODEL == 4 #define SUFF _acq_rel #define A a #define L l #define M 0x408000 #define N 0xc00000 -#define BARRIER -#elif MODEL == 5 -#define SUFF _sync -#ifdef L_swp -// swp has _acq semantics. -#define A a -#define L -#define M 0x400000 -#define N 0x800000 -#else -// All other _sync functions have _seq semantics. -#define A a -#define L l -#define M 0x408000 -#define N 0xc00000 -#endif -#define BARRIER dmb ish #else #error #endif // MODEL @@ -116,12 +96,7 @@ HIDDEN(___aarch64_have_lse_atomics) #endif #define NAME(BASE) GLUE4(__aarch64_, BASE, SIZE, SUFF) -#if MODEL == 5 -// Drop A for _sync functions. -#define LDXR GLUE3(ld, xr, S) -#else #define LDXR GLUE4(ld, A, xr, S) -#endif #define STXR GLUE4(st, L, xr, S) // Define temporary registers. @@ -161,15 +136,9 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(NAME(cas)) STXR w(tmp1), s(1), [x2] cbnz w(tmp1), 0b 1: - BARRIER ret #else -#if MODEL == 5 -// Drop A for _sync functions. -#define LDXP GLUE2(ld, xp) -#else #define LDXP GLUE3(ld, A, xp) -#endif #define STXP GLUE3(st, L, xp) #ifdef HAS_ASM_LSE #define CASP GLUE3(casp, A, L) x0, x1, x2, x3, [x4] @@ -190,7 +159,6 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(NAME(cas)) STXP w(tmp2), x2, x3, [x4] cbnz w(tmp2), 0b 1: - BARRIER ret #endif END_COMPILERRT_OUTLINE_FUNCTION(NAME(cas)) @@ -212,7 +180,6 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(NAME(swp)) LDXR s(0), [x1] STXR w(tmp1), s(tmp0), [x1] cbnz w(tmp1), 0b - BARRIER ret END_COMPILERRT_OUTLINE_FUNCTION(NAME(swp)) #endif // L_swp @@ -257,7 +224,6 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(NAME(LDNM)) OP s(tmp1), s(0), s(tmp0) STXR w(tmp2), s(tmp1), [x1] cbnz w(tmp2), 0b - BARRIER ret END_COMPILERRT_OUTLINE_FUNCTION(NAME(LDNM)) #endif // L_ldadd L_ldclr L_ldeor L_ldset diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/absvdi2.c b/contrib/llvm-project/compiler-rt/lib/builtins/absvdi2.c index b9566cd874fe..291ab5f7f91d 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/absvdi2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/absvdi2.c @@ -18,7 +18,7 @@ COMPILER_RT_ABI di_int __absvdi2(di_int a) { const int N = (int)(sizeof(di_int) * CHAR_BIT); - if (a == ((di_int)1 << (N - 1))) + if (a == ((di_int)((du_int)1 << (N - 1)))) compilerrt_abort(); const di_int t = a >> (N - 1); return (a ^ t) - t; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/absvsi2.c b/contrib/llvm-project/compiler-rt/lib/builtins/absvsi2.c index 9d5de7e8a3f2..9977c33d8f7e 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/absvsi2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/absvsi2.c @@ -18,7 +18,7 @@ COMPILER_RT_ABI si_int __absvsi2(si_int a) { const int N = (int)(sizeof(si_int) * CHAR_BIT); - if (a == ((si_int)1 << (N - 1))) + if (a == ((si_int)((su_int)1 << (N - 1)))) compilerrt_abort(); const si_int t = a >> (N - 1); return (a ^ t) - t; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/addtf3.c b/contrib/llvm-project/compiler-rt/lib/builtins/addtf3.c index 86e4f4cfc3fc..2cb3a4d59191 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/addtf3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/addtf3.c @@ -13,7 +13,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) #include "fp_add_impl.inc" COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) { diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S b/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S index bd039a0329ea..c7abdb003a68 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S +++ b/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S @@ -8,10 +8,6 @@ #include "../assembly.h" -#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ -#error big endian support not implemented -#endif - #define APSR_Z (1 << 30) #define APSR_C (1 << 29) diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S b/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S index a26cb2a3ce16..81c47661c8b5 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S +++ b/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S @@ -8,10 +8,6 @@ #include "../assembly.h" -#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ -#error big endian support not implemented -#endif - #define APSR_Z (1 << 30) #define APSR_C (1 << 29) diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/arm/divsi3.S b/contrib/llvm-project/compiler-rt/lib/builtins/arm/divsi3.S index 761bf49d3ed0..faf9af917ab6 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/arm/divsi3.S +++ b/contrib/llvm-project/compiler-rt/lib/builtins/arm/divsi3.S @@ -37,7 +37,8 @@ DEFINE_COMPILERRT_FUNCTION(__divsi3) sdiv r0, r0, r1 bx lr LOCAL_LABEL(divzero): - mov r0,#0 + // Use movs for compatibility with v8-m.base. + movs r0,#0 bx lr #else ESTABLISH_FRAME diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/arm/udivsi3.S b/contrib/llvm-project/compiler-rt/lib/builtins/arm/udivsi3.S index 9b1b035b33d6..0567ab4ab765 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/arm/udivsi3.S +++ b/contrib/llvm-project/compiler-rt/lib/builtins/arm/udivsi3.S @@ -32,7 +32,8 @@ DEFINE_COMPILERRT_FUNCTION(__udivsi3) bx lr LOCAL_LABEL(divby0): - mov r0, #0 + // Use movs for compatibility with v8-m.base. + movs r0, #0 # ifdef __ARM_EABI__ b __aeabi_idiv0 # else diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/ashlti3.c b/contrib/llvm-project/compiler-rt/lib/builtins/ashlti3.c index 2d7bd4a89380..99a133ffa22f 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/ashlti3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/ashlti3.c @@ -18,7 +18,7 @@ // Precondition: 0 <= b < bits_in_tword -COMPILER_RT_ABI ti_int __ashlti3(ti_int a, si_int b) { +COMPILER_RT_ABI ti_int __ashlti3(ti_int a, int b) { const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT); twords input; twords result; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/ashrti3.c b/contrib/llvm-project/compiler-rt/lib/builtins/ashrti3.c index f573b6d6ccba..b306051df028 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/ashrti3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/ashrti3.c @@ -18,7 +18,7 @@ // Precondition: 0 <= b < bits_in_tword -COMPILER_RT_ABI ti_int __ashrti3(ti_int a, si_int b) { +COMPILER_RT_ABI ti_int __ashrti3(ti_int a, int b) { const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT); twords input; twords result; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/assembly.h b/contrib/llvm-project/compiler-rt/lib/builtins/assembly.h index 69a3d8620f92..169d49683f50 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/assembly.h +++ b/contrib/llvm-project/compiler-rt/lib/builtins/assembly.h @@ -267,7 +267,7 @@ #define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \ .globl SYMBOL_NAME(name) SEPARATOR \ SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \ - DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \ + DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \ .set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR #if defined(__ARM_EABI__) diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/comparetf2.c b/contrib/llvm-project/compiler-rt/lib/builtins/comparetf2.c index f1592454138c..be5e9e5e44dd 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/comparetf2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/comparetf2.c @@ -39,7 +39,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) #include "fp_compare_impl.inc" COMPILER_RT_ABI CMP_RESULT __letf2(fp_t a, fp_t b) { return __leXf2__(a, b); } diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c b/contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c index f2dcd974008c..36eb696c39ee 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/cpu_model.c @@ -113,6 +113,7 @@ enum ProcessorSubtypes { ZHAOXIN_FAM7H_LUJIAZUI, AMDFAM19H_ZNVER4, INTEL_COREI7_GRANITERAPIDS, + INTEL_COREI7_GRANITERAPIDS_D, CPU_SUBTYPE_MAX }; @@ -474,13 +475,19 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model, break; // Granite Rapids: - case 0xae: case 0xad: CPU = "graniterapids"; *Type = INTEL_COREI7; *Subtype = INTEL_COREI7_GRANITERAPIDS; break; + // Granite Rapids D: + case 0xae: + CPU = "graniterapids-d"; + *Type = INTEL_COREI7; + *Subtype = INTEL_COREI7_GRANITERAPIDS_D; + break; + case 0x1c: // Most 45 nm Intel Atom processors case 0x26: // 45 nm Atom Lincroft case 0x27: // 32 nm Atom Medfield @@ -646,7 +653,7 @@ getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model, static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf, unsigned *Features) { - unsigned EAX, EBX; + unsigned EAX = 0, EBX = 0; #define setFeature(F) \ Features[F / 32] |= 1U << (F % 32) @@ -847,6 +854,17 @@ _Bool __aarch64_have_lse_atomics #if defined(__has_include) #if __has_include(<sys/auxv.h>) #include <sys/auxv.h> + +#if __has_include(<sys/ifunc.h>) +#include <sys/ifunc.h> +#else +typedef struct __ifunc_arg_t { + unsigned long _size; + unsigned long _hwcap; + unsigned long _hwcap2; +} __ifunc_arg_t; +#endif // __has_include(<sys/ifunc.h>) + #if __has_include(<asm/hwcap.h>) #include <asm/hwcap.h> @@ -858,6 +876,9 @@ _Bool __aarch64_have_lse_atomics #include <zircon/syscalls.h> #endif +#ifndef _IFUNC_ARG_HWCAP +#define _IFUNC_ARG_HWCAP (1ULL << 62) +#endif #ifndef AT_HWCAP #define AT_HWCAP 16 #endif @@ -1140,11 +1161,16 @@ struct { // As features grows new fields could be added } __aarch64_cpu_features __attribute__((visibility("hidden"), nocommon)); -void init_cpu_features_resolver(unsigned long hwcap, unsigned long hwcap2) { +void init_cpu_features_resolver(unsigned long hwcap, const __ifunc_arg_t *arg) { #define setCPUFeature(F) __aarch64_cpu_features.features |= 1ULL << F #define getCPUFeature(id, ftr) __asm__("mrs %0, " #id : "=r"(ftr)) #define extractBits(val, start, number) \ (val & ((1ULL << number) - 1ULL) << start) >> start + if (__aarch64_cpu_features.features) + return; + unsigned long hwcap2 = 0; + if (hwcap & _IFUNC_ARG_HWCAP) + hwcap2 = arg->_hwcap2; if (hwcap & HWCAP_CRC32) setCPUFeature(FEAT_CRC); if (hwcap & HWCAP_PMULL) @@ -1320,6 +1346,7 @@ void init_cpu_features_resolver(unsigned long hwcap, unsigned long hwcap2) { if (hwcap & HWCAP_SHA3) setCPUFeature(FEAT_SHA3); } + setCPUFeature(FEAT_MAX); } void CONSTRUCTOR_ATTRIBUTE init_cpu_features(void) { @@ -1328,7 +1355,6 @@ void CONSTRUCTOR_ATTRIBUTE init_cpu_features(void) { // CPU features already initialized. if (__aarch64_cpu_features.features) return; - setCPUFeature(FEAT_MAX); #if defined(__FreeBSD__) int res = 0; res = elf_aux_info(AT_HWCAP, &hwcap, sizeof hwcap); @@ -1344,7 +1370,11 @@ void CONSTRUCTOR_ATTRIBUTE init_cpu_features(void) { hwcap = getauxval(AT_HWCAP); hwcap2 = getauxval(AT_HWCAP2); #endif // defined(__FreeBSD__) - init_cpu_features_resolver(hwcap, hwcap2); + __ifunc_arg_t arg; + arg._size = sizeof(__ifunc_arg_t); + arg._hwcap = hwcap; + arg._hwcap2 = hwcap2; + init_cpu_features_resolver(hwcap | _IFUNC_ARG_HWCAP, &arg); #undef extractBits #undef getCPUFeature #undef setCPUFeature diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/crtbegin.c b/contrib/llvm-project/compiler-rt/lib/builtins/crtbegin.c new file mode 100644 index 000000000000..a0860ca12ea0 --- /dev/null +++ b/contrib/llvm-project/compiler-rt/lib/builtins/crtbegin.c @@ -0,0 +1,135 @@ +//===-- crtbegin.c - Start of constructors and destructors ----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stddef.h> + +__attribute__((visibility("hidden"))) void *__dso_handle = &__dso_handle; + +#ifdef EH_USE_FRAME_REGISTRY +__extension__ static void *__EH_FRAME_LIST__[] + __attribute__((section(".eh_frame"), aligned(sizeof(void *)))) = {}; + +extern void __register_frame_info(const void *, void *) __attribute__((weak)); +extern void *__deregister_frame_info(const void *) __attribute__((weak)); +#endif + +#ifndef CRT_HAS_INITFINI_ARRAY +typedef void (*fp)(void); + +static fp __CTOR_LIST__[] + __attribute__((section(".ctors"), aligned(sizeof(fp)))) = {(fp)-1}; +extern fp __CTOR_LIST_END__[]; +#endif + +extern void __cxa_finalize(void *) __attribute__((weak)); + +static void __attribute__((used)) __do_init(void) { + static _Bool __initialized; + if (__builtin_expect(__initialized, 0)) + return; + __initialized = 1; + +#ifdef EH_USE_FRAME_REGISTRY + static struct { void *p[8]; } __object; + if (__register_frame_info) + __register_frame_info(__EH_FRAME_LIST__, &__object); +#endif +#ifndef CRT_HAS_INITFINI_ARRAY + const size_t n = __CTOR_LIST_END__ - __CTOR_LIST__ - 1; + for (size_t i = n; i >= 1; i--) __CTOR_LIST__[i](); +#endif +} + +#ifdef CRT_HAS_INITFINI_ARRAY +__attribute__((section(".init_array"), + used)) static void (*__init)(void) = __do_init; +#elif defined(__i386__) || defined(__x86_64__) +__asm__(".pushsection .init,\"ax\",@progbits\n\t" + "call __do_init\n\t" + ".popsection"); +#elif defined(__riscv) +__asm__(".pushsection .init,\"ax\",%progbits\n\t" + "call __do_init\n\t" + ".popsection"); +#elif defined(__arm__) || defined(__aarch64__) +__asm__(".pushsection .init,\"ax\",%progbits\n\t" + "bl __do_init\n\t" + ".popsection"); +#elif defined(__mips__) +__asm__(".pushsection .init,\"ax\",@progbits\n\t" + "jal __do_init\n\t" + ".popsection"); +#elif defined(__powerpc__) || defined(__powerpc64__) +__asm__(".pushsection .init,\"ax\",@progbits\n\t" + "bl __do_init\n\t" + "nop\n\t" + ".popsection"); +#elif defined(__sparc__) +__asm__(".pushsection .init,\"ax\",@progbits\n\t" + "call __do_init\n\t" + ".popsection"); +#else +#error "crtbegin without .init_fini array unimplemented for this architecture" +#endif // CRT_HAS_INITFINI_ARRAY + +#ifndef CRT_HAS_INITFINI_ARRAY +static fp __DTOR_LIST__[] + __attribute__((section(".dtors"), aligned(sizeof(fp)))) = {(fp)-1}; +extern fp __DTOR_LIST_END__[]; +#endif + +static void __attribute__((used)) __do_fini(void) { + static _Bool __finalized; + if (__builtin_expect(__finalized, 0)) + return; + __finalized = 1; + + if (__cxa_finalize) + __cxa_finalize(__dso_handle); + +#ifndef CRT_HAS_INITFINI_ARRAY + const size_t n = __DTOR_LIST_END__ - __DTOR_LIST__ - 1; + for (size_t i = 1; i <= n; i++) __DTOR_LIST__[i](); +#endif +#ifdef EH_USE_FRAME_REGISTRY + if (__deregister_frame_info) + __deregister_frame_info(__EH_FRAME_LIST__); +#endif +} + +#ifdef CRT_HAS_INITFINI_ARRAY +__attribute__((section(".fini_array"), + used)) static void (*__fini)(void) = __do_fini; +#elif defined(__i386__) || defined(__x86_64__) +__asm__(".pushsection .fini,\"ax\",@progbits\n\t" + "call __do_fini\n\t" + ".popsection"); +#elif defined(__arm__) || defined(__aarch64__) +__asm__(".pushsection .fini,\"ax\",%progbits\n\t" + "bl __do_fini\n\t" + ".popsection"); +#elif defined(__mips__) +__asm__(".pushsection .fini,\"ax\",@progbits\n\t" + "jal __do_fini\n\t" + ".popsection"); +#elif defined(__powerpc__) || defined(__powerpc64__) +__asm__(".pushsection .fini,\"ax\",@progbits\n\t" + "bl __do_fini\n\t" + "nop\n\t" + ".popsection"); +#elif defined(__riscv) +__asm__(".pushsection .fini,\"ax\",@progbits\n\t" + "call __do_fini\n\t" + ".popsection"); +#elif defined(__sparc__) +__asm__(".pushsection .fini,\"ax\",@progbits\n\t" + "call __do_fini\n\t" + ".popsection"); +#else +#error "crtbegin without .init_fini array unimplemented for this architecture" +#endif // CRT_HAS_INIT_FINI_ARRAY diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/crtend.c b/contrib/llvm-project/compiler-rt/lib/builtins/crtend.c new file mode 100644 index 000000000000..ebcc60b89a10 --- /dev/null +++ b/contrib/llvm-project/compiler-rt/lib/builtins/crtend.c @@ -0,0 +1,22 @@ +//===-- crtend.c - End of constructors and destructors --------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <stdint.h> + +// Put 4-byte zero which is the length field in FDE at the end as a terminator. +const int32_t __EH_FRAME_LIST_END__[] + __attribute__((section(".eh_frame"), aligned(sizeof(int32_t)), + visibility("hidden"), used)) = {0}; + +#ifndef CRT_HAS_INITFINI_ARRAY +typedef void (*fp)(void); +fp __CTOR_LIST_END__[] + __attribute__((section(".ctors"), visibility("hidden"), used)) = {0}; +fp __DTOR_LIST_END__[] + __attribute__((section(".dtors"), visibility("hidden"), used)) = {0}; +#endif diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/divtf3.c b/contrib/llvm-project/compiler-rt/lib/builtins/divtf3.c index 5bcc9a8e4aa1..bd76763b07d3 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/divtf3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/divtf3.c @@ -14,7 +14,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) #define NUMBER_OF_HALF_ITERATIONS 4 #define NUMBER_OF_FULL_ITERATIONS 1 diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/extenddftf2.c b/contrib/llvm-project/compiler-rt/lib/builtins/extenddftf2.c index ddf470ecd629..835076be1f20 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/extenddftf2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/extenddftf2.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) #define SRC_DOUBLE #define DST_QUAD #include "fp_extend_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/extendhftf2.c b/contrib/llvm-project/compiler-rt/lib/builtins/extendhftf2.c index aefe9737d34f..a2cb0f771ee9 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/extendhftf2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/extendhftf2.c @@ -10,8 +10,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) && \ - defined(COMPILER_RT_HAS_FLOAT16) +#if defined(CRT_HAS_TF_MODE) && defined(COMPILER_RT_HAS_FLOAT16) #define SRC_HALF #define DST_QUAD #include "fp_extend_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/extendsftf2.c b/contrib/llvm-project/compiler-rt/lib/builtins/extendsftf2.c index cf1fd2face20..0739859bcbc1 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/extendsftf2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/extendsftf2.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) #define SRC_SINGLE #define DST_QUAD #include "fp_extend_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/fixtfdi.c b/contrib/llvm-project/compiler-rt/lib/builtins/fixtfdi.c index fe570e6b3755..d27a99b6f364 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/fixtfdi.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/fixtfdi.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) typedef di_int fixint_t; typedef du_int fixuint_t; #include "fp_fixint_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/fixtfsi.c b/contrib/llvm-project/compiler-rt/lib/builtins/fixtfsi.c index a32bd964caa3..01e352acc592 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/fixtfsi.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/fixtfsi.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) typedef si_int fixint_t; typedef su_int fixuint_t; #include "fp_fixint_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/fixtfti.c b/contrib/llvm-project/compiler-rt/lib/builtins/fixtfti.c index 19f84ce38907..491fca502113 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/fixtfti.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/fixtfti.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) typedef ti_int fixint_t; typedef tu_int fixuint_t; #include "fp_fixint_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfdi.c b/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfdi.c index a0805e63db82..febdb8f5682f 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfdi.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfdi.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) typedef du_int fixuint_t; #include "fp_fixuint_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfsi.c b/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfsi.c index 3a1320ed3e0a..4efc387df453 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfsi.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfsi.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) typedef su_int fixuint_t; #include "fp_fixuint_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfti.c b/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfti.c index 23cd1ab615a7..fa9e7aa07108 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfti.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/fixunstfti.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) typedef tu_int fixuint_t; #include "fp_fixuint_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floatdidf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floatdidf.c index d37c43b1f2f9..c994aad3f079 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floatdidf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floatdidf.c @@ -50,7 +50,7 @@ COMPILER_RT_ABI double __floatdidf(di_int a) { return 0.0; const unsigned N = sizeof(di_int) * CHAR_BIT; const di_int s = a >> (N - 1); - a = (a ^ s) - s; + a = (du_int)(a ^ s) - s; int sd = N - __builtin_clzll(a); // number of significant digits int e = sd - 1; // exponent if (sd > DBL_MANT_DIG) { diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floatdisf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floatdisf.c index 5c6316431e39..0b62ed8689bc 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floatdisf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floatdisf.c @@ -24,7 +24,7 @@ COMPILER_RT_ABI float __floatdisf(di_int a) { return 0.0F; const unsigned N = sizeof(di_int) * CHAR_BIT; const di_int s = a >> (N - 1); - a = (a ^ s) - s; + a = (du_int)(a ^ s) - s; int sd = N - __builtin_clzll(a); // number of significant digits si_int e = sd - 1; // exponent if (sd > FLT_MANT_DIG) { diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floatditf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floatditf.c index 9b07b65825b8..c6e326a1923a 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floatditf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floatditf.c @@ -15,7 +15,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) COMPILER_RT_ABI fp_t __floatditf(di_int a) { const int aWidth = sizeof a * CHAR_BIT; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floatsitf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floatsitf.c index 80a4ef08fb0e..4d5b52f4ed91 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floatsitf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floatsitf.c @@ -15,7 +15,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) COMPILER_RT_ABI fp_t __floatsitf(si_int a) { const int aWidth = sizeof a * CHAR_BIT; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floattidf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floattidf.c index 0a1c04bec82e..7bfe87f53aa0 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floattidf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floattidf.c @@ -29,7 +29,7 @@ COMPILER_RT_ABI double __floattidf(ti_int a) { const ti_int s = a >> (N - 1); a = (a ^ s) - s; int sd = N - __clzti2(a); // number of significant digits - int e = sd - 1; // exponent + si_int e = sd - 1; // exponent if (sd > DBL_MANT_DIG) { // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floattisf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floattisf.c index a8fcdbe14c07..717cb361f075 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floattisf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floattisf.c @@ -28,7 +28,7 @@ COMPILER_RT_ABI float __floattisf(ti_int a) { const ti_int s = a >> (N - 1); a = (a ^ s) - s; int sd = N - __clzti2(a); // number of significant digits - int e = sd - 1; // exponent + si_int e = sd - 1; // exponent if (sd > FLT_MANT_DIG) { // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floattitf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floattitf.c index 196cbdae14e0..fff0755c3bb4 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floattitf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floattitf.c @@ -25,7 +25,7 @@ // mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm // mmmm mmmm mmmm -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) COMPILER_RT_ABI fp_t __floattitf(ti_int a) { if (a == 0) return 0.0; @@ -34,7 +34,7 @@ COMPILER_RT_ABI fp_t __floattitf(ti_int a) { a = (a ^ s) - s; int sd = N - __clzti2(a); // number of significant digits int e = sd - 1; // exponent - if (sd > LDBL_MANT_DIG) { + if (sd > TF_MANT_DIG) { // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR // 12345678901234567890123456 @@ -43,27 +43,27 @@ COMPILER_RT_ABI fp_t __floattitf(ti_int a) { // Q = bit LDBL_MANT_DIG bits to the right of 1 // R = "or" of all bits to the right of Q switch (sd) { - case LDBL_MANT_DIG + 1: + case TF_MANT_DIG + 1: a <<= 1; break; - case LDBL_MANT_DIG + 2: + case TF_MANT_DIG + 2: break; default: - a = ((tu_int)a >> (sd - (LDBL_MANT_DIG + 2))) | - ((a & ((tu_int)(-1) >> ((N + LDBL_MANT_DIG + 2) - sd))) != 0); + a = ((tu_int)a >> (sd - (TF_MANT_DIG + 2))) | + ((a & ((tu_int)(-1) >> ((N + TF_MANT_DIG + 2) - sd))) != 0); }; // finish: a |= (a & 4) != 0; // Or P into R ++a; // round - this step may add a significant bit a >>= 2; // dump Q and R // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits - if (a & ((tu_int)1 << LDBL_MANT_DIG)) { + if (a & ((tu_int)1 << TF_MANT_DIG)) { a >>= 1; ++e; } // a is now rounded to LDBL_MANT_DIG bits } else { - a <<= (LDBL_MANT_DIG - sd); + a <<= (TF_MANT_DIG - sd); // a is now rounded to LDBL_MANT_DIG bits } diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floatunditf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floatunditf.c index 8d310851e179..abe0ca9ed8c5 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floatunditf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floatunditf.c @@ -15,7 +15,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) COMPILER_RT_ABI fp_t __floatunditf(du_int a) { const int aWidth = sizeof a * CHAR_BIT; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floatunsitf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floatunsitf.c index 7ba1fb6000dc..3f0a5249fddd 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floatunsitf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floatunsitf.c @@ -15,7 +15,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) COMPILER_RT_ABI fp_t __floatunsitf(su_int a) { const int aWidth = sizeof a * CHAR_BIT; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floatuntidf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floatuntidf.c index e69e65c1ace4..4dfca8e49309 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floatuntidf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floatuntidf.c @@ -27,7 +27,7 @@ COMPILER_RT_ABI double __floatuntidf(tu_int a) { return 0.0; const unsigned N = sizeof(tu_int) * CHAR_BIT; int sd = N - __clzti2(a); // number of significant digits - int e = sd - 1; // exponent + si_int e = sd - 1; // exponent if (sd > DBL_MANT_DIG) { // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floatuntisf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floatuntisf.c index 9dec0ab5c58f..a53659cd1fca 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floatuntisf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floatuntisf.c @@ -26,7 +26,7 @@ COMPILER_RT_ABI float __floatuntisf(tu_int a) { return 0.0F; const unsigned N = sizeof(tu_int) * CHAR_BIT; int sd = N - __clzti2(a); // number of significant digits - int e = sd - 1; // exponent + si_int e = sd - 1; // exponent if (sd > FLT_MANT_DIG) { // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/floatuntitf.c b/contrib/llvm-project/compiler-rt/lib/builtins/floatuntitf.c index d308d3118d03..33a81b34eeb1 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/floatuntitf.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/floatuntitf.c @@ -25,44 +25,44 @@ // mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm // mmmm mmmm mmmm -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) COMPILER_RT_ABI fp_t __floatuntitf(tu_int a) { if (a == 0) return 0.0; const unsigned N = sizeof(tu_int) * CHAR_BIT; int sd = N - __clzti2(a); // number of significant digits int e = sd - 1; // exponent - if (sd > LDBL_MANT_DIG) { + if (sd > TF_MANT_DIG) { // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR // 12345678901234567890123456 // 1 = msb 1 bit - // P = bit LDBL_MANT_DIG-1 bits to the right of 1 - // Q = bit LDBL_MANT_DIG bits to the right of 1 + // P = bit TF_MANT_DIG-1 bits to the right of 1 + // Q = bit TF_MANT_DIG bits to the right of 1 // R = "or" of all bits to the right of Q switch (sd) { - case LDBL_MANT_DIG + 1: + case TF_MANT_DIG + 1: a <<= 1; break; - case LDBL_MANT_DIG + 2: + case TF_MANT_DIG + 2: break; default: - a = (a >> (sd - (LDBL_MANT_DIG + 2))) | - ((a & ((tu_int)(-1) >> ((N + LDBL_MANT_DIG + 2) - sd))) != 0); + a = (a >> (sd - (TF_MANT_DIG + 2))) | + ((a & ((tu_int)(-1) >> ((N + TF_MANT_DIG + 2) - sd))) != 0); }; // finish: a |= (a & 4) != 0; // Or P into R ++a; // round - this step may add a significant bit a >>= 2; // dump Q and R - // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits - if (a & ((tu_int)1 << LDBL_MANT_DIG)) { + // a is now rounded to TF_MANT_DIG or TF_MANT_DIG+1 bits + if (a & ((tu_int)1 << TF_MANT_DIG)) { a >>= 1; ++e; } - // a is now rounded to LDBL_MANT_DIG bits + // a is now rounded to TF_MANT_DIG bits } else { - a <<= (LDBL_MANT_DIG - sd); - // a is now rounded to LDBL_MANT_DIG bits + a <<= (TF_MANT_DIG - sd); + // a is now rounded to TF_MANT_DIG bits } long_double_bits fb; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/fp_lib.h b/contrib/llvm-project/compiler-rt/lib/builtins/fp_lib.h index 3fb13a033a14..58eb45fcc729 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/fp_lib.h +++ b/contrib/llvm-project/compiler-rt/lib/builtins/fp_lib.h @@ -106,7 +106,13 @@ COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b); #elif defined QUAD_PRECISION #if __LDBL_MANT_DIG__ == 113 && defined(__SIZEOF_INT128__) +// TODO: Availability of the *tf functions should not depend on long double +// being IEEE 128, but instead on being able to use a 128-bit floating-point +// type, which includes __float128. +// Right now this (incorrectly) stops the builtins from being used for x86. #define CRT_LDBL_128BIT +#define CRT_HAS_TF_MODE +#define TF_C(c) c##L typedef uint64_t half_rep_t; typedef __uint128_t rep_t; typedef __int128_t srep_t; @@ -116,6 +122,7 @@ typedef long double fp_t; // Note: Since there is no explicit way to tell compiler the constant is a // 128-bit integer, we let the constant be casted to 128-bit integer #define significandBits 112 +#define TF_MANT_DIG (significandBits + 1) static __inline int rep_clz(rep_t a) { const union { diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/gcc_personality_v0.c b/contrib/llvm-project/compiler-rt/lib/builtins/gcc_personality_v0.c index a327a83eb9f6..3437205a1cc4 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/gcc_personality_v0.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/gcc_personality_v0.c @@ -234,7 +234,7 @@ COMPILER_RT_ABI _Unwind_Reason_Code __gcc_personality_v0( } // Walk call-site table looking for range that includes current PC. uint8_t callSiteEncoding = *lsda++; - uint32_t callSiteTableLength = readULEB128(&lsda); + size_t callSiteTableLength = readULEB128(&lsda); const uint8_t *callSiteTableStart = lsda; const uint8_t *callSiteTableEnd = callSiteTableStart + callSiteTableLength; const uint8_t *p = callSiteTableStart; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/int_mulo_impl.inc b/contrib/llvm-project/compiler-rt/lib/builtins/int_mulo_impl.inc index 567d8b9e6e60..27e7c8c43d60 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/int_mulo_impl.inc +++ b/contrib/llvm-project/compiler-rt/lib/builtins/int_mulo_impl.inc @@ -18,10 +18,10 @@ static __inline fixint_t __muloXi4(fixint_t a, fixint_t b, int *overflow) { const int N = (int)(sizeof(fixint_t) * CHAR_BIT); - const fixint_t MIN = (fixint_t)1 << (N - 1); + const fixint_t MIN = (fixint_t)((fixuint_t)1 << (N - 1)); const fixint_t MAX = ~MIN; *overflow = 0; - fixint_t result = a * b; + fixint_t result = (fixuint_t)a * b; if (a == MIN) { if (b != 0 && b != 1) *overflow = 1; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/int_mulv_impl.inc b/contrib/llvm-project/compiler-rt/lib/builtins/int_mulv_impl.inc index 1e920716ec49..06559cf302ea 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/int_mulv_impl.inc +++ b/contrib/llvm-project/compiler-rt/lib/builtins/int_mulv_impl.inc @@ -18,7 +18,7 @@ static __inline fixint_t __mulvXi3(fixint_t a, fixint_t b) { const int N = (int)(sizeof(fixint_t) * CHAR_BIT); - const fixint_t MIN = (fixint_t)1 << (N - 1); + const fixint_t MIN = (fixint_t)((fixuint_t)1 << (N - 1)); const fixint_t MAX = ~MIN; if (a == MIN) { if (b == 0 || b == 1) diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/lshrti3.c b/contrib/llvm-project/compiler-rt/lib/builtins/lshrti3.c index d00a22095993..5dc8a0a2347f 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/lshrti3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/lshrti3.c @@ -18,7 +18,7 @@ // Precondition: 0 <= b < bits_in_tword -COMPILER_RT_ABI ti_int __lshrti3(ti_int a, si_int b) { +COMPILER_RT_ABI ti_int __lshrti3(ti_int a, int b) { const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT); utwords input; utwords result; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/mulodi4.c b/contrib/llvm-project/compiler-rt/lib/builtins/mulodi4.c index 7209676a327e..6ecf92664fb5 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/mulodi4.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/mulodi4.c @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #define fixint_t di_int +#define fixuint_t du_int #include "int_mulo_impl.inc" // Returns: a * b diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/mulosi4.c b/contrib/llvm-project/compiler-rt/lib/builtins/mulosi4.c index 4e03c24455d6..3fd18a122a46 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/mulosi4.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/mulosi4.c @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #define fixint_t si_int +#define fixuint_t su_int #include "int_mulo_impl.inc" // Returns: a * b diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/muloti4.c b/contrib/llvm-project/compiler-rt/lib/builtins/muloti4.c index 9a7aa85b022b..9aab6fc3efb3 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/muloti4.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/muloti4.c @@ -19,6 +19,7 @@ // Effects: sets *overflow to 1 if a * b overflows #define fixint_t ti_int +#define fixuint_t tu_int #include "int_mulo_impl.inc" COMPILER_RT_ABI ti_int __muloti4(ti_int a, ti_int b, int *overflow) { diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/multf3.c b/contrib/llvm-project/compiler-rt/lib/builtins/multf3.c index 0626fb8c7fc9..8fd73688712c 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/multf3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/multf3.c @@ -14,7 +14,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) #include "fp_mul_impl.inc" COMPILER_RT_ABI fp_t __multf3(fp_t a, fp_t b) { return __mulXf3__(a, b); } diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/mulvdi3.c b/contrib/llvm-project/compiler-rt/lib/builtins/mulvdi3.c index 1d672c6dc155..d787d297d564 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/mulvdi3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/mulvdi3.c @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #define fixint_t di_int +#define fixuint_t du_int #include "int_mulv_impl.inc" // Returns: a * b diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/mulvsi3.c b/contrib/llvm-project/compiler-rt/lib/builtins/mulvsi3.c index 00b2e50eeca9..2571881195fc 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/mulvsi3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/mulvsi3.c @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #define fixint_t si_int +#define fixuint_t su_int #include "int_mulv_impl.inc" // Returns: a * b diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/mulvti3.c b/contrib/llvm-project/compiler-rt/lib/builtins/mulvti3.c index ba355149f9a7..fad9b2ae2765 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/mulvti3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/mulvti3.c @@ -19,6 +19,7 @@ // Effects: aborts if a * b overflows #define fixint_t ti_int +#define fixuint_t tu_int #include "int_mulv_impl.inc" COMPILER_RT_ABI ti_int __mulvti3(ti_int a, ti_int b) { return __mulvXi3(a, b); } diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/negvdi2.c b/contrib/llvm-project/compiler-rt/lib/builtins/negvdi2.c index 5c52b3ec2aa6..8c1cf2fa58d4 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/negvdi2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/negvdi2.c @@ -17,7 +17,8 @@ // Effects: aborts if -a overflows COMPILER_RT_ABI di_int __negvdi2(di_int a) { - const di_int MIN = (di_int)1 << ((int)(sizeof(di_int) * CHAR_BIT) - 1); + const di_int MIN = + (di_int)((du_int)1 << ((int)(sizeof(di_int) * CHAR_BIT) - 1)); if (a == MIN) compilerrt_abort(); return -a; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/negvsi2.c b/contrib/llvm-project/compiler-rt/lib/builtins/negvsi2.c index cccdee6dc5e5..70f214f9761d 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/negvsi2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/negvsi2.c @@ -17,7 +17,8 @@ // Effects: aborts if -a overflows COMPILER_RT_ABI si_int __negvsi2(si_int a) { - const si_int MIN = (si_int)1 << ((int)(sizeof(si_int) * CHAR_BIT) - 1); + const si_int MIN = + (si_int)((su_int)1 << ((int)(sizeof(si_int) * CHAR_BIT) - 1)); if (a == MIN) compilerrt_abort(); return -a; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/os_version_check.c b/contrib/llvm-project/compiler-rt/lib/builtins/os_version_check.c index ebfb2dfc72dd..182eabe7a6ae 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/os_version_check.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/os_version_check.c @@ -86,6 +86,10 @@ typedef Boolean (*CFStringGetCStringFuncTy)(CFStringRef, char *, CFIndex, CFStringEncoding); typedef void (*CFReleaseFuncTy)(CFTypeRef); +extern __attribute__((weak_import)) +bool _availability_version_check(uint32_t count, + dyld_build_version_t versions[]); + static void _initializeAvailabilityCheck(bool LoadPlist) { if (AvailabilityVersionCheck && !LoadPlist) { // New API is supported and we're not being asked to load the plist, @@ -94,8 +98,8 @@ static void _initializeAvailabilityCheck(bool LoadPlist) { } // Use the new API if it's is available. - AvailabilityVersionCheck = (AvailabilityVersionCheckFuncTy)dlsym( - RTLD_DEFAULT, "_availability_version_check"); + if (_availability_version_check) + AvailabilityVersionCheck = &_availability_version_check; if (AvailabilityVersionCheck && !LoadPlist) { // New API is supported and we're not being asked to load the plist, diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/powitf2.c b/contrib/llvm-project/compiler-rt/lib/builtins/powitf2.c index 8e639a03a3c4..74fe707a4e8c 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/powitf2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/powitf2.c @@ -13,7 +13,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) // Returns: a ^ b diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/riscv/fp_mode.c b/contrib/llvm-project/compiler-rt/lib/builtins/riscv/fp_mode.c index c542c34c9cc8..1a5a3de95de9 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/riscv/fp_mode.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/riscv/fp_mode.c @@ -15,7 +15,7 @@ #define RISCV_INEXACT 0x1 CRT_FE_ROUND_MODE __fe_getround(void) { -#if defined(__riscv_f) +#if defined(__riscv_f) || defined(__riscv_zfinx) int frm; __asm__ __volatile__("frrm %0" : "=r" (frm)); switch (frm) { @@ -35,7 +35,7 @@ CRT_FE_ROUND_MODE __fe_getround(void) { } int __fe_raise_inexact(void) { -#if defined(__riscv_f) +#if defined(__riscv_f) || defined(__riscv_zfinx) __asm__ __volatile__("csrsi fflags, %0" :: "i" (RISCV_INEXACT)); #endif return 0; diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/subtf3.c b/contrib/llvm-project/compiler-rt/lib/builtins/subtf3.c index 3364c28f8179..e1b1022034bf 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/subtf3.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/subtf3.c @@ -13,7 +13,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b); // Subtraction; flip the sign bit of b and add. diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/trunctfdf2.c b/contrib/llvm-project/compiler-rt/lib/builtins/trunctfdf2.c index 6857ea54d8a5..f0d2e4141f3b 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/trunctfdf2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/trunctfdf2.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) #define SRC_QUAD #define DST_DOUBLE #include "fp_trunc_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/trunctfhf2.c b/contrib/llvm-project/compiler-rt/lib/builtins/trunctfhf2.c index e3a2309d954b..f7776327251c 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/trunctfhf2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/trunctfhf2.c @@ -10,8 +10,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) && \ - defined(COMPILER_RT_HAS_FLOAT16) +#if defined(CRT_HAS_TF_MODE) && defined(COMPILER_RT_HAS_FLOAT16) #define SRC_QUAD #define DST_HALF #include "fp_trunc_impl.inc" diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/trunctfsf2.c b/contrib/llvm-project/compiler-rt/lib/builtins/trunctfsf2.c index 0261b1e90f5d..242735f738c1 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/trunctfsf2.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/trunctfsf2.c @@ -9,7 +9,7 @@ #define QUAD_PRECISION #include "fp_lib.h" -#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) +#if defined(CRT_HAS_TF_MODE) #define SRC_QUAD #define DST_SINGLE #include "fp_trunc_impl.inc" |