Skip to content

Commit 570e6f6

Browse files
committed
[llvm-nm] Fix how inlined dylibs are reported from tbd files
An Inlined library is a dylib that is reexported from an umbrella or top level library. When this is encoded in tbd files, ensure we are reading the symbol table from the inlined library when `--add-inlinedinfo` is used as opposed to the top level lib.
1 parent 6272e1f commit 570e6f6

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
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 size_t DocumentIdx;
116118
};
117119

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

llvm/lib/Object/TapiUniversal.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,31 @@ TapiUniversal::TapiUniversal(MemoryBufferRef Source, Error &Err)
2929
}
3030
ParsedFile = std::move(Result.get());
3131

32-
auto FlattenObjectInfo = [this](const auto &File) {
32+
auto FlattenObjectInfo = [this](const auto &File, unsigned DocIdx) {
3333
StringRef Name = File->getInstallName();
3434
for (const Architecture Arch : File->getArchitectures())
35-
Libraries.emplace_back(Library({Name, Arch}));
35+
Libraries.emplace_back(Library({Name, Arch, DocIdx}));
3636
};
37-
38-
FlattenObjectInfo(ParsedFile);
37+
size_t DocIdx = 0;
38+
FlattenObjectInfo(ParsedFile, DocIdx);
3939
// Get inlined documents from tapi file.
4040
for (const std::shared_ptr<InterfaceFile> &File : ParsedFile->documents())
41-
FlattenObjectInfo(File);
41+
FlattenObjectInfo(File, DocIdx++);
4242
}
4343

4444
TapiUniversal::~TapiUniversal() = default;
4545

4646
Expected<std::unique_ptr<TapiFile>>
4747
TapiUniversal::ObjectForArch::getAsObjectFile() const {
48-
return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(),
49-
*Parent->ParsedFile,
50-
Parent->Libraries[Index].Arch);
48+
const auto &InlinedDocuments = Parent->ParsedFile->documents();
49+
const Library &CurrLib = Parent->Libraries[Index];
50+
assert((isTopLevelLib() || (InlinedDocuments.size() > CurrLib.DocumentIdx)) &&
51+
"Index into documents exceeds the container for them");
52+
InterfaceFile *IF = isTopLevelLib()
53+
? Parent->ParsedFile.get()
54+
: InlinedDocuments[CurrLib.DocumentIdx].get();
55+
return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(), *IF,
56+
CurrLib.Arch);
5157
}
5258

5359
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)