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);
305 Symbol->setExternal(
true);
312 Symbol->setReferenceTypeUndefinedLazy(
false);
318 if (
Symbol->isUndefined())
319 Symbol->setReferenceTypeUndefinedLazy(
true);
330 Symbol->setSymbolResolver();
338 Symbol->setExternal(
true);
339 Symbol->setPrivateExtern(
true);
344 if (
Symbol->isUndefined())
345 Symbol->setWeakReference();
351 Symbol->setWeakDefinition();
355 Symbol->setWeakDefinition();
356 Symbol->setWeakReference();
367void MCMachOStreamer::emitSymbolDesc(MCSymbol *Symbol,
unsigned DescValue) {
369 getAssembler().registerSymbol(*Symbol);
370 static_cast<MCSymbolMachO *
>(
Symbol)->setDesc(DescValue);
373void MCMachOStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
374 Align ByteAlignment) {
375 auto &Sym =
static_cast<MCSymbolMachO &
>(*Symbol);
377 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
379 getAssembler().registerSymbol(Sym);
380 Sym.setExternal(
true);
384void MCMachOStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
385 Align ByteAlignment) {
387 return emitZerofill(
getContext().getObjectFileInfo()->getDataBSSSection(),
388 Symbol,
Size, ByteAlignment);
391void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
392 uint64_t
Size, Align ByteAlignment,
397 if (!
Section->isBssSection()) {
399 Loc,
"The usage of .zerofill is restricted to sections of "
400 "ZEROFILL type. Use .zero or .space instead.");
406 switchSection(Section);
410 emitValueToAlignment(ByteAlignment, 0, 1, 0);
419void MCMachOStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
420 uint64_t
Size, Align ByteAlignment) {
421 emitZerofill(Section, Symbol,
Size, ByteAlignment);
424void MCMachOStreamer::finishImpl() {
425 emitFrames(&getAssembler().getBackend());
432 DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
433 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
434 auto &Sym =
static_cast<const MCSymbolMachO &
>(
Symbol);
439 "Invalid offset in atom defining symbol!");
446 for (MCSection &Sec : getAssembler()) {
447 static_cast<MCSectionMachO &
>(Sec).allocAtoms();
448 const MCSymbol *CurrentAtom =
nullptr;
450 for (MCFragment &Frag : Sec) {
451 if (
const MCSymbol *Symbol = DefiningSymbolMap.
lookup(&Frag))
453 static_cast<MCSectionMachO &
>(Sec).setAtom(
I++, CurrentAtom);
459 createAddrSigSection();
463void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
466 if (getAssembler().registerSymbol(*S))
467 S->setExternal(
true);
470void MCMachOStreamer::finalizeCGProfile() {
471 MCAssembler &
Asm = getAssembler();
472 MCObjectWriter &
W = getWriter();
473 if (
W.getCGProfile().empty())
475 for (
auto &
E :
W.getCGProfile()) {
476 finalizeCGProfileEntry(
E.From);
477 finalizeCGProfileEntry(
E.To);
482 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
487 size_t SectionBytes =
488 W.getCGProfile().size() * (2 *
sizeof(uint32_t) +
sizeof(uint64_t));
489 (*CGProfileSection->
begin())
490 .setVarContents(std::vector<char>(SectionBytes, 0));
494 std::unique_ptr<MCAsmBackend> &&MAB,
495 std::unique_ptr<MCObjectWriter> &&OW,
496 std::unique_ptr<MCCodeEmitter> &&CE,
497 bool DWARFMustBeAtTheEnd,
498 bool LabelSections) {
499 return new MCMachOStreamer(Context, std::move(MAB), std::move(OW),
500 std::move(CE), LabelSections);
509void MCMachOStreamer::createAddrSigSection() {
517 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
526 constexpr char zero[8] = {};
527 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_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)