Skip to content

Commit 913f21a

Browse files
committed
[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
1 parent 67b7d3d commit 913f21a

File tree

6 files changed

+55
-3
lines changed

6 files changed

+55
-3
lines changed

llvm/include/llvm/TextAPI/InterfaceFile.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ class InterfaceFile {
254254
/// Check if the library is application extension safe.
255255
bool isApplicationExtensionSafe() const { return IsAppExtensionSafe; }
256256

257+
/// Check if the library has simulator support.
258+
bool hasSimulatorSupport() const { return HasSimSupport; }
259+
260+
/// Specify if the library has simulator support.
261+
void setSimulatorSupport(bool V = true) { HasSimSupport = V; }
262+
257263
/// Set the Objective-C constraint.
258264
void setObjCConstraint(ObjCConstraintType Constraint) {
259265
ObjcConstraint = Constraint;
@@ -451,6 +457,7 @@ class InterfaceFile {
451457
uint8_t SwiftABIVersion{0};
452458
bool IsTwoLevelNamespace{false};
453459
bool IsAppExtensionSafe{false};
460+
bool HasSimSupport{false};
454461
ObjCConstraintType ObjcConstraint = ObjCConstraintType::None;
455462
std::vector<std::pair<Target, std::string>> ParentUmbrellas;
456463
std::vector<InterfaceFileRef> AllowableClients;

llvm/lib/TextAPI/InterfaceFile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ bool InterfaceFile::operator==(const InterfaceFile &O) const {
361361
return false;
362362
if (IsAppExtensionSafe != O.IsAppExtensionSafe)
363363
return false;
364+
if (HasSimSupport != O.HasSimSupport)
365+
return false;
364366
if (ParentUmbrellas != O.ParentUmbrellas)
365367
return false;
366368
if (AllowableClients != O.AllowableClients)

llvm/lib/TextAPI/TextStubCommon.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ enum TBDFlags : unsigned {
2828
FlatNamespace = 1U << 0,
2929
NotApplicationExtensionSafe = 1U << 1,
3030
InstallAPI = 1U << 2,
31-
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/InstallAPI),
31+
SimulatorSupport = 1U << 3,
32+
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/SimulatorSupport),
3233
};
3334
// clang-format on
3435

llvm/lib/TextAPI/TextStubV5.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,11 @@ Expected<PackedVersion> getPackedVersion(const Object *File, TBDKey Key) {
547547
Expected<TBDFlags> getFlags(const Object *File) {
548548
TBDFlags Flags = TBDFlags::None;
549549
const Array *Section = File->getArray(Keys[TBDKey::Flags]);
550-
if (!Section)
550+
if (!Section || Section->empty())
551551
return Flags;
552552

553553
for (auto &Val : *Section) {
554-
// TODO: Just take first for now.
554+
// FIXME: Flags currently apply to all target triples.
555555
const auto *Obj = Val.getAsObject();
556556
if (!Obj)
557557
return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Flags));
@@ -563,6 +563,7 @@ Expected<TBDFlags> getFlags(const Object *File) {
563563
.Case("flat_namespace", TBDFlags::FlatNamespace)
564564
.Case("not_app_extension_safe",
565565
TBDFlags::NotApplicationExtensionSafe)
566+
.Case("sim_support", TBDFlags::SimulatorSupport)
566567
.Default(TBDFlags::None);
567568
Flags |= TBDFlag;
568569
});
@@ -653,6 +654,7 @@ Expected<IFPtr> parseToInterfaceFile(const Object *File) {
653654
F->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));
654655
F->setApplicationExtensionSafe(
655656
!(Flags & TBDFlags::NotApplicationExtensionSafe));
657+
F->setSimulatorSupport((Flags & TBDFlags::SimulatorSupport));
656658
for (auto &T : Targets)
657659
F->addTarget(T);
658660
for (auto &[Lib, Targets] : Clients)
@@ -919,6 +921,8 @@ Array serializeFlags(const InterfaceFile *File) {
919921
Flags.emplace_back("flat_namespace");
920922
if (!File->isApplicationExtensionSafe())
921923
Flags.emplace_back("not_app_extension_safe");
924+
if (File->hasSimulatorSupport())
925+
Flags.emplace_back("sim_support");
922926
return serializeScalar(TBDKey::Attributes, std::move(Flags));
923927
}
924928

llvm/tools/llvm-readtapi/DiffEngine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ DiffEngine::findDifferences(const InterfaceFile *IFLHS,
363363
rhs, IFRHS->isApplicationExtensionSafe()),
364364
"Application Extension Safe"));
365365

366+
if (IFLHS->hasSimulatorSupport() != IFRHS->hasSimulatorSupport())
367+
Output.push_back(recordDifferences(DiffScalarVal<bool, AD_Diff_Scalar_Bool>(
368+
lhs, IFLHS->hasSimulatorSupport()),
369+
DiffScalarVal<bool, AD_Diff_Scalar_Bool>(
370+
rhs, IFRHS->hasSimulatorSupport()),
371+
"Simulator Support"));
372+
366373
if (IFLHS->reexportedLibraries() != IFRHS->reexportedLibraries())
367374
Output.push_back(recordDifferences(IFLHS->reexportedLibraries(),
368375
IFRHS->reexportedLibraries(),

llvm/unittests/TextAPI/TextStubV5Tests.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,37 @@ TEST(TBDv5, InvalidMinOS) {
11511151
EXPECT_EQ("invalid min_deployment section\n", ErrorMessage);
11521152
}
11531153

1154+
TEST(TBDv5, SimSupport) {
1155+
static const char TBDv5File[] = R"({
1156+
"tapi_tbd_version": 5,
1157+
"main_library": {
1158+
"target_info": [
1159+
{
1160+
"target": "arm64-macos",
1161+
"min_deployment": "11.1"
1162+
}
1163+
],
1164+
"install_names":[
1165+
{ "name":"/S/L/F/Foo.framework/Foo" }
1166+
],
1167+
"flags":[
1168+
{ "attributes": ["sim_support"] }
1169+
]
1170+
}})";
1171+
1172+
Expected<TBDFile> Result =
1173+
TextAPIReader::get(MemoryBufferRef(TBDv5File, "Test.tbd"));
1174+
EXPECT_TRUE(!!Result);
1175+
Target ExpectedTarget = Target(AK_arm64, PLATFORM_MACOS, VersionTuple(11, 1));
1176+
TBDFile ReadFile = std::move(Result.get());
1177+
EXPECT_EQ(FileType::TBD_V5, ReadFile->getFileType());
1178+
EXPECT_EQ(std::string("/S/L/F/Foo.framework/Foo"),
1179+
ReadFile->getInstallName());
1180+
EXPECT_TRUE(ReadFile->targets().begin() != ReadFile->targets().end());
1181+
EXPECT_EQ(*ReadFile->targets().begin(), ExpectedTarget);
1182+
EXPECT_TRUE(ReadFile->hasSimulatorSupport());
1183+
}
1184+
11541185
TEST(TBDv5, MergeIF) {
11551186
static const char TBDv5FileA[] = R"({
11561187
"tapi_tbd_version": 5,

0 commit comments

Comments
 (0)