Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm] Teach MachO about XROS #78373

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

cyndyishida
Copy link
Member

Add support for XROS to encode in Mach-O file formats.

@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2024

@llvm/pr-subscribers-llvm-analysis
@llvm/pr-subscribers-mc

@llvm/pr-subscribers-llvm-transforms

Author: Cyndy Ishida (cyndyishida)

Changes

Add support for XROS to encode in Mach-O file formats.


Full diff: https://github.com/llvm/llvm-project/pull/78373.diff

9 Files Affected:

  • (modified) llvm/lib/Analysis/TargetLibraryInfo.cpp (+3)
  • (modified) llvm/lib/MC/MCObjectFileInfo.cpp (+4)
  • (modified) llvm/lib/MC/MCStreamer.cpp (+9)
  • (modified) llvm/lib/TargetParser/ARMTargetParser.cpp (+1)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+2)
  • (modified) llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s (+19)
  • (modified) llvm/test/MC/MachO/ARM/build-version-sdk-version.s (+3)
  • (modified) llvm/test/MC/MachO/ARM/build-version.s (+3)
  • (modified) llvm/unittests/TextAPI/TextStubV4Tests.cpp (+29)
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index bbb7c86d21856d..58749e559040a7 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -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()))) {
@@ -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;
@@ -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;
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index a79759557b2e3d..7b382c131ef91b 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -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;
 }
 
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 0062d08353141a..bc145aef0b8c53 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -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;
   }
@@ -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;
   }
@@ -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");
   }
diff --git a/llvm/lib/TargetParser/ARMTargetParser.cpp b/llvm/lib/TargetParser/ARMTargetParser.cpp
index ce640f5b8d45c5..c470a1321fcbdc 100644
--- a/llvm/lib/TargetParser/ARMTargetParser.cpp
+++ b/llvm/lib/TargetParser/ARMTargetParser.cpp
@@ -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;
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index fb5838bb7941ad..caab98c732eeeb 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2078,6 +2078,8 @@ bool ModuleAddressSanitizer::ShouldUseMachOGlobalsSection() const {
     return true;
   if (TargetTriple.isDriverKit())
     return true;
+  if (TargetTriple.isXROS())
+    return true;
 
   return false;
 }
diff --git a/llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s b/llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
index 2d008a84570f99..3ed41125314a21 100644
--- a/llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
+++ b/llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
@@ -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
@@ -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
@@ -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
diff --git a/llvm/test/MC/MachO/ARM/build-version-sdk-version.s b/llvm/test/MC/MachO/ARM/build-version-sdk-version.s
index 98f6d4d7bd2da6..42a9a2d9bce161 100644
--- a/llvm/test/MC/MachO/ARM/build-version-sdk-version.s
+++ b/llvm/test/MC/MachO/ARM/build-version-sdk-version.s
@@ -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
diff --git a/llvm/test/MC/MachO/ARM/build-version.s b/llvm/test/MC/MachO/ARM/build-version.s
index e3e3f14df08a1d..0c959c36efccac 100644
--- a/llvm/test/MC/MachO/ARM/build-version.s
+++ b/llvm/test/MC/MachO/ARM/build-version.s
@@ -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 
diff --git a/llvm/unittests/TextAPI/TextStubV4Tests.cpp b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
index 2fefd7910a70c2..850a6670889070 100644
--- a/llvm/unittests/TextAPI/TextStubV4Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
@@ -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"

@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Cyndy Ishida (cyndyishida)

Changes

Add support for XROS to encode in Mach-O file formats.


Full diff: https://github.com/llvm/llvm-project/pull/78373.diff

9 Files Affected:

  • (modified) llvm/lib/Analysis/TargetLibraryInfo.cpp (+3)
  • (modified) llvm/lib/MC/MCObjectFileInfo.cpp (+4)
  • (modified) llvm/lib/MC/MCStreamer.cpp (+9)
  • (modified) llvm/lib/TargetParser/ARMTargetParser.cpp (+1)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+2)
  • (modified) llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s (+19)
  • (modified) llvm/test/MC/MachO/ARM/build-version-sdk-version.s (+3)
  • (modified) llvm/test/MC/MachO/ARM/build-version.s (+3)
  • (modified) llvm/unittests/TextAPI/TextStubV4Tests.cpp (+29)
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index bbb7c86d21856d..58749e559040a7 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -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()))) {
@@ -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;
@@ -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;
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index a79759557b2e3d..7b382c131ef91b 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -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;
 }
 
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 0062d08353141a..bc145aef0b8c53 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -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;
   }
