void MCAssembler::AddSectionToTheEnd(MCSectionData &SD, MCAsmLayout &Layout) { // Create dummy fragments and assign section ordinals. unsigned SectionIndex = 0; for (MCAssembler::iterator it = begin(), ie = end(); it != ie; ++it) SectionIndex++; SD.setOrdinal(SectionIndex); // Assign layout order indices to sections and fragments. unsigned FragmentIndex = 0; unsigned i = 0; for (unsigned e = Layout.getSectionOrder().size(); i != e; ++i) { MCSectionData *SD = Layout.getSectionOrder()[i]; for (MCSectionData::iterator it2 = SD->begin(), ie2 = SD->end(); it2 != ie2; ++it2) FragmentIndex++; } SD.setLayoutOrder(i); for (MCSectionData::iterator it2 = SD.begin(), ie2 = SD.end(); it2 != ie2; ++it2) { it2->setLayoutOrder(FragmentIndex++); } Layout.getSectionOrder().push_back(&SD); Layout.LayoutSection(&SD); // Layout until everything fits. while (LayoutOnce(Layout)) continue; }
uint64_t MachObjectWriter::getPaddingSize(const MCSection *Sec, const MCAsmLayout &Layout) const { uint64_t EndAddr = getSectionAddress(Sec) + Layout.getSectionAddressSize(Sec); unsigned Next = Sec->getLayoutOrder() + 1; if (Next >= Layout.getSectionOrder().size()) return 0; const MCSection &NextSec = *Layout.getSectionOrder()[Next]; if (NextSec.isVirtualSection()) return 0; return OffsetToAlignment(EndAddr, NextSec.getAlignment()); }
void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm, const MCAsmLayout &Layout) { uint64_t StartAddress = 0; for (const MCSection *Sec : Layout.getSectionOrder()) { StartAddress = alignTo(StartAddress, Sec->getAlignment()); SectionAddress[Sec] = StartAddress; StartAddress += Layout.getSectionAddressSize(Sec); // Explicitly pad the section to match the alignment requirements of the // following one. This is for 'gas' compatibility, it shouldn't /// strictly be necessary. StartAddress += getPaddingSize(Sec, Layout); } }
void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm, const MCAsmLayout &Layout) { uint64_t StartAddress = 0; const SmallVectorImpl<MCSectionData*> &Order = Layout.getSectionOrder(); for (int i = 0, n = Order.size(); i != n ; ++i) { const MCSectionData *SD = Order[i]; StartAddress = RoundUpToAlignment(StartAddress, SD->getAlignment()); SectionAddress[SD] = StartAddress; StartAddress += Layout.getSectionAddressSize(SD); // Explicitly pad the section to match the alignment requirements of the // following one. This is for 'gas' compatibility, it shouldn't /// strictly be necessary. StartAddress += getPaddingSize(SD, Layout); } }