[PATCH] D10951: [LinkerScript] Fix bug in Segment::assignVirtualAddress()

Rafael Auler rafaelauler at gmail.com
Sun Jul 5 22:35:58 PDT 2015


rafaelauler created this revision.
rafaelauler added reviewers: shankar.easwaran, denis-protivensky.
rafaelauler added a subscriber: llvm-commits.

When calculating the start address and size of a segment, lld mistakenly
attributes 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 will be tested in my next patch.

http://reviews.llvm.org/D10951

Files:
  lib/ReaderWriter/ELF/SegmentChunks.cpp

Index: lib/ReaderWriter/ELF/SegmentChunks.cpp
===================================================================
--- lib/ReaderWriter/ELF/SegmentChunks.cpp
+++ lib/ReaderWriter/ELF/SegmentChunks.cpp
@@ -362,7 +362,7 @@
 
   // 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);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10951.29062.patch
Type: text/x-patch
Size: 550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150706/fa816be8/attachment.bin>


More information about the llvm-commits mailing list