48class MCMachOStreamer :
public MCObjectStreamer {
58 DenseMap<const MCSection*, bool> HasSectionLabel;
61 void emitDataRegionEnd();
64 MCMachOStreamer(MCContext &
Context, std::unique_ptr<MCAsmBackend> MAB,
65 std::unique_ptr<MCObjectWriter> OW,
66 std::unique_ptr<MCCodeEmitter>
Emitter,
bool label)
69 LabelSections(label) {}
72 void reset()
override {
73 HasSectionLabel.
clear();
77 MachObjectWriter &getWriter() {
78 return static_cast<MachObjectWriter &
>(getAssembler().getWriter());
84 void changeSection(MCSection *Sect, uint32_t Subsection = 0)
override;
85 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc())
override;
86 void emitAssignment(MCSymbol *Symbol,
const MCExpr *
Value)
override;
87 void emitEHSymAttributes(
const MCSymbol *Symbol, MCSymbol *EHSymbol)
override;
88 void emitSubsectionsViaSymbols()
override;
89 void emitLinkerOptions(ArrayRef<std::string>
Options)
override;
92 unsigned Update, VersionTuple SDKVersion)
override;
93 void emitBuildVersion(
unsigned Platform,
unsigned Major,
unsigned Minor,
94 unsigned Update, VersionTuple SDKVersion)
override;
95 void emitDarwinTargetVariantBuildVersion(
unsigned Platform,
unsigned Major,
96 unsigned Minor,
unsigned Update,
97 VersionTuple SDKVersion)
override;
99 void emitSymbolDesc(MCSymbol *Symbol,
unsigned DescValue)
override;
100 void emitCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
101 Align ByteAlignment)
override;
103 void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
104 Align ByteAlignment)
override;
105 void emitZerofill(MCSection *Section, MCSymbol *Symbol =
nullptr,
106 uint64_t
Size = 0, Align ByteAlignment =
Align(1),
107 SMLoc Loc = SMLoc())
override;
108 void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t
Size,
109 Align ByteAlignment =
Align(1))
override;
111 void emitIdent(StringRef IdentString)
override {
116 getWriter().getLOHContainer().addDirective(Kind, Args);
118 void emitCGProfileEntry(
const MCSymbolRefExpr *From,
119 const MCSymbolRefExpr *To, uint64_t
Count)
override {
121 getWriter().getCGProfile().push_back({From, To,
Count});
124 void finishImpl()
override;
126 void finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE);
127 void finalizeCGProfile();
128 void createAddrSigSection();
138 if (LabelSections && !HasSectionLabel[Section] &&
141 Section->setBeginSymbol(Label);
142 HasSectionLabel[
Section] =
true;
143 if (!
Label->isInSection())
148void MCMachOStreamer::emitEHSymAttributes(
const MCSymbol *Symbol,
149 MCSymbol *EHSymbol) {
150 auto *Sym =
static_cast<const MCSymbolMachO *
>(
Symbol);
151 getAssembler().registerSymbol(*Symbol);
152 if (Sym->isExternal())
154 if (Sym->isWeakDefinition())
156 if (Sym->isPrivateExtern())
160void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
175 static_cast<MCSymbolMachO *
>(
Symbol)->clearReferenceType();
178void MCMachOStreamer::emitAssignment(MCSymbol *Symbol,
const MCExpr *
Value) {
181 if (
Value->evaluateAsRelocatable(Res,
nullptr)) {
182 if (
const auto *SymA = Res.
getAddSym()) {
184 (SymA->getName().empty() || Res.
getConstant() != 0))
185 static_cast<MCSymbolMachO *
>(
Symbol)->setAltEntry();
196 getWriter().getDataRegions().push_back({
Kind,
Start,
nullptr});
199void MCMachOStreamer::emitDataRegionEnd() {
200 auto &Regions = getWriter().getDataRegions();
201 assert(!Regions.empty() &&
"Mismatched .end_data_region!");
202 auto &
Data = Regions.back();
203 assert(!
Data.End &&
"Mismatched .end_data_region!");
209void MCMachOStreamer::emitSubsectionsViaSymbols() {
210 getWriter().setSubsectionsViaSymbols(
true);
213void MCMachOStreamer::emitLinkerOptions(ArrayRef<std::string>
Options) {
214 getWriter().getLinkerOptions().push_back(
Options);
220 emitDataRegion(MachO::DataRegionType::DICE_KIND_DATA);
223 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE8);
226 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE16);
229 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE32);
238 unsigned Minor,
unsigned Update,
239 VersionTuple SDKVersion) {
240 getWriter().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
243void MCMachOStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
244 unsigned Minor,
unsigned Update,
245 VersionTuple SDKVersion) {
250void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
251 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
252 VersionTuple SDKVersion) {
254 Minor, Update, SDKVersion);
257bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
259 auto *
Symbol =
static_cast<MCSymbolMachO *
>(Sym);
266 getWriter().getIndirectSymbols().push_back(
267 {
Symbol, getCurrentSectionOnly()});
274 getAssembler().registerSymbol(*Symbol);
307 Symbol->setExternal(
true);
314 Symbol->setReferenceTypeUndefinedLazy(
false);
320 if (
Symbol->isUndefined())
321 Symbol->setReferenceTypeUndefinedLazy(
true);
332 Symbol->setSymbolResolver();
340 Symbol->setExternal(
true);
341 Symbol->setPrivateExtern(
true);
346 if (
Symbol->isUndefined())
347 Symbol->setWeakReference();
353 Symbol->setWeakDefinition();
357 Symbol->setWeakDefinition();
358 Symbol->setWeakReference();
369void MCMachOStreamer::emitSymbolDesc(MCSymbol *Symbol,
unsigned DescValue) {
371 getAssembler().registerSymbol(*Symbol);
372 static_cast<MCSymbolMachO *
>(
Symbol)->setDesc(DescValue);
375void MCMachOStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
376 Align ByteAlignment) {
377 auto &Sym =
static_cast<MCSymbolMachO &
>(*Symbol);
379 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
381 getAssembler().registerSymbol(Sym);
382 Sym.setExternal(
true);
386void MCMachOStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
387 Align ByteAlignment) {
389 return emitZerofill(
getContext().getObjectFileInfo()->getDataBSSSection(),
390 Symbol,
Size, ByteAlignment);
393void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
394 uint64_t
Size, Align ByteAlignment,
399 if (!
Section->isBssSection()) {
401 Loc,
"The usage of .zerofill is restricted to sections of "
402 "ZEROFILL type. Use .zero or .space instead.");
408 switchSection(Section);
412 emitValueToAlignment(ByteAlignment, 0, 1, 0);
421void MCMachOStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
422 uint64_t
Size, Align ByteAlignment) {
423 emitZerofill(Section, Symbol,
Size, ByteAlignment);
426void MCMachOStreamer::finishImpl() {
434 DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
435 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
436 auto &Sym =
static_cast<const MCSymbolMachO &
>(
Symbol);
441 "Invalid offset in atom defining symbol!");
448 for (MCSection &Sec : getAssembler()) {
449 static_cast<MCSectionMachO &
>(Sec).allocAtoms();
450 const MCSymbol *CurrentAtom =
nullptr;
452 for (MCFragment &Frag : Sec) {
453 if (
const MCSymbol *Symbol = DefiningSymbolMap.
lookup(&Frag))
455 static_cast<MCSectionMachO &
>(Sec).setAtom(
I++, CurrentAtom);
461 createAddrSigSection();
465void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
468 if (getAssembler().registerSymbol(*S))
469 S->setExternal(
true);
472void MCMachOStreamer::finalizeCGProfile() {
473 MCAssembler &
Asm = getAssembler();
474 MCObjectWriter &
W = getWriter();
475 if (
W.getCGProfile().empty())
477 for (
auto &
E :
W.getCGProfile()) {
478 finalizeCGProfileEntry(
E.From);
479 finalizeCGProfileEntry(
E.To);
484 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
489 size_t SectionBytes =
490 W.getCGProfile().size() * (2 *
sizeof(uint32_t) +
sizeof(uint64_t));
491 (*CGProfileSection->
begin())
492 .setVarContents(std::vector<char>(SectionBytes, 0));
496 std::unique_ptr<MCAsmBackend> &&MAB,
497 std::unique_ptr<MCObjectWriter> &&OW,
498 std::unique_ptr<MCCodeEmitter> &&CE,
499 bool DWARFMustBeAtTheEnd,
500 bool LabelSections) {
501 return new MCMachOStreamer(Context, std::move(MAB), std::move(OW),
502 std::move(CE), LabelSections);
511void MCMachOStreamer::createAddrSigSection() {
519 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
528 constexpr char zero[8] = {};
529 Frag->setVarContents(
zero);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
dxil DXContainer Global Emitter
This file defines the DenseMap class.
static bool isSymbolLinkerVisible(const MCSymbol &Symbol)
This file defines the SmallVector class.
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.
Instances of this class represent a single low-level machine instruction.
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.
void changeSection(MCSection *Section, uint32_t Subsection=0) override
This is called by popSection and switchSection, if the current section changes.
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.
const MCSymbol & getSymbol() const
void setCommon(uint64_t Size, Align Alignment)
Mark this symbol as being 'common'.
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
bool isVariable() const
isVariable - Check if this is a variable symbol.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
const MCSymbol * getAddSym() const
int64_t getConstant() const
const MCSymbol * getSubSym() const
static SectionKind getMetadata()
Triple - Helper class for working with autoconf configuration names.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Context & getContext() const
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
@ MCDR_DataRegionEnd
.end_data_region
@ MCDR_DataRegion
.data_region
@ MCDR_DataRegionJT8
.data_region jt8
@ MCDR_DataRegionJT32
.data_region jt32
@ MCDR_DataRegionJT16
.data_region jt16
LLVM_ABI MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
MCLOHDirective::LOHArgs MCLOHArgs
FunctionAddr VTableAddr Count
FunctionAddr VTableAddr uintptr_t uintptr_t Data
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.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_Protected
.protected (ELF)
@ MCSA_OSLinkage
symbol uses OS linkage (GOFF)
@ 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_XPLinkage
symbol uses XP linkage (GOFF)
@ 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)