[lld] r233769 - ELF: Make findAbsoluteAtom return AtomLayout* instead of an iterator.

Rui Ueyama ruiu at google.com
Tue Mar 31 15:38:00 PDT 2015


Author: ruiu
Date: Tue Mar 31 17:37:59 2015
New Revision: 233769

URL: http://llvm.org/viewvc/llvm-project?rev=233769&view=rev
Log:
ELF: Make findAbsoluteAtom return AtomLayout* instead of an iterator.

All calls of findAbsoluteAtoms seem a bit awkward because of the type
of the function. It semantically returns a pointer to an AtomLayout or
nothing, so I made the function return AtomLayout*.

In this patch, I also expanded some "auto"s because their actual type
were not obvious in their contexts.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h
    lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
    lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
    lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h
    lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
    lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h

Modified: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h Tue Mar 31 17:37:59 2015
@@ -66,9 +66,8 @@ template <class ELFT>
 void ARMExecutableWriter<ELFT>::finalizeDefaultAtomValues() {
   // Finalize the atom values that are part of the parent.
   ExecutableWriter<ELFT>::finalizeDefaultAtomValues();
-  auto gotAtomIter = _armLayout.findAbsoluteAtom(gotSymbol);
-  if (gotAtomIter != _armLayout.absoluteAtoms().end()) {
-    auto *gotAtom = *gotAtomIter;
+  AtomLayout *gotAtom = _armLayout.findAbsoluteAtom(gotSymbol);
+  if (gotAtom) {
     if (auto gotpltSection = _armLayout.findOutputSection(".got.plt"))
       gotAtom->_virtualAddr = gotpltSection->virtualAddr();
     else if (auto gotSection = _armLayout.findOutputSection(".got"))

Modified: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h Tue Mar 31 17:37:59 2015
@@ -27,10 +27,8 @@ public:
 
   uint64_t getGOTSymAddr() {
     if (!_gotSymAddr.hasValue()) {
-      auto gotAtomIter = this->findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
-      _gotSymAddr = (gotAtomIter != this->absoluteAtoms().end())
-                        ? (*gotAtomIter)->_virtualAddr
-                        : 0;
+      AtomLayout *gotAtom = this->findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
+      _gotSymAddr = gotAtom ? gotAtom->_virtualAddr : 0;
     }
     return *_gotSymAddr;
   }

Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Tue Mar 31 17:37:59 2015
@@ -204,10 +204,13 @@ public:
   }
 
   /// \brief find a absolute atom given a name
-  AbsoluteAtomIterT findAbsoluteAtom(StringRef name) {
-    return std::find_if(
+  lld::AtomLayout *findAbsoluteAtom(StringRef name) {
+    auto iter = std::find_if(
         _absoluteAtoms.begin(), _absoluteAtoms.end(),
         [=](const AtomLayout *a) { return a->_atom->name() == name; });
+    if (iter == _absoluteAtoms.end())
+      return nullptr;
+    return *iter;
   }
 
   // Output sections with the same name into a OutputSection

Modified: lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h Tue Mar 31 17:37:59 2015
@@ -79,13 +79,14 @@ bool DynamicLibraryWriter<ELFT>::createI
 
 template <class ELFT>
 void DynamicLibraryWriter<ELFT>::finalizeDefaultAtomValues() {
-  auto underScoreEndAtomIter = this->_layout.findAbsoluteAtom("_end");
+  lld::AtomLayout *underScoreEndAtom = this->_layout.findAbsoluteAtom("_end");
+  assert(underScoreEndAtom);
 
   if (auto bssSection = this->_layout.findOutputSection(".bss")) {
-    (*underScoreEndAtomIter)->_virtualAddr =
+    underScoreEndAtom->_virtualAddr =
         bssSection->virtualAddr() + bssSection->memSize();
   } else if (auto dataSection = this->_layout.findOutputSection(".data")) {
-    (*underScoreEndAtomIter)->_virtualAddr =
+    underScoreEndAtom->_virtualAddr =
         dataSection->virtualAddr() + dataSection->memSize();
   }
 }

Modified: lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ExecutableWriter.h Tue Mar 31 17:37:59 2015
@@ -126,23 +126,26 @@ template <class ELFT> void ExecutableWri
 /// created
 template <class ELFT> void ExecutableWriter<ELFT>::finalizeDefaultAtomValues() {
   OutputELFWriter<ELFT>::finalizeDefaultAtomValues();
-  auto bssStartAtomIter = this->_layout.findAbsoluteAtom("__bss_start");
-  auto bssEndAtomIter = this->_layout.findAbsoluteAtom("__bss_end");
-  auto underScoreEndAtomIter = this->_layout.findAbsoluteAtom("_end");
-  auto endAtomIter = this->_layout.findAbsoluteAtom("end");
+  AtomLayout *bssStartAtom = this->_layout.findAbsoluteAtom("__bss_start");
+  AtomLayout *bssEndAtom = this->_layout.findAbsoluteAtom("__bss_end");
+  AtomLayout *underScoreEndAtom = this->_layout.findAbsoluteAtom("_end");
+  AtomLayout *endAtom = this->_layout.findAbsoluteAtom("end");
+
+  assert((bssStartAtom || bssEndAtom || underScoreEndAtom || endAtom) &&
+         "Unable to find the absolute atoms that have been added by lld");
 
   auto startEnd = [&](StringRef sym, StringRef sec) -> void {
     std::string start = ("__" + sym + "_start").str();
     std::string end = ("__" + sym + "_end").str();
-    auto s = this->_layout.findAbsoluteAtom(start);
-    auto e = this->_layout.findAbsoluteAtom(end);
-    auto section = this->_layout.findOutputSection(sec);
+    AtomLayout *s = this->_layout.findAbsoluteAtom(start);
+    AtomLayout *e = this->_layout.findAbsoluteAtom(end);
+    OutputSection<ELFT> *section = this->_layout.findOutputSection(sec);
     if (section) {
-      (*s)->_virtualAddr = section->virtualAddr();
-      (*e)->_virtualAddr = section->virtualAddr() + section->memSize();
+      s->_virtualAddr = section->virtualAddr();
+      e->_virtualAddr = section->virtualAddr() + section->memSize();
     } else {
-      (*s)->_virtualAddr = 0;
-      (*e)->_virtualAddr = 0;
+      s->_virtualAddr = 0;
+      e->_virtualAddr = 0;
     }
   };
 
@@ -154,25 +157,19 @@ template <class ELFT> void ExecutableWri
     startEnd("rel_iplt", ".rel.plt");
   startEnd("fini_array", ".fini_array");
 
-  assert(!(bssStartAtomIter == this->_layout.absoluteAtoms().end() ||
-           bssEndAtomIter == this->_layout.absoluteAtoms().end() ||
-           underScoreEndAtomIter == this->_layout.absoluteAtoms().end() ||
-           endAtomIter == this->_layout.absoluteAtoms().end()) &&
-         "Unable to find the absolute atoms that have been added by lld");
-
   auto bssSection = this->_layout.findOutputSection(".bss");
 
   // If we don't find a bss section, then don't set these values
   if (bssSection) {
-    (*bssStartAtomIter)->_virtualAddr = bssSection->virtualAddr();
-    (*bssEndAtomIter)->_virtualAddr =
+    bssStartAtom->_virtualAddr = bssSection->virtualAddr();
+    bssEndAtom->_virtualAddr =
         bssSection->virtualAddr() + bssSection->memSize();
-    (*underScoreEndAtomIter)->_virtualAddr = (*bssEndAtomIter)->_virtualAddr;
-    (*endAtomIter)->_virtualAddr = (*bssEndAtomIter)->_virtualAddr;
+    underScoreEndAtom->_virtualAddr = bssEndAtom->_virtualAddr;
+    endAtom->_virtualAddr = bssEndAtom->_virtualAddr;
   } else if (auto dataSection = this->_layout.findOutputSection(".data")) {
-    (*underScoreEndAtomIter)->_virtualAddr =
+    underScoreEndAtom->_virtualAddr =
         dataSection->virtualAddr() + dataSection->memSize();
-    (*endAtomIter)->_virtualAddr = (*underScoreEndAtomIter)->_virtualAddr;
+    endAtom->_virtualAddr = underScoreEndAtom->_virtualAddr;
   }
 }
 

Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h Tue Mar 31 17:37:59 2015
@@ -70,9 +70,8 @@ template <class ELFT>
 void HexagonExecutableWriter<ELFT>::finalizeDefaultAtomValues() {
   // Finalize the atom values that are part of the parent.
   ExecutableWriter<ELFT>::finalizeDefaultAtomValues();
-  auto sdabaseAtomIter = _targetLayout.findAbsoluteAtom("_SDA_BASE_");
-  (*sdabaseAtomIter)->_virtualAddr =
-      _targetLayout.getSDataSection()->virtualAddr();
+  AtomLayout *sdabaseAtom = _targetLayout.findAbsoluteAtom("_SDA_BASE_");
+  sdabaseAtom->_virtualAddr = _targetLayout.getSDataSection()->virtualAddr();
   if (_ctx.isDynamic())
     finalizeHexagonRuntimeAtomValues(_targetLayout);
 }

Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h Tue Mar 31 17:37:59 2015
@@ -83,10 +83,8 @@ public:
   }
 
   uint64_t getGOTSymAddr() {
-    if (!_gotSymAtom.hasValue()) {
-      auto iter = this->findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
-      _gotSymAtom = (iter == this->absoluteAtoms().end()) ? nullptr : *iter;
-    }
+    if (!_gotSymAtom.hasValue())
+      _gotSymAtom = this->findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
     if (*_gotSymAtom)
       return (*_gotSymAtom)->_virtualAddr;
     return 0;
@@ -131,18 +129,18 @@ private:
 
 template <class ELFT>
 void finalizeHexagonRuntimeAtomValues(HexagonTargetLayout<ELFT> &layout) {
-  auto gotAtomIter = layout.findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
-  auto gotpltSection = layout.findOutputSection(".got.plt");
+  AtomLayout *gotAtom = layout.findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
+  OutputSection<ELFT> *gotpltSection = layout.findOutputSection(".got.plt");
   if (gotpltSection)
-    (*gotAtomIter)->_virtualAddr = gotpltSection->virtualAddr();
+    gotAtom->_virtualAddr = gotpltSection->virtualAddr();
   else
-    (*gotAtomIter)->_virtualAddr = 0;
-  auto dynamicAtomIter = layout.findAbsoluteAtom("_DYNAMIC");
-  auto dynamicSection = layout.findOutputSection(".dynamic");
+    gotAtom->_virtualAddr = 0;
+  AtomLayout *dynamicAtom = layout.findAbsoluteAtom("_DYNAMIC");
+  OutputSection<ELFT> *dynamicSection = layout.findOutputSection(".dynamic");
   if (dynamicSection)
-    (*dynamicAtomIter)->_virtualAddr = dynamicSection->virtualAddr();
+    dynamicAtom->_virtualAddr = dynamicSection->virtualAddr();
   else
-    (*dynamicAtomIter)->_virtualAddr = 0;
+    dynamicAtom->_virtualAddr = 0;
 }
 
 } // end namespace elf

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h Tue Mar 31 17:37:59 2015
@@ -68,9 +68,9 @@ private:
   MipsTargetLayout<ELFT> &_targetLayout;
 
   void setAtomValue(StringRef name, uint64_t value) {
-    auto atom = _targetLayout.findAbsoluteAtom(name);
-    assert(atom != _targetLayout.absoluteAtoms().end());
-    (*atom)->_virtualAddr = value;
+    AtomLayout *atom = _targetLayout.findAbsoluteAtom(name);
+    assert(atom);
+    atom->_virtualAddr = value;
   }
 };
 

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h Tue Mar 31 17:37:59 2015
@@ -48,19 +48,15 @@ public:
 
   /// \brief Get '_gp' symbol atom layout.
   AtomLayout *getGP() {
-    if (!_gpAtom.hasValue()) {
-      auto atom = this->findAbsoluteAtom("_gp");
-      _gpAtom = atom != this->absoluteAtoms().end() ? *atom : nullptr;
-    }
+    if (!_gpAtom.hasValue())
+      _gpAtom = this->findAbsoluteAtom("_gp");
     return *_gpAtom;
   }
 
   /// \brief Get '_gp_disp' symbol atom layout.
   AtomLayout *getGPDisp() {
-    if (!_gpDispAtom.hasValue()) {
-      auto atom = this->findAbsoluteAtom("_gp_disp");
-      _gpDispAtom = atom != this->absoluteAtoms().end() ? *atom : nullptr;
-    }
+    if (!_gpDispAtom.hasValue())
+      _gpDispAtom = this->findAbsoluteAtom("_gp_disp");
     return *_gpDispAtom;
   }
 

Modified: lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h?rev=233769&r1=233768&r2=233769&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h Tue Mar 31 17:37:59 2015
@@ -384,8 +384,9 @@ void OutputELFWriter<ELFT>::finalizeDefa
   for (auto &sym : symbols) {
     uint64_t res =
         _ctx.linkerScriptSema().getLinkerScriptExprValue(sym.getKey());
-    auto a = _layout.findAbsoluteAtom(sym.getKey());
-    (*a)->_virtualAddr = res;
+    AtomLayout *a = _layout.findAbsoluteAtom(sym.getKey());
+    assert(a);
+    a->_virtualAddr = res;
   }
 }
 





More information about the llvm-commits mailing list