[llvm] 913f21a - [TextAPI] Express MH_SIM_SUPPORT in tbd files.

Cyndy Ishida via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 10:17:48 PDT 2023


Author: Cyndy Ishida
Date: 2023-08-11T10:17:01-07:00
New Revision: 913f21ae5c460d6fdd73ac7663534e73f8e19044

URL: https://github.com/llvm/llvm-project/commit/913f21ae5c460d6fdd73ac7663534e73f8e19044
DIFF: https://github.com/llvm/llvm-project/commit/913f21ae5c460d6fdd73ac7663534e73f8e19044.diff

LOG: [TextAPI] Express MH_SIM_SUPPORT in tbd files.

This adds a new optional flag sim_support which is the same as
MH_SIM_SUPPORT in the MachO header.

Reviewed By: ributzka

Differential Revision: https://reviews.llvm.org/D157433

Added: 
    

Modified: 
    llvm/include/llvm/TextAPI/InterfaceFile.h
    llvm/lib/TextAPI/InterfaceFile.cpp
    llvm/lib/TextAPI/TextStubCommon.h
    llvm/lib/TextAPI/TextStubV5.cpp
    llvm/tools/llvm-readtapi/DiffEngine.cpp
    llvm/unittests/TextAPI/TextStubV5Tests.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/TextAPI/InterfaceFile.h b/llvm/include/llvm/TextAPI/InterfaceFile.h
index 673f25bafcf5ff..88139d8506524b 100644
--- a/llvm/include/llvm/TextAPI/InterfaceFile.h
+++ b/llvm/include/llvm/TextAPI/InterfaceFile.h
@@ -254,6 +254,12 @@ class InterfaceFile {
   /// Check if the library is application extension safe.
   bool isApplicationExtensionSafe() const { return IsAppExtensionSafe; }
 
+  /// Check if the library has simulator support.
+  bool hasSimulatorSupport() const { return HasSimSupport; }
+
+  /// Specify if the library has simulator support.
+  void setSimulatorSupport(bool V = true) { HasSimSupport = V; }
+
   /// Set the Objective-C constraint.
   void setObjCConstraint(ObjCConstraintType Constraint) {
     ObjcConstraint = Constraint;
@@ -451,6 +457,7 @@ class InterfaceFile {
   uint8_t SwiftABIVersion{0};
   bool IsTwoLevelNamespace{false};
   bool IsAppExtensionSafe{false};
+  bool HasSimSupport{false};
   ObjCConstraintType ObjcConstraint = ObjCConstraintType::None;
   std::vector<std::pair<Target, std::string>> ParentUmbrellas;
   std::vector<InterfaceFileRef> AllowableClients;

diff  --git a/llvm/lib/TextAPI/InterfaceFile.cpp b/llvm/lib/TextAPI/InterfaceFile.cpp
index b9ea02d8e097e3..d324e30f32863d 100644
--- a/llvm/lib/TextAPI/InterfaceFile.cpp
+++ b/llvm/lib/TextAPI/InterfaceFile.cpp
@@ -361,6 +361,8 @@ bool InterfaceFile::operator==(const InterfaceFile &O) const {
     return false;
   if (IsAppExtensionSafe != O.IsAppExtensionSafe)
     return false;
+  if (HasSimSupport != O.HasSimSupport)
+    return false;
   if (ParentUmbrellas != O.ParentUmbrellas)
     return false;
   if (AllowableClients != O.AllowableClients)

diff  --git a/llvm/lib/TextAPI/TextStubCommon.h b/llvm/lib/TextAPI/TextStubCommon.h
index d4dcd3af447a6a..385c2ceab51ae3 100644
--- a/llvm/lib/TextAPI/TextStubCommon.h
+++ b/llvm/lib/TextAPI/TextStubCommon.h
@@ -28,7 +28,8 @@ enum TBDFlags : unsigned {
   FlatNamespace                = 1U << 0,
   NotApplicationExtensionSafe  = 1U << 1,
   InstallAPI                   = 1U << 2,
-  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/InstallAPI),
+  SimulatorSupport             = 1U << 3,
+  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/SimulatorSupport),
 };
 // clang-format on
 

diff  --git a/llvm/lib/TextAPI/TextStubV5.cpp b/llvm/lib/TextAPI/TextStubV5.cpp
index b74250cca6cb2a..69778c52c68ece 100644
--- a/llvm/lib/TextAPI/TextStubV5.cpp
+++ b/llvm/lib/TextAPI/TextStubV5.cpp
@@ -547,11 +547,11 @@ Expected<PackedVersion> getPackedVersion(const Object *File, TBDKey Key) {
 Expected<TBDFlags> getFlags(const Object *File) {
   TBDFlags Flags = TBDFlags::None;
   const Array *Section = File->getArray(Keys[TBDKey::Flags]);
-  if (!Section)
+  if (!Section || Section->empty())
     return Flags;
 
   for (auto &Val : *Section) {
-    // TODO: Just take first for now.
+    // FIXME: Flags currently apply to all target triples.
     const auto *Obj = Val.getAsObject();
     if (!Obj)
       return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Flags));
@@ -563,6 +563,7 @@ Expected<TBDFlags> getFlags(const Object *File) {
                   .Case("flat_namespace", TBDFlags::FlatNamespace)
                   .Case("not_app_extension_safe",
                         TBDFlags::NotApplicationExtensionSafe)
+                  .Case("sim_support", TBDFlags::SimulatorSupport)
                   .Default(TBDFlags::None);
           Flags |= TBDFlag;
         });
@@ -653,6 +654,7 @@ Expected<IFPtr> parseToInterfaceFile(const Object *File) {
   F->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));
   F->setApplicationExtensionSafe(
       !(Flags & TBDFlags::NotApplicationExtensionSafe));
+  F->setSimulatorSupport((Flags & TBDFlags::SimulatorSupport));
   for (auto &T : Targets)
     F->addTarget(T);
   for (auto &[Lib, Targets] : Clients)
@@ -919,6 +921,8 @@ Array serializeFlags(const InterfaceFile *File) {
     Flags.emplace_back("flat_namespace");
   if (!File->isApplicationExtensionSafe())
     Flags.emplace_back("not_app_extension_safe");
+  if (File->hasSimulatorSupport())
+    Flags.emplace_back("sim_support");
   return serializeScalar(TBDKey::Attributes, std::move(Flags));
 }
 

diff  --git a/llvm/tools/llvm-readtapi/DiffEngine.cpp b/llvm/tools/llvm-readtapi/DiffEngine.cpp
index 3e07bb94f4df55..f149b1b97d58e5 100644
--- a/llvm/tools/llvm-readtapi/DiffEngine.cpp
+++ b/llvm/tools/llvm-readtapi/DiffEngine.cpp
@@ -363,6 +363,13 @@ DiffEngine::findDifferences(const InterfaceFile *IFLHS,
                               rhs, IFRHS->isApplicationExtensionSafe()),
                           "Application Extension Safe"));
 
