55 bool DWARFMustBeAtTheEnd;
56 bool CreatedADWARFSection;
66 void emitDataRegionEnd();
69 MCMachOStreamer(
MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
70 std::unique_ptr<MCObjectWriter> OW,
71 std::unique_ptr<MCCodeEmitter>
Emitter,
72 bool DWARFMustBeAtTheEnd,
bool label)
75 LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd),
76 CreatedADWARFSection(
false) {}
79 void reset()
override {
80 CreatedADWARFSection =
false;
81 HasSectionLabel.
clear();
91 void emitEHSymAttributes(
const MCSymbol *Symbol,
MCSymbol *EHSymbol)
override;
97 void emitBuildVersion(
unsigned Platform,
unsigned Major,
unsigned Minor,
99 void emitDarwinTargetVariantBuildVersion(
unsigned Platform,
unsigned Major,
100 unsigned Minor,
unsigned Update,
102 void emitThumbFunc(
MCSymbol *Func)
override;
104 void emitSymbolDesc(
MCSymbol *Symbol,
unsigned DescValue)
override;
106 Align ByteAlignment)
override;
109 Align ByteAlignment)
override;
116 void emitIdent(
StringRef IdentString)
override {
121 getAssembler().getLOHContainer().addDirective(Kind, Args);
126 getAssembler().CGProfile.push_back({
From, To, Count});
129 void finishImpl()
override;
132 void finalizeCGProfile();
133 void createAddrSigSection();
144 if (SegName ==
"__LD" && SecName ==
"__compact_unwind")
147 if (SegName ==
"__IMPORT") {
148 if (SecName ==
"__jump_table")
151 if (SecName ==
"__pointers")
155 if (SegName ==
"__TEXT" && SecName ==
"__eh_frame")
158 if (SegName ==
"__DATA" && (SecName ==
"__nl_symbol_ptr" ||
159 SecName ==
"__thread_ptr"))
161 if (SegName ==
"__LLVM" && SecName ==
"__cg_profile")
166void MCMachOStreamer::changeSection(
MCSection *Section,
167 const MCExpr *Subsection) {
169 bool Created = changeSectionImpl(Section, Subsection);
172 if (SegName ==
"__DWARF")
173 CreatedADWARFSection =
true;
175 assert(!CreatedADWARFSection &&
"Creating regular section after DWARF");
179 if (LabelSections && !HasSectionLabel[Section] &&
181 MCSymbol *
Label = getContext().createLinkerPrivateTempSymbol();
182 Section->setBeginSymbol(Label);
183 HasSectionLabel[
Section] =
true;
187void MCMachOStreamer::emitEHSymAttributes(
const MCSymbol *Symbol,
189 getAssembler().registerSymbol(*Symbol);
192 if (cast<MCSymbolMachO>(Symbol)->isWeakDefinition())
194 if (
Symbol->isPrivateExtern())
198void MCMachOStreamer::emitLabel(
MCSymbol *Symbol,
SMLoc Loc) {
201 if (getAssembler().isSymbolLinkerVisible(*Symbol))
213 cast<MCSymbolMachO>(Symbol)->clearReferenceType();
219 if (
Value->evaluateAsRelocatable(Res,
nullptr,
nullptr)) {
221 const MCSymbol &SymA = SymAExpr->getSymbol();
223 cast<MCSymbolMachO>(Symbol)->setAltEntry();
231 MCSymbol *Start = getContext().createTempSymbol();
235 std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
236 Regions.push_back(
Data);
239void MCMachOStreamer::emitDataRegionEnd() {
240 std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
241 assert(!Regions.empty() &&
"Mismatched .end_data_region!");
243 assert(!
Data.End &&
"Mismatched .end_data_region!");
245 Data.End = getContext().createTempSymbol();
251 getAssembler().getBackend().handleAssemblerFlag(Flag);
259 getAssembler().setSubsectionsViaSymbols(
true);
265 getAssembler().getLinkerOptions().push_back(
Options);
289 unsigned Minor,
unsigned Update,
291 getAssembler().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
294void MCMachOStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
295 unsigned Minor,
unsigned Update,
301void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
302 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
304 getAssembler().setDarwinTargetVariantBuildVersion(
308void MCMachOStreamer::emitThumbFunc(
MCSymbol *Symbol) {
311 getAssembler().setIsThumbFunc(Symbol);
312 cast<MCSymbolMachO>(Symbol)->setThumbFunc();
315bool MCMachOStreamer::emitSymbolAttribute(
MCSymbol *
Sym,
326 ISD.
Section = getCurrentSectionOnly();
327 getAssembler().getIndirectSymbols().push_back(ISD);
334 getAssembler().registerSymbol(*Symbol);
364 Symbol->setExternal(
true);
371 Symbol->setReferenceTypeUndefinedLazy(
false);
377 if (
Symbol->isUndefined())
378 Symbol->setReferenceTypeUndefinedLazy(
true);
389 Symbol->setSymbolResolver();
397 Symbol->setExternal(
true);
398 Symbol->setPrivateExtern(
true);
403 if (
Symbol->isUndefined())
404 Symbol->setWeakReference();
410 Symbol->setWeakDefinition();
414 Symbol->setWeakDefinition();
415 Symbol->setWeakReference();
426void MCMachOStreamer::emitSymbolDesc(
MCSymbol *Symbol,
unsigned DescValue) {
428 getAssembler().registerSymbol(*Symbol);
429 cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
433 Align ByteAlignment) {
435 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
437 getAssembler().registerSymbol(*Symbol);
438 Symbol->setExternal(
true);
443 Align ByteAlignment) {
445 return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
446 Symbol,
Size, ByteAlignment);
455 if (!
Section->isVirtualSection()) {
456 getContext().reportError(
457 Loc,
"The usage of .zerofill is restricted to sections of "
458 "ZEROFILL type. Use .zero or .space instead.");
464 switchSection(Section);
468 emitValueToAlignment(ByteAlignment, 0, 1, 0);
479 emitZerofill(Section, Symbol,
Size, ByteAlignment);
482void MCMachOStreamer::emitInstToData(
const MCInst &Inst,
488 getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
492 Fixup.setOffset(
Fixup.getOffset() +
DF->getContents().size());
493 DF->getFixups().push_back(
Fixup);
495 DF->setHasInstructions(STI);
496 DF->getContents().append(
Code.begin(),
Code.end());
499void MCMachOStreamer::finishImpl() {
500 emitFrames(&getAssembler().getBackend());
508 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
509 if (getAssembler().isSymbolLinkerVisible(Symbol) &&
Symbol.isInSection() &&
513 "Invalid offset in atom defining symbol!");
521 const MCSymbol *CurrentAtom =
nullptr;
525 Frag.setAtom(CurrentAtom);
531 createAddrSigSection();
535void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
537 if (getAssembler().registerSymbol(*S))
541void MCMachOStreamer::finalizeCGProfile() {
543 if (
Asm.CGProfile.empty())
546 finalizeCGProfileEntry(
E.From);
547 finalizeCGProfileEntry(
E.To);
552 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
554 Asm.registerSection(*CGProfileSection);
557 size_t SectionBytes =
559 Frag->getContents().resize(SectionBytes);
563 std::unique_ptr<MCAsmBackend> &&MAB,
564 std::unique_ptr<MCObjectWriter> &&OW,
565 std::unique_ptr<MCCodeEmitter> &&CE,
566 bool RelaxAll,
bool DWARFMustBeAtTheEnd,
567 bool LabelSections) {
569 new MCMachOStreamer(
Context, std::move(MAB), std::move(OW), std::move(CE),
570 DWARFMustBeAtTheEnd, LabelSections);
572 S->emitVersionForTarget(
574 Context.getObjectFileInfo()->getDarwinTargetVariantTriple(),
575 Context.getObjectFileInfo()->getDarwinTargetVariantSDKVersion());
577 S->getAssembler().setRelaxAll(
true);
587void MCMachOStreamer::createAddrSigSection() {
595 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
596 Asm.registerSection(*AddrSigSection);
603 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]]].
#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.