Skip to content

Commit 42c3f69

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ec0d8e6a7523' from swift/release/6.2 into stable/20240723
2 parents e606ddd + ec0d8e6 commit 42c3f69

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

llvm/include/llvm/Object/TapiUniversal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ class TapiUniversal : public Binary {
110110
static bool classof(const Binary *v) { return v->isTapiUniversal(); }
111111

112112
private:
113+
/// Attributes of a library that is inlined into a single TBD file.
113114
struct Library {
114-
StringRef InstallName;
115-
MachO::Architecture Arch;
115+
const StringRef InstallName;
116+
const MachO::Architecture Arch;
117+
const std::optional<size_t> DocumentIdx;
116118
};
117119

118120
std::unique_ptr<MachO::InterfaceFile> ParsedFile;

llvm/lib/Object/TapiUniversal.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,34 @@ TapiUniversal::TapiUniversal(MemoryBufferRef Source, Error &Err)
3131
}
3232
ParsedFile = std::move(Result.get());
3333

34-
auto FlattenObjectInfo = [this](const auto &File) {
34+
auto FlattenObjectInfo = [this](const auto &File,
35+
std::optional<size_t> DocIdx = std::nullopt) {
3536
StringRef Name = File->getInstallName();
3637
for (const Architecture Arch : File->getArchitectures())
37-
Libraries.emplace_back(Library({Name, Arch}));
38+
Libraries.emplace_back(Library({Name, Arch, DocIdx}));
3839
};
39-
4040
FlattenObjectInfo(ParsedFile);
4141
// Get inlined documents from tapi file.
42+
size_t DocIdx = 0;
4243
for (const std::shared_ptr<InterfaceFile> &File : ParsedFile->documents())
43-
FlattenObjectInfo(File);
44+
FlattenObjectInfo(File, DocIdx++);
4445
}
4546

4647
TapiUniversal::~TapiUniversal() = default;
4748

4849
Expected<std::unique_ptr<TapiFile>>
4950
TapiUniversal::ObjectForArch::getAsObjectFile() const {
50-
return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(),
51-
*Parent->ParsedFile,
52-
Parent->Libraries[Index].Arch);
51+
const auto &InlinedDocuments = Parent->ParsedFile->documents();
52+
const Library &CurrLib = Parent->Libraries[Index];
53+
assert(
54+
(isTopLevelLib() || (CurrLib.DocumentIdx.has_value() &&
55+
(InlinedDocuments.size() > *CurrLib.DocumentIdx))) &&
56+
"Index into documents exceeds the container for them");
57+
InterfaceFile *IF = isTopLevelLib()
58+
? Parent->ParsedFile.get()
59+
: InlinedDocuments[*CurrLib.DocumentIdx].get();
60+
return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(), *IF,
61+
CurrLib.Arch);
5362
}
5463

5564
Expected<std::unique_ptr<TapiUniversal>>

llvm/test/tools/llvm-nm/tapi-files.test

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,8 @@ V3-NEXT: 0000000000000000 S _OBJC_METACLASS_$_NSString
4545
V3-NEXT: 0000000000000000 S _sym1
4646
V3-NEXT: 0000000000000000 S _sym2
4747
V3: /usr/lib/liba.dylib (for architecture x86_64):
48-
V3-NEXT: 0000000000000000 S _OBJC_CLASS_$_NSBlockPredicate
49-
V3-NEXT: 0000000000000000 S _OBJC_CLASS_$_NSString
50-
V3-NEXT: 0000000000000000 S _OBJC_EHTYPE_$_NSString
51-
V3-NEXT: 0000000000000000 S _OBJC_IVAR_$_NSBlockPredicate._block
52-
V3-NEXT: 0000000000000000 S _OBJC_METACLASS_$_NSBlockPredicate
53-
V3-NEXT: 0000000000000000 S _OBJC_METACLASS_$_NSString
54-
V3-NEXT: 0000000000000000 S _sym1
55-
V3-NEXT: 0000000000000000 S _sym2
48+
V3-NEXT: 0000000000000000 S _sym10
49+
V3-NEXT: 0000000000000000 S _sym11
5650

5751
V4: /u/l/libFoo.dylib (for architecture i386):
5852
V4-NEXT: 00000000 S _sym1

0 commit comments

Comments
 (0)