This patch is the first in a series of patches to upstream the support for Apple's DriverKit. Once complete, it will allow targeting DriverKit platform with Clang similarly to AppleClang.
This code was originally authored by JF Bastien.
Differential Revision: https://reviews.llvm.org/D118046
ELFIAMCU,
TvOS, // Apple tvOS
WatchOS, // Apple watchOS
+ DriverKit, // Apple DriverKit
Mesa3D,
Contiki,
AMDPAL, // AMD PAL Runtime
/// with WatchOS or generic triples.
VersionTuple getWatchOSVersion() const;
+ /// Parse the version number as with getOSVersion.
+ VersionTuple getDriverKitVersion() const;
+
/// @}
/// @name Direct Component Access
/// @{
return getSubArch() == Triple::ARMSubArch_v7k;
}
+ /// Is this an Apple DriverKit triple.
+ bool isDriverKit() const { return getOS() == Triple::DriverKit; }
+
bool isOSzOS() const { return getOS() == Triple::ZOS; }
/// Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS).
bool isOSDarwin() const {
- return isMacOSX() || isiOS() || isWatchOS();
+ return isMacOSX() || isiOS() || isWatchOS() || isDriverKit();
}
bool isSimulatorEnvironment() const {
return *this;
}
+ /// Return a version tuple that contains a different major version but
+ /// everything else is the same.
+ VersionTuple withMajorReplaced(unsigned NewMajor) const {
+ return VersionTuple(NewMajor, Minor, Subminor, Build);
+ }
+
/// Return a version tuple that contains only components that are non-zero.
VersionTuple normalize() const {
VersionTuple Result = *this;
case MachO::PLATFORM_TVOS: return Triple::TvOS;
case MachO::PLATFORM_WATCHOS: return Triple::WatchOS;
case MachO::PLATFORM_BRIDGEOS: /* silence warning */ break;
+ case MachO::PLATFORM_DRIVERKIT:
+ return Triple::DriverKit;
case MachO::PLATFORM_MACCATALYST: return Triple::IOS;
case MachO::PLATFORM_IOSSIMULATOR: /* silence warning */ break;
case MachO::PLATFORM_TVOSSIMULATOR: /* silence warning */ break;
case MachO::PLATFORM_WATCHOSSIMULATOR: /* silence warning */ break;
- case MachO::PLATFORM_DRIVERKIT: /* silence warning */ break;
}
llvm_unreachable("Invalid mach-o platform type");
}
.Case("tvos", MachO::PLATFORM_TVOS)
.Case("watchos", MachO::PLATFORM_WATCHOS)
.Case("macCatalyst", MachO::PLATFORM_MACCATALYST)
+ .Case("driverkit", MachO::PLATFORM_DRIVERKIT)
.Default(0);
if (Platform == 0)
return Error(PlatformLoc, "unknown platform name");
return VersionTuple(12);
case Triple::WatchOS:
return VersionTuple(5);
+ case Triple::DriverKit:
+ // DriverKit always uses the build version load command.
+ return VersionTuple();
default:
break;
}
case Triple::WatchOS:
return Target.isSimulatorEnvironment() ? MachO::PLATFORM_WATCHOSSIMULATOR
: MachO::PLATFORM_WATCHOS;
+ case Triple::DriverKit:
+ return MachO::PLATFORM_DRIVERKIT;
default:
break;
}
case Triple::WatchOS:
Version = Target.getWatchOSVersion();
break;
+ case Triple::DriverKit:
+ Version = Target.getDriverKitVersion();
+ break;
default:
llvm_unreachable("unexpected OS type");
}
case Contiki: return "contiki";
case Darwin: return "darwin";
case DragonFly: return "dragonfly";
+ case DriverKit: return "driverkit";
case ELFIAMCU: return "elfiamcu";
case Emscripten: return "emscripten";
case FreeBSD: return "freebsd";
.StartsWith("elfiamcu", Triple::ELFIAMCU)
.StartsWith("tvos", Triple::TvOS)
.StartsWith("watchos", Triple::WatchOS)
+ .StartsWith("driverkit", Triple::DriverKit)
.StartsWith("mesa3d", Triple::Mesa3D)
.StartsWith("contiki", Triple::Contiki)
.StartsWith("amdpal", Triple::AMDPAL)
// IOS.
Version = VersionTuple(10, 4);
break;
+ case DriverKit:
+ llvm_unreachable("OSX version isn't relevant for DriverKit");
}
return true;
}
}
case WatchOS:
llvm_unreachable("conflicting triple info");
+ case DriverKit:
+ llvm_unreachable("DriverKit doesn't have an iOS version");
}
}
}
case IOS:
llvm_unreachable("conflicting triple info");
+ case DriverKit:
+ llvm_unreachable("DriverKit doesn't have a WatchOS version");
+ }
+}
+
+VersionTuple Triple::getDriverKitVersion() const {
+ switch (getOS()) {
+ default:
+ llvm_unreachable("unexpected OS for Darwin triple");
+ case DriverKit:
+ VersionTuple Version = getOSVersion();
+ if (Version.getMajor() == 0)
+ return Version.withMajorReplaced(19);
+ return Version;
}
}
if (isSimulatorEnvironment())
return VersionTuple(7, 0, 0);
break;
+ case Triple::DriverKit:
+ return VersionTuple(20, 0, 0);
default:
break;
}
case llvm::Triple::MacOSX:
case llvm::Triple::TvOS:
case llvm::Triple::WatchOS:
+ case llvm::Triple::DriverKit:
if (MArch == "v7k")
return "cortex-a7";
break;
if (!UseAddressTopByteIgnored)
return false;
+ if (TargetTriple.isDriverKit())
+ return true;
if (TargetTriple.isiOS()) {
return TargetTriple.getiOSVersion() >= VersionTuple(8);
}
setBooleanVectorContents(ZeroOrNegativeOneBooleanContent);
if (!Subtarget->isTargetDarwin() && !Subtarget->isTargetIOS() &&
- !Subtarget->isTargetWatchOS()) {
+ !Subtarget->isTargetWatchOS() && !Subtarget->isTargetDriverKit()) {
bool IsHFTarget = TM.Options.FloatABIType == FloatABI::Hard;
for (int LCID = 0; LCID < RTLIB::UNKNOWN_LIBCALL; ++LCID)
setLibcallCallingConv(static_cast<RTLIB::Libcall>(LCID),
bool isTargetIOS() const { return TargetTriple.isiOS(); }
bool isTargetWatchOS() const { return TargetTriple.isWatchOS(); }
bool isTargetWatchABI() const { return TargetTriple.isWatchABI(); }
+ bool isTargetDriverKit() const { return TargetTriple.isDriverKit(); }
bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
bool isTargetNetBSD() const { return TargetTriple.isOSNetBSD(); }
static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
bool IsKasan) {
bool IsAndroid = TargetTriple.isAndroid();
- bool IsIOS = TargetTriple.isiOS() || TargetTriple.isWatchOS();
+ bool IsIOS = TargetTriple.isiOS() || TargetTriple.isWatchOS() ||
+ TargetTriple.isDriverKit();
bool IsMacOS = TargetTriple.isMacOSX();
bool IsFreeBSD = TargetTriple.isOSFreeBSD();
bool IsNetBSD = TargetTriple.isOSNetBSD();
return true;
if (TargetTriple.isWatchOS() && !TargetTriple.isOSVersionLT(2))
return true;
+ if (TargetTriple.isDriverKit())
+ return true;
return false;
}
// RUN: llvm-mc -triple arm64-apple-tvos10-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-TVOSSIM2
// RUN: llvm-mc -triple arm64-apple-watchos3-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-BUILD-WATCHOSSIM2
+// RUN: llvm-mc -triple arm64-apple-driverkit19.0 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-DRIVERKIT-ARM64
+// RUN: llvm-mc -triple arm64e-apple-driverkit19.0 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-DRIVERKIT-ARM64
+// RUN: llvm-mc -triple arm64-apple-driverkit20.1 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-DRIVERKIT-ARM64_1
+
// CHECK-BUILD-IOS-ARM64E: cmd LC_BUILD_VERSION
// CHECK-BUILD-IOS-ARM64E-NEXT: cmdsize 24
// CHECK-BUILD-IOS-ARM64E-NEXT: platform ios
// CHECK-MACCATALYST-ARM64_1-NEXT: sdk n/a
// CHECK-MACCATALYST-ARM64_1-NEXT: minos 14.1
// CHECK-MACCATALYST-ARM64_1-NEXT: ntools 0
+
+// CHECK-DRIVERKIT-ARM64: cmd LC_BUILD_VERSION
+// CHECK-DRIVERKIT-ARM64-NEXT: cmdsize 24
+// CHECK-DRIVERKIT-ARM64-NEXT: platform driverkit
+// CHECK-DRIVERKIT-ARM64-NEXT: sdk n/a
+// CHECK-DRIVERKIT-ARM64-NEXT: minos 20.0
+// CHECK-DRIVERKIT-ARM64-NEXT: ntools 0
+
+// CHECK-DRIVERKIT-ARM64_1: cmd LC_BUILD_VERSION
+// CHECK-DRIVERKIT-ARM64_1-NEXT: cmdsize 24
+// CHECK-DRIVERKIT-ARM64_1-NEXT: platform driverkit
+// CHECK-DRIVERKIT-ARM64_1-NEXT: sdk n/a
+// CHECK-DRIVERKIT-ARM64_1-NEXT: minos 20.1
+// CHECK-DRIVERKIT-ARM64_1-NEXT: ntools 0
// RUN: llvm-mc -triple x86_64-apple-watchos1.0.0 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-WATCHOS
// RUN: llvm-mc -triple x86_64-apple-tvos8.0.0 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-TVOS
+// RUN: llvm-mc -triple x86_64-apple-driverkit19.0 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s --check-prefix=CHECK-DRIVERKIT
// CHECK-WATCHOS: Load command
// CHECK-WATCHOS: cmd LC_VERSION_MIN_WATCHOS
// CHECK-WATCHOS-NEXT: cmdsize 16
// CHECK-MACCATALYST-NEXT: minos 13.0
// CHECK-MACCATALYST-NEXT: ntools 0
+// CHECK-DRIVERKIT: cmd LC_BUILD_VERSION
+// CHECK-DRIVERKIT-NEXT: cmdsize 24
+// CHECK-DRIVERKIT-NEXT: platform driverkit
+// CHECK-DRIVERKIT-NEXT: sdk n/a
+// CHECK-DRIVERKIT-NEXT: minos 19.0
+// CHECK-DRIVERKIT-NEXT: ntools 0
+
// CHECK-BUILD-MACOS: cmd LC_BUILD_VERSION
// CHECK-BUILD-MACOS-NEXT: cmdsize 24
// CHECK-BUILD-MACOS-NEXT: platform macos
--- /dev/null
+; RUN: llc %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck %s
+; RUN: llc %s -filetype=asm -o - | FileCheck --check-prefix=ASM %s
+
+target triple = "x86_64-apple-driverkit19.0.0"
+
+define void @foo() {
+entry:
+ ret void
+}
+
+; CHECK: cmd LC_BUILD_VERSION
+; CHECK-NEXT: cmdsize 24
+; CHECK-NEXT: platform driverkit
+; CHECK-NEXT: sdk n/a
+; CHECK-NEXT: minos 19.0
+; CHECK-NEXT: ntools 0
+
+; ASM: .build_version driverkit, 19, 0
EXPECT_TRUE(T.getEnvironment() == Triple::MacABI);
EXPECT_TRUE(T.isMacCatalystEnvironment());
EXPECT_FALSE(T.isSimulatorEnvironment());
+
+ T = Triple("x86_64-apple-driverkit20.1.0");
+ EXPECT_TRUE(T.isDriverKit());
+ EXPECT_TRUE(T.isOSDarwin());
+ EXPECT_FALSE(T.isMacOSX());
+ EXPECT_FALSE(T.isiOS());
+ Version = T.getDriverKitVersion();
+ EXPECT_EQ(VersionTuple(20, 1), Version);
+
+ T = Triple("x86_64-apple-driverkit20");
+ Version = T.getDriverKitVersion();
+ EXPECT_EQ(VersionTuple(20, 0), Version);
+
+ // DriverKit version should default to 19.0.
+ T = Triple("x86_64-apple-driverkit");
+ Version = T.getDriverKitVersion();
+ EXPECT_EQ(VersionTuple(19, 0), Version);
}
TEST(TripleTest, getEnvironmentVersion) {