1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

Don't return error_code from a function that doesn't fail.

llvm-svn: 241033
This commit is contained in:
Rafael Espindola 2015-06-30 01:53:01 +00:00
parent a3e07eb2de
commit 6f9850f8a9
13 changed files with 26 additions and 49 deletions

View File

@ -678,8 +678,7 @@ protected:
uint64_t &Res) const override; uint64_t &Res) const override;
uint64_t getRelocationOffset(DataRefImpl Rel) const override; uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override; symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
std::error_code getRelocationType(DataRefImpl Rel, uint64_t getRelocationType(DataRefImpl Rel) const override;
uint64_t &Res) const override;
std::error_code std::error_code
getRelocationTypeName(DataRefImpl Rel, getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const override; SmallVectorImpl<char> &Result) const override;

View File

@ -233,8 +233,7 @@ protected:
uint64_t &Res) const override; uint64_t &Res) const override;
uint64_t getRelocationOffset(DataRefImpl Rel) const override; uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override; symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
std::error_code getRelocationType(DataRefImpl Rel, uint64_t getRelocationType(DataRefImpl Rel) const override;
uint64_t &Res) const override;
std::error_code std::error_code
getRelocationTypeName(DataRefImpl Rel, getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const override; SmallVectorImpl<char> &Result) const override;
@ -725,14 +724,12 @@ uint64_t ELFObjectFile<ELFT>::getROffset(DataRefImpl Rel) const {
} }
template <class ELFT> template <class ELFT>
std::error_code ELFObjectFile<ELFT>::getRelocationType(DataRefImpl Rel, uint64_t ELFObjectFile<ELFT>::getRelocationType(DataRefImpl Rel) const {
uint64_t &Result) const {
const Elf_Shdr *sec = getRelSection(Rel); const Elf_Shdr *sec = getRelSection(Rel);
if (sec->sh_type == ELF::SHT_REL) if (sec->sh_type == ELF::SHT_REL)
Result = getRel(Rel)->getType(EF.isMips64EL()); return getRel(Rel)->getType(EF.isMips64EL());
else else
Result = getRela(Rel)->getType(EF.isMips64EL()); return getRela(Rel)->getType(EF.isMips64EL());
return std::error_code();
} }
template <class ELFT> template <class ELFT>

View File

@ -240,8 +240,7 @@ public:
uint64_t getRelocationOffset(DataRefImpl Rel) const override; uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override; symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
section_iterator getRelocationSection(DataRefImpl Rel) const; section_iterator getRelocationSection(DataRefImpl Rel) const;
std::error_code getRelocationType(DataRefImpl Rel, uint64_t getRelocationType(DataRefImpl Rel) const override;
uint64_t &Res) const override;
std::error_code std::error_code
getRelocationTypeName(DataRefImpl Rel, getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const override; SmallVectorImpl<char> &Result) const override;

View File

@ -53,7 +53,7 @@ public:
std::error_code getAddress(uint64_t &Result) const; std::error_code getAddress(uint64_t &Result) const;
uint64_t getOffset() const; uint64_t getOffset() const;
symbol_iterator getSymbol() const; symbol_iterator getSymbol() const;
std::error_code getType(uint64_t &Result) const; uint64_t getType() const;
/// @brief Indicates whether this relocation should hidden when listing /// @brief Indicates whether this relocation should hidden when listing
/// relocations, usually because it is the trailing part of a multipart /// relocations, usually because it is the trailing part of a multipart
@ -242,8 +242,7 @@ protected:
uint64_t &Res) const = 0; uint64_t &Res) const = 0;
virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0; virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0; virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
virtual std::error_code getRelocationType(DataRefImpl Rel, virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
uint64_t &Res) const = 0;
virtual std::error_code virtual std::error_code
getRelocationTypeName(DataRefImpl Rel, getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const = 0; SmallVectorImpl<char> &Result) const = 0;
@ -464,8 +463,8 @@ inline symbol_iterator RelocationRef::getSymbol() const {
return OwningObject->getRelocationSymbol(RelocationPimpl); return OwningObject->getRelocationSymbol(RelocationPimpl);
} }
inline std::error_code RelocationRef::getType(uint64_t &Result) const { inline uint64_t RelocationRef::getType() const {
return OwningObject->getRelocationType(RelocationPimpl, Result); return OwningObject->getRelocationType(RelocationPimpl);
} }
inline std::error_code inline std::error_code

