diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2016-03-28 19:23:51 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2016-03-28 19:23:51 +0000 |
commit | 9cb885d5c3bb16e8f8a9d133c85f0540984e9ad0 (patch) | |
tree | bba8cc421b082eb3e9a4796d79f206c4b919e946 /llvm/include | |
parent | 9825491bbdb5571a799a49ba2ae154dc1f636096 (diff) | |
download | bcm5719-llvm-9cb885d5c3bb16e8f8a9d133c85f0540984e9ad0.tar.gz bcm5719-llvm-9cb885d5c3bb16e8f8a9d133c85f0540984e9ad0.zip |
Simplify how we represent relocation iterators.
Instead of using a bit to detect if they are "dynamic", just look at
sh_link.
This is a simplification on its own, and will help with using
llvm-objdump in dynamic objects.
llvm-svn: 264624
Diffstat (limited to 'llvm/include')
-rw-r--r-- | llvm/include/llvm/Object/ELFObjectFile.h | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h index efff38f11c4..5acb4ae3f4e 100644 --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/llvm/include/llvm/Object/ELFObjectFile.h @@ -607,22 +607,6 @@ ELFObjectFile<ELFT>::section_rel_begin(DataRefImpl Sec) const { uintptr_t SHT = reinterpret_cast<uintptr_t>(EF.section_begin()); RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize; RelData.d.b = 0; - - const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p); - if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL) - return relocation_iterator(RelocationRef(RelData, this)); - - const Elf_Shdr *RelSec = getRelSection(RelData); - ErrorOr<const Elf_Shdr *> SymSecOrErr = EF.getSection(RelSec->sh_link); - if (std::error_code EC = SymSecOrErr.getError()) - report_fatal_error(EC.message()); - const Elf_Shdr *SymSec = *SymSecOrErr; - uint32_t SymSecType = SymSec->sh_type; - if (SymSecType != ELF::SHT_SYMTAB && SymSecType != ELF::SHT_DYNSYM) - report_fatal_error("Invalid symbol table section type!"); - if (SymSecType == ELF::SHT_DYNSYM) - RelData.d.b = 1; - return relocation_iterator(RelocationRef(RelData, this)); } @@ -634,7 +618,14 @@ ELFObjectFile<ELFT>::section_rel_end(DataRefImpl Sec) const { if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL) return Begin; DataRefImpl RelData = Begin->getRawDataRefImpl(); - RelData.d.b += (S->sh_size / S->sh_entsize) << 1; + const Elf_Shdr *RelSec = getRelSection(RelData); + + // Error check sh_link here so that getRelocationSymbol can just use it. + ErrorOr<const Elf_Shdr *> SymSecOrErr = EF.getSection(RelSec->sh_link); + if (std::error_code EC = SymSecOrErr.getError()) + report_fatal_error(EC.message()); + + RelData.d.b += S->sh_size / S->sh_entsize; return relocation_iterator(RelocationRef(RelData, this)); } @@ -658,7 +649,7 @@ ELFObjectFile<ELFT>::getRelocatedSection(DataRefImpl Sec) const { // Relocations template <class ELFT> void ELFObjectFile<ELFT>::moveRelocationNext(DataRefImpl &Rel) const { - Rel.d.b += 2; + ++Rel.d.b; } template <class ELFT> @@ -673,12 +664,10 @@ ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel) const { if (!symbolIdx) return symbol_end(); - bool IsDyn = Rel.d.b & 1; + // FIXME: error check symbolIdx DataRefImpl SymbolData; - if (IsDyn) - SymbolData = toDRI(DotDynSymSec, symbolIdx); - else - SymbolData = toDRI(DotSymtabSec, symbolIdx); + SymbolData.d.a = sec->sh_link; + SymbolData.d.b = symbolIdx; return symbol_iterator(SymbolRef(SymbolData, this)); } @@ -726,14 +715,14 @@ template <class ELFT> const typename ELFObjectFile<ELFT>::Elf_Rel * ELFObjectFile<ELFT>::getRel(DataRefImpl Rel) const { assert(getRelSection(Rel)->sh_type == ELF::SHT_REL); - return EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b >> 1); + return EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b); } template <class ELFT> const typename ELFObjectFile<ELFT>::Elf_Rela * ELFObjectFile<ELFT>::getRela(DataRefImpl Rela) const { assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA); - return EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b >> 1); + return EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b); } template <class ELFT> |