Skip to content

Commit 798bb09

Browse files
committed
[llvm][TextAPI] Clean up minor bugs in YAML TextStub
* Always print out maccatalyst in format * Traverse symbols via InterfaceFile symbol APIs * Properly track addition of flags. Reviewed By: ributzka Differential Revision: https://reviews.llvm.org/D144428 (cherry picked from commit 9b29de1)
1 parent fe6aada commit 798bb09

File tree

6 files changed

+47
-37
lines changed

6 files changed

+47
-37
lines changed

llvm/lib/TextAPI/TextStub.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ template <> struct MappingTraits<const InterfaceFile *> {
456456
ArchSet.insert(Library.getArchitectures());
457457

458458
std::map<const Symbol *, ArchitectureSet> SymbolToArchSet;
459-
for (const auto *Symbol : File->exports()) {
459+
for (const auto *Symbol : File->symbols()) {
460460
auto Architectures = Symbol->getArchitectures();
461461
SymbolToArchSet[Symbol] = Architectures;
462462
ArchSet.insert(Architectures);
@@ -833,13 +833,10 @@ template <> struct MappingTraits<const InterfaceFile *> {
833833

834834
auto handleSymbols =
835835
[](SectionList &CurrentSections,
836-
InterfaceFile::const_filtered_symbol_range Symbols,
837-
std::function<bool(const Symbol *)> Pred) {
836+
InterfaceFile::const_filtered_symbol_range Symbols) {
838837
std::set<TargetList> TargetSet;
839838
std::map<const Symbol *, TargetList> SymbolToTargetList;
840839
for (const auto *Symbol : Symbols) {
841-
if (!Pred(Symbol))
842-
continue;
843840
TargetList Targets(Symbol->targets());
844841
SymbolToTargetList[Symbol] = Targets;
845842
TargetSet.emplace(std::move(Targets));
@@ -884,14 +881,9 @@ template <> struct MappingTraits<const InterfaceFile *> {
884881
}
885882
};
886883

887-
handleSymbols(Exports, File->exports(), [](const Symbol *Symbol) {
888-
return !Symbol->isReexported();
889-
});
890-
handleSymbols(Reexports, File->exports(), [](const Symbol *Symbol) {
891-
return Symbol->isReexported();
892-
});
893-
handleSymbols(Undefineds, File->undefineds(),
894-
[](const Symbol *Symbol) { return true; });
884+
handleSymbols(Exports, File->exports());
885+
handleSymbols(Reexports, File->reexports());
886+
handleSymbols(Undefineds, File->undefineds());
895887
}
896888

897889
const InterfaceFile *denormalize(IO &IO) {
@@ -937,24 +929,28 @@ template <> struct MappingTraits<const InterfaceFile *> {
937929

938930
for (auto &sym : CurrentSection.Classes)
939931
File->addSymbol(SymbolKind::ObjectiveCClass, sym,
940-
CurrentSection.Targets);
932+
CurrentSection.Targets, Flag);
941933

942934
for (auto &sym : CurrentSection.ClassEHs)
943935
File->addSymbol(SymbolKind::ObjectiveCClassEHType, sym,
944-
CurrentSection.Targets);
936+
CurrentSection.Targets, Flag);
945937

946938
for (auto &sym : CurrentSection.Ivars)
947939
File->addSymbol(SymbolKind::ObjectiveCInstanceVariable, sym,
948-
CurrentSection.Targets);
940+
CurrentSection.Targets, Flag);
949941

950-
for (auto &sym : CurrentSection.WeakSymbols)
942+
SymbolFlags SymFlag = (Flag == SymbolFlags::Undefined)
943+
? SymbolFlags::WeakReferenced
944+
: SymbolFlags::WeakDefined;
945+
for (auto &sym : CurrentSection.WeakSymbols) {
951946
File->addSymbol(SymbolKind::GlobalSymbol, sym,
952-
CurrentSection.Targets, SymbolFlags::WeakDefined);
947+
CurrentSection.Targets, Flag | SymFlag);
948+
}
953949

954950
for (auto &sym : CurrentSection.TlvSymbols)
955951
File->addSymbol(SymbolKind::GlobalSymbol, sym,
956952
CurrentSection.Targets,
957-
SymbolFlags::ThreadLocalValue);
953+
Flag | SymbolFlags::ThreadLocalValue);
958954
}
959955
};
960956

