[llvm] r279088 - llvm-objdump: add coff import library symbol listing support
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 18 09:39:19 PDT 2016
Author: compnerd
Date: Thu Aug 18 11:39:19 2016
New Revision: 279088
URL: http://llvm.org/viewvc/llvm-project?rev=279088&view=rev
Log:
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.
Added:
llvm/trunk/test/tools/llvm-objdump/Inputs/library.lib (with props)
llvm/trunk/test/tools/llvm-objdump/coff-import-library.test
Modified:
llvm/trunk/tools/llvm-objdump/COFFDump.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.h
Added: llvm/trunk/test/tools/llvm-objdump/Inputs/library.lib
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/Inputs/library.lib?rev=279088&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-objdump/Inputs/library.lib (added) and llvm/trunk/test/tools/llvm-objdump/Inputs/library.lib Thu Aug 18 11:39:19 2016 differ
Propchange: llvm/trunk/test/tools/llvm-objdump/Inputs/library.lib
------------------------------------------------------------------------------
svn:executable = *
Added: llvm/trunk/test/tools/llvm-objdump/coff-import-library.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/coff-import-library.test?rev=279088&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/coff-import-library.test (added)
+++ llvm/trunk/test/tools/llvm-objdump/coff-import-library.test Thu Aug 18 11:39:19 2016
@@ -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
+
Modified: llvm/trunk/tools/llvm-objdump/COFFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/COFFDump.cpp?rev=279088&r1=279087&r2=279088&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/COFFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp Thu Aug 18 11:39:19 2016
@@ -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 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);
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=279088&r1=279087&r2=279088&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Thu Aug 18 11:39:19 2016
@@ -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
}
}
+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);
}
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.h?rev=279088&r1=279087&r2=279088&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.h (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.h Thu Aug 18 11:39:19 2016
@@ -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 objec
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);
More information about the llvm-commits
mailing list