MC: Tweak section layout to not relying on accumulating address value.

llvm-svn: 103648
This commit is contained in:
Daniel Dunbar 2010-05-12 21:35:22 +00:00
parent 959ae59997
commit 2abec791f1
1 changed files with 13 additions and 7 deletions

View File

@ -396,10 +396,15 @@ void MCAssembler::LayoutSection(MCAsmLayout &Layout,
// Set the aligned section address.
Layout.setSectionAddress(&SD, StartAddress);
uint64_t Address = StartAddress;
for (MCSectionData::iterator it = SD.begin(), ie = SD.end(); it != ie; ++it) {
MCFragment &F = *it;
// Compute the fragment start address.
uint64_t Address = StartAddress;
if (MCFragment *Prev = F.getPrevNode())
Address = (Layout.getFragmentAddress(Prev) +
Layout.getFragmentEffectiveSize(Prev));
++stats::FragmentLayouts;
uint64_t FragmentOffset = Address - StartAddress;
@ -464,15 +469,16 @@ void MCAssembler::LayoutSection(MCAsmLayout &Layout,
}
Layout.setFragmentEffectiveSize(&F, EffectiveSize);
Address += EffectiveSize;
}
// Set the section sizes.
Layout.setSectionSize(&SD, Address - StartAddress);
if (IsVirtual)
Layout.setSectionFileSize(&SD, 0);
else
Layout.setSectionFileSize(&SD, Address - StartAddress);
uint64_t Size = 0;
if (!SD.getFragmentList().empty()) {
MCFragment *F = &SD.getFragmentList().back();
Size = Layout.getFragmentOffset(F) + Layout.getFragmentEffectiveSize(F);
}
Layout.setSectionSize(&SD, Size);
Layout.setSectionFileSize(&SD, IsVirtual ? 0 : Size);
}
/// WriteFragmentData - Write the \arg F data to the output file.