56 bool DWARFMustBeAtTheEnd;
57 bool CreatedADWARFSection;
67 void emitDataRegionEnd();
70 MCMachOStreamer(
MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
71 std::unique_ptr<MCObjectWriter> OW,
72 std::unique_ptr<MCCodeEmitter>
Emitter,
73 bool DWARFMustBeAtTheEnd,
bool label)
76 LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd),
77 CreatedADWARFSection(
false) {}
80 void reset()
override {
81 CreatedADWARFSection =
false;
82 HasSectionLabel.
clear();
92 void emitEHSymAttributes(
const MCSymbol *Symbol,
MCSymbol *EHSymbol)
override;
98 void emitBuildVersion(
unsigned Platform,
unsigned Major,
unsigned Minor,
100 void emitDarwinTargetVariantBuildVersion(
unsigned Platform,
unsigned Major,
101 unsigned Minor,
unsigned Update,
103 void emitThumbFunc(
MCSymbol *Func)
override;
105 void emitSymbolDesc(
MCSymbol *Symbol,
unsigned DescValue)
override;
107 Align ByteAlignment)
override;
110 Align ByteAlignment)
override;
117 void emitIdent(
StringRef IdentString)
override {
122 getAssembler().getLOHContainer().addDirective(Kind, Args);
127 getAssembler().CGProfile.push_back({
From, To, Count});
130 void finishImpl()
override;
133 void finalizeCGProfile();
134 void createAddrSigSection();
145 if (SegName ==
"__LD" && SecName ==
"__compact_unwind")
148 if (SegName ==
"__IMPORT") {
149 if (SecName ==
"__jump_table")
152 if (SecName ==
"__pointers")
156 if (SegName ==
"__TEXT" && SecName ==
"__eh_frame")
159 if (SegName ==
"__DATA" && (SecName ==
"__nl_symbol_ptr" ||
160 SecName ==
"__thread_ptr"))
162 if (SegName ==
"__LLVM" && SecName ==
"__cg_profile")
167void MCMachOStreamer::changeSection(
MCSection *Section,
168 const MCExpr *Subsection) {
170 bool Created = changeSectionImpl(Section, Subsection);
173 if (SegName ==
"__DWARF")
174 CreatedADWARFSection =
true;
176 assert(!CreatedADWARFSection &&
"Creating regular section after DWARF");
180 if (LabelSections && !HasSectionLabel[Section] &&
182 MCSymbol *
Label = getContext().createLinkerPrivateTempSymbol();
183 Section->setBeginSymbol(Label);
184 HasSectionLabel[
Section] =
true;
188void MCMachOStreamer::emitEHSymAttributes(
const MCSymbol *Symbol,
190 getAssembler().registerSymbol(*Symbol);
193 if (cast<MCSymbolMachO>(Symbol)->isWeakDefinition())
195 if (
Symbol->isPrivateExtern())
199void MCMachOStreamer::emitLabel(
MCSymbol *Symbol,
SMLoc Loc) {
202 if (getAssembler().isSymbolLinkerVisible(*Symbol))
214 cast<MCSymbolMachO>(Symbol)->clearReferenceType();
220 if (
Value->evaluateAsRelocatable(Res,
nullptr,
nullptr)) {
222 const MCSymbol &SymA = SymAExpr->getSymbol();
224 cast<MCSymbolMachO>(Symbol)->setAltEntry();
232 MCSymbol *Start = getContext().createTempSymbol();
236 std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
237 Regions.push_back(
Data);
240void MCMachOStreamer::emitDataRegionEnd() {
241 std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
242 assert(!Regions.empty() &&
"Mismatched .end_data_region!");
244 assert(!
Data.End &&
"Mismatched .end_data_region!");
246 Data.End = getContext().createTempSymbol();
252 getAssembler().getBackend().handleAssemblerFlag(Flag);
260 getAssembler().setSubsectionsViaSymbols(
true);
266 getAssembler().getLinkerOptions().push_back(
Options);
290 unsigned Minor,
unsigned Update,
292 getAssembler().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
295void MCMachOStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
296 unsigned Minor,
unsigned Update,
302void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
303 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
305 getAssembler().setDarwinTargetVariantBuildVersion(
309void MCMachOStreamer::emitThumbFunc(
MCSymbol *Symbol) {
312 getAssembler().setIsThumbFunc(Symbol);
313 cast<MCSymbolMachO>(Symbol)->setThumbFunc();
316bool MCMachOStreamer::emitSymbolAttribute(
MCSymbol *Sym,
327 ISD.
Section = getCurrentSectionOnly();
328 getAssembler().getIndirectSymbols().push_back(ISD);
335 getAssembler().registerSymbol(*Symbol);
365 Symbol->setExternal(
true);
372 Symbol->setReferenceTypeUndefinedLazy(
false);
378 if (
Symbol->isUndefined())
379 Symbol->setReferenceTypeUndefinedLazy(
true);
390 Symbol->setSymbolResolver();
398 Symbol->setExternal(
true);
399 Symbol->setPrivateExtern(
true);
404 if (
Symbol->isUndefined())
405 Symbol->setWeakReference();
411 Symbol->setWeakDefinition();
415 Symbol->setWeakDefinition();
416 Symbol->setWeakReference();
427void MCMachOStreamer::emitSymbolDesc(
MCSymbol *Symbol,
unsigned DescValue) {
429 getAssembler().registerSymbol(*Symbol);
430 cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
434 Align ByteAlignment) {
436 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
438 getAssembler().registerSymbol(*Symbol);
439 Symbol->setExternal(
true);
444 Align ByteAlignment) {
446 return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
447 Symbol,
Size, ByteAlignment);
456 if (!
Section->isVirtualSection()) {
457 getContext().reportError(
458 Loc,
"The usage of .zerofill is restricted to sections of "
459 "ZEROFILL type. Use .zero or .space instead.");
465 switchSection(Section);
469 emitValueToAlignment(ByteAlignment, 0, 1, 0);
480 emitZerofill(Section, Symbol,
Size, ByteAlignment);
483void MCMachOStreamer::emitInstToData(
const MCInst &Inst,
490 getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
494 Fixup.setOffset(
Fixup.getOffset() +
DF->getContents().size());
495 DF->getFixups().push_back(
Fixup);
497 DF->setHasInstructions(STI);
498 DF->getContents().append(
Code.begin(),
Code.end());
501void MCMachOStreamer::finishImpl() {
502 emitFrames(&getAssembler().getBackend());
510 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
511 if (getAssembler().isSymbolLinkerVisible(Symbol) &&
Symbol.isInSection() &&
515 "Invalid offset in atom defining symbol!");
523 const MCSymbol *CurrentAtom =
nullptr;
527 Frag.setAtom(CurrentAtom);
533 createAddrSigSection();
537void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
540 getAssembler().registerSymbol(*S, &Created);
545void MCMachOStreamer::finalizeCGProfile() {
547 if (
Asm.CGProfile.empty())
550 finalizeCGProfileEntry(
E.From);
551 finalizeCGProfileEntry(
E.To);
556 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
558 Asm.registerSection(*CGProfileSection);
561 size_t SectionBytes =
563 Frag->getContents().resize(SectionBytes);
567 std::unique_ptr<MCAsmBackend> &&MAB,
568 std::unique_ptr<MCObjectWriter> &&OW,
569 std::unique_ptr<MCCodeEmitter> &&CE,
570 bool RelaxAll,
bool DWARFMustBeAtTheEnd,
571 bool LabelSections) {
573 new MCMachOStreamer(
Context, std::move(MAB), std::move(OW), std::move(CE),
574 DWARFMustBeAtTheEnd, LabelSections);
576 S->emitVersionForTarget(
578 Context.getObjectFileInfo()->getDarwinTargetVariantTriple(),
579 Context.getObjectFileInfo()->getDarwinTargetVariantSDKVersion());
581 S->getAssembler().setRelaxAll(
true);
591void MCMachOStreamer::createAddrSigSection() {
599 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
600 Asm.registerSection(*AddrSigSection);
607 Frag->getContents().resize(8);
BlockVerifier::State From
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
dxil DXContainer Global Emitter
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
This file defines the DenseMap class.
static bool canGoAfterDWARF(const MCSectionMachO &MSec)
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Context object for machine code objects.
Fragment for data and encoded instructions.
Base class for the full range of assembler expressions which are needed for parsing.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Instances of this class represent a single low-level machine instruction.
Streaming object file generation interface.
void reset() override
state management
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void finishImpl() override
Streamer specific finalization.
Defines the object file and target independent interfaces used by the assembler backend to write nati...
bool getEmitAddrsigSection()
This represents a section on a Mach-O system (used by Mac OS X).
StringRef getSegmentName() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
StringRef getName() const
Streaming machine code generation interface.
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void setExternal(bool Value) const
StringRef getName() const
getName - Get the symbol name.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
This represents an "assembler immediate".
int64_t getConstant() const
const MCSymbolRefExpr * getSymB() const
const MCSymbolRefExpr * getSymA() const
Represents a location in source code.
static SectionKind getMetadata()
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
LLVM Value Representation.
Represents a version number in the form major[.minor[.subminor[.build]]].
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
@ MCDR_DataRegionEnd
.end_data_region
@ MCDR_DataRegion
.data_region
@ MCDR_DataRegionJT8
.data_region jt8
@ MCDR_DataRegionJT32
.data_region jt32
@ MCDR_DataRegionJT16
.data_region jt16
MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
@ MCAF_SyntaxUnified
.syntax (ARM/ELF)
@ MCAF_Code64
.code64 (X86)
@ MCAF_Code16
.code16 (X86) / .code 16 (ARM)
@ MCAF_Code32
.code32 (X86) / .code 32 (ARM)
@ MCAF_SubsectionsViaSymbols
.subsections_via_symbols (MachO)
MCLOHType
Linker Optimization Hint Type.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_Protected
.protected (ELF)
@ MCSA_Exported
.globl _foo, exported (XCOFF)
@ MCSA_PrivateExtern
.private_extern (MachO)
@ MCSA_Internal
.internal (ELF)
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_AltEntry
.alt_entry (MachO)
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
@ MCSA_LazyReference
.lazy_reference (MachO)
@ MCSA_ELF_TypeNoType
.type _foo, STT_NOTYPE # aka @notype
@ MCSA_Reference
.reference (MachO)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
@ MCSA_ELF_TypeTLS
.type _foo, STT_TLS # aka @tls_object
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_ELF_TypeCommon
.type _foo, STT_COMMON # aka @common
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_Extern
.extern (XCOFF)
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
@ MCSA_ELF_TypeGnuUniqueObject
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
@ MCSA_Hidden
.hidden (ELF)
@ MCSA_LGlobal
.lglobl (XCOFF)
@ MCSA_Invalid
Not a valid directive.
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
This struct is a compact representation of a valid (non-zero power of two) alignment.