65 void emitDataRegionEnd();
68 MCMachOStreamer(
MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
69 std::unique_ptr<MCObjectWriter> OW,
70 std::unique_ptr<MCCodeEmitter>
Emitter,
bool label)
73 LabelSections(label) {}
76 void reset()
override {
77 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 getWriter().getLOHContainer().addDirective(Kind, Args);
126 getWriter().getCGProfile().push_back({
From, To, Count});
129 void finishImpl()
override;
132 void finalizeCGProfile();
133 void createAddrSigSection();
140 changeSectionImpl(Section, Subsection);
144 if (LabelSections && !HasSectionLabel[Section] &&
146 MCSymbol *
Label = getContext().createLinkerPrivateTempSymbol();
147 Section->setBeginSymbol(Label);
148 HasSectionLabel[
Section] =
true;
152void MCMachOStreamer::emitEHSymAttributes(
const MCSymbol *Symbol,
154 auto *
Sym = cast<MCSymbolMachO>(Symbol);
155 getAssembler().registerSymbol(*Symbol);
158 if (
Sym->isWeakDefinition())
160 if (
Sym->isPrivateExtern())
164void MCMachOStreamer::emitLabel(
MCSymbol *Symbol,
SMLoc Loc) {
168 insert(getContext().allocFragment<MCDataFragment>());
179 cast<MCSymbolMachO>(Symbol)->clearReferenceType();
185 if (
Value->evaluateAsRelocatable(Res,
nullptr,
nullptr)) {
187 const MCSymbol &SymA = SymAExpr->getSymbol();
189 cast<MCSymbolMachO>(Symbol)->setAltEntry();
197 MCSymbol *Start = getContext().createTempSymbol();
200 getWriter().getDataRegions().push_back({
Kind, Start,
nullptr});
203void MCMachOStreamer::emitDataRegionEnd() {
204 auto &Regions = getWriter().getDataRegions();
205 assert(!Regions.empty() &&
"Mismatched .end_data_region!");
206 auto &Data = Regions.back();
207 assert(!Data.End &&
"Mismatched .end_data_region!");
209 Data.End = getContext().createTempSymbol();
215 getAssembler().getBackend().handleAssemblerFlag(Flag);
223 getWriter().setSubsectionsViaSymbols(
true);
229 getWriter().getLinkerOptions().push_back(
Options);
235 emitDataRegion(MachO::DataRegionType::DICE_KIND_DATA);
238 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE8);
241 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE16);
244 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE32);
253 unsigned Minor,
unsigned Update,
255 getWriter().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
258void MCMachOStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
259 unsigned Minor,
unsigned Update,
265void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
266 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
269 Minor, Update, SDKVersion);
272void MCMachOStreamer::emitThumbFunc(
MCSymbol *Symbol) {
275 getAssembler().setIsThumbFunc(Symbol);
276 cast<MCSymbolMachO>(Symbol)->setThumbFunc();
279bool MCMachOStreamer::emitSymbolAttribute(
MCSymbol *
Sym,
288 getWriter().getIndirectSymbols().push_back(
289 {
Symbol, getCurrentSectionOnly()});
296 getAssembler().registerSymbol(*Symbol);
327 Symbol->setExternal(
true);
334 Symbol->setReferenceTypeUndefinedLazy(
false);
340 if (
Symbol->isUndefined())
341 Symbol->setReferenceTypeUndefinedLazy(
true);
352 Symbol->setSymbolResolver();
360 Symbol->setExternal(
true);
361 Symbol->setPrivateExtern(
true);
366 if (
Symbol->isUndefined())
367 Symbol->setWeakReference();
373 Symbol->setWeakDefinition();
377 Symbol->setWeakDefinition();
378 Symbol->setWeakReference();
389void MCMachOStreamer::emitSymbolDesc(
MCSymbol *Symbol,
unsigned DescValue) {
391 getAssembler().registerSymbol(*Symbol);
392 cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
396 Align ByteAlignment) {
398 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
400 getAssembler().registerSymbol(*Symbol);
401 Symbol->setExternal(
true);
406 Align ByteAlignment) {
408 return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
409 Symbol,
Size, ByteAlignment);
418 if (!
Section->isVirtualSection()) {
419 getContext().reportError(
420 Loc,
"The usage of .zerofill is restricted to sections of "
421 "ZEROFILL type. Use .zero or .space instead.");
427 switchSection(Section);
431 emitValueToAlignment(ByteAlignment, 0, 1, 0);
442 emitZerofill(Section, Symbol,
Size, ByteAlignment);
445void MCMachOStreamer::emitInstToData(
const MCInst &Inst,
451 getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
455 Fixup.setOffset(
Fixup.getOffset() +
DF->getContents().size());
456 DF->getFixups().push_back(
Fixup);
458 DF->setHasInstructions(STI);
459 DF->getContents().append(
Code.begin(),
Code.end());
462void MCMachOStreamer::finishImpl() {
463 emitFrames(&getAssembler().getBackend());
471 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
472 auto &
Sym = cast<MCSymbolMachO>(Symbol);
473 if (
Sym.isSymbolLinkerVisible() &&
Sym.isInSection() && !
Sym.isVariable() &&
477 "Invalid offset in atom defining symbol!");
485 cast<MCSectionMachO>(Sec).allocAtoms();
486 const MCSymbol *CurrentAtom =
nullptr;
491 cast<MCSectionMachO>(Sec).setAtom(
I++, CurrentAtom);
497 createAddrSigSection();
501void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
503 if (getAssembler().registerSymbol(*S))
507void MCMachOStreamer::finalizeCGProfile() {
510 if (
W.getCGProfile().empty())
512 for (
auto &E :
W.getCGProfile()) {
513 finalizeCGProfileEntry(E.From);
514 finalizeCGProfileEntry(E.To);
519 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
521 changeSection(CGProfileSection);
523 size_t SectionBytes =
525 cast<MCDataFragment>(*CGProfileSection->
begin())
527 .resize(SectionBytes);
531 std::unique_ptr<MCAsmBackend> &&MAB,
532 std::unique_ptr<MCObjectWriter> &&OW,
533 std::unique_ptr<MCCodeEmitter> &&CE,
534 bool DWARFMustBeAtTheEnd,
535 bool LabelSections) {
536 return new MCMachOStreamer(Context, std::move(MAB), std::move(OW),
537 std::move(CE), LabelSections);
546void MCMachOStreamer::createAddrSigSection() {
554 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
555 changeSection(AddrSigSection);
556 auto *Frag = cast<MCDataFragment>(AddrSigSection->
curFragList()->
Head);
562 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 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.
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()
Instances of this class represent a uniqued identifier for a section in the current translation unit.
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.
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.