[Mips] Factor out the code assign a value to the absolute atom into the
authorSimon Atanasyan <simon@atanasyan.com>
Sun, 25 May 2014 09:05:06 +0000 (09:05 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Sun, 25 May 2014 09:05:06 +0000 (09:05 +0000)
separate function.

llvm-svn: 209593

lld/lib/ReaderWriter/ELF/Mips/MipsELFWriters.h

index 51734c9..7c417d1 100644 (file)
@@ -49,17 +49,9 @@ public:
     auto got = gotSection ? gotSection->virtualAddr() : 0;
     auto gp = gotSection ? got + _targetLayout.getGPOffset() : 0;
 
-    auto gotAtomIter = _targetLayout.findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
-    assert(gotAtomIter != _targetLayout.absoluteAtoms().end());
-    (*gotAtomIter)->_virtualAddr = got;
-
-    auto gpAtomIter = _targetLayout.findAbsoluteAtom("_gp");
-    assert(gpAtomIter != _targetLayout.absoluteAtoms().end());
-    (*gpAtomIter)->_virtualAddr = gp;
-
-    AtomLayout *gpAtom = _targetLayout.getGP();
-    assert(gpAtom != nullptr);
-    gpAtom->_virtualAddr = gp;
+    setAtomValue("_GLOBAL_OFFSET_TABLE_", got);
+    setAtomValue("_gp", gp);
+    setAtomValue("_gp_disp", gp);
   }
 
   bool hasGlobalGOTEntry(const Atom *a) const {
@@ -79,6 +71,12 @@ public:
 private:
   MipsLinkingContext &_context;
   MipsTargetLayout<ELFT> &_targetLayout;
+
+  void setAtomValue(StringRef name, uint64_t value) {
+    auto atom = _targetLayout.findAbsoluteAtom(name);
+    assert(atom != _targetLayout.absoluteAtoms().end());
+    (*atom)->_virtualAddr = value;
+  }
 };
 
 } // elf