llvm/lib/TextAPI/TextStubCommon.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void ScalarTraits<PlatformSet>::output(const PlatformSet &Values, void *IO,
8282
OS << "bridgeos";
8383
break;
8484
case PLATFORM_MACCATALYST:
85-
OS << "iosmac";
85+
OS << "maccatalyst";
8686
break;
8787
case PLATFORM_DRIVERKIT:
8888
OS << "driverkit";
@@ -112,6 +112,7 @@ StringRef ScalarTraits<PlatformSet>::input(StringRef Scalar, void *IO,
112112
.Case("tvos", PLATFORM_TVOS)
113113
.Case("bridgeos", PLATFORM_BRIDGEOS)
114114
.Case("iosmac", PLATFORM_MACCATALYST)
115+
.Case("maccatalyst", PLATFORM_MACCATALYST)
115116
.Case("driverkit", PLATFORM_DRIVERKIT)
116117
.Default(PLATFORM_UNKNOWN);
117118

llvm/lib/TextAPI/TextStubV5.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "TextStubCommon.h"
1313
#include "llvm/ADT/StringSwitch.h"
1414
#include "llvm/Support/JSON.h"
15+
#include <utility>
1516

1617
// clang-format off
1718
/*
@@ -334,9 +335,11 @@ Error collectSymbolsFromSegment(const Object *Segment, TargetsToSymbols &Result,
334335
if (Err)
335336
return Err;
336337

337-
SymbolFlags WeakFlag = SectionFlag | (SectionFlag == SymbolFlags::Undefined
338-
? SymbolFlags::WeakReferenced
339-
: SymbolFlags::WeakDefined);
338+
SymbolFlags WeakFlag =
339+
SectionFlag |
340+
(((SectionFlag & SymbolFlags::Undefined) == SymbolFlags::Undefined)
341+
? SymbolFlags::WeakReferenced
342+
: SymbolFlags::WeakDefined);
340343
Err = collectFromArray(
341344
TBDKey::Weak, Segment, [&Result, WeakFlag](StringRef Name) {
342345
JSONSymbol Sym = {SymbolKind::GlobalSymbol, Name.str(), WeakFlag};
@@ -405,7 +408,8 @@ Expected<TargetsToSymbols> getSymbolSection(const Object *File, TBDKey Key,
405408
} else {
406409
MappedTargets = *TargetsOrErr;
407410
}
408-
Result.emplace_back(std::make_pair(Targets, std::vector<JSONSymbol>()));
411+
Result.emplace_back(
412+
std::make_pair(std::move(MappedTargets), std::vector<JSONSymbol>()));
409413

410414
auto *DataSection = Obj->getObject(Keys[TBDKey::Data]);
411415
auto *TextSection = Obj->getObject(Keys[TBDKey::Text]);

llvm/unittests/TextAPI/TextStubV3Tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ TEST(TBDv3, Platform_bridgeOS) {
495495
TEST(TBDv3, Platform_macCatalyst) {
496496
static const char TBDv3PlatformiOSmac[] = "--- !tapi-tbd-v3\n"
497497
"archs: [ armv7k ]\n"
498-
"platform: iosmac\n"
498+
"platform: maccatalyst\n"
499499
"install-name: Test.dylib\n"
500500
"...\n";
501501

llvm/unittests/TextAPI/TextStubV4Tests.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ TEST(TBDv4, ReadFile) {
6464
" objc-classes: []\n"
6565
" objc-eh-types: []\n"
6666
" objc-ivars: []\n"
67-
" weak-symbols: []\n"
67+
" weak-symbols: [weakReexport]\n"
6868
" thread-local-symbols: []\n"
6969
"undefineds:\n"
7070
" - targets: [ i386-macos ]\n"
7171
" symbols: [ _symD ]\n"
7272
" objc-classes: []\n"
7373
" objc-eh-types: []\n"
7474
" objc-ivars: []\n"
75-
" weak-symbols: []\n"
75+
" weak-symbols: [weakReference]\n"
7676
" thread-local-symbols: []\n"
7777
"...\n";
7878

@@ -114,16 +114,23 @@ TEST(TBDv4, ReadFile) {
114114
EXPECT_EQ(reexport, File->reexportedLibraries().front());
115115

116116
ExportedSymbolSeq Exports, Reexports, Undefineds;
117-
ExportedSymbol temp;
118117
for (const auto *Sym : File->symbols()) {
119-
temp = ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),
120-
Sym->isWeakDefined(), Sym->isThreadLocalValue()};
121-
EXPECT_FALSE(Sym->isWeakReferenced());
122-
if (Sym->isUndefined())
123-
Undefineds.emplace_back(std::move(temp));
124-
else
125-
Sym->isReexported() ? Reexports.emplace_back(std::move(temp))
126-
: Exports.emplace_back(std::move(temp));
118+
ExportedSymbol Temp =
119+
ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),
120+
Sym->isWeakDefined() || Sym->isWeakReferenced(),
121+
Sym->isThreadLocalValue()};
122+
if (Sym->isUndefined()) {
123+
EXPECT_FALSE(Sym->isWeakDefined());
124+
Undefineds.emplace_back(std::move(Temp));
125+
}
126+
// Check that defined symbols cannot be set as weak referenced.
127+
else if (Sym->isReexported()) {
128+
EXPECT_FALSE(Sym->isWeakReferenced());
129+
Reexports.emplace_back(std::move(Temp));
130+
} else {
131+
EXPECT_FALSE(Sym->isWeakReferenced());
132+
Exports.emplace_back(std::move(Temp));
133+
}
127134
}
128135
llvm::sort(Exports);
129136
llvm::sort(Reexports);
@@ -137,10 +144,12 @@ TEST(TBDv4, ReadFile) {
137144

138145
static ExportedSymbol ExpectedReexportedSymbols[] = {
139146
{SymbolKind::GlobalSymbol, "_symC", false, false},
147+
{SymbolKind::GlobalSymbol, "weakReexport", true, false},
140148
};
141149

142150
static ExportedSymbol ExpectedUndefinedSymbols[] = {
143151
{SymbolKind::GlobalSymbol, "_symD", false, false},
152+
{SymbolKind::GlobalSymbol, "weakReference", true, false},
144153
};
145154

146155
EXPECT_EQ(sizeof(ExpectedExportedSymbols) / sizeof(ExportedSymbol),

llvm/unittests/TextAPI/TextStubV5Tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ TEST(TBDv5, WriteMultipleDocuments) {
877877
NestedFileB.setCurrentVersion(PackedVersion(1, 0, 0));
878878
NestedFileB.setTwoLevelNamespace();
879879
NestedFileB.setApplicationExtensionSafe(true);
880-
NestedFileB.addSymbol(SymbolKind::GlobalSymbol, "_varFooBaz", AllTargets,
880+
NestedFileB.addSymbol(SymbolKind::GlobalSymbol, "_varFooBaz", {AllTargets[0]},
881881
SymbolFlags::Data);
882882
File.addDocument(std::make_shared<InterfaceFile>(std::move(NestedFileB)));
883883

0 commit comments

Comments
 (0)