llvmPackages_13.compiler-rt: fix build on darwin

Ported from cf4e1b9e62ab987552eb676f7618ea085f12a751.

+73
+71
pkgs/development/compilers/llvm/13/compiler-rt/darwin-targetconditionals.patch
···
··· 1 + diff --git a/lib/sanitizer_common/sanitizer_mac.cpp b/lib/sanitizer_common/sanitizer_mac.cpp 2 + --- a/lib/sanitizer_common/sanitizer_mac.cpp 3 + +++ b/lib/sanitizer_common/sanitizer_mac.cpp 4 + @@ -613,9 +613,15 @@ HandleSignalMode GetHandleSignalMode(int signum) { 5 + // Offset example: 6 + // XNU 17 -- macOS 10.13 -- iOS 11 -- tvOS 11 -- watchOS 4 7 + constexpr u16 GetOSMajorKernelOffset() { 8 + - if (TARGET_OS_OSX) return 4; 9 + - if (TARGET_OS_IOS || TARGET_OS_TV) return 6; 10 + - if (TARGET_OS_WATCH) return 13; 11 + +#if TARGET_OS_OSX 12 + + return 4; 13 + +#endif 14 + +#if TARGET_OS_IOS || TARGET_OS_TV 15 + + return 6; 16 + +#endif 17 + +#if TARGET_OS_WATCH 18 + + return 13; 19 + +#endif 20 + } 21 + 22 + using VersStr = char[64]; 23 + @@ -627,13 +633,13 @@ static uptr ApproximateOSVersionViaKernelVersion(VersStr vers) { 24 + u16 os_major = kernel_major - offset; 25 + 26 + const char *format = "%d.0"; 27 + - if (TARGET_OS_OSX) { 28 + - if (os_major >= 16) { // macOS 11+ 29 + - os_major -= 5; 30 + - } else { // macOS 10.15 and below 31 + - format = "10.%d"; 32 + - } 33 + +#if TARGET_OS_OSX 34 + + if (os_major >= 16) { // macOS 11+ 35 + + os_major -= 5; 36 + + } else { // macOS 10.15 and below 37 + + format = "10.%d"; 38 + } 39 + +#endif 40 + return internal_snprintf(vers, sizeof(VersStr), format, os_major); 41 + } 42 + 43 + @@ -681,15 +687,14 @@ void ParseVersion(const char *vers, u16 *major, u16 *minor) { 44 + // Aligned versions example: 45 + // macOS 10.15 -- iOS 13 -- tvOS 13 -- watchOS 6 46 + static void MapToMacos(u16 *major, u16 *minor) { 47 + - if (TARGET_OS_OSX) 48 + - return; 49 + - 50 + - if (TARGET_OS_IOS || TARGET_OS_TV) 51 + +#if !TARGET_OS_OSX 52 + +#if TARGET_OS_IOS || TARGET_OS_TV 53 + *major += 2; 54 + - else if (TARGET_OS_WATCH) 55 + +#elif TARGET_OS_WATCH 56 + *major += 9; 57 + - else 58 + +#else 59 + UNREACHABLE("unsupported platform"); 60 + +#endif 61 + 62 + if (*major >= 16) { // macOS 11+ 63 + *major -= 5; 64 + @@ -697,6 +702,7 @@ static void MapToMacos(u16 *major, u16 *minor) { 65 + *minor = *major; 66 + *major = 10; 67 + } 68 + +#endif 69 + } 70 + 71 + static MacosVersion GetMacosAlignedVersionInternal() {
+2
pkgs/development/compilers/llvm/13/compiler-rt/default.nix
··· 60 # extra `/`. 61 ./normalize-var.patch 62 ]# ++ lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch 63 ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; 64 65 # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
··· 60 # extra `/`. 61 ./normalize-var.patch 62 ]# ++ lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch 63 + # Prevent a compilation error on darwin 64 + ++ lib.optional stdenv.hostPlatform.isDarwin ./darwin-targetconditionals.patch 65 ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; 66 67 # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks