uint64_t MachObjectWriter::getPaddingSize(const MCSection *Sec,
const MCAsmLayout &Layout) const {
- uint64_t EndAddr = getSectionAddress(Sec) +
- Layout.getSectionAddressSize(&Sec->getSectionData());
+ uint64_t EndAddr = getSectionAddress(Sec) + Layout.getSectionAddressSize(Sec);
unsigned Next = Sec->getLayoutOrder() + 1;
if (Next >= Layout.getSectionOrder().size())
return 0;
- const MCSectionData &NextSD = *Layout.getSectionOrder()[Next];
- if (NextSD.getSection().isVirtualSection())
+ const MCSection &NextSec = *Layout.getSectionOrder()[Next];
+ if (NextSec.isVirtualSection())
return 0;
- return OffsetToAlignment(EndAddr, NextSD.getSection().getAlignment());
+ return OffsetToAlignment(EndAddr, NextSec.getAlignment());
}
void MachObjectWriter::WriteHeader(unsigned NumLoadCommands,
const MCSection &Sec, uint64_t FileOffset,
uint64_t RelocationsStart,
unsigned NumRelocations) {
- const MCSectionData &SD = Sec.getSectionData();
- uint64_t SectionSize = Layout.getSectionAddressSize(&SD);
+ uint64_t SectionSize = Layout.getSectionAddressSize(&Sec);
const MCSectionMachO &Section = cast<MCSectionMachO>(Sec);
// The offset is unused for virtual sections.
if (Section.isVirtualSection()) {
- assert(Layout.getSectionFileSize(&SD) == 0 && "Invalid file size!");
+ assert(Layout.getSectionFileSize(&Sec) == 0 && "Invalid file size!");
FileOffset = 0;
}
WriteBytes(Section.getSectionName(), 16);
WriteBytes(Section.getSegmentName(), 16);
if (is64Bit()) {
- Write64(getSectionAddress(&SD.getSection())); // address
+ Write64(getSectionAddress(&Sec)); // address
Write64(SectionSize); // size
} else {
- Write32(getSectionAddress(&SD.getSection())); // address
+ Write32(getSectionAddress(&Sec)); // address
Write32(SectionSize); // size
}
Write32(FileOffset);
Write32(NumRelocations ? RelocationsStart : 0);
Write32(NumRelocations);
Write32(Flags);
- Write32(IndirectSymBase.lookup(&SD.getSection())); // reserved1
+ Write32(IndirectSymBase.lookup(&Sec)); // reserved1
Write32(Section.getStubSize()); // reserved2
if (is64Bit())
Write32(0); // reserved3
Address = AliaseeInfo->StringIndex;
else if (Symbol->isDefined())
Address = getSymbolAddress(OrigSymbol, Layout);
- else if (Data.isCommon()) {
+ else if (Symbol->isCommon()) {
// Common symbols are encoded with the size in the address
// field, and their alignment in the flags.
- Address = Data.getCommonSize();
+ Address = Symbol->getCommonSize();
// Common alignment is packed into the 'desc' bits.
- if (unsigned Align = Data.getCommonAlignment()) {
+ if (unsigned Align = Symbol->getCommonAlignment()) {
unsigned Log2Size = Log2_32(Align);
assert((1U << Log2Size) == Align && "Invalid 'common' alignment!");
if (Log2Size > 15)
// or stub section.
for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
ie = Asm.indirect_symbol_end(); it != ie; ++it) {
- const MCSectionMachO &Section =
- cast<MCSectionMachO>(it->SectionData->getSection());
+ const MCSectionMachO &Section = cast<MCSectionMachO>(*it->Section);
if (Section.getType() != MachO::S_NON_LAZY_SYMBOL_POINTERS &&
Section.getType() != MachO::S_LAZY_SYMBOL_POINTERS &&
unsigned IndirectIndex = 0;
for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
ie = Asm.indirect_symbol_end(); it != ie; ++it, ++IndirectIndex) {
- const MCSectionMachO &Section =
- cast<MCSectionMachO>(it->SectionData->getSection());
+ const MCSectionMachO &Section = cast<MCSectionMachO>(*it->Section);
if (Section.getType() != MachO::S_NON_LAZY_SYMBOL_POINTERS)
continue;
// Initialize the section indirect symbol base, if necessary.
- IndirectSymBase.insert(
- std::make_pair(&it->SectionData->getSection(), IndirectIndex));
+ IndirectSymBase.insert(std::make_pair(it->Section, IndirectIndex));
Asm.getOrCreateSymbolData(*it->Symbol);
}
IndirectIndex = 0;
for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
ie = Asm.indirect_symbol_end(); it != ie; ++it, ++IndirectIndex) {
- const MCSectionMachO &Section =
- cast<MCSectionMachO>(it->SectionData->getSection());
+ const MCSectionMachO &Section = cast<MCSectionMachO>(*it->Section);
if (Section.getType() != MachO::S_LAZY_SYMBOL_POINTERS &&
Section.getType() != MachO::S_SYMBOL_STUBS)
continue;
// Initialize the section indirect symbol base, if necessary.
- IndirectSymBase.insert(
- std::make_pair(&it->SectionData->getSection(), IndirectIndex));
+ IndirectSymBase.insert(std::make_pair(it->Section, IndirectIndex));
// Set the symbol type to undefined lazy, but only on construction.
//
void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm,
const MCAsmLayout &Layout) {
uint64_t StartAddress = 0;
- const SmallVectorImpl<MCSectionData*> &Order = Layout.getSectionOrder();
+ const SmallVectorImpl<MCSection *> &Order = Layout.getSectionOrder();
for (int i = 0, n = Order.size(); i != n ; ++i) {
- const MCSectionData *SD = Order[i];
- StartAddress =
- RoundUpToAlignment(StartAddress, SD->getSection().getAlignment());
- SectionAddress[&SD->getSection()] = StartAddress;
- StartAddress += Layout.getSectionAddressSize(SD);
+ const MCSection *Sec = Order[i];
+ StartAddress = RoundUpToAlignment(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(&SD->getSection(), Layout);
+ StartAddress += getPaddingSize(Sec, Layout);
}
}
if (!hasReliableSymbolDifference) {
if (!SA.isInSection() || &SecA != &SecB ||
(!SA.isTemporary() &&
- FB.getAtom() != Asm.getSymbolData(SA).getFragment()->getAtom() &&
+ FB.getAtom() != SA.getData().getFragment()->getAtom() &&
Asm.getSubsectionsViaSymbols()))
return false;
return true;
if (&SecA != &SecB)
return false;
- const MCFragment *FA = Asm.getSymbolData(SA).getFragment();
+ const MCFragment *FA = SA.getData().getFragment();
// Bail if the symbol has no fragment.
if (!FA)
uint64_t VMSize = 0;
for (MCAssembler::const_iterator it = Asm.begin(),
ie = Asm.end(); it != ie; ++it) {
- const MCSectionData &SD = it->getSectionData();
- uint64_t Address = getSectionAddress(&*it);
- uint64_t Size = Layout.getSectionAddressSize(&SD);
- uint64_t FileSize = Layout.getSectionFileSize(&SD);
- FileSize += getPaddingSize(&*it, Layout);
+ const MCSection &Sec = *it;
+ uint64_t Address = getSectionAddress(&Sec);
+ uint64_t Size = Layout.getSectionAddressSize(&Sec);
+ uint64_t FileSize = Layout.getSectionFileSize(&Sec);
+ FileSize += getPaddingSize(&Sec, Layout);
VMSize = std::max(VMSize, Address + Size);
- if (SD.getSection().isVirtualSection())
+ if (it->isVirtualSection())
continue;
SectionDataSize = std::max(SectionDataSize, Address + Size);
// Write the actual section data.
for (MCAssembler::const_iterator it = Asm.begin(),
ie = Asm.end(); it != ie; ++it) {
- const MCSectionData &SD = it->getSectionData();
- Asm.writeSectionData(&SD, Layout);
+ MCSection &Sec = *it;
+ Asm.writeSectionData(&Sec, Layout);
- uint64_t Pad = getPaddingSize(&*it, Layout);
+ uint64_t Pad = getPaddingSize(&Sec, Layout);
WriteZeros(Pad);
}
// Indirect symbols in the non-lazy symbol pointer section have some
// special handling.
const MCSectionMachO &Section =
- static_cast<const MCSectionMachO&>(it->SectionData->getSection());
+ static_cast<const MCSectionMachO &>(*it->Section);
if (Section.getType() == MachO::S_NON_LAZY_SYMBOL_POINTERS) {
// If this symbol is defined and internal, mark it as such.
- if (it->Symbol->isDefined() &&
- !Asm.getSymbolData(*it->Symbol).isExternal()) {
+ if (it->Symbol->isDefined() && !it->Symbol->getData().isExternal()) {
uint32_t Flags = MachO::INDIRECT_SYMBOL_LOCAL;
if (it->Symbol->isAbsolute())
Flags |= MachO::INDIRECT_SYMBOL_ABS;