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);
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,
489 getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
493 Fixup.setOffset(
Fixup.getOffset() +
DF->getContents().size());
494 DF->getFixups().push_back(
Fixup);
496 DF->setHasInstructions(STI);
497 DF->getContents().append(
Code.begin(),
Code.end());
500void MCMachOStreamer::finishImpl() {
501 emitFrames(&getAssembler().getBackend());
509 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
510 if (getAssembler().isSymbolLinkerVisible(Symbol) &&
Symbol.isInSection() &&
514 "Invalid offset in atom defining symbol!");
522 const MCSymbol *CurrentAtom =
nullptr;
526 Frag.setAtom(CurrentAtom);
532 createAddrSigSection();
536void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
538 if (getAssembler().registerSymbol(*S))
542void MCMachOStreamer::finalizeCGProfile() {
544 if (
Asm.CGProfile.empty())
547 finalizeCGProfileEntry(
E.From);
548 finalizeCGProfileEntry(
E.To);
553 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
555 Asm.registerSection(*CGProfileSection);
558 size_t SectionBytes =
560 Frag->getContents().resize(SectionBytes);
564 std::unique_ptr<MCAsmBackend> &&MAB,
565 std::unique_ptr<MCObjectWriter> &&OW,
566 std::unique_ptr<MCCodeEmitter> &&CE,
567 bool RelaxAll,
bool DWARFMustBeAtTheEnd,
568 bool LabelSections) {
570 new MCMachOStreamer(
Context, std::move(MAB), std::move(OW), std::move(CE),
571 DWARFMustBeAtTheEnd, LabelSections);
573 S->emitVersionForTarget(
575 Context.getObjectFileInfo()->getDarwinTargetVariantTriple(),
576 Context.getObjectFileInfo()->getDarwinTargetVariantSDKVersion());
578 S->getAssembler().setRelaxAll(
true);
588void MCMachOStreamer::createAddrSigSection() {
596 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
597 Asm.registerSection(*AddrSigSection);
604 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.
NodeAddr< CodeNode * > Code
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_WeakAntiDep
.weak_anti_dep (COFF)
@ 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)
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.