Skip to content

Commit

Permalink
llvm-readobj: Dump more info for COFF import libraries.
Browse files Browse the repository at this point in the history
This patch teaches llvm-readobj to print out COFF import file header fields.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246291 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rui314 committed Aug 28, 2015
1 parent 9befb59 commit c2aa179
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 11 deletions.
9 changes: 6 additions & 3 deletions include/llvm/Object/COFFImportFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ class COFFImportFile : public SymbolicFile {
return BasicSymbolRef(Symb, this);
}

const coff_import_header *getCOFFImportHeader() const {
return reinterpret_cast<const object::coff_import_header *>(
Data.getBufferStart());
}

private:
bool isCode() const {
auto *Import = reinterpret_cast<const object::coff_import_header *>(
Data.getBufferStart());
return Import->getType() == COFF::IMPORT_CODE;
return getCOFFImportHeader()->getType() == COFF::IMPORT_CODE;
}
};

Expand Down
6 changes: 5 additions & 1 deletion test/tools/llvm-readobj/file-headers.test
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,8 @@ COFF-UNKNOWN-NEXT: Characteristics [ (0x0)
COFF-UNKNOWN-NEXT: ]
COFF-UNKNOWN-NEXT: }

COFF-IMPORTLIB: Format: COFF-import-file
COFF-IMPORTLIB: Format: COFF-import-file
COFF-IMPORTLIB-NEXT: Type: code
COFF-IMPORTLIB-NEXT: Name type: noprefix
COFF-IMPORTLIB-NEXT: Symbol: _func
COFF-IMPORTLIB-NEXT: Symbol: __imp__func
1 change: 1 addition & 0 deletions tools/llvm-readobj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_llvm_tool(llvm-readobj
ARMAttributeParser.cpp
ARMWinEHPrinter.cpp
COFFDumper.cpp
COFFImportDumper.cpp
ELFDumper.cpp
Error.cpp
llvm-readobj.cpp
Expand Down
52 changes: 52 additions & 0 deletions tools/llvm-readobj/COFFImportDumper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===-- COFFImportDumper.cpp - COFF import library dumper -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file implements the COFF import library dumper for llvm-readobj.
///
//===----------------------------------------------------------------------===//

#include "Error.h"
#include "ObjDumper.h"
#include "llvm-readobj.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/COFFImportFile.h"
#include "llvm/Support/COFF.h"

using namespace llvm::object;

namespace llvm {

void dumpCOFFImportFile(const COFFImportFile *File) {
outs() << '\n';
outs() << "File: " << File->getFileName() << "\n";
outs() << "Format: COFF-import-file\n";

const coff_import_header *H = File->getCOFFImportHeader();
switch (H->getType()) {
case COFF::IMPORT_CODE: outs() << "Type: code\n"; break;
case COFF::IMPORT_DATA: outs() << "Type: data\n"; break;
case COFF::IMPORT_CONST: outs() << "Type: const\n"; break;
}

switch (H->getNameType()) {
case COFF::IMPORT_ORDINAL: outs() << "Name type: ordinal\n"; break;
case COFF::IMPORT_NAME: outs() << "Name type: name\n"; break;
case COFF::IMPORT_NAME_NOPREFIX: outs() << "Name type: noprefix\n"; break;
case COFF::IMPORT_NAME_UNDECORATE: outs() << "Name type: undecorate\n"; break;
}

for (const object::BasicSymbolRef &Sym : File->symbols()) {
outs() << "Symbol: ";
Sym.printName(outs());
outs() << "\n";
}
}

} // namespace llvm
5 changes: 4 additions & 1 deletion tools/llvm-readobj/ObjDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

namespace llvm {
namespace object {
class ObjectFile;
class COFFImportFile;
class ObjectFile;
}

class StreamWriter;
Expand Down Expand Up @@ -76,6 +77,8 @@ std::error_code createMachODumper(const object::ObjectFile *Obj,
StreamWriter &Writer,
std::unique_ptr<ObjDumper> &Result);

void dumpCOFFImportFile(const object::COFFImportFile *File);

} // namespace llvm

#endif
6 changes: 0 additions & 6 deletions tools/llvm-readobj/llvm-readobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,6 @@ static void dumpObject(const ObjectFile *Obj) {
Dumper->printStackMap();
}

static void dumpCOFFImportFile(const COFFImportFile *File) {
outs() << '\n';
outs() << "File: " << File->getFileName() << "\n";
outs() << "Format: COFF-import-file\n";
}

/// @brief Dumps each object file in \a Arc;
static void dumpArchive(const Archive *Arc) {
for (const auto &Child : Arc->children()) {
Expand Down

0 comments on commit c2aa179

Please sign in to comment.