57 bool DWARFMustBeAtTheEnd;
58 bool CreatedADWARFSection;
68 void emitDataRegionEnd();
71 MCMachOStreamer(
MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
72 std::unique_ptr<MCObjectWriter> OW,
73 std::unique_ptr<MCCodeEmitter>
Emitter,
74 bool DWARFMustBeAtTheEnd,
bool label)
77 LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd),
78 CreatedADWARFSection(
false) {}
81 void reset()
override {
82 CreatedADWARFSection =
false;
83 HasSectionLabel.
clear();
97 void emitEHSymAttributes(
const MCSymbol *Symbol,
MCSymbol *EHSymbol)
override;
103 void emitBuildVersion(
unsigned Platform,
unsigned Major,
unsigned Minor,
105 void emitDarwinTargetVariantBuildVersion(
unsigned Platform,
unsigned Major,
106 unsigned Minor,
unsigned Update,
108 void emitThumbFunc(
MCSymbol *Func)
override;
110 void emitSymbolDesc(
MCSymbol *Symbol,
unsigned DescValue)
override;
112 Align ByteAlignment)
override;
115 Align ByteAlignment)
override;
122 void emitIdent(
StringRef IdentString)
override {
127 getAssembler().getLOHContainer().addDirective(Kind, Args);
132 getAssembler().CGProfile.push_back({
From, To, Count});
135 void finishImpl()
override;
138 void finalizeCGProfile();
139 void createAddrSigSection();
150 if (SegName ==
"__LD" && SecName ==
"__compact_unwind")
153 if (SegName ==
"__IMPORT") {
154 if (SecName ==
"__jump_table")
157 if (SecName ==
"__pointers")
161 if (SegName ==
"__TEXT" && SecName ==
"__eh_frame")
164 if (SegName ==
"__DATA" &&
165 (SecName ==
"__llvm_addrsig" || SecName ==
"__nl_symbol_ptr" ||
166 SecName ==
"__thread_ptr"))
168 if (SegName ==
"__LLVM" && (SecName ==
"__cg_profile"))
171 if (SegName ==
"__DATA" && SecName ==
"__auth_ptr")
179 bool Created = changeSectionImpl(Section, Subsection);
182 if (SegName ==
"__DWARF")
183 CreatedADWARFSection =
true;
185 assert(!CreatedADWARFSection &&
"Creating regular section after DWARF");
189 if (LabelSections && !HasSectionLabel[Section] &&
191 MCSymbol *
Label = getContext().createLinkerPrivateTempSymbol();
192 Section->setBeginSymbol(Label);
193 HasSectionLabel[
Section] =
true;
197void MCMachOStreamer::emitEHSymAttributes(
const MCSymbol *Symbol,
199 getAssembler().registerSymbol(*Symbol);
202 if (cast<MCSymbolMachO>(Symbol)->isWeakDefinition())
204 if (
Symbol->isPrivateExtern())
208void MCMachOStreamer::emitLabel(
MCSymbol *Symbol,
SMLoc Loc) {
212 insert(getContext().allocFragment<MCDataFragment>());
223 cast<MCSymbolMachO>(Symbol)->clearReferenceType();
229 if (
Value->evaluateAsRelocatable(Res,
nullptr,
nullptr)) {
231 const MCSymbol &SymA = SymAExpr->getSymbol();
233 cast<MCSymbolMachO>(Symbol)->setAltEntry();
241 MCSymbol *Start = getContext().createTempSymbol();
244 getWriter().getDataRegions().push_back({
Kind, Start,
nullptr});
247void MCMachOStreamer::emitDataRegionEnd() {
248 auto &Regions = getWriter().getDataRegions();
249 assert(!Regions.empty() &&
"Mismatched .end_data_region!");
250 auto &Data = Regions.back();
251 assert(!Data.End &&
"Mismatched .end_data_region!");
253 Data.End = getContext().createTempSymbol();
259 getAssembler().getBackend().handleAssemblerFlag(Flag);
267 getAssembler().setSubsectionsViaSymbols(
true);
273 getAssembler().getLinkerOptions().push_back(
Options);
279 emitDataRegion(MachO::DataRegionType::DICE_KIND_DATA);
282 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE8);
285 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE16);
288 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE32);
297 unsigned Minor,
unsigned Update,
299 getAssembler().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
302void MCMachOStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
303 unsigned Minor,
unsigned Update,
309void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
310 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
312 getAssembler().setDarwinTargetVariantBuildVersion(
316void MCMachOStreamer::emitThumbFunc(
MCSymbol *Symbol) {
319 getAssembler().setIsThumbFunc(Symbol);
320 cast<MCSymbolMachO>(Symbol)->setThumbFunc();
323bool MCMachOStreamer::emitSymbolAttribute(
MCSymbol *
Sym,
332 getWriter().getIndirectSymbols().push_back(
333 {
Symbol, getCurrentSectionOnly()});
340 getAssembler().registerSymbol(*Symbol);
371 Symbol->setExternal(
true);
378 Symbol->setReferenceTypeUndefinedLazy(
false);
384 if (
Symbol->isUndefined())
385 Symbol->setReferenceTypeUndefinedLazy(
true);
396 Symbol->setSymbolResolver();
404 Symbol->setExternal(
true);
405 Symbol->setPrivateExtern(
true);
410 if (
Symbol->isUndefined())
411 Symbol->setWeakReference();
417 Symbol->setWeakDefinition();
421 Symbol->setWeakDefinition();
422 Symbol->setWeakReference();
433void MCMachOStreamer::emitSymbolDesc(
MCSymbol *Symbol,
unsigned DescValue) {
435 getAssembler().registerSymbol(*Symbol);
436 cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
440 Align ByteAlignment) {
442 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
444 getAssembler().registerSymbol(*Symbol);
445 Symbol->setExternal(
true);
450 Align ByteAlignment) {
452 return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
453 Symbol,
Size, ByteAlignment);
462 if (!
Section->isVirtualSection()) {
463 getContext().reportError(
464 Loc,
"The usage of .zerofill is restricted to sections of "
465 "ZEROFILL type. Use .zero or .space instead.");
471 switchSection(Section);
475 emitValueToAlignment(ByteAlignment, 0, 1, 0);
486 emitZerofill(Section, Symbol,
Size, ByteAlignment);
489void MCMachOStreamer::emitInstToData(
const MCInst &Inst,
495 getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
499 Fixup.setOffset(
Fixup.getOffset() +
DF->getContents().size());
500 DF->getFixups().push_back(
Fixup);
502 DF->setHasInstructions(STI);
503 DF->getContents().append(
Code.begin(),
Code.end());
506void MCMachOStreamer::finishImpl() {
507 emitFrames(&getAssembler().getBackend());
515 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
516 auto &
Sym = cast<MCSymbolMachO>(Symbol);
517 if (
Sym.isSymbolLinkerVisible() &&
Sym.isInSection() && !
Sym.isVariable() &&
521 "Invalid offset in atom defining symbol!");
529 cast<MCSectionMachO>(Sec).allocAtoms();
530 const MCSymbol *CurrentAtom =
nullptr;
535 cast<MCSectionMachO>(Sec).setAtom(
I++, CurrentAtom);
541 createAddrSigSection();
545void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
547 if (getAssembler().registerSymbol(*S))
551void MCMachOStreamer::finalizeCGProfile() {
553 if (
Asm.CGProfile.empty())
556 finalizeCGProfileEntry(E.
From);
557 finalizeCGProfileEntry(E.
To);
562 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
564 changeSection(CGProfileSection);
566 size_t SectionBytes =
568 cast<MCDataFragment>(*CGProfileSection->
begin())
570 .resize(SectionBytes);
574 std::unique_ptr<MCAsmBackend> &&MAB,
575 std::unique_ptr<MCObjectWriter> &&OW,
576 std::unique_ptr<MCCodeEmitter> &&CE,
577 bool DWARFMustBeAtTheEnd,
578 bool LabelSections) {
580 new MCMachOStreamer(Context, std::move(MAB), std::move(OW), std::move(CE),
581 DWARFMustBeAtTheEnd, LabelSections);
583 S->emitVersionForTarget(
596void MCMachOStreamer::createAddrSigSection() {
604 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
605 changeSection(AddrSigSection);
606 auto *Frag = cast<MCDataFragment>(AddrSigSection->
curFragList()->
Head);
612 Frag->getContents().resize(8);
BlockVerifier::State From
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)
static bool isSymbolLinkerVisible(const MCSymbol &Symbol)
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.
const MCObjectFileInfo * getObjectFileInfo() const
const Triple & getTargetTriple() const
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.
const VersionTuple & getDarwinTargetVariantSDKVersion() const
const Triple * getDarwinTargetVariantTriple() const
const VersionTuple & getSDKVersion() const
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
FragList * curFragList() 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 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.
const MCSymbolRefExpr * From
const MCSymbolRefExpr * To