[lld] r250095 - ELF2: Create a function to get VA from Elf_Rel.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 12 13:28:22 PDT 2015


Author: ruiu
Date: Mon Oct 12 15:28:22 2015
New Revision: 250095

URL: http://llvm.org/viewvc/llvm-project?rev=250095&view=rev
Log:
ELF2: Create a function to get VA from Elf_Rel.

And remove git getLocalSymVA because there's no user of the function anymore.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=250095&r1=250094&r2=250095&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Oct 12 15:28:22 2015
@@ -41,10 +41,7 @@ void InputSection<ELFT>::relocate(
     // resolved so we don't allocate a SymbolBody.
     const Elf_Shdr *SymTab = File.getSymbolTable();
     if (SymIndex < SymTab->sh_info) {
-      const Elf_Sym *Sym = File.getObj().getRelocationSymbol(&RI, SymTab);
-      if (!Sym)
-        continue;
-      SymVA = getLocalSymVA(Sym, File);
+      SymVA = getLocalRelTarget(File, RI);
     } else {
       SymbolBody &Body = *File.getSymbolBody(SymIndex)->repl();
       SymVA = getSymVA<ELFT>(Body);

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=250095&r1=250094&r2=250095&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Oct 12 15:28:22 2015
@@ -117,7 +117,6 @@ template <class ELFT> void RelocationSec
     uint32_t SymIndex = RI.getSymbol(IsMips64EL);
     const ObjectFile<ELFT> &File = *C.getFile();
     SymbolBody *Body = File.getSymbolBody(SymIndex);
-    const ELFFile<ELFT> &Obj = File.getObj();
     if (Body)
       Body = Body->repl();
 
@@ -130,8 +129,7 @@ template <class ELFT> void RelocationSec
         if (Body)
           Addend += getSymVA<ELFT>(cast<ELFSymbolBody<ELFT>>(*Body));
         else
-          Addend += getLocalSymVA(
-              Obj.getRelocationSymbol(&RI, File.getSymbolTable()), File);
+          Addend += getLocalRelTarget(File, RI);
       }
       P->setSymbolAndType(0, Target->getRelativeReloc(), IsMips64EL);
     }
@@ -423,10 +421,18 @@ typename ELFFile<ELFT>::uintX_t lld::elf
 
 template <class ELFT>
 typename ELFFile<ELFT>::uintX_t
-lld::elf2::getLocalSymVA(const typename ELFFile<ELFT>::Elf_Sym *Sym,
-                         const ObjectFile<ELFT> &File) {
-  uint32_t SecIndex = Sym->st_shndx;
+lld::elf2::getLocalRelTarget(const ObjectFile<ELFT> &File,
+                             const typename ELFFile<ELFT>::Elf_Rel &RI) {
+  typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
+  const Elf_Sym *Sym =
+      File.getObj().getRelocationSymbol(&RI, File.getSymbolTable());
+
+  // For certain special relocations, such as R_PPC64_TOC, there's no
+  // corresponding symbol. Just return 0 in that case.
+  if (!Sym)
+    return 0;
 
+  uint32_t SecIndex = Sym->st_shndx;
   if (SecIndex == SHN_XINDEX)
     SecIndex = File.getObj().getExtendedSymbolTableIndex(
         Sym, File.getSymbolTable(), File.getSymbolTableShndx());
@@ -736,16 +742,20 @@ template ELFFile<ELF64LE>::uintX_t getSy
 template ELFFile<ELF64BE>::uintX_t getSymVA<ELF64BE>(const SymbolBody &);
 
 template ELFFile<ELF32LE>::uintX_t
-getLocalSymVA(const ELFFile<ELF32LE>::Elf_Sym *, const ObjectFile<ELF32LE> &);
+getLocalRelTarget(const ObjectFile<ELF32LE> &,
+                  const ELFFile<ELF32LE>::Elf_Rel &);
 
 template ELFFile<ELF32BE>::uintX_t
-getLocalSymVA(const ELFFile<ELF32BE>::Elf_Sym *, const ObjectFile<ELF32BE> &);
+getLocalRelTarget(const ObjectFile<ELF32BE> &,
+                  const ELFFile<ELF32BE>::Elf_Rel &);
 
 template ELFFile<ELF64LE>::uintX_t
-getLocalSymVA(const ELFFile<ELF64LE>::Elf_Sym *, const ObjectFile<ELF64LE> &);
+getLocalRelTarget(const ObjectFile<ELF64LE> &,
+                  const ELFFile<ELF64LE>::Elf_Rel &);
 
 template ELFFile<ELF64BE>::uintX_t
-getLocalSymVA(const ELFFile<ELF64BE>::Elf_Sym *, const ObjectFile<ELF64BE> &);
+getLocalRelTarget(const ObjectFile<ELF64BE> &,
+                  const ELFFile<ELF64BE>::Elf_Rel &);
 
 template bool includeInSymtab<ELF32LE>(const SymbolBody &);
 template bool includeInSymtab<ELF32BE>(const SymbolBody &);

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=250095&r1=250094&r2=250095&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Mon Oct 12 15:28:22 2015
@@ -37,8 +37,8 @@ typename llvm::object::ELFFile<ELFT>::ui
 
 template <class ELFT>
 typename llvm::object::ELFFile<ELFT>::uintX_t
-getLocalSymVA(const typename llvm::object::ELFFile<ELFT>::Elf_Sym *Sym,
-              const ObjectFile<ELFT> &File);
+getLocalRelTarget(const ObjectFile<ELFT> &File,
+                  const typename llvm::object::ELFFile<ELFT>::Elf_Rel &Sym);
 bool canBePreempted(const SymbolBody *Body);
 template <class ELFT> bool includeInSymtab(const SymbolBody &B);
 




More information about the llvm-commits mailing list