[llvm-commits] [llvm] r120204 - in /llvm/trunk: include/llvm/Object/MachOFormat.h include/llvm/Object/MachOObject.h lib/Object/MachOObject.cpp tools/macho-dump/macho-dump.cpp
Daniel Dunbar
daniel at zuster.org
Sat Nov 27 00:33:45 PST 2010
Author: ddunbar
Date: Sat Nov 27 02:33:44 2010
New Revision: 120204
URL: http://llvm.org/viewvc/llvm-project?rev=120204&view=rev
Log:
macho-dump: Add support for dumping symtab and dysymtab commands.
Modified:
llvm/trunk/include/llvm/Object/MachOFormat.h
llvm/trunk/include/llvm/Object/MachOObject.h
llvm/trunk/lib/Object/MachOObject.cpp
llvm/trunk/tools/macho-dump/macho-dump.cpp
Modified: llvm/trunk/include/llvm/Object/MachOFormat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOFormat.h?rev=120204&r1=120203&r2=120204&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOFormat.h (original)
+++ llvm/trunk/include/llvm/Object/MachOFormat.h Sat Nov 27 02:33:44 2010
@@ -177,6 +177,47 @@
uint32_t Flags;
};
+ struct SymtabLoadCommand {
+ uint32_t Type;
+ uint32_t Size;
+ uint32_t SymbolTableOffset;
+ uint32_t NumSymbolTableEntries;
+ uint32_t StringTableOffset;
+ uint32_t StringTableSize;
+ };
+
+ struct DysymtabLoadCommand {
+ uint32_t Type;
+ uint32_t Size;
+
+ uint32_t LocalSymbolIndex;
+ uint32_t NumLocalSymbols;
+
+ uint32_t ExternalSymbolsIndex;
+ uint32_t NumExternalSymbols;
+
+ uint32_t UndefinedSymbolsIndex;
+ uint32_t NumUndefinedSymbols;
+
+ uint32_t TOCOffset;
+ uint32_t NumTOCEntries;
+
+ uint32_t ModuleTableOffset;
+ uint32_t NumModuleTableEntries;
+
+ uint32_t ReferenceSymbolTableOffset;
+ uint32_t NumReferencedSymbolTableEntries;
+
+ uint32_t IndirectSymbolTableOffset;
+ uint32_t NumIndirectSymbolTableEntries;
+
+ uint32_t ExternalRelocationTableOffset;
+ uint32_t NumExternalRelocationTableEntries;
+
+ uint32_t LocalRelocationTableOffset;
+ uint32_t NumLocalRelocationTableEntries;
+ };
+
/// @}
// See <mach-o/nlist.h>.
Modified: llvm/trunk/include/llvm/Object/MachOObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOObject.h?rev=120204&r1=120203&r2=120204&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOObject.h (original)
+++ llvm/trunk/include/llvm/Object/MachOObject.h Sat Nov 27 02:33:44 2010
@@ -119,6 +119,12 @@
void ReadSegment64LoadCommand(
const LoadCommandInfo &LCI,
InMemoryStruct<macho::Segment64LoadCommand> &Res) const;
+ void ReadSymtabLoadCommand(
+ const LoadCommandInfo &LCI,
+ InMemoryStruct<macho::SymtabLoadCommand> &Res) const;
+ void ReadDysymtabLoadCommand(
+ const LoadCommandInfo &LCI,
+ InMemoryStruct<macho::DysymtabLoadCommand> &Res) const;
/// @}
};
Modified: llvm/trunk/lib/Object/MachOObject.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObject.cpp?rev=120204&r1=120203&r2=120204&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObject.cpp (original)
+++ llvm/trunk/lib/Object/MachOObject.cpp Sat Nov 27 02:33:44 2010
@@ -188,3 +188,45 @@
InMemoryStruct<macho::Segment64LoadCommand> &Res) const {
ReadInMemoryStruct(*this, Buffer->getBuffer(), LCI.Offset, Res);
}
+
+template<>
+static void SwapStruct(macho::SymtabLoadCommand &Value) {
+ SwapValue(Value.Type);
+ SwapValue(Value.Size);
+ SwapValue(Value.SymbolTableOffset);
+ SwapValue(Value.NumSymbolTableEntries);
+ SwapValue(Value.StringTableOffset);
+ SwapValue(Value.StringTableSize);
+}
+void MachOObject::ReadSymtabLoadCommand(const LoadCommandInfo &LCI,
+ InMemoryStruct<macho::SymtabLoadCommand> &Res) const {
+ ReadInMemoryStruct(*this, Buffer->getBuffer(), LCI.Offset, Res);
+}
+
+template<>
+static void SwapStruct(macho::DysymtabLoadCommand &Value) {
+ SwapValue(Value.Type);
+ SwapValue(Value.Size);
+ SwapValue(Value.LocalSymbolIndex);
+ SwapValue(Value.NumLocalSymbols);
+ SwapValue(Value.ExternalSymbolsIndex);
+ SwapValue(Value.NumExternalSymbols);
+ SwapValue(Value.UndefinedSymbolsIndex);
+ SwapValue(Value.NumUndefinedSymbols);
+ SwapValue(Value.TOCOffset);
+ SwapValue(Value.NumTOCEntries);
+ SwapValue(Value.ModuleTableOffset);
+ SwapValue(Value.NumModuleTableEntries);
+ SwapValue(Value.ReferenceSymbolTableOffset);
+ SwapValue(Value.NumReferencedSymbolTableEntries);
+ SwapValue(Value.IndirectSymbolTableOffset);
+ SwapValue(Value.NumIndirectSymbolTableEntries);
+ SwapValue(Value.ExternalRelocationTableOffset);
+ SwapValue(Value.NumExternalRelocationTableEntries);
+ SwapValue(Value.LocalRelocationTableOffset);
+ SwapValue(Value.NumLocalRelocationTableEntries);
+}
+void MachOObject::ReadDysymtabLoadCommand(const LoadCommandInfo &LCI,
+ InMemoryStruct<macho::DysymtabLoadCommand> &Res) const {
+ ReadInMemoryStruct(*this, Buffer->getBuffer(), LCI.Offset, Res);
+}
Modified: llvm/trunk/tools/macho-dump/macho-dump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/macho-dump/macho-dump.cpp?rev=120204&r1=120203&r2=120204&view=diff
==============================================================================
--- llvm/trunk/tools/macho-dump/macho-dump.cpp (original)
+++ llvm/trunk/tools/macho-dump/macho-dump.cpp Sat Nov 27 02:33:44 2010
@@ -111,6 +111,52 @@
return 0;
}
+static int DumpSymtabCommand(MachOObject &Obj,
+ const MachOObject::LoadCommandInfo &LCI) {
+ InMemoryStruct<macho::SymtabLoadCommand> SLC;
+ Obj.ReadSymtabLoadCommand(LCI, SLC);
+ if (!SLC)
+ return Error("unable to read segment load command");
+
+ outs() << " ('symoff', " << SLC->SymbolTableOffset << ")\n";
+ outs() << " ('nsyms', " << SLC->NumSymbolTableEntries << ")\n";
+ outs() << " ('stroff', " << SLC->StringTableOffset << ")\n";
+ outs() << " ('strsize', " << SLC->StringTableSize << ")\n";
+
+ return 0;
+}
+
+static int DumpDysymtabCommand(MachOObject &Obj,
+ const MachOObject::LoadCommandInfo &LCI) {
+ InMemoryStruct<macho::DysymtabLoadCommand> DLC;
+ Obj.ReadDysymtabLoadCommand(LCI, DLC);
+ if (!DLC)
+ return Error("unable to read segment load command");
+
+ outs() << " ('ilocalsym', " << DLC->LocalSymbolIndex << ")\n";
+ outs() << " ('nlocalsym', " << DLC->NumLocalSymbols << ")\n";
+ outs() << " ('iextdefsym', " << DLC->ExternalSymbolsIndex << ")\n";
+ outs() << " ('nextdefsym', " << DLC->NumExternalSymbols << ")\n";
+ outs() << " ('iundefsym', " << DLC->UndefinedSymbolsIndex << ")\n";
+ outs() << " ('nundefsym', " << DLC->NumUndefinedSymbols << ")\n";
+ outs() << " ('tocoff', " << DLC->TOCOffset << ")\n";
+ outs() << " ('ntoc', " << DLC->NumTOCEntries << ")\n";
+ outs() << " ('modtaboff', " << DLC->ModuleTableOffset << ")\n";
+ outs() << " ('nmodtab', " << DLC->NumModuleTableEntries << ")\n";
+ outs() << " ('extrefsymoff', " << DLC->ReferenceSymbolTableOffset << ")\n";
+ outs() << " ('nextrefsyms', "
+ << DLC->NumReferencedSymbolTableEntries << ")\n";
+ outs() << " ('indirectsymoff', " << DLC->IndirectSymbolTableOffset << ")\n";
+ outs() << " ('nindirectsyms', "
+ << DLC->NumIndirectSymbolTableEntries << ")\n";
+ outs() << " ('extreloff', " << DLC->ExternalRelocationTableOffset << ")\n";
+ outs() << " ('nextrel', " << DLC->NumExternalRelocationTableEntries << ")\n";
+ outs() << " ('locreloff', " << DLC->LocalRelocationTableOffset << ")\n";
+ outs() << " ('nlocrel', " << DLC->NumLocalRelocationTableEntries << ")\n";
+
+ return 0;
+}
+
static int DumpLoadCommand(MachOObject &Obj, unsigned Index) {
const MachOObject::LoadCommandInfo &LCI = Obj.getLoadCommandInfo(Index);
int Res = 0;
@@ -125,6 +171,12 @@
case macho::LCT_Segment64:
Res = DumpSegment64Command(Obj, LCI);
break;
+ case macho::LCT_Symtab:
+ Res = DumpSymtabCommand(Obj, LCI);
+ break;
+ case macho::LCT_Dysymtab:
+ Res = DumpDysymtabCommand(Obj, LCI);
+ break;
default:
Warning("unknown load command: " + Twine(LCI.Command.Type));
break;
More information about the llvm-commits
mailing list