Skip to content

[llvm-nm] Fix how inlined dylibs are reported from tbd files #134498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llvm/include/llvm/Object/TapiUniversal.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ class TapiUniversal : public Binary {
static bool classof(const Binary *v) { return v->isTapiUniversal(); }

private:
/// Attributes of a library that is inlined into a single TBD file.
struct Library {
StringRef InstallName;
MachO::Architecture Arch;
const StringRef InstallName;
const MachO::Architecture Arch;
const size_t DocumentIdx;
};

std::unique_ptr<MachO::InterfaceFile> ParsedFile;
Expand Down
22 changes: 14 additions & 8 deletions llvm/lib/Object/TapiUniversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,31 @@ TapiUniversal::TapiUniversal(MemoryBufferRef Source, Error &Err)
}
ParsedFile = std::move(Result.get());

auto FlattenObjectInfo = [this](const auto &File) {
auto FlattenObjectInfo = [this](const auto &File, size_t DocIdx) {
StringRef Name = File->getInstallName();
for (const Architecture Arch : File->getArchitectures())
Libraries.emplace_back(Library({Name, Arch}));
Libraries.emplace_back(Library({Name, Arch, DocIdx}));
};

FlattenObjectInfo(ParsedFile);
size_t DocIdx = 0;
FlattenObjectInfo(ParsedFile, DocIdx);
// Get inlined documents from tapi file.
for (const std::shared_ptr<InterfaceFile> &File : ParsedFile->documents())
FlattenObjectInfo(File);
FlattenObjectInfo(File, DocIdx++);
}

TapiUniversal::~TapiUniversal() = default;

Expected<std::unique_ptr<TapiFile>>
TapiUniversal::ObjectForArch::getAsObjectFile() const {
return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(),
*Parent->ParsedFile,
Parent->Libraries[Index].Arch);
const auto &InlinedDocuments = Parent->ParsedFile->documents();
const Library &CurrLib = Parent->Libraries[Index];
assert((isTopLevelLib() || (InlinedDocuments.size() > CurrLib.DocumentIdx)) &&
"Index into documents exceeds the container for them");
InterfaceFile *IF = isTopLevelLib()
? Parent->ParsedFile.get()
: InlinedDocuments[CurrLib.DocumentIdx].get();
return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(), *IF,
CurrLib.Arch);
}

Expected<std::unique_ptr<TapiUniversal>>
Expand Down
10 changes: 2 additions & 8 deletions llvm/test/tools/llvm-nm/tapi-files.test
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,8 @@ V3-NEXT: 0000000000000000 S _OBJC_METACLASS_$_NSString
V3-NEXT: 0000000000000000 S _sym1
V3-NEXT: 0000000000000000 S _sym2
V3: /usr/lib/liba.dylib (for architecture x86_64):
V3-NEXT: 0000000000000000 S _OBJC_CLASS_$_NSBlockPredicate
V3-NEXT: 0000000000000000 S _OBJC_CLASS_$_NSString
V3-NEXT: 0000000000000000 S _OBJC_EHTYPE_$_NSString
V3-NEXT: 0000000000000000 S _OBJC_IVAR_$_NSBlockPredicate._block
V3-NEXT: 0000000000000000 S _OBJC_METACLASS_$_NSBlockPredicate
V3-NEXT: 0000000000000000 S _OBJC_METACLASS_$_NSString
V3-NEXT: 0000000000000000 S _sym1
V3-NEXT: 0000000000000000 S _sym2
V3-NEXT: 0000000000000000 S _sym10
V3-NEXT: 0000000000000000 S _sym11

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