@@ -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;
   }
@@ -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");
   }
diff --git a/llvm/lib/TargetParser/ARMTargetParser.cpp b/llvm/lib/TargetParser/ARMTargetParser.cpp
index ce640f5b8d45c5..c470a1321fcbdc 100644
--- a/llvm/lib/TargetParser/ARMTargetParser.cpp
+++ b/llvm/lib/TargetParser/ARMTargetParser.cpp
@@ -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;
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index fb5838bb7941ad..caab98c732eeeb 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2078,6 +2078,8 @@ bool ModuleAddressSanitizer::ShouldUseMachOGlobalsSection() const {
     return true;
   if (TargetTriple.isDriverKit())
     return true;
+  if (TargetTriple.isXROS())
+    return true;
 
   return false;
 }
diff --git a/llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s b/llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
index 2d008a84570f99..3ed41125314a21 100644
--- a/llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
+++ b/llvm/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
@@ -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
@@ -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
@@ -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
diff --git a/llvm/test/MC/MachO/ARM/build-version-sdk-version.s b/llvm/test/MC/MachO/ARM/build-version-sdk-version.s
index 98f6d4d7bd2da6..42a9a2d9bce161 100644
--- a/llvm/test/MC/MachO/ARM/build-version-sdk-version.s
+++ b/llvm/test/MC/MachO/ARM/build-version-sdk-version.s
@@ -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
diff --git a/llvm/test/MC/MachO/ARM/build-version.s b/llvm/test/MC/MachO/ARM/build-version.s
index e3e3f14df08a1d..0c959c36efccac 100644
--- a/llvm/test/MC/MachO/ARM/build-version.s
+++ b/llvm/test/MC/MachO/ARM/build-version.s
@@ -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 
diff --git a/llvm/unittests/TextAPI/TextStubV4Tests.cpp b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
index 2fefd7910a70c2..850a6670889070 100644
--- a/llvm/unittests/TextAPI/TextStubV4Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
@@ -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"

Copy link
Contributor

@jroelofs jroelofs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Add support for XROS to encode in Mach-O file formats.
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 25c7c231149813692db1dbfc348d2df87ecc5307 9be88883fe2b8762e60253c0c2c73c6634cbe99c -- llvm/lib/Analysis/TargetLibraryInfo.cpp llvm/lib/MC/MCObjectFileInfo.cpp llvm/lib/MC/MCParser/DarwinAsmParser.cpp llvm/lib/MC/MCStreamer.cpp llvm/lib/TargetParser/ARMTargetParser.cpp llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp llvm/unittests/TextAPI/TextStubV4Tests.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
index 3cd44e7195..bc8acb5320 100644
--- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
@@ -1147,14 +1147,16 @@ 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_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_WATCHOSSIMULATOR: /* silence warning */
+    break;
   case MachO::PLATFORM_XROS_SIMULATOR:   /* silence warning */ break;
   }
   llvm_unreachable("Invalid mach-o platform type");

@cyndyishida cyndyishida merged commit 735adbf into llvm:main Jan 17, 2024
3 of 4 checks passed
@cyndyishida cyndyishida deleted the platformsGaloreMachOEdition branch January 17, 2024 18:35
ampandey-1995 pushed a commit to ampandey-1995/llvm-project that referenced this pull request Jan 19, 2024
Add support for XROS to encode in Mach-O file formats.
cyndyishida added a commit to cyndyishida/llvm-project that referenced this pull request Feb 7, 2024
Add support for XROS to encode in Mach-O file formats.

(cherry picked from commit 735adbf)
cyndyishida added a commit to swiftlang/llvm-project that referenced this pull request Feb 8, 2024
Add support for XROS to encode in Mach-O file formats.

(cherry picked from commit 735adbf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants