Skip to content

Commit 517567f

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 (cherry picked from commit 913f21a)
1 parent 35f9bac commit 517567f

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
@@ -546,11 +546,11 @@ Expected<PackedVersion> getPackedVersion(const Object *File, TBDKey Key) {
546546
Expected<TBDFlags> getFlags(const Object *File) {
547547
TBDFlags Flags = TBDFlags::None;
548548
const Array *Section = File->getArray(Keys[TBDKey::Flags]);
549-
if (!Section)
549+
if (!Section || Section->empty())
550550
return Flags;
551551

552552
for (auto &Val : *Section) {
553-
// TODO: Just take first for now.
553+
// FIXME: Flags currently apply to all target triples.
554554
const auto *Obj = Val.getAsObject();
555555
if (!Obj)
556556
return make_error<JSONStubError>(getParseErrorMsg(TBDKey::Flags));
@@ -562,6 +562,7 @@ Expected<TBDFlags> getFlags(const Object *File) {
562562
.Case("flat_namespace", TBDFlags::FlatNamespace)
563563
.Case("not_app_extension_safe",
564564
TBDFlags::NotApplicationExtensionSafe)
565+
.Case("sim_support", TBDFlags::SimulatorSupport)
565566
.Default(TBDFlags::None);
566567
Flags |= TBDFlag;
567568
});
@@ -652,6 +653,7 @@ Expected<IFPtr> parseToInterfaceFile(const Object *File) {
652653
F->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));
653654
F->setApplicationExtensionSafe(
654655
!(Flags & TBDFlags::NotApplicationExtensionSafe));
656+
F->setSimulatorSupport((Flags & TBDFlags::SimulatorSupport));
655657
for (auto &T : Targets)
656658
F->addTarget(T);
657659
for (auto &[Lib, Targets] : Clients)
@@ -917,6 +919,8 @@ Array serializeFlags(const InterfaceFile *File) {
917919
Flags.emplace_back("flat_namespace");
918920
if (!File->isApplicationExtensionSafe())
919921
Flags.emplace_back("not_app_extension_safe");
922+
if (File->hasSimulatorSupport())
923+
Flags.emplace_back("sim_support");
920924
return serializeScalar(TBDKey::Attributes, std::move(Flags));
921925
}
922926

llvm/tools/llvm-readtapi/DiffEngine.cpp

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

365+
if (IFLHS->hasSimulatorSupport() != IFRHS->hasSimulatorSupport())
366+
Output.push_back(recordDifferences(DiffScalarVal<bool, AD_Diff_Scalar_Bool>(
367+
lhs, IFLHS->hasSimulatorSupport()),
368+
DiffScalarVal<bool, AD_Diff_Scalar_Bool>(
369+
rhs, IFRHS->hasSimulatorSupport()),
370+
"Simulator Support"));
371+
365372
if (IFLHS->reexportedLibraries() != IFRHS->reexportedLibraries())
366373
Output.push_back(recordDifferences(IFLHS->reexportedLibraries(),
367374
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)