mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-23 20:22:09 +00:00
llvm-objdump: add coff import library symbol listing support
This adds behaviour similar to binutils' objdump which can show symbols in an import library. Differences from that stem around the fact that we do not create section symbols nor the all import import descriptor symbol reference. However, this does mean that the tool can serve as a possible replacement for the existing tool. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279088 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
67f28904e3
commit
8a8360251d
BIN
test/tools/llvm-objdump/Inputs/library.lib
Executable file
BIN
test/tools/llvm-objdump/Inputs/library.lib
Executable file
Binary file not shown.
12
test/tools/llvm-objdump/coff-import-library.test
Normal file
12
test/tools/llvm-objdump/coff-import-library.test
Normal file
@ -0,0 +1,12 @@
|
||||
RUN: llvm-objdump -t %p/Inputs/library.lib
|
||||
|
||||
CHECK: [ 0](sec 0)(fl 0x00)(ty 0)(scl 0) (nx 0) 0x00000000 __imp__constant
|
||||
|
||||
CHECK: [ 0](sec 0)(fl 0x00)(ty 0)(scl 0) (nx 0) 0x00000000 __imp__data
|
||||
|
||||
CHECK: [ 0](sec 0)(fl 0x00)(ty 0)(scl 0) (nx 0) 0x00000000 __imp__function
|
||||
CHECK: [ 1](sec 0)(fl 0x00)(ty 20)(scl 0) (nx 0) 0x00000000 _function
|
||||
|
||||
CHECK: [ 0](sec 0)(fl 0x00)(ty 0)(scl 0) (nx 0) 0x00000000 __imp__ordinal
|
||||
CHECK: [ 1](sec 0)(fl 0x00)(ty 20)(scl 0) (nx 0) 0x00000000 _ordinal
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "llvm-objdump.h"
|
||||
#include "llvm/Object/COFF.h"
|
||||
#include "llvm/Object/COFFImportFile.h"
|
||||
#include "llvm/Object/ObjectFile.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
@ -617,6 +618,29 @@ void llvm::printCOFFFileHeader(const object::ObjectFile *Obj) {
|
||||
printExportTable(file);
|
||||
}
|
||||
|
||||
void llvm::printCOFFSymbolTable(const object::COFFImportFile *i) {
|
||||
unsigned Index = 0;
|
||||
bool IsCode = i->getCOFFImportHeader()->getType() == COFF::IMPORT_CODE;
|
||||
|
||||
for (const object::BasicSymbolRef &Sym : i->symbols()) {
|
||||
std::string Name;
|
||||
raw_string_ostream NS(Name);
|
||||
|
||||
Sym.printName(NS);
|
||||
NS.flush();
|
||||
|
||||
outs() << "[" << format("%2d", Index) << "]"
|
||||
<< "(sec " << format("%2d", 0) << ")"
|
||||
<< "(fl 0x00)" // Flag bits, which COFF doesn't have.
|
||||
<< "(ty " << format("%3x", (IsCode && Index) ? 32 : 0) << ")"
|
||||
<< "(scl " << format("%3x", 0) << ") "
|
||||
<< "(nx " << 0 << ") "
|
||||
<< "0x" << format("%08x", 0) << " " << Name << '\n';
|
||||
|
||||
++Index;
|
||||
}
|
||||
}
|
||||
|
||||
void llvm::printCOFFSymbolTable(const COFFObjectFile *coff) {
|
||||
for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
|
||||
ErrorOr<COFFSymbolRef> Symbol = coff->getSymbol(SI);
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "llvm/MC/MCSubtargetInfo.h"
|
||||
#include "llvm/Object/Archive.h"
|
||||
#include "llvm/Object/COFF.h"
|
||||
#include "llvm/Object/COFFImportFile.h"
|
||||
#include "llvm/Object/ELFObjectFile.h"
|
||||
#include "llvm/Object/MachO.h"
|
||||
#include "llvm/Object/ObjectFile.h"
|
||||
@ -1824,6 +1825,20 @@ static void DumpObject(const ObjectFile *o, const Archive *a = nullptr) {
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpObject(const COFFImportFile *I, const Archive *A) {
|
||||
StringRef ArchiveName = A ? A->getFileName() : "";
|
||||
|
||||
// Avoid other output when using a raw option.
|
||||
if (!RawClangAST)
|
||||
outs() << '\n'
|
||||
<< ArchiveName << "(" << I->getFileName() << ")"
|
||||
<< ":\tfile format COFF-import-file"
|
||||
<< "\n\n";
|
||||
|
||||
if (SymbolTable)
|
||||
printCOFFSymbolTable(I);
|
||||
}
|
||||
|
||||
/// @brief Dump each object file in \a a;
|
||||
static void DumpArchive(const Archive *a) {
|
||||
Error Err;
|
||||
@ -1836,6 +1851,8 @@ static void DumpArchive(const Archive *a) {
|
||||
}
|
||||
if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get()))
|
||||
DumpObject(o, a);
|
||||
else if (COFFImportFile *I = dyn_cast<COFFImportFile>(&*ChildOrErr.get()))
|
||||
DumpObject(I, a);
|
||||
else
|
||||
report_error(a->getFileName(), object_error::invalid_file_type);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ class StringRef;
|
||||
|
||||
namespace object {
|
||||
class COFFObjectFile;
|
||||
class COFFImportFile;
|
||||
class MachOObjectFile;
|
||||
class ObjectFile;
|
||||
class Archive;
|
||||
@ -74,6 +75,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::COFFImportFile *i);
|
||||
void printCOFFSymbolTable(const object::COFFObjectFile *o);
|
||||
void printMachOFileHeader(const object::ObjectFile *o);
|
||||
void printMachOLoadCommands(const object::ObjectFile *o);
|
||||
|
Loading…
x
Reference in New Issue
Block a user