mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-17 20:23:59 +00:00
Object/llvm-objdump: allow dumping of mach-o exports trie
MachOObjectFile in lib/Object currently has no support for parsing the rebase, binding, and export information from the LC_DYLD_INFO load command in final linked mach-o images. This patch adds support for parsing the exports trie data structure. It also adds an option to llvm-objdump to dump that export info. I did the exports parsing first because it is the hardest. The information is encoded in a trie structure, but the standard ObjectFile way to inspect content is through iterators. So I needed to make an iterator that would do a non-recursive walk through the trie and maintain the concatenation of edges needed for the current string prefix. I plan to add similar support in MachOObjectFile and llvm-objdump to parse/display the rebasing and binding info too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216808 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1783,3 +1783,63 @@ void llvm::printMachOFileHeader(const object::ObjectFile *Obj) {
|
||||
getAndPrintMachHeader(file, ncmds, filetype, cputype, true);
|
||||
PrintLoadCommands(file, ncmds, filetype, cputype, true);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// export trie dumping
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void llvm::printMachOExportsTrie(const object::MachOObjectFile *Obj) {
|
||||
for (const llvm::object::ExportEntry &entry : Obj->exports()) {
|
||||
uint64_t Flags = entry.flags();
|
||||
bool ReExport = (Flags & MachO::EXPORT_SYMBOL_FLAGS_REEXPORT);
|
||||
bool WeakDef = (Flags & MachO::EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION);
|
||||
bool ThreadLocal = ((Flags & MachO::EXPORT_SYMBOL_FLAGS_KIND_MASK) ==
|
||||
MachO::EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL);
|
||||
bool Abs = ((Flags & MachO::EXPORT_SYMBOL_FLAGS_KIND_MASK) ==
|
||||
MachO::EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE);
|
||||
bool Resolver = (Flags & MachO::EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER);
|
||||
if (ReExport)
|
||||
outs() << "[re-export] ";
|
||||
else
|
||||
outs()
|
||||
<< format("0x%08llX ", entry.address()); // FIXME:add in base address
|
||||
outs() << entry.name();
|
||||
if (WeakDef || ThreadLocal || Resolver || Abs) {
|
||||
bool needComma = false;
|
||||
printf(" [");
|
||||
if (WeakDef) {
|
||||
outs() << "weak_def";
|
||||
needComma = true;
|
||||
}
|
||||
if (ThreadLocal) {
|
||||
if (needComma)
|
||||
outs() << ", ";
|
||||
outs() << "per-thread";
|
||||
needComma = true;
|
||||
}
|
||||
if (Abs) {
|
||||
if (needComma)
|
||||
outs() << ", ";
|
||||
outs() << "absolute";
|
||||
needComma = true;
|
||||
}
|
||||
if (Resolver) {
|
||||
if (needComma)
|
||||
outs() << ", ";
|
||||
outs() << format("resolver=0x%08llX", entry.other());
|
||||
needComma = true;
|
||||
}
|
||||
outs() << "]";
|
||||
}
|
||||
if (ReExport) {
|
||||
StringRef DylibName = "unknown";
|
||||
int ordinal = entry.other() - 1;
|
||||
Obj->getLibraryShortNameByIndex(ordinal, DylibName);
|
||||
if (entry.otherName().empty())
|
||||
outs() << " (from " << DylibName << ")";
|
||||
else
|
||||
outs() << " (" << entry.otherName() << " from " << DylibName << ")";
|
||||
}
|
||||
outs() << "\n";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user