View File

@ -668,8 +668,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
uint64_t SectionSize = RelocatedSection->getSize(); uint64_t SectionSize = RelocatedSection->getSize();
for (const RelocationRef &Reloc : Section.relocations()) { for (const RelocationRef &Reloc : Section.relocations()) {
uint64_t Address = Reloc.getOffset(); uint64_t Address = Reloc.getOffset();
uint64_t Type; uint64_t Type = Reloc.getType();
Reloc.getType(Type);
uint64_t SymAddr = 0; uint64_t SymAddr = 0;
uint64_t SectionLoadAddress = 0; uint64_t SectionLoadAddress = 0;
object::symbol_iterator Sym = Reloc.getSymbol(); object::symbol_iterator Sym = Reloc.getSymbol();

View File

@ -772,8 +772,7 @@ void RuntimeDyldELF::findOPDEntrySection(const ELFObjectFileBase &Obj,
i != e;) { i != e;) {
// The R_PPC64_ADDR64 relocation indicates the first field // The R_PPC64_ADDR64 relocation indicates the first field
// of a .opd entry // of a .opd entry
uint64_t TypeFunc; uint64_t TypeFunc = i->getType();
check(i->getType(TypeFunc));
if (TypeFunc != ELF::R_PPC64_ADDR64) { if (TypeFunc != ELF::R_PPC64_ADDR64) {
++i; ++i;
continue; continue;
@ -790,8 +789,7 @@ void RuntimeDyldELF::findOPDEntrySection(const ELFObjectFileBase &Obj,
break; break;
// Just check if following relocation is a R_PPC64_TOC // Just check if following relocation is a R_PPC64_TOC
uint64_t TypeTOC; uint64_t TypeTOC = i->getType();
check(i->getType(TypeTOC));
if (TypeTOC != ELF::R_PPC64_TOC) if (TypeTOC != ELF::R_PPC64_TOC)
continue; continue;
@ -1059,8 +1057,7 @@ relocation_iterator RuntimeDyldELF::processRelocationRef(
unsigned SectionID, relocation_iterator RelI, const ObjectFile &O, unsigned SectionID, relocation_iterator RelI, const ObjectFile &O,
ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) { ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) {
const auto &Obj = cast<ELFObjectFileBase>(O); const auto &Obj = cast<ELFObjectFileBase>(O);
uint64_t RelType; uint64_t RelType = RelI->getType();
Check(RelI->getType(RelType));
ErrorOr<int64_t> AddendOrErr = ELFRelocationRef(*RelI).getAddend(); ErrorOr<int64_t> AddendOrErr = ELFRelocationRef(*RelI).getAddend();
int64_t Addend = AddendOrErr ? *AddendOrErr : 0; int64_t Addend = AddendOrErr ? *AddendOrErr : 0;
elf_symbol_iterator Symbol = RelI->getSymbol(); elf_symbol_iterator Symbol = RelI->getSymbol();

View File

@ -125,8 +125,7 @@ public:
const bool IsExtern = SecI == Obj.section_end(); const bool IsExtern = SecI == Obj.section_end();
// Determine the Addend used to adjust the relocation value. // Determine the Addend used to adjust the relocation value.
uint64_t RelType; uint64_t RelType = RelI->getType();
Check(RelI->getType(RelType));
uint64_t Offset = RelI->getOffset(); uint64_t Offset = RelI->getOffset();
uint64_t Addend = 0; uint64_t Addend = 0;
SectionEntry &Section = Sections[SectionID]; SectionEntry &Section = Sections[SectionID];

View File

@ -990,11 +990,9 @@ symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const {
return symbol_iterator(SymbolRef(Ref, this)); return symbol_iterator(SymbolRef(Ref, this));
} }
std::error_code COFFObjectFile::getRelocationType(DataRefImpl Rel, uint64_t COFFObjectFile::getRelocationType(DataRefImpl Rel) const {
uint64_t &Res) const {
const coff_relocation* R = toRel(Rel); const coff_relocation* R = toRel(Rel);
Res = R->Type; return R->Type;
return std::error_code();
} }
const coff_section * const coff_section *

View File

@ -654,19 +654,16 @@ MachOObjectFile::getRelocationSection(DataRefImpl Rel) const {
return section_iterator(getAnyRelocationSection(getRelocation(Rel))); return section_iterator(getAnyRelocationSection(getRelocation(Rel)));
} }
std::error_code MachOObjectFile::getRelocationType(DataRefImpl Rel, uint64_t MachOObjectFile::getRelocationType(DataRefImpl Rel) const {
uint64_t &Res) const {
MachO::any_relocation_info RE = getRelocation(Rel); MachO::any_relocation_info RE = getRelocation(Rel);
Res = getAnyRelocationType(RE); return getAnyRelocationType(RE);
return std::error_code();
} }
std::error_code std::error_code
MachOObjectFile::getRelocationTypeName(DataRefImpl Rel, MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const { SmallVectorImpl<char> &Result) const {
StringRef res; StringRef res;
uint64_t RType; uint64_t RType = getRelocationType(Rel);
getRelocationType(Rel, RType);
unsigned Arch = this->getArch(); unsigned Arch = this->getArch();
@ -776,8 +773,7 @@ MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
std::error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel, std::error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel,
bool &Result) const { bool &Result) const {
unsigned Arch = getArch(); unsigned Arch = getArch();
uint64_t Type; uint64_t Type = getRelocationType(Rel);
getRelocationType(Rel, Type);
Result = false; Result = false;
@ -791,8 +787,7 @@ std::error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel,
if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) { if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
DataRefImpl RelPrev = Rel; DataRefImpl RelPrev = Rel;
RelPrev.d.a--; RelPrev.d.a--;
uint64_t PrevType; uint64_t PrevType = getRelocationType(RelPrev);
getRelocationType(RelPrev, PrevType);
if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR) if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR)
Result = true; Result = true;
} }

View File

@ -208,10 +208,7 @@ LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) {
} }
uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) { uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) {
uint64_t ret; return (*unwrap(RI))->getType();
if (std::error_code ec = (*unwrap(RI))->getType(ret))
report_fatal_error(ec.message());
return ret;
} }
// NOTE: Caller takes ownership of returned string. // NOTE: Caller takes ownership of returned string.

