Clarify getRelocationAddress x getRelocationOffset a bit.

getRelocationAddress is for dynamic libraries and executables,
getRelocationOffset for relocatable objects.

Mark the getRelocationAddress of COFF and MachO as not implemented yet. Add a
test of ELF's. llvm-readobj -r now prints the same values as readelf -r.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180259 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2013-04-25 12:28:45 +00:00
parent 02066838b5
commit 956ca7265c
11 changed files with 54 additions and 58 deletions

View File

@@ -607,6 +607,8 @@ private:
mutable const char *dt_soname;
private:
uint64_t getROffset(DataRefImpl Rel) const;
// Records for each version index the corresponding Verdef or Vernaux entry.
// This is filled the first time LoadVersionMap() is called.
class VersionMapEntry : public PointerIntPair<const void*, 1> {
@@ -1521,45 +1523,32 @@ error_code ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel,
template<class ELFT>
error_code ELFObjectFile<ELFT>::getRelocationAddress(DataRefImpl Rel,
uint64_t &Result) const {
uint64_t offset;
const Elf_Shdr *sec = getSection(Rel.w.b);
switch (sec->sh_type) {
default :
report_fatal_error("Invalid section type in Rel!");
case ELF::SHT_REL : {
offset = getRel(Rel)->r_offset;
break;
}
case ELF::SHT_RELA : {
offset = getRela(Rel)->r_offset;
break;
}
}
Result = offset;
assert((Header->e_type == ELF::ET_EXEC || Header->e_type == ELF::ET_DYN) &&
"Only executable and shared objects files have addresses");
Result = getROffset(Rel);
return object_error::success;
}
template<class ELFT>
error_code ELFObjectFile<ELFT>::getRelocationOffset(DataRefImpl Rel,
uint64_t &Result) const {
uint64_t offset;
assert(Header->e_type == ELF::ET_REL &&
"Only relocatable object files have relocation offsets");
Result = getROffset(Rel);
return object_error::success;
}
template<class ELFT>
uint64_t ELFObjectFile<ELFT>::getROffset(DataRefImpl Rel) const {
const Elf_Shdr *sec = getSection(Rel.w.b);
switch (sec->sh_type) {
default :
report_fatal_error("Invalid section type in Rel!");
case ELF::SHT_REL : {
offset = getRel(Rel)->r_offset;
break;
}
case ELF::SHT_RELA : {
offset = getRela(Rel)->r_offset;
break;
}
default:
report_fatal_error("Invalid section type in Rel!");
case ELF::SHT_REL:
return getRel(Rel)->r_offset;
case ELF::SHT_RELA:
return getRela(Rel)->r_offset;
}
Result = offset - sec->sh_addr;
return object_error::success;
}
template<class ELFT>

View File

@@ -133,7 +133,7 @@ private:
int64_t Addend;
R.getAdditionalInfo(Addend);
uint64_t Address;
R.getAddress(Address);
R.getOffset(Address);
return RelocToApply(Value + Addend - Address, 4);
}
@@ -151,7 +151,7 @@ private:
int64_t Addend;
R.getAdditionalInfo(Addend);
uint64_t Address;
R.getAddress(Address);
R.getOffset(Address);
return RelocToApply(Value + Addend - Address, 4);
}
RelocToApply visitELF_X86_64_32(RelocationRef R, uint64_t Value) {