[llvm] 735adbf - [llvm] Teach MachO about XROS (#78373)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 10:35:24 PST 2024


Author: Cyndy Ishida
Date: 2024-01-17T10:35:20-08:00
New Revision: 735adbf1a80db3fe9ea8edaa172582ed2729a220

URL: https://github.com/llvm/llvm-project/commit/735adbf1a80db3fe9ea8edaa172582ed2729a220
DIFF: https://github.com/llvm/llvm-project/commit/735adbf1a80db3fe9ea8edaa172582ed2729a220.diff

LOG:  [llvm] Teach MachO about XROS (#78373)

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

Added: 
    

Modified: 
    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/test/MC/MachO/AArch64/arm-darwin-version-min-load-command.s
    llvm/test/MC/MachO/ARM/build-version-sdk-version.s
    llvm/test/MC/MachO/ARM/build-version.s
    llvm/unittests/TextAPI/TextStubV4Tests.cpp

Removed: 
    


################################################################################
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/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
index 5055b3a073b44c..3cd44e7195be62 100644
--- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
@@ -1147,6 +1147,7 @@ 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;
@@ -1154,7 +1155,6 @@ static Triple::OSType getOSTypeFromPlatform(MachO::PlatformType Type) {
   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");

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"


        


More information about the llvm-commits mailing list