View File

@ -26,7 +26,7 @@ public:
X86_64ELFRelocationInfo(MCContext &Ctx) : MCRelocationInfo(Ctx) {} X86_64ELFRelocationInfo(MCContext &Ctx) : MCRelocationInfo(Ctx) {}
const MCExpr *createExprForRelocation(RelocationRef Rel) override { const MCExpr *createExprForRelocation(RelocationRef Rel) override {
uint64_t RelType; Rel.getType(RelType); uint64_t RelType = Rel.getType();
elf_symbol_iterator SymI = Rel.getSymbol(); elf_symbol_iterator SymI = Rel.getSymbol();
StringRef SymName; SymI->getName(SymName); StringRef SymName; SymI->getName(SymName);

View File

@ -27,7 +27,7 @@ public:
const MCExpr *createExprForRelocation(RelocationRef Rel) override { const MCExpr *createExprForRelocation(RelocationRef Rel) override {
const MachOObjectFile *Obj = cast<MachOObjectFile>(Rel.getObject()); const MachOObjectFile *Obj = cast<MachOObjectFile>(Rel.getObject());
uint64_t RelType; Rel.getType(RelType); uint64_t RelType = Rel.getType();
symbol_iterator SymI = Rel.getSymbol(); symbol_iterator SymI = Rel.getSymbol();
StringRef SymName; SymI->getName(SymName); StringRef SymName; SymI->getName(SymName);

View File

@ -804,11 +804,9 @@ void COFFDumper::printRelocations() {
void COFFDumper::printRelocation(const SectionRef &Section, void COFFDumper::printRelocation(const SectionRef &Section,
const RelocationRef &Reloc) { const RelocationRef &Reloc) {
uint64_t Offset = Reloc.getOffset(); uint64_t Offset = Reloc.getOffset();
uint64_t RelocType; uint64_t RelocType = Reloc.getType();
SmallString<32> RelocName; SmallString<32> RelocName;
StringRef SymbolName; StringRef SymbolName;
if (error(Reloc.getType(RelocType)))
return;
if (error(Reloc.getTypeName(RelocName))) if (error(Reloc.getTypeName(RelocName)))
return; return;
symbol_iterator Symbol = Reloc.getSymbol(); symbol_iterator Symbol = Reloc.getSymbol();