From abe8418ff7e12a2ac07f0cfbc4900e30dc8db99c Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Sun, 20 Dec 2015 09:54:34 +0000 Subject: [llvm-objdump] Move COFF function to where it belongs. Ideally much more stuff should be moved out of llvm-objdump.cpp, but that will happen later. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256118 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-objdump/COFFDump.cpp | 49 +++++++++++++++++++++++++++++++++++ tools/llvm-objdump/llvm-objdump.cpp | 51 +------------------------------------ tools/llvm-objdump/llvm-objdump.h | 1 + 3 files changed, 51 insertions(+), 50 deletions(-) (limited to 'tools') diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp index 001e352c8d0..f286351614a 100644 --- a/tools/llvm-objdump/COFFDump.cpp +++ b/tools/llvm-objdump/COFFDump.cpp @@ -542,3 +542,52 @@ void llvm::printCOFFFileHeader(const object::ObjectFile *Obj) { printImportTables(file); printExportTable(file); } + +void llvm::printCOFFSymbolTable(const COFFObjectFile *coff) { + for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) { + ErrorOr Symbol = coff->getSymbol(SI); + StringRef Name; + error(Symbol.getError()); + error(coff->getSymbolName(*Symbol, Name)); + + outs() << "[" << format("%2d", SI) << "]" + << "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")" + << "(fl 0x00)" // Flag bits, which COFF doesn't have. + << "(ty " << format("%3x", unsigned(Symbol->getType())) << ")" + << "(scl " << format("%3x", unsigned(Symbol->getStorageClass())) << ") " + << "(nx " << unsigned(Symbol->getNumberOfAuxSymbols()) << ") " + << "0x" << format("%08x", unsigned(Symbol->getValue())) << " " + << Name << "\n"; + + for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) { + if (Symbol->isSectionDefinition()) { + const coff_aux_section_definition *asd; + error(coff->getAuxSymbol(SI + 1, asd)); + + int32_t AuxNumber = asd->getNumber(Symbol->isBigObj()); + + outs() << "AUX " + << format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x " + , unsigned(asd->Length) + , unsigned(asd->NumberOfRelocations) + , unsigned(asd->NumberOfLinenumbers) + , unsigned(asd->CheckSum)) + << format("assoc %d comdat %d\n" + , unsigned(AuxNumber) + , unsigned(asd->Selection)); + } else if (Symbol->isFileRecord()) { + const char *FileName; + error(coff->getAuxSymbol(SI + 1, FileName)); + + StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() * + coff->getSymbolTableEntrySize()); + outs() << "AUX " << Name.rtrim(StringRef("\0", 1)) << '\n'; + + SI = SI + Symbol->getNumberOfAuxSymbols(); + break; + } else { + outs() << "AUX Unknown\n"; + } + } + } +} diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 3057a1d099e..e89243340cc 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -1247,60 +1247,11 @@ void llvm::PrintSectionContents(const ObjectFile *Obj) { } } -static void PrintCOFFSymbolTable(const COFFObjectFile *coff) { - for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) { - ErrorOr Symbol = coff->getSymbol(SI); - StringRef Name; - error(Symbol.getError()); - error(coff->getSymbolName(*Symbol, Name)); - - outs() << "[" << format("%2d", SI) << "]" - << "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")" - << "(fl 0x00)" // Flag bits, which COFF doesn't have. - << "(ty " << format("%3x", unsigned(Symbol->getType())) << ")" - << "(scl " << format("%3x", unsigned(Symbol->getStorageClass())) << ") " - << "(nx " << unsigned(Symbol->getNumberOfAuxSymbols()) << ") " - << "0x" << format("%08x", unsigned(Symbol->getValue())) << " " - << Name << "\n"; - - for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) { - if (Symbol->isSectionDefinition()) { - const coff_aux_section_definition *asd; - error(coff->getAuxSymbol(SI + 1, asd)); - - int32_t AuxNumber = asd->getNumber(Symbol->isBigObj()); - - outs() << "AUX " - << format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x " - , unsigned(asd->Length) - , unsigned(asd->NumberOfRelocations) - , unsigned(asd->NumberOfLinenumbers) - , unsigned(asd->CheckSum)) - << format("assoc %d comdat %d\n" - , unsigned(AuxNumber) - , unsigned(asd->Selection)); - } else if (Symbol->isFileRecord()) { - const char *FileName; - error(coff->getAuxSymbol(SI + 1, FileName)); - - StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() * - coff->getSymbolTableEntrySize()); - outs() << "AUX " << Name.rtrim(StringRef("\0", 1)) << '\n'; - - SI = SI + Symbol->getNumberOfAuxSymbols(); - break; - } else { - outs() << "AUX Unknown\n"; - } - } - } -} - void llvm::PrintSymbolTable(const ObjectFile *o) { outs() << "SYMBOL TABLE:\n"; if (const COFFObjectFile *coff = dyn_cast(o)) { - PrintCOFFSymbolTable(coff); + printCOFFSymbolTable(coff); return; } for (const SymbolRef &Symbol : o->symbols()) { diff --git a/tools/llvm-objdump/llvm-objdump.h b/tools/llvm-objdump/llvm-objdump.h index f74ed010d1d..e7c28f53abe 100644 --- a/tools/llvm-objdump/llvm-objdump.h +++ b/tools/llvm-objdump/llvm-objdump.h @@ -67,6 +67,7 @@ void printMachOLazyBindTable(const object::MachOObjectFile* o); void printMachOWeakBindTable(const object::MachOObjectFile* o); void printELFFileHeader(const object::ObjectFile *o); void printCOFFFileHeader(const object::ObjectFile *o); +void printCOFFSymbolTable(const object::COFFObjectFile *o); void printMachOFileHeader(const object::ObjectFile *o); void printExportsTrie(const object::ObjectFile *o); void printRebaseTable(const object::ObjectFile *o); -- cgit v1.2.3