mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[llvm-objdump] Migrate relocation handling functions from error_code to Error
llvm-svn: 357920
This commit is contained in:
parent
c08b465d91
commit
3762556375
@ -468,17 +468,16 @@ static bool getPDataSection(const COFFObjectFile *Obj,
|
||||
return false;
|
||||
}
|
||||
|
||||
std::error_code
|
||||
llvm::getCOFFRelocationValueString(const COFFObjectFile *Obj,
|
||||
const RelocationRef &Rel,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
Error llvm::getCOFFRelocationValueString(const COFFObjectFile *Obj,
|
||||
const RelocationRef &Rel,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
symbol_iterator SymI = Rel.getSymbol();
|
||||
Expected<StringRef> SymNameOrErr = SymI->getName();
|
||||
if (!SymNameOrErr)
|
||||
return errorToErrorCode(SymNameOrErr.takeError());
|
||||
return SymNameOrErr.takeError();
|
||||
StringRef SymName = *SymNameOrErr;
|
||||
Result.append(SymName.begin(), SymName.end());
|
||||
return std::error_code();
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
static void printWin64EHUnwindInfo(const Win64EH::UnwindInfo *UI) {
|
||||
|
@ -50,14 +50,14 @@ Expected<StringRef> getDynamicStrTab(const ELFFile<ELFT> *Elf) {
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
||||
const RelocationRef &RelRef,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
static Error getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
||||
const RelocationRef &RelRef,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
const ELFFile<ELFT> &EF = *Obj->getELFFile();
|
||||
DataRefImpl Rel = RelRef.getRawDataRefImpl();
|
||||
auto SecOrErr = EF.getSection(Rel.d.a);
|
||||
if (!SecOrErr)
|
||||
return errorToErrorCode(SecOrErr.takeError());
|
||||
return SecOrErr.takeError();
|
||||
|
||||
int64_t Addend = 0;
|
||||
// If there is no Symbol associated with the relocation, we set the undef
|
||||
@ -72,7 +72,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
||||
Addend = ERela->r_addend;
|
||||
Undef = ERela->getSymbol(false) == 0;
|
||||
} else if ((*SecOrErr)->sh_type != ELF::SHT_REL) {
|
||||
return object_error::parse_failed;
|
||||
return make_error<BinaryError>();
|
||||
}
|
||||
|
||||
// Default scheme is to print Target, as well as "+ <addend>" for nonzero
|
||||
@ -86,17 +86,17 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
||||
if (Sym->getType() == ELF::STT_SECTION) {
|
||||
Expected<section_iterator> SymSI = SI->getSection();
|
||||
if (!SymSI)
|
||||
return errorToErrorCode(SymSI.takeError());
|
||||
return SymSI.takeError();
|
||||
const typename ELFT::Shdr *SymSec =
|
||||
Obj->getSection((*SymSI)->getRawDataRefImpl());
|
||||
auto SecName = EF.getSectionName(SymSec);
|
||||
if (!SecName)
|
||||
return errorToErrorCode(SecName.takeError());
|
||||
return SecName.takeError();
|
||||
Fmt << *SecName;
|
||||
} else {
|
||||
Expected<StringRef> SymName = SI->getName();
|
||||
if (!SymName)
|
||||
return errorToErrorCode(SymName.takeError());
|
||||
return SymName.takeError();
|
||||
if (Demangle)
|
||||
Fmt << demangle(*SymName);
|
||||
else
|
||||
@ -110,13 +110,12 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
||||
Fmt << (Addend < 0 ? "" : "+") << Addend;
|
||||
Fmt.flush();
|
||||
Result.append(FmtBuf.begin(), FmtBuf.end());
|
||||
return std::error_code();
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
std::error_code
|
||||
llvm::getELFRelocationValueString(const ELFObjectFileBase *Obj,
|
||||
const RelocationRef &Rel,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
Error llvm::getELFRelocationValueString(const ELFObjectFileBase *Obj,
|
||||
const RelocationRef &Rel,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
if (auto *ELF32LE = dyn_cast<ELF32LEObjectFile>(Obj))
|
||||
return getRelocationValueString(ELF32LE, Rel, Result);
|
||||
if (auto *ELF64LE = dyn_cast<ELF64LEObjectFile>(Obj))
|
||||
|
@ -412,10 +412,9 @@ static void printRelocationTargetName(const MachOObjectFile *O,
|
||||
Fmt << S;
|
||||
}
|
||||
|
||||
std::error_code
|
||||
llvm::getMachORelocationValueString(const MachOObjectFile *Obj,
|
||||
const RelocationRef &RelRef,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
Error llvm::getMachORelocationValueString(const MachOObjectFile *Obj,
|
||||
const RelocationRef &RelRef,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
DataRefImpl Rel = RelRef.getRawDataRefImpl();
|
||||
MachO::any_relocation_info RE = Obj->getRelocation(Rel);
|
||||
|
||||
@ -488,7 +487,7 @@ llvm::getMachORelocationValueString(const MachOObjectFile *Obj,
|
||||
// Generic relocation types...
|
||||
switch (Type) {
|
||||
case MachO::GENERIC_RELOC_PAIR: // prints no info
|
||||
return std::error_code();
|
||||
return Error::success();
|
||||
case MachO::GENERIC_RELOC_SECTDIFF: {
|
||||
DataRefImpl RelNext = Rel;
|
||||
Obj->moveRelocationNext(RelNext);
|
||||
@ -588,7 +587,7 @@ llvm::getMachORelocationValueString(const MachOObjectFile *Obj,
|
||||
|
||||
Fmt.flush();
|
||||
Result.append(FmtBuf.begin(), FmtBuf.end());
|
||||
return std::error_code();
|
||||
return Error::success();
|
||||
}
|
||||
|
||||
static void PrintIndirectSymbolTable(MachOObjectFile *O, bool verbose,
|
||||
|
@ -26,10 +26,9 @@ void llvm::printWasmFileHeader(const object::ObjectFile *Obj) {
|
||||
outs() << "\n";
|
||||
}
|
||||
|
||||
std::error_code
|
||||
llvm::getWasmRelocationValueString(const WasmObjectFile *Obj,
|
||||
const RelocationRef &RelRef,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
Error llvm::getWasmRelocationValueString(const WasmObjectFile *Obj,
|
||||
const RelocationRef &RelRef,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
const wasm::WasmRelocation &Rel = Obj->getWasmRelocation(RelRef);
|
||||
symbol_iterator SI = RelRef.getSymbol();
|
||||
std::string FmtBuf;
|
||||
@ -41,12 +40,12 @@ llvm::getWasmRelocationValueString(const WasmObjectFile *Obj,
|
||||
} else {
|
||||
Expected<StringRef> SymNameOrErr = SI->getName();
|
||||
if (!SymNameOrErr)
|
||||
return errorToErrorCode(SymNameOrErr.takeError());
|
||||
return SymNameOrErr.takeError();
|
||||
StringRef SymName = *SymNameOrErr;
|
||||
Result.append(SymName.begin(), SymName.end());
|
||||
}
|
||||
Fmt << (Rel.Addend < 0 ? "" : "+") << Rel.Addend;
|
||||
Fmt.flush();
|
||||
Result.append(FmtBuf.begin(), FmtBuf.end());
|
||||
return std::error_code();
|
||||
return Error::success();
|
||||
}
|
||||
|
@ -330,6 +330,13 @@ void llvm::error(std::error_code EC) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void llvm::error(Error E) {
|
||||
if (!E)
|
||||
return;
|
||||
WithColor::error(errs(), ToolName) << toString(std::move(E));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
LLVM_ATTRIBUTE_NORETURN void llvm::error(Twine Message) {
|
||||
WithColor::error(errs(), ToolName) << Message << ".\n";
|
||||
errs().flush();
|
||||
@ -437,8 +444,8 @@ bool llvm::isRelocAddressLess(RelocationRef A, RelocationRef B) {
|
||||
return A.getOffset() < B.getOffset();
|
||||
}
|
||||
|
||||
static std::error_code getRelocationValueString(const RelocationRef &Rel,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
static Error getRelocationValueString(const RelocationRef &Rel,
|
||||
SmallVectorImpl<char> &Result) {
|
||||
const ObjectFile *Obj = Rel.getObject();
|
||||
if (auto *ELF = dyn_cast<ELFObjectFileBase>(Obj))
|
||||
return getELFRelocationValueString(ELF, Rel, Result);
|
||||
@ -1554,7 +1561,6 @@ void llvm::printSectionHeaders(const ObjectFile *Obj) {
|
||||
}
|
||||
|
||||
void llvm::printSectionContents(const ObjectFile *Obj) {
|
||||
std::error_code EC;
|
||||
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
|
||||
StringRef Name;
|
||||
StringRef Contents;
|
||||
|
@ -121,26 +121,23 @@ private:
|
||||
// Various helper functions.
|
||||
SectionFilter ToolSectionFilter(llvm::object::ObjectFile const &O);
|
||||
|
||||
std::error_code
|
||||
getELFRelocationValueString(const object::ELFObjectFileBase *Obj,
|
||||
const object::RelocationRef &Rel,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
std::error_code
|
||||
getCOFFRelocationValueString(const object::COFFObjectFile *Obj,
|
||||
const object::RelocationRef &Rel,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
std::error_code
|
||||
getWasmRelocationValueString(const object::WasmObjectFile *Obj,
|
||||
const object::RelocationRef &RelRef,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
std::error_code
|
||||
getMachORelocationValueString(const object::MachOObjectFile *Obj,
|
||||
const object::RelocationRef &RelRef,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
Error getELFRelocationValueString(const object::ELFObjectFileBase *Obj,
|
||||
const object::RelocationRef &Rel,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
Error getCOFFRelocationValueString(const object::COFFObjectFile *Obj,
|
||||
const object::RelocationRef &Rel,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
Error getWasmRelocationValueString(const object::WasmObjectFile *Obj,
|
||||
const object::RelocationRef &RelRef,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
Error getMachORelocationValueString(const object::MachOObjectFile *Obj,
|
||||
const object::RelocationRef &RelRef,
|
||||
llvm::SmallVectorImpl<char> &Result);
|
||||
|
||||
uint64_t getELFSectionLMA(const object::ELFSectionRef& Sec);
|
||||
|
||||
void error(std::error_code ec);
|
||||
void error(Error E);
|
||||
bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
|
||||
void parseInputMachO(StringRef Filename);
|
||||
void parseInputMachO(object::MachOUniversalBinary *UB);
|
||||
|
Loading…
x
Reference in New Issue
Block a user