[lld] r252753 - Add a helper for getting the output offset of an input offset.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 11 08:50:37 PST 2015


Author: rafael
Date: Wed Nov 11 10:50:37 2015
New Revision: 252753

URL: http://llvm.org/viewvc/llvm-project?rev=252753&view=rev
Log:
Add a helper for getting the output offset of an input offset.

This will get a non st_value use shortly.

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

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=252753&r1=252752&r2=252753&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Nov 11 10:50:37 2015
@@ -43,10 +43,19 @@ ArrayRef<uint8_t> InputSectionBase<ELFT>
 
 template <class ELFT>
 typename ELFFile<ELFT>::uintX_t
+InputSectionBase<ELFT>::getOffset(uintX_t Offset) {
+  switch (SectionKind) {
+  case Regular:
+    return cast<InputSection<ELFT>>(this)->OutSecOff + Offset;
+  case Merge:
+    return cast<MergeInputSection<ELFT>>(this)->getOffset(Offset);
+  }
+}
+
+template <class ELFT>
+typename ELFFile<ELFT>::uintX_t
 InputSectionBase<ELFT>::getOffset(const Elf_Sym &Sym) {
-  if (auto *S = dyn_cast<InputSection<ELFT>>(this))
-    return S->OutSecOff + Sym.st_value;
-  return cast<MergeInputSection<ELFT>>(this)->getOffset(Sym.st_value);
+  return getOffset(Sym.st_value);
 }
 
 // Returns a section that Rel relocation is pointing to.

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=252753&r1=252752&r2=252753&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed Nov 11 10:50:37 2015
@@ -64,6 +64,11 @@ public:
   }
 
   uintX_t getOffset(const Elf_Sym &Sym);
+
+  // Translate an offset in the input section to an offset in the output
+  // section.
+  uintX_t getOffset(uintX_t Offset);
+
   ArrayRef<uint8_t> getSectionData() const;
 
   // Returns a section that Rel is pointing to. Used by the garbage collector.




More information about the llvm-commits mailing list