[lld] r242089 - [LinkerScript] Fix bug in Segment::assignVirtualAddress()

Rafael Auler rafaelauler at gmail.com
Mon Jul 13 16:52:58 PDT 2015


Author: rafauler
Date: Mon Jul 13 18:52:58 2015
New Revision: 242089

URL: http://llvm.org/viewvc/llvm-project?rev=242089&view=rev
Log:
[LinkerScript] Fix bug in Segment::assignVirtualAddress()

When calculating the start address and size of a segment, lld mistakenly
attributed the start address of the last segment slice to the whole segment
when it should consider the start address of the first slice. In this case, in a
multi-slice segment, Segment::assignVirtualAddress() will return a wrong
segment start address to TargetLayout::assignVirtualAddress(). The effect of
this miscalculation is to allocate some program headers in unnecessarily far
away addresses. This commit fixes this.

Differential Revision: http://reviews.llvm.org/D10951

Modified:
    lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp

Modified: lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp?rev=242089&r1=242088&r2=242089&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.cpp Mon Jul 13 18:52:58 2015
@@ -362,7 +362,7 @@ template <class ELFT> void Segment<ELFT>
 
   // Set the segment memory size and the virtual address.
   this->setMemSize(curSliceAddress - startAddr + curSliceSize);
-  this->setVirtualAddr(curSliceAddress);
+  this->setVirtualAddr(startAddr);
   std::stable_sort(_segmentSlices.begin(), _segmentSlices.end(),
                    SegmentSlice<ELFT>::compare_slices);
 }





More information about the llvm-commits mailing list