[llvm] r264624 - Simplify how we represent relocation iterators.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 12:23:51 PDT 2016


Author: rafael
Date: Mon Mar 28 14:23:51 2016
New Revision: 264624

URL: http://llvm.org/viewvc/llvm-project?rev=264624&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Object/ELFObjectFile.h

Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=264624&r1=264623&r2=264624&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Mon Mar 28 14:23:51 2016
@@ -607,22 +607,6 @@ ELFObjectFile<ELFT>::section_rel_begin(D
   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(Dat
   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
 // 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
   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>




More information about the llvm-commits mailing list