Follow up on D138653.
Differential Revision: https://reviews.llvm.org/D138686
// Set section alignment to at least maximum possible object alignment.
// We need this to support LongJmp and other passes that calculates
// tentative layout.
- if (Section->getAlign() < opts::AlignFunctions)
- Section->setAlignment(Align(opts::AlignFunctions));
+ Section->ensureMinAlignment(Align(opts::AlignFunctions));
Streamer.emitCodeAlignment(Align(BinaryFunction::MinAlign), &*BC.STI);
uint16_t MaxAlignBytes = FF.isSplitFragment()
Align getAlign() const { return Alignment; }
void setAlignment(Align Value) { Alignment = Value; }
+ /// Makes sure that Alignment is at least MinAlignment.
+ void ensureMinAlignment(Align MinAlignment) {
+ if (Alignment < MinAlignment)
+ Alignment = MinAlignment;
+ }
+
unsigned getOrdinal() const { return Ordinal; }
void setOrdinal(unsigned Value) { Ordinal = Value; }
// needs to be aligned to at least the bundle size.
static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
MCSection *Section) {
- if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions() &&
- Section->getAlign() < Assembler.getBundleAlignSize())
- Section->setAlignment(Align(Assembler.getBundleAlignSize()));
+ if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions())
+ Section->ensureMinAlignment(Align(Assembler.getBundleAlignSize()));
}
void MCELFStreamer::changeSection(MCSection *Section,
// Update the maximum alignment on the current section if necessary.
MCSection *CurSec = getCurrentSectionOnly();
- if (CurSec->getAlign() < Alignment)
- CurSec->setAlignment(Alignment);
+ CurSec->ensureMinAlignment(Alignment);
}
void MCObjectStreamer::emitCodeAlignment(Align Alignment,
MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection();
getAssembler().registerSection(*SXData);
- if (SXData->getAlign() < 4)
- SXData->setAlignment(Align(4));
+ SXData->ensureMinAlignment(Align(4));
new MCSymbolIdFragment(Symbol, SXData);
void MCWinCOFFStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) {
MCSection *Sec = getCurrentSectionOnly();
getAssembler().registerSection(*Sec);
- if (Sec->getAlign() < 4)
- Sec->setAlignment(Align(4));
+ Sec->ensureMinAlignment(Align(4));
new MCSymbolIdFragment(Symbol, getCurrentSectionOnly());
// CP microcode requires the kernel descriptor to be allocated on 64 byte
// alignment.
Streamer.emitValueToAlignment(Align(64), 0, 1, 0);
- if (ReadOnlySection.getAlign() < 64)
- ReadOnlySection.setAlignment(Align(64));
+ ReadOnlySection.ensureMinAlignment(Align(64));
const GCNSubtarget &STM = MF->getSubtarget<GCNSubtarget>();
}
// Update the maximum alignment of the section if necessary.
- if (Section.getAlign() < ByteAlignment)
- Section.setAlignment(Align(ByteAlignment));
+ Section.ensureMinAlignment(Align(ByteAlignment));
switchSection(P.first, P.second);
} else {
MCSection &BSSSection = *OFI.getBSSSection();
MCA.registerSection(BSSSection);
- TextSection.setAlignment(std::max(Align(16), TextSection.getAlign()));
- DataSection.setAlignment(std::max(Align(16), DataSection.getAlign()));
- BSSSection.setAlignment(std::max(Align(16), BSSSection.getAlign()));
+ TextSection.ensureMinAlignment(Align(16));
+ DataSection.ensureMinAlignment(Align(16));
+ BSSSection.ensureMinAlignment(Align(16));
if (RoundSectionSizes) {
// Make sections sizes a multiple of the alignment. This is useful for
getObjFileLowering().SectionForGlobal(GO, GOKind, TM));
Align GOAlign = getGVAlignment(GO, GO->getParent()->getDataLayout());
- if (GOAlign > Csect->getAlign())
- Csect->setAlignment(GOAlign);
+ Csect->ensureMinAlignment(GOAlign);
};
// We need to know, up front, the alignment of csects for the assembly path,
// Update the maximum alignment on the current section if necessary.
MCSection *Sec = OS.getCurrentSectionOnly();
- if (Sec->getAlign() < AlignBoundary)
- Sec->setAlignment(AlignBoundary);
+ Sec->ensureMinAlignment(AlignBoundary);
}
Optional<MCFixupKind> X86AsmBackend::getFixupKind(StringRef Name) const {