本文整理汇总了C++中MCSection类的典型用法代码示例。如果您正苦于以下问题:C++ MCSection类的具体用法?C++ MCSection怎么用?C++ MCSection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MCSection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getContext
void MCWinCOFFStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) {
// SafeSEH is a feature specific to 32-bit x86. It does not exist (and is
// unnecessary) on all platforms which use table-based exception dispatch.
if (getContext().getObjectFileInfo()->getTargetTriple().getArch() !=
Triple::x86)
return;
const MCSymbolCOFF *CSymbol = cast<MCSymbolCOFF>(Symbol);
if (CSymbol->isSafeSEH())
return;
MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection();
getAssembler().registerSection(*SXData);
if (SXData->getAlignment() < 4)
SXData->setAlignment(4);
new MCSafeSEHFragment(Symbol, SXData);
getAssembler().registerSymbol(*Symbol);
CSymbol->setIsSafeSEH();
// The Microsoft linker requires that the symbol type of a handler be
// function. Go ahead and oblige it here.
CSymbol->setType(COFF::IMAGE_SYM_DTYPE_FUNCTION
<< COFF::SCT_COMPLEX_TYPE_SHIFT);
}
示例2: registerSection
bool MCAssembler::registerSection(MCSection &Section) {
if (Section.isRegistered())
return false;
Sections.push_back(&Section);
Section.setIsRegistered(true);
return true;
}
示例3: getCurrentSectionOnly
void MCObjectStreamer::EmitBytes(StringRef Data) {
MCDwarfLineEntry::Make(this, getCurrentSectionOnly());
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
DF->getContents().append(Data.begin(), Data.end());
// EmitBytes might not cover all possible ways we emit data (or could be used
// to emit executable code in some cases), but is the best method we have
// right now for checking this.
MCSection *Sec = getCurrentSectionOnly();
Sec->setHasData(true);
}
示例4: insert
void MCObjectStreamer::EmitValueToAlignment(unsigned ByteAlignment,
int64_t Value,
unsigned ValueSize,
unsigned MaxBytesToEmit) {
if (MaxBytesToEmit == 0)
MaxBytesToEmit = ByteAlignment;
insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
// Update the maximum alignment on the current section if necessary.
MCSection *CurSec = getCurrentSection().first;
if (ByteAlignment > CurSec->getAlignment())
CurSec->setAlignment(ByteAlignment);
}
示例5: ensureValid
void MCAsmLayout::ensureValid(const MCFragment *F) const {
MCSection *Sec = F->getParent();
MCSection::iterator I;
if (MCFragment *Cur = LastValidFragment[Sec])
I = ++MCSection::iterator(Cur);
else
I = Sec->begin();
// Advance the layout position until the fragment is valid.
while (!isFragmentValid(F)) {
assert(I != Sec->end() && "Layout bookkeeping error");
const_cast<MCAsmLayout *>(this)->layoutFragment(&*I);
++I;
}
}
示例6: MCDataFragment
void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) {
if (PendingLabels.empty())
return;
if (!F) {
F = new MCDataFragment();
MCSection *CurSection = getCurrentSectionOnly();
CurSection->getFragmentList().insert(CurInsertionPoint, F);
F->setParent(CurSection);
}
for (MCSymbol *Sym : PendingLabels) {
Sym->setFragment(F);
Sym->setOffset(FOffset);
}
PendingLabels.clear();
}
示例7: getContext
void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
unsigned ByteAlignment) {
auto *Symbol = cast<MCSymbolCOFF>(S);
MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
getAssembler().registerSection(*Section);
if (Section->getAlignment() < ByteAlignment)
Section->setAlignment(ByteAlignment);
getAssembler().registerSymbol(*Symbol);
Symbol->setExternal(false);
if (ByteAlignment != 1)
new MCAlignFragment(ByteAlignment, /*Value=*/0, /*ValueSize=*/0,
ByteAlignment, Section);
MCFillFragment *Fragment = new MCFillFragment(
/*Value=*/0, Size, Section);
Symbol->setFragment(Fragment);
}
示例8: assert
void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {
assert(!Symbol->isInSection() && "Symbol must not already have a section!");
MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
getAssembler().registerSection(*Section);
if (Section->getAlignment() < ByteAlignment)
Section->setAlignment(ByteAlignment);
getAssembler().registerSymbol(*Symbol);
Symbol->setExternal(false);
if (ByteAlignment != 1)
new MCAlignFragment(ByteAlignment, /*Value=*/0, /*ValueSize=*/0,
ByteAlignment, Section);
MCFillFragment *Fragment = new MCFillFragment(
/*Value=*/0, Size, Section);
Symbol->setFragment(Fragment);
}
示例9: writeSectionData
void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
const MCAsmLayout &Layout) {
MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);
StringRef SectionName = Section.getSectionName();
auto &MC = Asm.getContext();
const auto &MAI = MC.getAsmInfo();
// Compressing debug_frame requires handling alignment fragments which is
// more work (possibly generalizing MCAssembler.cpp:writeFragment to allow
// for writing to arbitrary buffers) for little benefit.
bool CompressionEnabled =
MAI->compressDebugSections() != DebugCompressionType::None;
if (!CompressionEnabled || !SectionName.startswith(".debug_") ||
SectionName == ".debug_frame") {
Asm.writeSectionData(&Section, Layout);
return;
}
assert((MAI->compressDebugSections() == DebugCompressionType::Z ||
MAI->compressDebugSections() == DebugCompressionType::GNU) &&
"expected zlib or zlib-gnu style compression");
SmallVector<char, 128> UncompressedData;
raw_svector_ostream VecOS(UncompressedData);
raw_pwrite_stream &OldStream = getStream();
setStream(VecOS);
Asm.writeSectionData(&Section, Layout);
setStream(OldStream);
SmallVector<char, 128> CompressedContents;
if (Error E = zlib::compress(
StringRef(UncompressedData.data(), UncompressedData.size()),
CompressedContents)) {
consumeError(std::move(E));
getStream() << UncompressedData;
return;
}
bool ZlibStyle = MAI->compressDebugSections() == DebugCompressionType::Z;
if (!maybeWriteCompression(UncompressedData.size(), CompressedContents,
ZlibStyle, Sec.getAlignment())) {
getStream() << UncompressedData;
return;
}
if (ZlibStyle)
// Set the compressed flag. That is zlib style.
Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED);
else
// Add "z" prefix to section name. This is zlib-gnu style.
MC.renameELFSection(&Section, (".z" + SectionName.drop_front(1)).str());
getStream() << CompressedContents;
}
示例10: SwitchSection
extern "C" void SwitchSection(ObjectWriter *OW, const char *SectionName) {
assert(OW && "ObjWriter is null");
auto *AsmPrinter = &OW->getAsmPrinter();
auto &OST = *AsmPrinter->OutStreamer;
MCContext &OutContext = OST.getContext();
const MCObjectFileInfo *MOFI = OutContext.getObjectFileInfo();
MCSection *Section = nullptr;
if (strcmp(SectionName, "text") == 0) {
Section = MOFI->getTextSection();
if (!Section->hasInstructions()) {
Section->setHasInstructions(true);
OutContext.addGenDwarfSection(Section);
}
} else if (strcmp(SectionName, "data") == 0) {
Section = MOFI->getDataSection();
} else if (strcmp(SectionName, "rdata") == 0) {
Section = MOFI->getReadOnlySection();
} else if (strcmp(SectionName, "xdata") == 0) {
Section = MOFI->getXDataSection();
} else {
std::string SectionNameStr(SectionName);
if (OW->CustomSections.find(SectionNameStr) != OW->CustomSections.end()) {
Section = OW->CustomSections[SectionNameStr];
} else {
// Add more general cases
assert(!"Unsupported section");
}
}
OW->Sections.insert(Section);
OST.SwitchSection(Section);
if (!Section->getBeginSymbol()) {
MCSymbol *SectionStartSym = OutContext.createTempSymbol();
OST.EmitLabel(SectionStartSym);
Section->setBeginSymbol(SectionStartSym);
}
}
示例11: switch
/// EmitValue - Emit debug information entry offset.
///
void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
switch (Form) {
case dwarf::DW_FORM_ref1:
case dwarf::DW_FORM_ref2:
case dwarf::DW_FORM_ref4:
case dwarf::DW_FORM_ref8:
AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
return;
case dwarf::DW_FORM_ref_udata:
AP->EmitULEB128(Entry->getOffset());
return;
case dwarf::DW_FORM_ref_addr: {
// Get the absolute offset for this DIE within the debug info/types section.
unsigned Addr = Entry->getDebugSectionOffset();
if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
const DwarfDebug *DD = AP->getDwarfDebug();
if (DD)
assert(!DD->useSplitDwarf() &&
"TODO: dwo files can't have relocations.");
const DIEUnit *Unit = Entry->getUnit();
assert(Unit && "CUDie should belong to a CU.");
MCSection *Section = Unit->getSection();
if (Section) {
const MCSymbol *SectionSym = Section->getBeginSymbol();
AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
return;
}
}
AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
return;
}
default:
llvm_unreachable("Improper form for DIE reference");
}
}
示例12: getCurrentSectionOnly
void MCObjectStreamer::EmitInstruction(const MCInst &Inst,
const MCSubtargetInfo &STI) {
MCStreamer::EmitInstruction(Inst, STI);
MCSection *Sec = getCurrentSectionOnly();
Sec->setHasInstructions(true);
// Now that a machine instruction has been assembled into this section, make
// a line entry for any .loc directive that has been seen.
MCCVLineEntry::Make(this);
MCDwarfLineEntry::Make(this, getCurrentSection().first);
// If this instruction doesn't need relaxation, just emit it as data.
MCAssembler &Assembler = getAssembler();
if (!Assembler.getBackend().mayNeedRelaxation(Inst)) {
EmitInstToData(Inst, STI);
return;
}
// Otherwise, relax and emit it as data if either:
// - The RelaxAll flag was passed
// - Bundling is enabled and this instruction is inside a bundle-locked
// group. We want to emit all such instructions into the same data
// fragment.
if (Assembler.getRelaxAll() ||
(Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
MCInst Relaxed;
getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
while (getAssembler().getBackend().mayNeedRelaxation(Relaxed))
getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
EmitInstToData(Relaxed, STI);
return;
}
// Otherwise emit to a separate fragment.
EmitInstToFragment(Inst, STI);
}
示例13: Section
MCSectionData::MCSectionData(const MCSection &_Section, MCAssembler *A)
: Section(&_Section),
Ordinal(~UINT32_C(0)),
Alignment(1),
BundleLockState(NotBundleLocked), BundleGroupBeforeFirstInst(false),
HasInstructions(false)
{
// @LOCALMOD-BEGIN
if (A) {
// Necessary for IRT building because the IRT loader expects the end of
// the section to be bundle-aligned. Padding happens with 0's though,
// so it's not really ideal. TODO(dschuff) figure out how to do it right.
A->getSectionList().push_back(this);
if (A->isBundlingEnabled() && _Section.UseCodeAlign())
setAlignment(A->getBundleAlignSize());
}
// @LOCALMOD-END
}
示例14: emitSwiftAST
/// Emit the swift_ast section stored in \p Buffers.
void DwarfStreamer::emitSwiftAST(StringRef Buffer) {
MCSection *SwiftASTSection = MOFI->getDwarfSwiftASTSection();
SwiftASTSection->setAlignment(1 << 5);
MS->SwitchSection(SwiftASTSection);
MS->EmitBytes(Buffer);
}
示例15: CreateCustomSection
extern "C" bool CreateCustomSection(ObjectWriter *OW, const char *SectionName,
CustomSectionAttributes attributes,
const char *ComdatName) {
assert(OW && "ObjWriter is null");
Triple TheTriple(TripleName);
auto *AsmPrinter = &OW->getAsmPrinter();
auto &OST = *AsmPrinter->OutStreamer;
MCContext &OutContext = OST.getContext();
std::string SectionNameStr(SectionName);
assert(OW->CustomSections.find(SectionNameStr) == OW->CustomSections.end() &&
"Section with duplicate name already exists");
assert(ComdatName == nullptr ||
OW->MOFI->getObjectFileType() == OW->MOFI->IsCOFF);
MCSection *Section = nullptr;
SectionKind Kind = (attributes & CustomSectionAttributes_Executable)
? SectionKind::getText()
: (attributes & CustomSectionAttributes_Writeable)
? SectionKind::getData()
: SectionKind::getReadOnly();
switch (TheTriple.getObjectFormat()) {
case Triple::MachO: {
unsigned typeAndAttributes = 0;
if (attributes & CustomSectionAttributes_MachO_Init_Func_Pointers) {
typeAndAttributes |= MachO::SectionType::S_MOD_INIT_FUNC_POINTERS;
}
Section = OutContext.getMachOSection(
(attributes & CustomSectionAttributes_Executable) ? "__TEXT" : "__DATA",
SectionName, typeAndAttributes, Kind);
break;
}
case Triple::COFF: {
unsigned Characteristics = COFF::IMAGE_SCN_MEM_READ;
if (attributes & CustomSectionAttributes_Executable) {
Characteristics |= COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE;
} else if (attributes & CustomSectionAttributes_Writeable) {
Characteristics |=
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_WRITE;
} else {
Characteristics |= COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
}
if (ComdatName != nullptr) {
Section = OutContext.getCOFFSection(
SectionName, Characteristics | COFF::IMAGE_SCN_LNK_COMDAT, Kind,
ComdatName, COFF::COMDATType::IMAGE_COMDAT_SELECT_ANY);
} else {
Section = OutContext.getCOFFSection(SectionName, Characteristics, Kind);
}
break;
}
case Triple::ELF: {
unsigned Flags = ELF::SHF_ALLOC;
if (attributes & CustomSectionAttributes_Executable) {
Flags |= ELF::SHF_EXECINSTR;
} else if (attributes & CustomSectionAttributes_Writeable) {
Flags |= ELF::SHF_WRITE;
}
Section = OutContext.getELFSection(SectionName, ELF::SHT_PROGBITS, Flags);
break;
}
default:
return error("Unknown output format for target " + TripleName);
break;
}
if (attributes & CustomSectionAttributes_Executable) {
Section->setHasInstructions(true);
OutContext.addGenDwarfSection(Section);
}
OW->CustomSections[SectionNameStr] = Section;
return true;
}