Skip to content

Commit e17efa6

Browse files
authored
[llvm][TextAPI] Add new not_for_dyld_shared_cache attribute to file… (#71735)
… format. Formats >= TBDv4 will now encode new attribute that the system static linker wil read when tbd files replace binary dylibs.
1 parent dfecfc7 commit e17efa6

File tree

9 files changed

+139
-1
lines changed

9 files changed

+139
-1
lines changed

llvm/include/llvm/TextAPI/InterfaceFile.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ class InterfaceFile {
248248
/// Check if the library uses two-level namespace.
249249
bool isTwoLevelNamespace() const { return IsTwoLevelNamespace; }
250250

251+
/// Specify if the library is an OS library but not shared cache eligible.
252+
void setOSLibNotForSharedCache(bool V = true) {
253+
IsOSLibNotForSharedCache = V;
254+
}
255+
256+
/// Check if the library is an OS library that is not shared cache eligible.
257+
bool isOSLibNotForSharedCache() const { return IsOSLibNotForSharedCache; }
258+
251259
/// Specify if the library is application extension safe (or not).
252260
void setApplicationExtensionSafe(bool V = true) { IsAppExtensionSafe = V; }
253261

@@ -455,6 +463,7 @@ class InterfaceFile {
455463
PackedVersion CompatibilityVersion;
456464
uint8_t SwiftABIVersion{0};
457465
bool IsTwoLevelNamespace{false};
466+
bool IsOSLibNotForSharedCache{false};
458467
bool IsAppExtensionSafe{false};
459468
bool HasSimSupport{false};
460469
ObjCConstraintType ObjcConstraint = ObjCConstraintType::None;

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 (IsOSLibNotForSharedCache != O.IsOSLibNotForSharedCache)
365+
return false;
364366
if (HasSimSupport != O.HasSimSupport)
365367
return false;
366368
if (ParentUmbrellas != O.ParentUmbrellas)

llvm/lib/TextAPI/TextStub.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ template <> struct ScalarBitSetTraits<TBDFlags> {
360360
IO.bitSetCase(Flags, "not_app_extension_safe",
361361
TBDFlags::NotApplicationExtensionSafe);
362362
IO.bitSetCase(Flags, "installapi", TBDFlags::InstallAPI);
363+
IO.bitSetCase(Flags, "not_for_dyld_shared_cache",
364+
TBDFlags::OSLibNotForSharedCache);
363365
}
364366
};
365367

@@ -782,6 +784,9 @@ template <> struct MappingTraits<const InterfaceFile *> {
782784
if (!File->isTwoLevelNamespace())
783785
Flags |= TBDFlags::FlatNamespace;
784786

787+
if (File->isOSLibNotForSharedCache())
788+
Flags |= TBDFlags::OSLibNotForSharedCache;
789+
785790
{
786791
std::map<std::string, TargetList> valueToTargetList;
787792
for (const auto &it : File->umbrellas())
@@ -872,6 +877,8 @@ template <> struct MappingTraits<const InterfaceFile *> {
872877
File->setTwoLevelNamespace(!(Flags & TBDFlags::FlatNamespace));
873878
File->setApplicationExtensionSafe(
874879
!(Flags & TBDFlags::NotApplicationExtensionSafe));
880+
File->setOSLibNotForSharedCache(
881+
(Flags & TBDFlags::OSLibNotForSharedCache));
875882

876883
for (const auto &CurrentSection : AllowableClients) {
877884
for (const auto &lib : CurrentSection.Values)

llvm/lib/TextAPI/TextStubCommon.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ enum TBDFlags : unsigned {
2929
NotApplicationExtensionSafe = 1U << 1,
3030
InstallAPI = 1U << 2,
3131
SimulatorSupport = 1U << 3,
32-
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/SimulatorSupport),
32+
OSLibNotForSharedCache = 1U << 4,
33+
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/OSLibNotForSharedCache),
3334
};
3435
// clang-format on
3536

llvm/lib/TextAPI/TextStubV5.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ Expected<TBDFlags> getFlags(const Object *File) {
564564
.Case("not_app_extension_safe",
565565
TBDFlags::NotApplicationExtensionSafe)
566566
.Case("sim_support", TBDFlags::SimulatorSupport)
567+
.Case("not_for_dyld_shared_cache",
568+
TBDFlags::OSLibNotForSharedCache)
567569
.Default(TBDFlags::None);
568570
Flags |= TBDFlag;
569571
});
@@ -655,6 +657,7 @@ Expected<IFPtr> parseToInterfaceFile(const Object *File) {
655657
F->setApplicationExtensionSafe(
656658
!(Flags & TBDFlags::NotApplicationExtensionSafe));
657659
F->setSimulatorSupport((Flags & TBDFlags::SimulatorSupport));
660+
F->setOSLibNotForSharedCache((Flags & TBDFlags::OSLibNotForSharedCache));
658661
for (auto &T : Targets)
659662
F->addTarget(T);
660663
for (auto &[Lib, Targets] : Clients)
@@ -923,6 +926,8 @@ Array serializeFlags(const InterfaceFile *File) {
923926
Flags.emplace_back("not_app_extension_safe");
924927
if (File->hasSimulatorSupport())
925928
Flags.emplace_back("sim_support");
929+
if (File->isOSLibNotForSharedCache())
930+
Flags.emplace_back("not_for_dyld_shared_cache");
926931
return serializeScalar(TBDKey::Attributes, std::move(Flags));
927932
}
928933

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; RUN: rm -rf %t
2+
; RUN: split-file %s %t
3+
; RUN: not llvm-readtapi --compare %t/tbdv4.tbd %t/tbdv5.tbd 2>&1 | FileCheck %s
4+
5+
; CHECK: < {{.*}}tbdv4.tbd
6+
; CHECK: > {{.*}}tbdv5.tbd
7+
8+
CHECK: Two Level Namespace
9+
CHECK-NEXT: < true
10+
CHECK-NEXT: > false
11+
CHECK-NEXT: Shared Cache Ineligible
12+
CHECK-NEXT: < true
13+
CHECK-NEXT: > false
14+
15+
16+
//--- tbdv4.tbd
17+
--- !tapi-tbd
18+
tbd-version: 4
19+
targets: [ arm64-macos ]
20+
flags: [ not_app_extension_safe, not_for_dyld_shared_cache ]
21+
install-name: '/usr/lib/libFake.dylib'
22+
...
23+
24+
//--- tbdv5.tbd
25+
{
26+
"main_library": {
27+
"flags": [
28+
{
29+
"attributes": [
30+
"not_app_extension_safe",
31+
"flat_namespace"
32+
]
33+
}
34+
],
35+
"install_names": [
36+
{
37+
"name": "/usr/lib/libFake.dylib"
38+
}
39+
],
40+
"target_info": [
41+
{
42+
"min_deployment": "13",
43+
"target": "arm64-macos"
44+
}
45+
]
46+
},
47+
"tapi_tbd_version": 5
48+
}
49+

llvm/tools/llvm-readtapi/DiffEngine.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,14 @@ DiffEngine::findDifferences(const InterfaceFile *IFLHS,
370370
rhs, IFRHS->hasSimulatorSupport()),
371371
"Simulator Support"));
372372

373+
if (IFLHS->isOSLibNotForSharedCache() != IFRHS->isOSLibNotForSharedCache())
374+
Output.push_back(
375+
recordDifferences(DiffScalarVal<bool, AD_Diff_Scalar_Bool>(
376+
lhs, IFLHS->isOSLibNotForSharedCache()),
377+
DiffScalarVal<bool, AD_Diff_Scalar_Bool>(
378+
rhs, IFRHS->isOSLibNotForSharedCache()),
379+
"Shared Cache Ineligible"));
380+
373381
if (IFLHS->reexportedLibraries() != IFRHS->reexportedLibraries())
374382
Output.push_back(recordDifferences(IFLHS->reexportedLibraries(),
375383
IFRHS->reexportedLibraries(),

llvm/unittests/TextAPI/TextStubV4Tests.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ TEST(TBDv4, ReadFile) {
100100
EXPECT_EQ(5U, File->getSwiftABIVersion());
101101
EXPECT_FALSE(File->isTwoLevelNamespace());
102102
EXPECT_TRUE(File->isApplicationExtensionSafe());
103+
EXPECT_FALSE(File->isOSLibNotForSharedCache());
103104
InterfaceFileRef client("ClientA", Targets);
104105
InterfaceFileRef reexport("/System/Library/Frameworks/A.framework/A",
105106
{Targets[0]});
@@ -832,6 +833,29 @@ TEST(TBDv4, Swift_99) {
832833
stripWhitespace(Buffer.c_str()));
833834
}
834835

836+
TEST(TBDv4, NotForSharedCache) {
837+
838+
static const char TBDv4NotForSharedCache[] =
839+
"--- !tapi-tbd\n"
840+
"tbd-version: 4\n"
841+
"targets: [ arm64-macos ]\n"
842+
"flags: [ not_for_dyld_shared_cache ]\n"
843+
"install-name: /S/L/F/Foo.framework/Foo\n"
844+
"...\n";
845+
846+
Expected<TBDFile> Result =
847+
TextAPIReader::get(MemoryBufferRef(TBDv4NotForSharedCache, "Test.tbd"));
848+
EXPECT_TRUE(!!Result);
849+
Target ExpectedTarget = Target(AK_arm64, PLATFORM_MACOS);
850+
TBDFile ReadFile = std::move(Result.get());
851+
EXPECT_EQ(FileType::TBD_V4, ReadFile->getFileType());
852+
EXPECT_EQ(std::string("/S/L/F/Foo.framework/Foo"),
853+
ReadFile->getInstallName());
854+
EXPECT_TRUE(ReadFile->targets().begin() != ReadFile->targets().end());
855+
EXPECT_EQ(*ReadFile->targets().begin(), ExpectedTarget);
856+
EXPECT_TRUE(ReadFile->isOSLibNotForSharedCache());
857+
}
858+
835859
TEST(TBDv4, InvalidArchitecture) {
836860
static const char TBDv4UnknownArch[] = "--- !tapi-tbd\n"
837861
"tbd-version: 4\n"

llvm/unittests/TextAPI/TextStubV5Tests.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ TEST(TBDv5, ReadFile) {
218218
EXPECT_EQ(PackedVersion(1, 1, 0), File->getCompatibilityVersion());
219219
EXPECT_TRUE(File->isApplicationExtensionSafe());
220220
EXPECT_FALSE(File->isTwoLevelNamespace());
221+
EXPECT_FALSE(File->isOSLibNotForSharedCache());
221222
EXPECT_EQ(0U, File->documents().size());
222223

223224
InterfaceFileRef ClientA("ClientA", AllTargets);
@@ -1197,6 +1198,38 @@ TEST(TBDv5, SimSupport) {
11971198
EXPECT_TRUE(ReadFile->hasSimulatorSupport());
11981199
}
11991200

1201+
TEST(TBDv5, NotForSharedCache) {
1202+
static const char TBDv5File[] = R"({
1203+
"tapi_tbd_version": 5,
1204+
"main_library": {
1205+
"target_info": [
1206+
{
1207+
"target": "arm64-macos",
1208+
"min_deployment": "11.1"
1209+
}
1210+
],
1211+
"install_names":[
1212+
{ "name":"/S/L/F/Foo.framework/Foo" }
1213+
],
1214+
"flags":[
1215+
{ "attributes": ["not_for_dyld_shared_cache"] }
1216+
]
1217+
}})";
1218+
1219+
Expected<TBDFile> Result =
1220+
TextAPIReader::get(MemoryBufferRef(TBDv5File, "Test.tbd"));
1221+
EXPECT_TRUE(!!Result);
1222+
Target ExpectedTarget = Target(AK_arm64, PLATFORM_MACOS, VersionTuple(11, 1));
1223+
TBDFile ReadFile = std::move(Result.get());
1224+
EXPECT_EQ(FileType::TBD_V5, ReadFile->getFileType());
1225+
EXPECT_EQ(std::string("/S/L/F/Foo.framework/Foo"),
1226+
ReadFile->getInstallName());
1227+
EXPECT_TRUE(ReadFile->targets().begin() != ReadFile->targets().end());
1228+
EXPECT_EQ(*ReadFile->targets().begin(), ExpectedTarget);
1229+
EXPECT_FALSE(ReadFile->hasSimulatorSupport());
1230+
EXPECT_TRUE(ReadFile->isOSLibNotForSharedCache());
1231+
}
1232+
12001233
TEST(TBDv5, MergeIF) {
12011234
static const char TBDv5FileA[] = R"({
12021235
"tapi_tbd_version": 5,

0 commit comments

Comments
 (0)