[llvm] r246291 - llvm-readobj: Dump more info for COFF import libraries.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 03:27:51 PDT 2015
Author: ruiu
Date: Fri Aug 28 05:27:50 2015
New Revision: 246291
URL: http://llvm.org/viewvc/llvm-project?rev=246291&view=rev
Log:
llvm-readobj: Dump more info for COFF import libraries.
This patch teaches llvm-readobj to print out COFF import file header fields.
Added:
llvm/trunk/tools/llvm-readobj/COFFImportDumper.cpp
Modified:
llvm/trunk/include/llvm/Object/COFFImportFile.h
llvm/trunk/test/tools/llvm-readobj/file-headers.test
llvm/trunk/tools/llvm-readobj/CMakeLists.txt
llvm/trunk/tools/llvm-readobj/ObjDumper.h
llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
Modified: llvm/trunk/include/llvm/Object/COFFImportFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFFImportFile.h?rev=246291&r1=246290&r2=246291&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFFImportFile.h (original)
+++ llvm/trunk/include/llvm/Object/COFFImportFile.h Fri Aug 28 05:27:50 2015
@@ -57,11 +57,14 @@ public:
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;
}
};
Modified: llvm/trunk/test/tools/llvm-readobj/file-headers.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/file-headers.test?rev=246291&r1=246290&r2=246291&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/file-headers.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/file-headers.test Fri Aug 28 05:27:50 2015
@@ -330,4 +330,8 @@ COFF-UNKNOWN-NEXT: Characteristics [ (
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
Modified: llvm/trunk/tools/llvm-readobj/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/CMakeLists.txt?rev=246291&r1=246290&r2=246291&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-readobj/CMakeLists.txt Fri Aug 28 05:27:50 2015
@@ -7,6 +7,7 @@ add_llvm_tool(llvm-readobj
ARMAttributeParser.cpp
ARMWinEHPrinter.cpp
COFFDumper.cpp
+ COFFImportDumper.cpp
ELFDumper.cpp
Error.cpp
llvm-readobj.cpp
Added: llvm/trunk/tools/llvm-readobj/COFFImportDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFImportDumper.cpp?rev=246291&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFImportDumper.cpp (added)
+++ llvm/trunk/tools/llvm-readobj/COFFImportDumper.cpp Fri Aug 28 05:27:50 2015
@@ -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
Modified: llvm/trunk/tools/llvm-readobj/ObjDumper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ObjDumper.h?rev=246291&r1=246290&r2=246291&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ObjDumper.h (original)
+++ llvm/trunk/tools/llvm-readobj/ObjDumper.h Fri Aug 28 05:27:50 2015
@@ -15,7 +15,8 @@
namespace llvm {
namespace object {
- class ObjectFile;
+class COFFImportFile;
+class ObjectFile;
}
class StreamWriter;
@@ -76,6 +77,8 @@ std::error_code createMachODumper(const
StreamWriter &Writer,
std::unique_ptr<ObjDumper> &Result);
+void dumpCOFFImportFile(const object::COFFImportFile *File);
+
} // namespace llvm
#endif
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=246291&r1=246290&r2=246291&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Fri Aug 28 05:27:50 2015
@@ -331,12 +331,6 @@ static void dumpObject(const ObjectFile
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()) {
More information about the llvm-commits
mailing list