mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
Remove getRelocationAddress.
Originally added in r139314. Back then it didn't actually get the address, it got whatever value the relocation used: address or offset. The values in different object formats are: * MachO: Always an offset. * COFF: Always an address, but when talking about the virtual address of sections it says: "for simplicity, compilers should set this to zero". * ELF: An offset for .o files and and address for .so files. In the case of the .so, the relocation in not linked to any section (sh_info is 0). We can't really compute an offset. Some API mappings would be: * Use getAddress for everything. It would be quite cumbersome. To compute the address elf has to follow sh_info, which can be corrupted and therefore the method has to return an ErrorOr. The address of the section is also the same for every relocation in a section, so we shouldn't have to check the error and fetch the value for every relocation. * Use a getValue and make it up to the user to know what it is getting. * Use a getOffset and: * Assert for dynamic ELF objects. That is a very peculiar case and it is probably fair to ask any tool that wants to support it to use ELF.h. The only tool we have that reads those (llvm-readobj) already does that. The only other use case I can think of is a dynamic linker. * Check that COFF .obj files have sections with zero virtual address spaces. If it turns out that some assembler/compiler produces these, we can change COFFObjectFile::getRelocationOffset to subtract it. Given COFF format, this can be done without the need for ErrorOr. The getRelocationAddress method was never implemented for COFF. It also had exactly one use in a very peculiar case: a shortcut for adding the section value to a pcrel reloc on MachO. Given that, I don't expect that there is any use out there of the C API. If that is not the case, let me know and I will add it back with the implementation inlined and do a proper deprecation. llvm-svn: 241450
This commit is contained in:
parent
46c71906bc
commit
94aac821b6
@ -371,14 +371,6 @@ class Relocation(LLVMObject):
|
||||
|
||||
self.expired = False
|
||||
|
||||
@CachedProperty
|
||||
def address(self):
|
||||
"""The address of this relocation, in long bytes."""
|
||||
if self.expired:
|
||||
raise Exception('Relocation instance has expired.')
|
||||
|
||||
return lib.LLVMGetRelocationAddress(self)
|
||||
|
||||
@CachedProperty
|
||||
def offset(self):
|
||||
"""The offset of this relocation, in long bytes."""
|
||||
@ -498,9 +490,6 @@ def register_library(library):
|
||||
library.LLVMGetSymbolSize.argtypes = [Symbol]
|
||||
library.LLVMGetSymbolSize.restype = c_uint64
|
||||
|
||||
library.LLVMGetRelocationAddress.argtypes = [c_object_p]
|
||||
library.LLVMGetRelocationAddress.restype = c_uint64
|
||||
|
||||
library.LLVMGetRelocationOffset.argtypes = [c_object_p]
|
||||
library.LLVMGetRelocationOffset.restype = c_uint64
|
||||
|
||||
|
@ -81,7 +81,6 @@ uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
|
||||
uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
|
||||
|
||||
// RelocationRef accessors
|
||||
uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI);
|
||||
uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
|
||||
LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
|
||||
uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
|
||||
|
@ -671,7 +671,6 @@ protected:
|
||||
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
|
||||
|
||||
void moveRelocationNext(DataRefImpl &Rel) const override;
|
||||
ErrorOr<uint64_t> getRelocationAddress(DataRefImpl Rel) const override;
|
||||
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
|
||||
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
|
||||
uint64_t getRelocationType(DataRefImpl Rel) const override;
|
||||
|
@ -225,7 +225,6 @@ protected:
|
||||
section_iterator getRelocatedSection(DataRefImpl Sec) const override;
|
||||
|
||||
void moveRelocationNext(DataRefImpl &Rel) const override;
|
||||
ErrorOr<uint64_t> getRelocationAddress(DataRefImpl Rel) const override;
|
||||
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
|
||||
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
|
||||
uint64_t getRelocationType(DataRefImpl Rel) const override;
|
||||
@ -682,23 +681,6 @@ ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel) const {
|
||||
return symbol_iterator(SymbolRef(SymbolData, this));
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
ErrorOr<uint64_t>
|
||||
ELFObjectFile<ELFT>::getRelocationAddress(DataRefImpl Rel) const {
|
||||
uint64_t ROffset = getROffset(Rel);
|
||||
const Elf_Ehdr *Header = EF.getHeader();
|
||||
|
||||
if (Header->e_type == ELF::ET_REL) {
|
||||
const Elf_Shdr *RelocationSec = getRelSection(Rel);
|
||||
ErrorOr<const Elf_Shdr *> RelocatedSec =
|
||||
EF.getSection(RelocationSec->sh_info);
|
||||
if (std::error_code EC = RelocatedSec.getError())
|
||||
return EC;
|
||||
return ROffset + (*RelocatedSec)->sh_addr;
|
||||
}
|
||||
return ROffset;
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
uint64_t ELFObjectFile<ELFT>::getRelocationOffset(DataRefImpl Rel) const {
|
||||
assert(EF.getHeader()->e_type == ELF::ET_REL &&
|
||||
|
@ -232,7 +232,6 @@ public:
|
||||
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
|
||||
|
||||
void moveRelocationNext(DataRefImpl &Rel) const override;
|
||||
ErrorOr<uint64_t> getRelocationAddress(DataRefImpl Rel) const override;
|
||||
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
|
||||
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
|
||||
section_iterator getRelocationSection(DataRefImpl Rel) const;
|
||||
@ -244,6 +243,8 @@ public:
|
||||
// MachO specific.
|
||||
std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const;
|
||||
|
||||
section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const;
|
||||
|
||||
// TODO: Would be useful to have an iterator based version
|
||||
// of the load command interface too.
|
||||
|
||||
|
@ -50,7 +50,6 @@ public:
|
||||
|
||||
void moveNext();
|
||||
|
||||
ErrorOr<uint64_t> getAddress() const;
|
||||
uint64_t getOffset() const;
|
||||
symbol_iterator getSymbol() const;
|
||||
uint64_t getType() const;
|
||||
@ -228,7 +227,6 @@ protected:
|
||||
// Same as above for RelocationRef.
|
||||
friend class RelocationRef;
|
||||
virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
|
||||
virtual ErrorOr<uint64_t> getRelocationAddress(DataRefImpl Rel) const = 0;
|
||||
virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
|
||||
virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
|
||||
virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
|
||||
@ -429,10 +427,6 @@ inline void RelocationRef::moveNext() {
|
||||
return OwningObject->moveRelocationNext(RelocationPimpl);
|
||||
}
|
||||
|
||||
inline ErrorOr<uint64_t> RelocationRef::getAddress() const {
|
||||
return OwningObject->getRelocationAddress(RelocationPimpl);
|
||||
}
|
||||
|
||||
inline uint64_t RelocationRef::getOffset() const {
|
||||
return OwningObject->getRelocationOffset(RelocationPimpl);
|
||||
}
|
||||
|
@ -89,19 +89,11 @@ RelocationValueRef RuntimeDyldMachO::getRelocationValueRef(
|
||||
}
|
||||
|
||||
void RuntimeDyldMachO::makeValueAddendPCRel(RelocationValueRef &Value,
|
||||
const ObjectFile &BaseTObj,
|
||||
const relocation_iterator &RI,
|
||||
unsigned OffsetToNextPC) {
|
||||
const MachOObjectFile &Obj =
|
||||
static_cast<const MachOObjectFile &>(BaseTObj);
|
||||
MachO::any_relocation_info RelInfo =
|
||||
Obj.getRelocation(RI->getRawDataRefImpl());
|
||||
|
||||
bool IsPCRel = Obj.getAnyRelocationPCRel(RelInfo);
|
||||
if (IsPCRel) {
|
||||
ErrorOr<uint64_t> RelocAddr = RI->getAddress();
|
||||
Value.Offset += *RelocAddr + OffsetToNextPC;
|
||||
}
|
||||
auto &O = *cast<MachOObjectFile>(RI->getObject());
|
||||
section_iterator SecI = O.getRelocationRelocatedSection(RI);
|
||||
Value.Offset += RI->getOffset() + OffsetToNextPC + SecI->getAddress();
|
||||
}
|
||||
|
||||
void RuntimeDyldMachO::dumpRelocationToResolve(const RelocationEntry &RE,
|
||||
|
@ -95,7 +95,6 @@ protected:
|
||||
|
||||
/// Make the RelocationValueRef addend PC-relative.
|
||||
void makeValueAddendPCRel(RelocationValueRef &Value,
|
||||
const ObjectFile &BaseTObj,
|
||||
const relocation_iterator &RI,
|
||||
unsigned OffsetToNextPC);
|
||||
|
||||
|
@ -284,7 +284,7 @@ public:
|
||||
|
||||
bool IsExtern = Obj.getPlainRelocationExternal(RelInfo);
|
||||
if (!IsExtern && RE.IsPCRel)
|
||||
makeValueAddendPCRel(Value, Obj, RelI, 1 << RE.Size);
|
||||
makeValueAddendPCRel(Value, RelI, 1 << RE.Size);
|
||||
|
||||
RE.Addend = Value.Offset;
|
||||
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
getRelocationValueRef(Obj, RelI, RE, ObjSectionToID));
|
||||
|
||||
if (RE.IsPCRel)
|
||||
makeValueAddendPCRel(Value, Obj, RelI, 8);
|
||||
makeValueAddendPCRel(Value, RelI, 8);
|
||||
|
||||
if ((RE.RelType & 0xf) == MachO::ARM_RELOC_BR24)
|
||||
processBranchRelocation(RE, Value, Stubs);
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
// Value.Addend += RelocAddr + 4;
|
||||
// }
|
||||
if (RE.IsPCRel)
|
||||
makeValueAddendPCRel(Value, Obj, RelI, 1 << RE.Size);
|
||||
makeValueAddendPCRel(Value, RelI, 1 << RE.Size);
|
||||
|
||||
RE.Addend = Value.Offset;
|
||||
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
|
||||
bool IsExtern = Obj.getPlainRelocationExternal(RelInfo);
|
||||
if (!IsExtern && RE.IsPCRel)
|
||||
makeValueAddendPCRel(Value, Obj, RelI, 1 << RE.Size);
|
||||
makeValueAddendPCRel(Value, RelI, 1 << RE.Size);
|
||||
|
||||
if (RE.RelType == MachO::X86_64_RELOC_GOT ||
|
||||
RE.RelType == MachO::X86_64_RELOC_GOT_LOAD)
|
||||
|
@ -958,10 +958,6 @@ void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
|
||||
reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
|
||||
}
|
||||
|
||||
ErrorOr<uint64_t> COFFObjectFile::getRelocationAddress(DataRefImpl Rel) const {
|
||||
report_fatal_error("getRelocationAddress not implemented in COFFObjectFile");
|
||||
}
|
||||
|
||||
uint64_t COFFObjectFile::getRelocationOffset(DataRefImpl Rel) const {
|
||||
const coff_relocation *R = toRel(Rel);
|
||||
return R->VirtualAddress;
|
||||
|
@ -588,15 +588,6 @@ void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
|
||||
++Rel.d.b;
|
||||
}
|
||||
|
||||
ErrorOr<uint64_t> MachOObjectFile::getRelocationAddress(DataRefImpl Rel) const {
|
||||
uint64_t Offset = getRelocationOffset(Rel);
|
||||
|
||||
DataRefImpl Sec;
|
||||
Sec.d.a = Rel.d.a;
|
||||
uint64_t SecAddress = getSectionAddress(Sec);
|
||||
return SecAddress + Offset;
|
||||
}
|
||||
|
||||
uint64_t MachOObjectFile::getRelocationOffset(DataRefImpl Rel) const {
|
||||
assert(getHeader().filetype == MachO::MH_OBJECT &&
|
||||
"Only implemented for MH_OBJECT");
|
||||
@ -927,6 +918,13 @@ std::error_code MachOObjectFile::getLibraryShortNameByIndex(unsigned Index,
|
||||
return std::error_code();
|
||||
}
|
||||
|
||||
section_iterator
|
||||
MachOObjectFile::getRelocationRelocatedSection(relocation_iterator Rel) const {
|
||||
DataRefImpl Sec;
|
||||
Sec.d.a = Rel->getRawDataRefImpl().d.a;
|
||||
return section_iterator(SectionRef(Sec, this));
|
||||
}
|
||||
|
||||
basic_symbol_iterator MachOObjectFile::symbol_begin_impl() const {
|
||||
return getSymbolByIndex(0);
|
||||
}
|
||||
|
@ -191,13 +191,6 @@ uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) {
|
||||
}
|
||||
|
||||
// RelocationRef accessors
|
||||
uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI) {
|
||||
ErrorOr<uint64_t> Ret = (*unwrap(RI))->getAddress();
|
||||
if (std::error_code EC = Ret.getError())
|
||||
report_fatal_error(EC.message());
|
||||
return *Ret;
|
||||
}
|
||||
|
||||
uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI) {
|
||||
return (*unwrap(RI))->getOffset();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user