<div dir="ltr">Hmm, I failed to squash local temporary commits before committing. I'm really sorry. I'll check for it twice next time.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 14, 2015 at 4:11 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ruiu<br>
Date: Tue Apr 14 18:11:10 2015<br>
New Revision: 234953<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=234953&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=234953&view=rev</a><br>
Log:<br>
temporary<br>
<br>
Modified:<br>
    lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp<br>
<br>
Modified: lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp?rev=234953&r1=234952&r2=234953&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp?rev=234953&r1=234952&r2=234953&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp (original)<br>
+++ lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp Tue Apr 14 18:11:10 2015<br>
@@ -182,7 +182,6 @@ template <class ELFT> void Segment<ELFT><br>
<br>
   startSectionIter = _sections.begin();<br>
   startSection = 0;<br>
-  bool isFirstSection = true;<br>
   bool isDataPageAlignedForNMagic = false;<br>
   uint64_t startAddr = addr;<br>
   SegmentSlice<ELFT> *slice = nullptr;<br>
@@ -190,144 +189,147 @@ template <class ELFT> void Segment<ELFT><br>
   bool alignSegments = this->_ctx.alignSegments();<br>
   StringRef prevOutputSectionName = StringRef();<br>
<br>
-  for (auto si = _sections.begin(); si != _sections.end(); ++si) {<br>
-    // If this is first section in the segment, page align the section start<br>
-    // address. The linker needs to align the data section to a page boundary<br>
-    // only if NMAGIC is set.<br>
-    if (isFirstSection) {<br>
-      isFirstSection = false;<br>
-      if (alignSegments &&<br>
-          _outputMagic != ELFLinkingContext::OutputMagic::NMAGIC &&<br>
-          _outputMagic != ELFLinkingContext::OutputMagic::OMAGIC)<br>
-        // Align to a page only if the output is not<br>
-        // OutputMagic::NMAGIC/OutputMagic::OMAGIC<br>
-        startAddr =<br>
-            llvm::RoundUpToAlignment(startAddr, this->_ctx.getPageSize());<br>
-      else if (!isDataPageAlignedForNMagic && needAlign(*si)) {<br>
-        // If the linker outputmagic is set to OutputMagic::NMAGIC, align the<br>
-        // Data to a page boundary.<br>
-        startAddr =<br>
-            llvm::RoundUpToAlignment(startAddr, this->_ctx.getPageSize());<br>
-        isDataPageAlignedForNMagic = true;<br>
+  // If this is first section in the segment, page align the section start<br>
+  // address. The linker needs to align the data section to a page boundary<br>
+  // only if NMAGIC is set.<br>
+  auto si = _sections.begin();<br>
+  if (si != _sections.end()) {<br>
+    if (alignSegments &&<br>
+        _outputMagic != ELFLinkingContext::OutputMagic::NMAGIC &&<br>
+        _outputMagic != ELFLinkingContext::OutputMagic::OMAGIC) {<br>
+      // Align to a page only if the output is not<br>
+      // OutputMagic::NMAGIC/OutputMagic::OMAGIC<br>
+      startAddr =<br>
+        llvm::RoundUpToAlignment(startAddr, this->_ctx.getPageSize());<br>
+    } else if (!isDataPageAlignedForNMagic && needAlign(*si)) {<br>
+      // If the linker outputmagic is set to OutputMagic::NMAGIC, align the<br>
+      // Data to a page boundary.<br>
+      startAddr =<br>
+        llvm::RoundUpToAlignment(startAddr, this->_ctx.getPageSize());<br>
+      isDataPageAlignedForNMagic = true;<br>
+    }<br>
+    // align the startOffset to the section alignment<br>
+    uint64_t newAddr =<br>
+      llvm::RoundUpToAlignment(startAddr, (*si)->alignment());<br>
+    // Handle linker script expressions, which *may update newAddr* if the<br>
+    // expression assigns to "."<br>
+    if (auto expr = dyn_cast<ExpressionChunk<ELFT>>(*si))<br>
+      expr->evalExpr(newAddr);<br>
+    curSliceAddress = newAddr;<br>
+    sliceAlign = (*si)->alignment();<br>
+    (*si)->setVirtualAddr(curSliceAddress);<br>
+<br>
+    // Handle TLS.<br>
+    if (auto section = dyn_cast<Section<ELFT>>(*si)) {<br>
+      if (section->getSegmentType() == llvm::ELF::PT_TLS) {<br>
+        tlsStartAddr =<br>
+          llvm::RoundUpToAlignment(tlsStartAddr, (*si)->alignment());<br>
+        section->assignVirtualAddress(tlsStartAddr);<br>
+        tlsStartAddr += (*si)->memSize();<br>
+      } else {<br>
+        section->assignVirtualAddress(newAddr);<br>
+      }<br>
+    }<br>
+    // TBSS section is special in that it doesn't contribute to memory of any<br>
+    // segment. If we see a tbss section, don't add memory size to addr The<br>
+    // fileOffset is automatically taken care of since TBSS section does not<br>
+    // end up using file size<br>
+    if ((*si)->order() != TargetLayout<ELFT>::ORDER_TBSS)<br>
+      curSliceSize = (*si)->memSize();<br>
+    ++currSection;<br>
+    ++si;<br>
+  }<br>
+<br>
+  for (auto e = _sections.end(); si != e; ++si) {<br>
+    uint64_t curAddr = curSliceAddress + curSliceSize;<br>
+    if (!isDataPageAlignedForNMagic && needAlign(*si)) {<br>
+      // If the linker outputmagic is set to OutputMagic::NMAGIC, align the<br>
+      // Data<br>
+      // to a page boundary<br>
+      curAddr = llvm::RoundUpToAlignment(curAddr, this->_ctx.getPageSize());<br>
+      isDataPageAlignedForNMagic = true;<br>
+    }<br>
+    uint64_t newAddr = llvm::RoundUpToAlignment(curAddr, (*si)->alignment());<br>
+    // Handle linker script expressions, which *may update newAddr* if the<br>
+    // expression assigns to "."<br>
+    if (auto expr = dyn_cast<ExpressionChunk<ELFT>>(*si))<br>
+      expr->evalExpr(newAddr);<br>
+    Section<ELFT> *sec = dyn_cast<Section<ELFT>>(*si);<br>
+    StringRef curOutputSectionName;<br>
+    if (sec) {<br>
+      curOutputSectionName = sec->outputSectionName();<br>
+    } else {<br>
+      // If this is a linker script expression, propagate the name of the<br>
+      // previous section instead<br>
+      if (isa<ExpressionChunk<ELFT>>(*si))<br>
+        curOutputSectionName = prevOutputSectionName;<br>
+      else<br>
+        curOutputSectionName = (*si)->name();<br>
+    }<br>
+    bool autoCreateSlice = true;<br>
+    if (curOutputSectionName == prevOutputSectionName)<br>
+      autoCreateSlice = false;<br>
+    // If the newAddress computed is more than a page away, let's create<br>
+    // a separate segment, so that memory is not used up while running.<br>
+    // Dont create a slice, if the new section falls in the same output<br>
+    // section as the previous section.<br>
+    if (autoCreateSlice && ((newAddr - curAddr) > this->_ctx.getPageSize()) &&<br>
+        (_outputMagic != ELFLinkingContext::OutputMagic::NMAGIC &&<br>
+         _outputMagic != ELFLinkingContext::OutputMagic::OMAGIC)) {<br>
+      auto sliceIter =<br>
+        std::find_if(_segmentSlices.begin(), _segmentSlices.end(),<br>
+                     [startSection](SegmentSlice<ELFT> *s) -> bool {<br>
+                       return s->startSection() == startSection;<br>
+                     });<br>
+      if (sliceIter == _segmentSlices.end()) {<br>
+        slice = new (_segmentAllocate.Allocate<SegmentSlice<ELFT>>())<br>
+          SegmentSlice<ELFT>();<br>
+        _segmentSlices.push_back(slice);<br>
+      } else {<br>
+        slice = *sliceIter;<br>
       }<br>
-      // align the startOffset to the section alignment<br>
-      uint64_t newAddr =<br>
-          llvm::RoundUpToAlignment(startAddr, (*si)->alignment());<br>
-      // Handle linker script expressions, which *may update newAddr* if the<br>
-      // expression assigns to "."<br>
-      if (auto expr = dyn_cast<ExpressionChunk<ELFT>>(*si))<br>
-        expr->evalExpr(newAddr);<br>
+      slice->setStart(startSection);<br>
+      slice->setSections(make_range(startSectionIter, si));<br>
+      slice->setMemSize(curSliceSize);<br>
+      slice->setAlign(sliceAlign);<br>
+      slice->setVirtualAddr(curSliceAddress);<br>
+      // Start new slice<br>
       curSliceAddress = newAddr;<br>
-      sliceAlign = (*si)->alignment();<br>
       (*si)->setVirtualAddr(curSliceAddress);<br>
-<br>
+      startSectionIter = si;<br>
+      startSection = currSection;<br>
+      if (auto section = dyn_cast<Section<ELFT>>(*si))<br>
+        section->assignVirtualAddress(newAddr);<br>
+      curSliceSize = newAddr - curSliceAddress + (*si)->memSize();<br>
+      sliceAlign = (*si)->alignment();<br>
+    } else {<br>
+      if (sliceAlign < (*si)->alignment())<br>
+        sliceAlign = (*si)->alignment();<br>
+      (*si)->setVirtualAddr(newAddr);<br>
       // Handle TLS.<br>
       if (auto section = dyn_cast<Section<ELFT>>(*si)) {<br>
         if (section->getSegmentType() == llvm::ELF::PT_TLS) {<br>
           tlsStartAddr =<br>
-              llvm::RoundUpToAlignment(tlsStartAddr, (*si)->alignment());<br>
+            llvm::RoundUpToAlignment(tlsStartAddr, (*si)->alignment());<br>
           section->assignVirtualAddress(tlsStartAddr);<br>
           tlsStartAddr += (*si)->memSize();<br>
         } else {<br>
           section->assignVirtualAddress(newAddr);<br>
         }<br>
       }<br>
-      // TBSS section is special in that it doesn't contribute to memory of any<br>
-      // segment. If we see a tbss section, don't add memory size to addr The<br>
-      // fileOffset is automatically taken care of since TBSS section does not<br>
-      // end up using file size<br>
+      // TBSS section is special in that it doesn't contribute to memory of<br>
+      // any segment. If we see a tbss section, don't add memory size to addr<br>
+      // The fileOffset is automatically taken care of since TBSS section does<br>
+      // not end up using file size.<br>
       if ((*si)->order() != TargetLayout<ELFT>::ORDER_TBSS)<br>
-        curSliceSize = (*si)->memSize();<br>
-    } else {<br>
-      uint64_t curAddr = curSliceAddress + curSliceSize;<br>
-      if (!isDataPageAlignedForNMagic && needAlign(*si)) {<br>
-        // If the linker outputmagic is set to OutputMagic::NMAGIC, align the<br>
-        // Data<br>
-        // to a page boundary<br>
-        curAddr = llvm::RoundUpToAlignment(curAddr, this->_ctx.getPageSize());<br>
-        isDataPageAlignedForNMagic = true;<br>
-      }<br>
-      uint64_t newAddr = llvm::RoundUpToAlignment(curAddr, (*si)->alignment());<br>
-      // Handle linker script expressions, which *may update newAddr* if the<br>
-      // expression assigns to "."<br>
-      if (auto expr = dyn_cast<ExpressionChunk<ELFT>>(*si))<br>
-        expr->evalExpr(newAddr);<br>
-      Section<ELFT> *sec = dyn_cast<Section<ELFT>>(*si);<br>
-      StringRef curOutputSectionName;<br>
-      if (sec)<br>
-        curOutputSectionName = sec->outputSectionName();<br>
-      else {<br>
-        // If this is a linker script expression, propagate the name of the<br>
-        // previous section instead<br>
-        if (isa<ExpressionChunk<ELFT>>(*si))<br>
-          curOutputSectionName = prevOutputSectionName;<br>
-        else<br>
-          curOutputSectionName = (*si)->name();<br>
-      }<br>
-      bool autoCreateSlice = true;<br>
-      if (curOutputSectionName == prevOutputSectionName)<br>
-        autoCreateSlice = false;<br>
-      // If the newAddress computed is more than a page away, let's create<br>
-      // a separate segment, so that memory is not used up while running.<br>
-      // Dont create a slice, if the new section falls in the same output<br>
-      // section as the previous section.<br>
-      if (autoCreateSlice && ((newAddr - curAddr) > this->_ctx.getPageSize()) &&<br>
-          (_outputMagic != ELFLinkingContext::OutputMagic::NMAGIC &&<br>
-           _outputMagic != ELFLinkingContext::OutputMagic::OMAGIC)) {<br>
-        auto sliceIter =<br>
-            std::find_if(_segmentSlices.begin(), _segmentSlices.end(),<br>
-                         [startSection](SegmentSlice<ELFT> *s) -> bool {<br>
-                           return s->startSection() == startSection;<br>
-                         });<br>
-        if (sliceIter == _segmentSlices.end()) {<br>
-          slice = new (_segmentAllocate.Allocate<SegmentSlice<ELFT>>())<br>
-              SegmentSlice<ELFT>();<br>
-          _segmentSlices.push_back(slice);<br>
-        } else {<br>
-          slice = (*sliceIter);<br>
-        }<br>
-        slice->setStart(startSection);<br>
-        slice->setSections(make_range(startSectionIter, si));<br>
-        slice->setMemSize(curSliceSize);<br>
-        slice->setAlign(sliceAlign);<br>
-        slice->setVirtualAddr(curSliceAddress);<br>
-        // Start new slice<br>
-        curSliceAddress = newAddr;<br>
-        (*si)->setVirtualAddr(curSliceAddress);<br>
-        startSectionIter = si;<br>
-        startSection = currSection;<br>
-        if (auto section = dyn_cast<Section<ELFT>>(*si))<br>
-          section->assignVirtualAddress(newAddr);<br>
         curSliceSize = newAddr - curSliceAddress + (*si)->memSize();<br>
-        sliceAlign = (*si)->alignment();<br>
-      } else {<br>
-        if (sliceAlign < (*si)->alignment())<br>
-          sliceAlign = (*si)->alignment();<br>
-        (*si)->setVirtualAddr(newAddr);<br>
-        // Handle TLS.<br>
-        if (auto section = dyn_cast<Section<ELFT>>(*si)) {<br>
-          if (section->getSegmentType() == llvm::ELF::PT_TLS) {<br>
-            tlsStartAddr =<br>
-                llvm::RoundUpToAlignment(tlsStartAddr, (*si)->alignment());<br>
-            section->assignVirtualAddress(tlsStartAddr);<br>
-            tlsStartAddr += (*si)->memSize();<br>
-          } else {<br>
-            section->assignVirtualAddress(newAddr);<br>
-          }<br>
-        }<br>
-        // TBSS section is special in that it doesn't contribute to memory of<br>
-        // any segment. If we see a tbss section, don't add memory size to addr<br>
-        // The fileOffset is automatically taken care of since TBSS section does<br>
-        // not end up using file size.<br>
-        if ((*si)->order() != TargetLayout<ELFT>::ORDER_TBSS)<br>
-          curSliceSize = newAddr - curSliceAddress + (*si)->memSize();<br>
-        else<br>
-          curSliceSize = newAddr - curSliceAddress;<br>
-      }<br>
-      prevOutputSectionName = curOutputSectionName;<br>
+      else<br>
+        curSliceSize = newAddr - curSliceAddress;<br>
     }<br>
-    currSection++;<br>
+    prevOutputSectionName = curOutputSectionName;<br>
+    ++currSection;<br>
   }<br>
+<br>
   auto sliceIter = std::find_if(_segmentSlices.begin(), _segmentSlices.end(),<br>
                                 [startSection](SegmentSlice<ELFT> *s) -> bool {<br>
                                   return s->startSection() == startSection;<br>
@@ -337,8 +339,9 @@ template <class ELFT> void Segment<ELFT><br>
         SegmentSlice<ELFT>();<br>
     _segmentSlices.push_back(slice);<br>
   } else {<br>
-    slice = (*sliceIter);<br>
+    slice = *sliceIter;<br>
   }<br>
+<br>
   slice->setStart(startSection);<br>
   slice->setVirtualAddr(curSliceAddress);<br>
   slice->setMemSize(curSliceSize);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>