Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
Don't return error_code from function that never fails.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241021 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Jun 29, 2015
1 parent d5c6d50 commit 3adaf02
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 106 deletions.
3 changes: 1 addition & 2 deletions include/llvm/Object/COFF.h
Expand Up @@ -661,8 +661,7 @@ class COFFObjectFile : public ObjectFile {
void moveRelocationNext(DataRefImpl &Rel) const override;
std::error_code getRelocationAddress(DataRefImpl Rel,
uint64_t &Res) const override;
std::error_code getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const override;
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
std::error_code getRelocationType(DataRefImpl Rel,
uint64_t &Res) const override;
Expand Down
10 changes: 3 additions & 7 deletions include/llvm/Object/ELFObjectFile.h
Expand Up @@ -201,8 +201,7 @@ template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
void moveRelocationNext(DataRefImpl &Rel) const override;
std::error_code getRelocationAddress(DataRefImpl Rel,
uint64_t &Res) const override;
std::error_code getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const override;
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
std::error_code getRelocationType(DataRefImpl Rel,
uint64_t &Res) const override;
Expand Down Expand Up @@ -689,13 +688,10 @@ ELFObjectFile<ELFT>::getRelocationAddress(DataRefImpl Rel,
}

template <class ELFT>
std::error_code
ELFObjectFile<ELFT>::getRelocationOffset(DataRefImpl Rel,
uint64_t &Result) const {
uint64_t ELFObjectFile<ELFT>::getRelocationOffset(DataRefImpl Rel) const {
assert(EF.getHeader()->e_type == ELF::ET_REL &&
"Only relocatable object files have relocation offsets");
Result = getROffset(Rel);
return std::error_code();
return getROffset(Rel);
}

template <class ELFT>
Expand Down
3 changes: 1 addition & 2 deletions include/llvm/Object/MachO.h
Expand Up @@ -237,8 +237,7 @@ class MachOObjectFile : public ObjectFile {
void moveRelocationNext(DataRefImpl &Rel) const override;
std::error_code getRelocationAddress(DataRefImpl Rel,
uint64_t &Res) const override;
std::error_code getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const override;
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
section_iterator getRelocationSection(DataRefImpl Rel) const;
std::error_code getRelocationType(DataRefImpl Rel,
Expand Down
9 changes: 4 additions & 5 deletions include/llvm/Object/ObjectFile.h
Expand Up @@ -51,7 +51,7 @@ class RelocationRef {
void moveNext();

std::error_code getAddress(uint64_t &Result) const;
std::error_code getOffset(uint64_t &Result) const;
uint64_t getOffset() const;
symbol_iterator getSymbol() const;
std::error_code getType(uint64_t &Result) const;

Expand Down Expand Up @@ -240,8 +240,7 @@ class ObjectFile : public SymbolicFile {
virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
virtual std::error_code getRelocationAddress(DataRefImpl Rel,
uint64_t &Res) const = 0;
virtual std::error_code getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const = 0;
virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
virtual std::error_code getRelocationType(DataRefImpl Rel,
uint64_t &Res) const = 0;
Expand Down Expand Up @@ -457,8 +456,8 @@ inline std::error_code RelocationRef::getAddress(uint64_t &Result) const {
return OwningObject->getRelocationAddress(RelocationPimpl, Result);
}

inline std::error_code RelocationRef::getOffset(uint64_t &Result) const {
return OwningObject->getRelocationOffset(RelocationPimpl, Result);
inline uint64_t RelocationRef::getOffset() const {
return OwningObject->getRelocationOffset(RelocationPimpl);
}

inline symbol_iterator RelocationRef::getSymbol() const {
Expand Down
6 changes: 2 additions & 4 deletions include/llvm/Object/RelocVisitor.h
Expand Up @@ -267,8 +267,7 @@ class RelocVisitor {
}

RelocToApply visitELF_386_PC32(RelocationRef R, uint64_t Value) {
uint64_t Address;
R.getOffset(Address);
uint64_t Address = R.getOffset();
return RelocToApply(Value - Address, 4);
}

Expand All @@ -282,8 +281,7 @@ class RelocVisitor {
}
RelocToApply visitELF_X86_64_PC32(RelocationRef R, uint64_t Value) {
int64_t Addend = getELFAddend(R);
uint64_t Address;
R.getOffset(Address);
uint64_t Address = R.getOffset();
return RelocToApply(Value + Addend - Address, 4);
}
RelocToApply visitELF_X86_64_32(RelocationRef R, uint64_t Value) {
Expand Down
3 changes: 1 addition & 2 deletions lib/DebugInfo/DWARF/DWARFContext.cpp
Expand Up @@ -667,8 +667,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
if (Section.relocation_begin() != Section.relocation_end()) {
uint64_t SectionSize = RelocatedSection->getSize();
for (const RelocationRef &Reloc : Section.relocations()) {
uint64_t Address;
Reloc.getOffset(Address);
uint64_t Address = Reloc.getOffset();
uint64_t Type;
Reloc.getType(Type);
uint64_t SymAddr = 0;
Expand Down
6 changes: 2 additions & 4 deletions lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
Expand Up @@ -779,9 +779,8 @@ void RuntimeDyldELF::findOPDEntrySection(const ELFObjectFileBase &Obj,
continue;
}

uint64_t TargetSymbolOffset;
uint64_t TargetSymbolOffset = i->getOffset();
symbol_iterator TargetSymbol = i->getSymbol();
check(i->getOffset(TargetSymbolOffset));
ErrorOr<int64_t> AddendOrErr =
Obj.getRelocationAddend(i->getRawDataRefImpl());
Check(AddendOrErr.getError());
Expand Down Expand Up @@ -1124,8 +1123,7 @@ relocation_iterator RuntimeDyldELF::processRelocationRef(
}
}

uint64_t Offset;
Check(RelI->getOffset(Offset));
uint64_t Offset = RelI->getOffset();

DEBUG(dbgs() << "\t\tSectionID: " << SectionID << " Offset: " << Offset
<< "\n");
Expand Down
3 changes: 1 addition & 2 deletions lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h
Expand Up @@ -72,8 +72,7 @@ class RuntimeDyldMachO : public RuntimeDyldImpl {

bool IsPCRel = Obj.getAnyRelocationPCRel(RelInfo);
unsigned Size = Obj.getAnyRelocationLength(RelInfo);
uint64_t Offset;
RI->getOffset(Offset);
uint64_t Offset = RI->getOffset();
MachO::RelocationInfoType RelType =
static_cast<MachO::RelocationInfoType>(Obj.getAnyRelocationType(RelInfo));

Expand Down
Expand Up @@ -127,8 +127,7 @@ class RuntimeDyldCOFFX86_64 : public RuntimeDyldCOFF {
// Determine the Addend used to adjust the relocation value.
uint64_t RelType;
Check(RelI->getType(RelType));
uint64_t Offset;
Check(RelI->getOffset(Offset));
uint64_t Offset = RelI->getOffset();
uint64_t Addend = 0;
SectionEntry &Section = Sections[SectionID];
uintptr_t ObjTarget = Section.ObjAddress + Offset;
Expand Down
Expand Up @@ -220,8 +220,7 @@ class RuntimeDyldMachOARM
SectionEntry &Section = Sections[SectionID];
uint32_t RelocType = MachO.getAnyRelocationType(RE);
bool IsPCRel = MachO.getAnyRelocationPCRel(RE);
uint64_t Offset;
RelI->getOffset(Offset);
uint64_t Offset = RelI->getOffset();
uint8_t *LocalAddress = Section.Address + Offset;
int64_t Immediate = readBytesUnaligned(LocalAddress, 4); // Copy the whole instruction out.
Immediate = ((Immediate >> 4) & 0xf000) | (Immediate & 0xfff);
Expand Down
Expand Up @@ -138,8 +138,7 @@ class RuntimeDyldMachOI386
uint32_t RelocType = Obj.getAnyRelocationType(RE);
bool IsPCRel = Obj.getAnyRelocationPCRel(RE);
unsigned Size = Obj.getAnyRelocationLength(RE);
uint64_t Offset;
RelI->getOffset(Offset);
uint64_t Offset = RelI->getOffset();
uint8_t *LocalAddress = Section.Address + Offset;
unsigned NumBytes = 1 << Size;
uint64_t Addend = readBytesUnaligned(LocalAddress, NumBytes);
Expand Down Expand Up @@ -197,8 +196,7 @@ class RuntimeDyldMachOI386
uint32_t RelocType = Obj.getAnyRelocationType(RE);
bool IsPCRel = Obj.getAnyRelocationPCRel(RE);
unsigned Size = Obj.getAnyRelocationLength(RE);
uint64_t Offset;
RelI->getOffset(Offset);
uint64_t Offset = RelI->getOffset();
uint8_t *LocalAddress = Section.Address + Offset;
unsigned NumBytes = 1 << Size;
int64_t Addend = readBytesUnaligned(LocalAddress, NumBytes);
Expand Down
10 changes: 2 additions & 8 deletions lib/Object/COFFObjectFile.cpp
Expand Up @@ -967,15 +967,9 @@ std::error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
report_fatal_error("getRelocationAddress not implemented in COFFObjectFile");
}

std::error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const {
uint64_t COFFObjectFile::getRelocationOffset(DataRefImpl Rel) const {
const coff_relocation *R = toRel(Rel);
const support::ulittle32_t *VirtualAddressPtr;
if (std::error_code EC =
getObject(VirtualAddressPtr, Data, &R->VirtualAddress))
return EC;
Res = *VirtualAddressPtr;
return std::error_code();
return R->VirtualAddress;
}

symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const {
Expand Down
9 changes: 3 additions & 6 deletions lib/Object/MachOObjectFile.cpp
Expand Up @@ -612,8 +612,7 @@ void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const {

std::error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
uint64_t &Res) const {
uint64_t Offset;
getRelocationOffset(Rel, Offset);
uint64_t Offset = getRelocationOffset(Rel);

DataRefImpl Sec;
Sec.d.a = Rel.d.a;
Expand All @@ -622,13 +621,11 @@ std::error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
return std::error_code();
}

std::error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel,
uint64_t &Res) const {
uint64_t MachOObjectFile::getRelocationOffset(DataRefImpl Rel) const {
assert(getHeader().filetype == MachO::MH_OBJECT &&
"Only implemented for MH_OBJECT");
MachO::any_relocation_info RE = getRelocation(Rel);
Res = getAnyRelocationAddress(RE);
return std::error_code();
return getAnyRelocationAddress(RE);
}

symbol_iterator
Expand Down
5 changes: 1 addition & 4 deletions lib/Object/Object.cpp
Expand Up @@ -199,10 +199,7 @@ uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI) {
}

uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI) {
uint64_t ret;
if (std::error_code ec = (*unwrap(RI))->getOffset(ret))
report_fatal_error(ec.message());
return ret;
return (*unwrap(RI))->getOffset();
}

LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) {
Expand Down
4 changes: 2 additions & 2 deletions tools/dsymutil/DwarfLinker.cpp
Expand Up @@ -1451,8 +1451,8 @@ void DwarfLinker::findValidRelocsMachO(const object::SectionRef &Section,
object::DataRefImpl RelocDataRef = Reloc.getRawDataRefImpl();
MachO::any_relocation_info MachOReloc = Obj.getRelocation(RelocDataRef);
unsigned RelocSize = 1 << Obj.getAnyRelocationLength(MachOReloc);
uint64_t Offset64;
if ((RelocSize != 4 && RelocSize != 8) || Reloc.getOffset(Offset64)) {
uint64_t Offset64 = Reloc.getOffset();
if ((RelocSize != 4 && RelocSize != 8)) {
reportWarning(" unsupported relocation in debug_info section.");
continue;
}
Expand Down
8 changes: 2 additions & 6 deletions tools/llvm-cxxdump/llvm-cxxdump.cpp
Expand Up @@ -100,9 +100,7 @@ static bool collectRelocatedSymbols(const ObjectFile *Obj,
StringRef RelocSymName;
if (error(RelocSymI->getName(RelocSymName)))
return true;
uint64_t Offset;
if (error(Reloc.getOffset(Offset)))
return true;
uint64_t Offset = Reloc.getOffset();
if (Offset >= SymOffset && Offset < SymEnd) {
*I = RelocSymName;
++I;
Expand All @@ -126,9 +124,7 @@ static bool collectRelocationOffsets(
StringRef RelocSymName;
if (error(RelocSymI->getName(RelocSymName)))
return true;
uint64_t Offset;
if (error(Reloc.getOffset(Offset)))
return true;
uint64_t Offset = Reloc.getOffset();
if (Offset >= SymOffset && Offset < SymEnd)
Collection[std::make_pair(SymName, Offset - SymOffset)] = RelocSymName;
}
Expand Down
4 changes: 1 addition & 3 deletions tools/llvm-objdump/COFFDump.cpp
Expand Up @@ -177,9 +177,7 @@ static std::error_code resolveSymbol(const std::vector<RelocationRef> &Rels,
for (std::vector<RelocationRef>::const_iterator I = Rels.begin(),
E = Rels.end();
I != E; ++I) {
uint64_t Ofs;
if (std::error_code EC = I->getOffset(Ofs))
return EC;
uint64_t Ofs = I->getOffset();
if (Ofs == Offset) {
Sym = *I->getSymbol();
return std::error_code();
Expand Down
27 changes: 9 additions & 18 deletions tools/llvm-objdump/MachODump.cpp
Expand Up @@ -796,8 +796,7 @@ static void DumpLiteralPointerSection(MachOObjectFile *O,
RE = O->getRelocation(Rel);
isExtern = O->getPlainRelocationExternal(RE);
if (isExtern) {
uint64_t RelocOffset;
Reloc.getOffset(RelocOffset);
uint64_t RelocOffset = Reloc.getOffset();
symbol_iterator RelocSym = Reloc.getSymbol();
Relocs.push_back(std::make_pair(RelocOffset, *RelocSym));
}
Expand Down Expand Up @@ -1763,8 +1762,7 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
bool r_scattered = false;
uint32_t r_value, pair_r_value, r_type;
for (const RelocationRef &Reloc : info->S.relocations()) {
uint64_t RelocOffset;
Reloc.getOffset(RelocOffset);
uint64_t RelocOffset = Reloc.getOffset();
if (RelocOffset == sect_offset) {
Rel = Reloc.getRawDataRefImpl();
RE = info->O->getRelocation(Rel);
Expand Down Expand Up @@ -1841,8 +1839,7 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
bool isExtern = false;
SymbolRef Symbol;
for (const RelocationRef &Reloc : info->S.relocations()) {
uint64_t RelocOffset;
Reloc.getOffset(RelocOffset);
uint64_t RelocOffset = Reloc.getOffset();
if (RelocOffset == sect_offset) {
Rel = Reloc.getRawDataRefImpl();
RE = info->O->getRelocation(Rel);
Expand Down Expand Up @@ -1911,8 +1908,7 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
auto Reloc =
std::find_if(info->S.relocations().begin(), info->S.relocations().end(),
[&](const RelocationRef &Reloc) {
uint64_t RelocOffset;
Reloc.getOffset(RelocOffset);
uint64_t RelocOffset = Reloc.getOffset();
return RelocOffset == sect_offset;
});

Expand Down Expand Up @@ -2038,8 +2034,7 @@ static int SymbolizerGetOpInfo(void *DisInfo, uint64_t Pc, uint64_t Offset,
auto Reloc =
std::find_if(info->S.relocations().begin(), info->S.relocations().end(),
[&](const RelocationRef &Reloc) {
uint64_t RelocOffset;
Reloc.getOffset(RelocOffset);
uint64_t RelocOffset = Reloc.getOffset();
return RelocOffset == sect_offset;
});

Expand Down Expand Up @@ -2429,8 +2424,7 @@ static const char *get_symbol_64(uint32_t sect_offset, SectionRef S,
bool isExtern = false;
SymbolRef Symbol;
for (const RelocationRef &Reloc : S.relocations()) {
uint64_t RelocOffset;
Reloc.getOffset(RelocOffset);
uint64_t RelocOffset = Reloc.getOffset();
if (RelocOffset == sect_offset) {
Rel = Reloc.getRawDataRefImpl();
RE = info->O->getRelocation(Rel);
Expand Down Expand Up @@ -5611,8 +5605,7 @@ static const char *GuessLiteralPointer(uint64_t ReferenceValue,
bool isExtern = false;
SymbolRef Symbol;
for (const RelocationRef &Reloc : info->S.relocations()) {
uint64_t RelocOffset;
Reloc.getOffset(RelocOffset);
uint64_t RelocOffset = Reloc.getOffset();
if (RelocOffset == sect_offset) {
Rel = Reloc.getRawDataRefImpl();
RE = info->O->getRelocation(Rel);
Expand Down Expand Up @@ -6106,8 +6099,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
// Parse relocations.
std::vector<std::pair<uint64_t, SymbolRef>> Relocs;
for (const RelocationRef &Reloc : Sections[SectIdx].relocations()) {
uint64_t RelocOffset;
Reloc.getOffset(RelocOffset);
uint64_t RelocOffset = Reloc.getOffset();
uint64_t SectionAddress = Sections[SectIdx].getAddress();
RelocOffset -= SectionAddress;

Expand Down Expand Up @@ -6510,8 +6502,7 @@ printMachOCompactUnwindSection(const MachOObjectFile *Obj,
// Next we need to look at the relocations to find out what objects are
// actually being referred to.
for (const RelocationRef &Reloc : CompactUnwind.relocations()) {
uint64_t RelocAddress;
Reloc.getOffset(RelocAddress);
uint64_t RelocAddress = Reloc.getOffset();

uint32_t EntryIdx = RelocAddress / EntrySize;
uint32_t OffsetInEntry = RelocAddress - EntryIdx * EntrySize;
Expand Down

0 comments on commit 3adaf02

Please sign in to comment.