summaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/COFFDump.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-objdump/COFFDump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/COFFDump.cpp72
1 files changed, 35 insertions, 37 deletions
diff --git a/llvm/tools/llvm-objdump/COFFDump.cpp b/llvm/tools/llvm-objdump/COFFDump.cpp
index 60b0f5a3cbd15..b9d69d62e4e71 100644
--- a/llvm/tools/llvm-objdump/COFFDump.cpp
+++ b/llvm/tools/llvm-objdump/COFFDump.cpp
@@ -14,6 +14,8 @@
///
//===----------------------------------------------------------------------===//
+#include "COFFDump.h"
+
#include "llvm-objdump.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Object/COFF.h"
@@ -24,10 +26,11 @@
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
+using namespace llvm;
+using namespace llvm::objdump;
using namespace llvm::object;
using namespace llvm::Win64EH;
-namespace llvm {
// Returns the name of the unwind code.
static StringRef getUnwindCodeTypeName(uint8_t Code) {
switch(Code) {
@@ -235,8 +238,8 @@ printSEHTable(const COFFObjectFile *Obj, uint32_t TableVA, int Count) {
return;
uintptr_t IntPtr = 0;
- if (std::error_code EC = Obj->getVaPtr(TableVA, IntPtr))
- reportError(errorCodeToError(EC), Obj->getFileName());
+ if (Error E = Obj->getVaPtr(TableVA, IntPtr))
+ reportError(std::move(E), Obj->getFileName());
const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr;
outs() << "SEH Table:";
@@ -274,17 +277,17 @@ static void printTLSDirectory(const COFFObjectFile *Obj) {
if (!PE32Header && !PE32PlusHeader)
return;
- const data_directory *DataDir;
- if (std::error_code EC = Obj->getDataDirectory(COFF::TLS_TABLE, DataDir))
- reportError(errorCodeToError(EC), Obj->getFileName());
+ const data_directory *DataDir = Obj->getDataDirectory(COFF::TLS_TABLE);
+ if (!DataDir)
+ reportError("missing data dir for TLS table", Obj->getFileName());
if (DataDir->RelativeVirtualAddress == 0)
return;
uintptr_t IntPtr = 0;
- if (std::error_code EC =
+ if (Error E =
Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
- reportError(errorCodeToError(EC), Obj->getFileName());
+ reportError(std::move(E), Obj->getFileName());
if (PE32Header) {
auto *TLSDir = reinterpret_cast<const coff_tls_directory32 *>(IntPtr);
@@ -306,19 +309,17 @@ static void printLoadConfiguration(const COFFObjectFile *Obj) {
if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_I386)
return;
- const data_directory *DataDir;
-
- if (std::error_code EC =
- Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir))
- reportError(errorCodeToError(EC), Obj->getFileName());
+ const data_directory *DataDir = Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE);
+ if (!DataDir)
+ reportError("no load config data dir", Obj->getFileName());
uintptr_t IntPtr = 0;
if (DataDir->RelativeVirtualAddress == 0)
return;
- if (std::error_code EC =
+ if (Error E =
Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
- reportError(errorCodeToError(EC), Obj->getFileName());
+ reportError(std::move(E), Obj->getFileName());
auto *LoadConf = reinterpret_cast<const coff_load_configuration32 *>(IntPtr);
outs() << "Load configuration:"
@@ -473,9 +474,9 @@ static bool getPDataSection(const COFFObjectFile *Obj,
return false;
}
-Error getCOFFRelocationValueString(const COFFObjectFile *Obj,
- const RelocationRef &Rel,
- SmallVectorImpl<char> &Result) {
+Error objdump::getCOFFRelocationValueString(const COFFObjectFile *Obj,
+ const RelocationRef &Rel,
+ SmallVectorImpl<char> &Result) {
symbol_iterator SymI = Rel.getSymbol();
Expected<StringRef> SymNameOrErr = SymI->getName();
if (!SymNameOrErr)
@@ -596,7 +597,7 @@ static void printRuntimeFunctionRels(const COFFObjectFile *Obj,
printWin64EHUnwindInfo(UI);
}
-void printCOFFUnwindInfo(const COFFObjectFile *Obj) {
+void objdump::printCOFFUnwindInfo(const COFFObjectFile *Obj) {
if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_AMD64) {
WithColor::error(errs(), "llvm-objdump")
<< "unsupported image machine type "
@@ -625,7 +626,7 @@ void printCOFFUnwindInfo(const COFFObjectFile *Obj) {
}
}
-void printCOFFFileHeader(const object::ObjectFile *Obj) {
+void objdump::printCOFFFileHeader(const object::ObjectFile *Obj) {
const COFFObjectFile *file = dyn_cast<const COFFObjectFile>(Obj);
printTLSDirectory(file);
printLoadConfiguration(file);
@@ -633,7 +634,7 @@ void printCOFFFileHeader(const object::ObjectFile *Obj) {
printExportTable(file);
}
-void printCOFFSymbolTable(const object::COFFImportFile *i) {
+void objdump::printCOFFSymbolTable(const object::COFFImportFile *i) {
unsigned Index = 0;
bool IsCode = i->getCOFFImportHeader()->getType() == COFF::IMPORT_CODE;
@@ -656,15 +657,16 @@ void printCOFFSymbolTable(const object::COFFImportFile *i) {
}
}
-void printCOFFSymbolTable(const COFFObjectFile *coff) {
+void objdump::printCOFFSymbolTable(const COFFObjectFile *coff) {
for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
Expected<COFFSymbolRef> Symbol = coff->getSymbol(SI);
if (!Symbol)
reportError(Symbol.takeError(), coff->getFileName());
- StringRef Name;
- if (std::error_code EC = coff->getSymbolName(*Symbol, Name))
- reportError(errorCodeToError(EC), coff->getFileName());
+ Expected<StringRef> NameOrErr = coff->getSymbolName(*Symbol);
+ if (!NameOrErr)
+ reportError(NameOrErr.takeError(), coff->getFileName());
+ StringRef Name = *NameOrErr;
outs() << "[" << format("%2d", SI) << "]"
<< "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")"
@@ -676,11 +678,9 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
<< "0x" << format("%08x", unsigned(Symbol->getValue())) << " "
<< Name;
if (Demangle && Name.startswith("?")) {
- char *DemangledSymbol = nullptr;
- size_t Size = 0;
int Status = -1;
- DemangledSymbol =
- microsoftDemangle(Name.data(), DemangledSymbol, &Size, &Status);
+ char *DemangledSymbol =
+ microsoftDemangle(Name.data(), nullptr, nullptr, nullptr, &Status);
if (Status == 0 && DemangledSymbol) {
outs() << " (" << StringRef(DemangledSymbol) << ")";
@@ -694,9 +694,9 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) {
if (Symbol->isSectionDefinition()) {
const coff_aux_section_definition *asd;
- if (std::error_code EC =
+ if (Error E =
coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd))
- reportError(errorCodeToError(EC), coff->getFileName());
+ reportError(std::move(E), coff->getFileName());
int32_t AuxNumber = asd->getNumber(Symbol->isBigObj());
@@ -711,8 +711,8 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
, unsigned(asd->Selection));
} else if (Symbol->isFileRecord()) {
const char *FileName;
- if (std::error_code EC = coff->getAuxSymbol<char>(SI + 1, FileName))
- reportError(errorCodeToError(EC), coff->getFileName());
+ if (Error E = coff->getAuxSymbol<char>(SI + 1, FileName))
+ reportError(std::move(E), coff->getFileName());
StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() *
coff->getSymbolTableEntrySize());
@@ -722,9 +722,8 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
break;
} else if (Symbol->isWeakExternal()) {
const coff_aux_weak_external *awe;
- if (std::error_code EC =
- coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe))
- reportError(errorCodeToError(EC), coff->getFileName());
+ if (Error E = coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe))
+ reportError(std::move(E), coff->getFileName());
outs() << "AUX " << format("indx %d srch %d\n",
static_cast<uint32_t>(awe->TagIndex),
@@ -735,4 +734,3 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
}
}
}
-} // namespace llvm