[lld] r263152 - Move getLocalRelTarget to the file where it is used.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 10 11:00:22 PST 2016


Author: rafael
Date: Thu Mar 10 13:00:22 2016
New Revision: 263152

URL: http://llvm.org/viewvc/llvm-project?rev=263152&view=rev
Log:
Move getLocalRelTarget to the file where it is used.

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=263152&r1=263151&r2=263152&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Mar 10 13:00:22 2016
@@ -183,6 +183,48 @@ InputSectionBase<ELFT>::findMipsPairedRe
   return nullptr;
 }
 
+// Returns a VA which a relocatin RI refers to. Used only for local symbols.
+// For non-local symbols, use SymbolBody::getVA instead.
+template <class ELFT, bool IsRela>
+static typename ELFFile<ELFT>::uintX_t
+getLocalRelTarget(const ObjectFile<ELFT> &File,
+                  const Elf_Rel_Impl<ELFT, IsRela> &RI,
+                  typename ELFFile<ELFT>::uintX_t Addend) {
+  typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
+  typedef typename ELFFile<ELFT>::uintX_t uintX_t;
+
+  // PPC64 has a special relocation representing the TOC base pointer
+  // that does not have a corresponding symbol.
+  if (Config->EMachine == EM_PPC64 && RI.getType(false) == R_PPC64_TOC)
+    return getPPC64TocBase() + Addend;
+
+  const Elf_Sym *Sym =
+      File.getObj().getRelocationSymbol(&RI, File.getSymbolTable());
+
+  if (!Sym)
+    fatal("Unsupported relocation without symbol");
+
+  InputSectionBase<ELFT> *Section = File.getSection(*Sym);
+
+  if (Sym->getType() == STT_TLS)
+    return (Section->OutSec->getVA() + Section->getOffset(*Sym) + Addend) -
+           Out<ELFT>::TlsPhdr->p_vaddr;
+
+  // According to the ELF spec reference to a local symbol from outside
+  // the group are not allowed. Unfortunately .eh_frame breaks that rule
+  // and must be treated specially. For now we just replace the symbol with
+  // 0.
+  if (Section == InputSection<ELFT>::Discarded || !Section->Live)
+    return Addend;
+
+  uintX_t Offset = Sym->st_value;
+  if (Sym->getType() == STT_SECTION) {
+    Offset += Addend;
+    Addend = 0;
+  }
+  return Section->OutSec->getVA() + Section->getOffset(Offset) + Addend;
+}
+
 template <class ELFT>
 template <bool isRela>
 void InputSectionBase<ELFT>::relocate(uint8_t *Buf, uint8_t *BufEnd,

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=263152&r1=263151&r2=263152&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Mar 10 13:00:22 2016
@@ -888,48 +888,6 @@ template <class ELFT> void OutputSection
   reassignOffsets();
 }
 
-// Returns a VA which a relocatin RI refers to. Used only for local symbols.
-// For non-local symbols, use SymbolBody::getVA instead.
-template <class ELFT, bool IsRela>
-typename ELFFile<ELFT>::uintX_t
-elf::getLocalRelTarget(const ObjectFile<ELFT> &File,
-                       const Elf_Rel_Impl<ELFT, IsRela> &RI,
-                       typename ELFFile<ELFT>::uintX_t Addend) {
-  typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
-  typedef typename ELFFile<ELFT>::uintX_t uintX_t;
-
-  // PPC64 has a special relocation representing the TOC base pointer
-  // that does not have a corresponding symbol.
-  if (Config->EMachine == EM_PPC64 && RI.getType(false) == R_PPC64_TOC)
-    return getPPC64TocBase() + Addend;
-
-  const Elf_Sym *Sym =
-      File.getObj().getRelocationSymbol(&RI, File.getSymbolTable());
-
-  if (!Sym)
-    fatal("Unsupported relocation without symbol");
-
-  InputSectionBase<ELFT> *Section = File.getSection(*Sym);
-
-  if (Sym->getType() == STT_TLS)
-    return (Section->OutSec->getVA() + Section->getOffset(*Sym) + Addend) -
-           Out<ELFT>::TlsPhdr->p_vaddr;
-
-  // According to the ELF spec reference to a local symbol from outside
-  // the group are not allowed. Unfortunately .eh_frame breaks that rule
-  // and must be treated specially. For now we just replace the symbol with
-  // 0.
-  if (Section == InputSection<ELFT>::Discarded || !Section->Live)
-    return Addend;
-
-  uintX_t Offset = Sym->st_value;
-  if (Sym->getType() == STT_SECTION) {
-    Offset += Addend;
-    Addend = 0;
-  }
-  return Section->OutSec->getVA() + Section->getOffset(Offset) + Addend;
-}
-
 // Returns true if a symbol can be replaced at load-time by a symbol
 // with the same name defined in other ELF executable or DSO.
 bool elf::canBePreempted(const SymbolBody *Body) {
@@ -1668,30 +1626,5 @@ template class SymbolTableSection<ELF32L
 template class SymbolTableSection<ELF32BE>;
 template class SymbolTableSection<ELF64LE>;
 template class SymbolTableSection<ELF64BE>;
-
-template uint32_t getLocalRelTarget(const ObjectFile<ELF32LE> &,
-                                    const ELFFile<ELF32LE>::Elf_Rel &,
-                                    uint32_t);
-template uint32_t getLocalRelTarget(const ObjectFile<ELF32BE> &,
-                                    const ELFFile<ELF32BE>::Elf_Rel &,
-                                    uint32_t);
-template uint64_t getLocalRelTarget(const ObjectFile<ELF64LE> &,
-                                    const ELFFile<ELF64LE>::Elf_Rel &,
-                                    uint64_t);
-template uint64_t getLocalRelTarget(const ObjectFile<ELF64BE> &,
-                                    const ELFFile<ELF64BE>::Elf_Rel &,
-                                    uint64_t);
-template uint32_t getLocalRelTarget(const ObjectFile<ELF32LE> &,
-                                    const ELFFile<ELF32LE>::Elf_Rela &,
-                                    uint32_t);
-template uint32_t getLocalRelTarget(const ObjectFile<ELF32BE> &,
-                                    const ELFFile<ELF32BE>::Elf_Rela &,
-                                    uint32_t);
-template uint64_t getLocalRelTarget(const ObjectFile<ELF64LE> &,
-                                    const ELFFile<ELF64LE>::Elf_Rela &,
-                                    uint64_t);
-template uint64_t getLocalRelTarget(const ObjectFile<ELF64BE> &,
-                                    const ELFFile<ELF64BE>::Elf_Rela &,
-                                    uint64_t);
 }
 }

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=263152&r1=263151&r2=263152&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Thu Mar 10 13:00:22 2016
@@ -47,12 +47,6 @@ getAddend(const typename llvm::object::E
   return Rel.r_addend;
 }
 
-template <class ELFT, bool IsRela>
-typename llvm::object::ELFFile<ELFT>::uintX_t
-getLocalRelTarget(const ObjectFile<ELFT> &File,
-                  const llvm::object::Elf_Rel_Impl<ELFT, IsRela> &Rel,
-                  typename llvm::object::ELFFile<ELFT>::uintX_t Addend);
-
 bool canBePreempted(const SymbolBody *Body);
 
 bool isValidCIdentifier(StringRef S);




More information about the llvm-commits mailing list