+  if (IFLHS->hasSimulatorSupport() != IFRHS->hasSimulatorSupport())
+    Output.push_back(recordDifferences(DiffScalarVal<bool, AD_Diff_Scalar_Bool>(
+                                           lhs, IFLHS->hasSimulatorSupport()),
+                                       DiffScalarVal<bool, AD_Diff_Scalar_Bool>(
+                                           rhs, IFRHS->hasSimulatorSupport()),
+                                       "Simulator Support"));
+
   if (IFLHS->reexportedLibraries() != IFRHS->reexportedLibraries())
     Output.push_back(recordDifferences(IFLHS->reexportedLibraries(),
                                        IFRHS->reexportedLibraries(),

diff  --git a/llvm/unittests/TextAPI/TextStubV5Tests.cpp b/llvm/unittests/TextAPI/TextStubV5Tests.cpp
index d628ee8f43cbd3..e6b87fa5592728 100644
--- a/llvm/unittests/TextAPI/TextStubV5Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV5Tests.cpp
@@ -1151,6 +1151,37 @@ TEST(TBDv5, InvalidMinOS) {
   EXPECT_EQ("invalid min_deployment section\n", ErrorMessage);
 }
 
+TEST(TBDv5, SimSupport) {
+  static const char TBDv5File[] = R"({ 
+"tapi_tbd_version": 5,
+"main_library": {
+  "target_info": [
+    {
+      "target": "arm64-macos",
+      "min_deployment": "11.1" 
+    }
+  ],
+  "install_names":[
+    { "name":"/S/L/F/Foo.framework/Foo" }
+  ],
+  "flags":[ 
+    { "attributes": ["sim_support"] }
+  ] 
+}})";
+
+  Expected<TBDFile> Result =
+      TextAPIReader::get(MemoryBufferRef(TBDv5File, "Test.tbd"));
+  EXPECT_TRUE(!!Result);
+  Target ExpectedTarget = Target(AK_arm64, PLATFORM_MACOS, VersionTuple(11, 1));
+  TBDFile ReadFile = std::move(Result.get());
+  EXPECT_EQ(FileType::TBD_V5, ReadFile->getFileType());
+  EXPECT_EQ(std::string("/S/L/F/Foo.framework/Foo"),
+            ReadFile->getInstallName());
+  EXPECT_TRUE(ReadFile->targets().begin() != ReadFile->targets().end());
+  EXPECT_EQ(*ReadFile->targets().begin(), ExpectedTarget);
+  EXPECT_TRUE(ReadFile->hasSimulatorSupport());
+}
+
 TEST(TBDv5, MergeIF) {
   static const char TBDv5FileA[] = R"({
 "tapi_tbd_version": 5,


        


More information about the llvm-commits mailing list