Skip to content

Commit cf4e1b9

Browse files
committed
llvmPackages_12.compiler-rt: fix build on darwin
``` /tmp/nix-build-compiler-rt-libc-12.0.0.drv-0/compiler-rt-12.0.0.src/lib/sanitizer_common/sanitizer_mac.cpp:617:7: error: use of undeclared identifier 'TARGET_OS_IOS' if (TARGET_OS_IOS || TARGET_OS_TV) return 6; ^ /tmp/nix-build-compiler-rt-libc-12.0.0.drv-0/compiler-rt-12.0.0.src/lib/sanitizer_common/sanitizer_mac.cpp:617:24: error: use of undeclared identifier 'TARGET_OS_TV' if (TARGET_OS_IOS || TARGET_OS_TV) return 6; ^ /tmp/nix-build-compiler-rt-libc-12.0.0.drv-0/compiler-rt-12.0.0.src/lib/sanitizer_common/sanitizer_mac.cpp:618:7: error: use of undeclared identifier 'TARGET_OS_WATCH' if (TARGET_OS_WATCH) return 13; ^ /tmp/nix-build-compiler-rt-libc-12.0.0.drv-0/compiler-rt-12.0.0.src/lib/sanitizer_common/sanitizer_mac.cpp:687:7: error: use of undeclared identifier 'TARGET_OS_IOS' if (TARGET_OS_IOS || TARGET_OS_TV) ^ /tmp/nix-build-compiler-rt-libc-12.0.0.drv-0/compiler-rt-12.0.0.src/lib/sanitizer_common/sanitizer_mac.cpp:687:24: error: use of undeclared identifier 'TARGET_OS_TV' if (TARGET_OS_IOS || TARGET_OS_TV) ^ /tmp/nix-build-compiler-rt-libc-12.0.0.drv-0/compiler-rt-12.0.0.src/lib/sanitizer_common/sanitizer_mac.cpp:689:12: error: use of undeclared identifier 'TARGET_OS_WATCH' else if (TARGET_OS_WATCH) ^ 6 errors generated. ```
1 parent f924460 commit cf4e1b9

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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() {

pkgs/development/compilers/llvm/12/compiler-rt/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ stdenv.mkDerivation {
5959
# extra `/`.
6060
./normalize-var.patch
6161
]# ++ lib.optional stdenv.hostPlatform.isMusl ./sanitizers-nongnu.patch
62+
# Prevent a compilation error on darwin
63+
++ lib.optional stdenv.hostPlatform.isDarwin ./darwin-targetconditionals.patch
6264
++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch;
6365

6466
# TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks

0 commit comments

Comments
 (0)