Skip to content

Commit

Permalink
[llvm] Teach MachO about XROS (llvm#78373)
Browse files Browse the repository at this point in the history
Add support for XROS to encode in Mach-O file formats.
  • Loading branch information
cyndyishida authored and ampandey-1995 committed Jan 19, 2024
1 parent 22f51e8 commit ce36c96
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 1 deletion.
3 changes: 3 additions & 0 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
case Triple::IOS:
case Triple::TvOS:
case Triple::WatchOS:
case Triple::XROS:
TLI.setUnavailable(LibFunc_exp10l);
if (!T.isWatchOS() &&
(T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86()))) {
Expand Down Expand Up @@ -581,6 +582,7 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
case Triple::IOS:
case Triple::TvOS:
case Triple::WatchOS:
case Triple::XROS:
case Triple::FreeBSD:
case Triple::Linux:
break;
Expand All @@ -597,6 +599,7 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
case Triple::IOS:
case Triple::TvOS:
case Triple::WatchOS:
case Triple::XROS:
case Triple::FreeBSD:
case Triple::Linux:
break;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/MC/MCObjectFileInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ static bool useCompactUnwind(const Triple &T) {
if (T.isSimulatorEnvironment())
return true;

// XROS always has it.
if (T.isXROS())
return true;

return false;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCParser/DarwinAsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,14 +1147,14 @@ static Triple::OSType getOSTypeFromPlatform(MachO::PlatformType Type) {
case MachO::PLATFORM_IOS: return Triple::IOS;
case MachO::PLATFORM_TVOS: return Triple::TvOS;
case MachO::PLATFORM_WATCHOS: return Triple::WatchOS;
case MachO::PLATFORM_XROS: return Triple::XROS;
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_XROS: /* silence warning */ break;
case MachO::PLATFORM_XROS_SIMULATOR: /* silence warning */ break;
}
llvm_unreachable("Invalid mach-o platform type");
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/MC/MCStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,9 @@ static VersionTuple getMachoBuildVersionSupportedOS(const Triple &Target) {
case Triple::DriverKit:
// DriverKit always uses the build version load command.
return VersionTuple();
case Triple::XROS:
// XROS always uses the build version load command.
return VersionTuple();
default:
break;
}
Expand All @@ -1339,6 +1342,9 @@ getMachoBuildVersionPlatformType(const Triple &Target) {
: MachO::PLATFORM_WATCHOS;
case Triple::DriverKit:
return MachO::PLATFORM_DRIVERKIT;
case Triple::XROS:
return Target.isSimulatorEnvironment() ? MachO::PLATFORM_XROS_SIMULATOR
: MachO::PLATFORM_XROS;
default:
break;
}
Expand Down Expand Up @@ -1371,6 +1377,9 @@ void MCStreamer::emitVersionForTarget(
case Triple::DriverKit:
Version = Target.getDriverKitVersion();
break;
case Triple::XROS:
Version = Target.getOSVersion();
break;
default:
llvm_unreachable("unexpected OS type");
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/TargetParser/ARMTargetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ StringRef ARM::getARMCPUForArch(const llvm::Triple &Triple, StringRef MArch) {
case llvm::Triple::TvOS:
case llvm::Triple::WatchOS:
case llvm::Triple::DriverKit:
case llvm::Triple::XROS:
if (MArch == "v7k")
return "cortex-a7";
break;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,8 @@ bool ModuleAddressSanitizer::ShouldUseMachOGlobalsSection() const {
return true;
if (TargetTriple.isDriverKit())
return true;
if (TargetTriple.isXROS())
return true;

return false;
}
Expand Down
19 changes: 19 additions & 0 deletions llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
// 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

// RUN: llvm-mc -triple arm64-apple-xros1 %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck --check-prefix=CHECK-XROS-ARM64 %s
// RUN: llvm-mc -triple arm64-apple-xros1-simulator %s -filetype=obj -o - | llvm-objdump --macho --private-headers - | FileCheck --check-prefix=CHECK-XROS-SIM %s

// CHECK-BUILD-IOS-ARM64E: cmd LC_BUILD_VERSION
// CHECK-BUILD-IOS-ARM64E-NEXT: cmdsize 24
// CHECK-BUILD-IOS-ARM64E-NEXT: platform ios
Expand All @@ -38,6 +41,14 @@
// CHECK-BUILD-IOS-ARM64E3-NEXT: ntools 0
// CHECK-BUILD-IOS-ARM64E3-NOT: LC_VERSION_MIN

// CHECK-XROS-ARM64: cmd LC_BUILD_VERSION
// CHECK-XROS-ARM64-NEXT: cmdsize 24
// CHECK-XROS-ARM64-NEXT: platform xros
// CHECK-XROS-ARM64-NEXT: sdk n/a
// CHECK-XROS-ARM64-NEXT: minos 1.0
// CHECK-XROS-ARM64-NEXT: ntools 0
// CHECK-XROS-ARM64-NOT: LC_VERSION_MIN

// CHECK-BUILD-IOSSIM2: cmd LC_BUILD_VERSION
// CHECK-BUILD-IOSSIM2-NEXT: cmdsize 24
// CHECK-BUILD-IOSSIM2-NEXT: platform iossim
Expand Down Expand Up @@ -70,6 +81,14 @@
// CHECK-BUILD-WATCHOSSIM2-NEXT: ntools 0
// CHECK-BUILD-WATCHOSSIM2-NOT: LC_VERSION_MIN

// CHECK-XROS-SIM: cmd LC_BUILD_VERSION
// CHECK-XROS-SIM-NEXT: cmdsize 24
// CHECK-XROS-SIM-NEXT: platform xrsimulator
// CHECK-XROS-SIM-NEXT: sdk n/a
// CHECK-XROS-SIM-NEXT: minos 1.0
// CHECK-XROS-SIM-NEXT: ntools 0
// CHECK-XROS-SIM-NOT: LC_VERSION_MIN

// CHECK-BUILD-MACOS-ARM64: cmd LC_BUILD_VERSION
// CHECK-BUILD-MACOS-ARM64-NEXT: cmdsize 24
// CHECK-BUILD-MACOS-ARM64-NEXT: platform macos
Expand Down
3 changes: 3 additions & 0 deletions llvm/test/MC/MachO/ARM/build-version-sdk-version.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@

.build_version watchos,10,11 sdk_version 10,11
// CHECK: .build_version watchos, 10, 11 sdk_version 10, 11

.build_version xros,1, 0 sdk_version 1,0
// CHECK: .build_version xros, 1, 0 sdk_version 1, 0
3 changes: 3 additions & 0 deletions llvm/test/MC/MachO/ARM/build-version.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@

.build_version watchos,10,11
// CHECK: .build_version watchos, 10, 11

.build_version xros,1, 0
// CHECK: .build_version xros, 1, 0
29 changes: 29 additions & 0 deletions llvm/unittests/TextAPI/TextStubV4Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,35 @@ TEST(TBDv4, Target_i386_driverkit) {
stripWhitespace(Buffer.c_str()));
}

TEST(TBDv4, Target_arm64_xros) {
static const char TBDv4ArchArm64e[] =
"--- !tapi-tbd\n"
"tbd-version: 4\n"
"targets: [ arm64e-xros, arm64e-xros-simulator ]\n"
"install-name: Test.dylib\n"
"...\n";

auto Result =
TextAPIReader::get(MemoryBufferRef(TBDv4ArchArm64e, "Test.tbd"));
EXPECT_TRUE(!!Result);
auto File = std::move(Result.get());
EXPECT_EQ(FileType::TBD_V4, File->getFileType());
PlatformSet ExpectedSet;
ExpectedSet.insert(PLATFORM_XROS);
ExpectedSet.insert(PLATFORM_XROS_SIMULATOR);
EXPECT_EQ(File->getPlatforms().size(), 2U);
for (auto Platform : File->getPlatforms())
EXPECT_EQ(ExpectedSet.count(Platform), 1U);

EXPECT_EQ(ArchitectureSet(AK_arm64e), File->getArchitectures());

SmallString<4096> Buffer;
raw_svector_ostream OS(Buffer);
auto WriteResult = TextAPIWriter::writeToStream(OS, *File);
EXPECT_TRUE(!WriteResult);
EXPECT_EQ(stripWhitespace(TBDv4ArchArm64e), stripWhitespace(Buffer.c_str()));
}

TEST(TBDv4, Swift_1) {
static const char TBDv4SwiftVersion1[] = "--- !tapi-tbd\n"
"tbd-version: 4\n"
Expand Down

0 comments on commit ce36c96

Please sign in to comment.