aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-objdump/COFFDump.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/llvm-objdump/COFFDump.cpp')
-rw-r--r--tools/llvm-objdump/COFFDump.cpp77
1 files changed, 47 insertions, 30 deletions
diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp
index 1ba0a68902c9..60b0f5a3cbd1 100644
--- a/tools/llvm-objdump/COFFDump.cpp
+++ b/tools/llvm-objdump/COFFDump.cpp
@@ -234,15 +234,14 @@ printSEHTable(const COFFObjectFile *Obj, uint32_t TableVA, int Count) {
if (Count == 0)
return;
- const pe32_header *PE32Header;
- error(Obj->getPE32Header(PE32Header));
- uint32_t ImageBase = PE32Header->ImageBase;
uintptr_t IntPtr = 0;
- error(Obj->getVaPtr(TableVA, IntPtr));
+ if (std::error_code EC = Obj->getVaPtr(TableVA, IntPtr))
+ reportError(errorCodeToError(EC), Obj->getFileName());
+
const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr;
outs() << "SEH Table:";
for (int I = 0; I < Count; ++I)
- outs() << format(" 0x%x", P[I] + ImageBase);
+ outs() << format(" 0x%x", P[I] + Obj->getPE32Header()->ImageBase);
outs() << "\n\n";
}
@@ -268,22 +267,24 @@ static void printTLSDirectoryT(const coff_tls_directory<T> *TLSDir) {
}
static void printTLSDirectory(const COFFObjectFile *Obj) {
- const pe32_header *PE32Header;
- error(Obj->getPE32Header(PE32Header));
-
- const pe32plus_header *PE32PlusHeader;
- error(Obj->getPE32PlusHeader(PE32PlusHeader));
+ const pe32_header *PE32Header = Obj->getPE32Header();
+ const pe32plus_header *PE32PlusHeader = Obj->getPE32PlusHeader();
// Skip if it's not executable.
if (!PE32Header && !PE32PlusHeader)
return;
const data_directory *DataDir;
- error(Obj->getDataDirectory(COFF::TLS_TABLE, DataDir));
- uintptr_t IntPtr = 0;
+ if (std::error_code EC = Obj->getDataDirectory(COFF::TLS_TABLE, DataDir))
+ reportError(errorCodeToError(EC), Obj->getFileName());
+
if (DataDir->RelativeVirtualAddress == 0)
return;
- error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr));
+
+ uintptr_t IntPtr = 0;
+ if (std::error_code EC =
+ Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
+ reportError(errorCodeToError(EC), Obj->getFileName());
if (PE32Header) {
auto *TLSDir = reinterpret_cast<const coff_tls_directory32 *>(IntPtr);
@@ -298,9 +299,7 @@ static void printTLSDirectory(const COFFObjectFile *Obj) {
static void printLoadConfiguration(const COFFObjectFile *Obj) {
// Skip if it's not executable.
- const pe32_header *PE32Header;
- error(Obj->getPE32Header(PE32Header));
- if (!PE32Header)
+ if (!Obj->getPE32Header())
return;
// Currently only x86 is supported
@@ -308,11 +307,18 @@ static void printLoadConfiguration(const COFFObjectFile *Obj) {
return;
const data_directory *DataDir;
- error(Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir));
+
+ if (std::error_code EC =
+ Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir))
+ reportError(errorCodeToError(EC), Obj->getFileName());
+
uintptr_t IntPtr = 0;
if (DataDir->RelativeVirtualAddress == 0)
return;
- error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr));
+
+ if (std::error_code EC =
+ Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
+ reportError(errorCodeToError(EC), Obj->getFileName());
auto *LoadConf = reinterpret_cast<const coff_load_configuration32 *>(IntPtr);
outs() << "Load configuration:"
@@ -442,8 +448,7 @@ static bool getPDataSection(const COFFObjectFile *Obj,
std::vector<RelocationRef> &Rels,
const RuntimeFunction *&RFStart, int &NumRFs) {
for (const SectionRef &Section : Obj->sections()) {
- StringRef Name;
- error(Section.getName(Name));
+ StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
if (Name != ".pdata")
continue;
@@ -455,7 +460,9 @@ static bool getPDataSection(const COFFObjectFile *Obj,
llvm::sort(Rels, isRelocAddressLess);
ArrayRef<uint8_t> Contents;
- error(Obj->getSectionContents(Pdata, Contents));
+ if (Error E = Obj->getSectionContents(Pdata, Contents))
+ reportError(std::move(E), Obj->getFileName());
+
if (Contents.empty())
continue;
@@ -571,10 +578,12 @@ static void printRuntimeFunctionRels(const COFFObjectFile *Obj,
ArrayRef<uint8_t> XContents;
uint64_t UnwindInfoOffset = 0;
- error(getSectionContents(
- Obj, Rels, SectionOffset +
- /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
- XContents, UnwindInfoOffset));
+ if (Error E = getSectionContents(
+ Obj, Rels,
+ SectionOffset +
+ /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
+ XContents, UnwindInfoOffset))
+ reportError(std::move(E), Obj->getFileName());
if (XContents.empty())
return;
@@ -650,9 +659,12 @@ void printCOFFSymbolTable(const object::COFFImportFile *i) {
void 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;
- error(Symbol.takeError());
- error(coff->getSymbolName(*Symbol, Name));
+ if (std::error_code EC = coff->getSymbolName(*Symbol, Name))
+ reportError(errorCodeToError(EC), coff->getFileName());
outs() << "[" << format("%2d", SI) << "]"
<< "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")"
@@ -682,7 +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;
- error(coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd));
+ if (std::error_code EC =
+ coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd))
+ reportError(errorCodeToError(EC), coff->getFileName());
int32_t AuxNumber = asd->getNumber(Symbol->isBigObj());
@@ -697,7 +711,8 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
, unsigned(asd->Selection));
} else if (Symbol->isFileRecord()) {
const char *FileName;
- error(coff->getAuxSymbol<char>(SI + 1, FileName));
+ if (std::error_code EC = coff->getAuxSymbol<char>(SI + 1, FileName))
+ reportError(errorCodeToError(EC), coff->getFileName());
StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() *
coff->getSymbolTableEntrySize());
@@ -707,7 +722,9 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
break;
} else if (Symbol->isWeakExternal()) {
const coff_aux_weak_external *awe;
- error(coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe));
+ if (std::error_code EC =
+ coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe))
+ reportError(errorCodeToError(EC), coff->getFileName());
outs() << "AUX " << format("indx %d srch %d\n",
static_cast<uint32_t>(awe->TagIndex),