45class MCMachOStreamer :
public MCObjectStreamer {
55 DenseMap<const MCSection*, bool> HasSectionLabel;
58 void emitDataRegionEnd();
61 MCMachOStreamer(MCContext &
Context, std::unique_ptr<MCAsmBackend> MAB,
62 std::unique_ptr<MCObjectWriter> OW,
63 std::unique_ptr<MCCodeEmitter>
Emitter,
bool label)
66 LabelSections(label) {}
69 void reset()
override {
70 HasSectionLabel.
clear();
74 MachObjectWriter &getWriter() {
75 return static_cast<MachObjectWriter &
>(getAssembler().getWriter());
81 void changeSection(MCSection *Sect, uint32_t Subsection = 0)
override;
82 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc())
override;
83 void emitAssignment(MCSymbol *Symbol,
const MCExpr *
Value)
override;
84 void emitEHSymAttributes(
const MCSymbol *Symbol, MCSymbol *EHSymbol)
override;
85 void emitSubsectionsViaSymbols()
override;
86 void emitLinkerOptions(ArrayRef<std::string>
Options)
override;
89 unsigned Update, VersionTuple SDKVersion)
override;
90 void emitBuildVersion(
unsigned Platform,
unsigned Major,
unsigned Minor,
91 unsigned Update, VersionTuple SDKVersion)
override;
92 void emitDarwinTargetVariantBuildVersion(
unsigned Platform,
unsigned Major,
93 unsigned Minor,
unsigned Update,
94 VersionTuple SDKVersion)
override;
95 void emitTargetTriple(StringRef TargetTriple)
override;
97 void emitSymbolDesc(MCSymbol *Symbol,
unsigned DescValue)
override;
99 Align ByteAlignment)
override;
101 void emitLocalCommonSymbol(MCSymbol *Symbol,
uint64_t Size,
102 Align ByteAlignment)
override;
103 void emitZerofill(MCSection *Section, MCSymbol *Symbol =
nullptr,
105 SMLoc Loc = SMLoc())
override;
106 void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
uint64_t Size,
107 Align ByteAlignment =
Align(1))
override;
109 void emitIdent(StringRef IdentString)
override {
114 getWriter().getLOHContainer().addDirective(Kind, Args);
116 void emitCGProfileEntry(
const MCSymbolRefExpr *From,
119 getWriter().getCGProfile().push_back({From, To,
Count});
122 void finishImpl()
override;
124 void finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE);
125 void finalizeCGProfile();
126 void createAddrSigSection();
136 if (LabelSections && !HasSectionLabel[Section] &&
139 Section->setBeginSymbol(Label);
140 HasSectionLabel[
Section] =
true;
141 if (!
Label->isInSection())
146void MCMachOStreamer::emitEHSymAttributes(
const MCSymbol *Symbol,
147 MCSymbol *EHSymbol) {
148 auto *Sym =
static_cast<const MCSymbolMachO *
>(
Symbol);
149 getAssembler().registerSymbol(*Symbol);
150 if (Sym->isExternal())
152 if (Sym->isWeakDefinition())
154 if (Sym->isPrivateExtern())
158void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
173 static_cast<MCSymbolMachO *
>(
Symbol)->clearReferenceType();
176void MCMachOStreamer::emitAssignment(MCSymbol *Symbol,
const MCExpr *
Value) {
179 if (
Value->evaluateAsRelocatable(Res,
nullptr)) {
180 if (
const auto *SymA = Res.
getAddSym()) {
182 (SymA->getName().empty() || Res.
getConstant() != 0))
183 static_cast<MCSymbolMachO *
>(
Symbol)->setAltEntry();
194 getWriter().getDataRegions().push_back({
Kind,
Start,
nullptr});
197void MCMachOStreamer::emitDataRegionEnd() {
198 auto &Regions = getWriter().getDataRegions();
199 assert(!Regions.empty() &&
"Mismatched .end_data_region!");
200 auto &
Data = Regions.back();
201 assert(!
Data.End &&
"Mismatched .end_data_region!");
207void MCMachOStreamer::emitSubsectionsViaSymbols() {
208 getWriter().setSubsectionsViaSymbols(
true);
211void MCMachOStreamer::emitLinkerOptions(ArrayRef<std::string>
Options) {
212 getWriter().getLinkerOptions().push_back(
Options);
218 emitDataRegion(MachO::DataRegionType::DICE_KIND_DATA);
221 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE8);
224 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE16);
227 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE32);
236 unsigned Minor,
unsigned Update,
237 VersionTuple SDKVersion) {
238 getWriter().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
241void MCMachOStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
242 unsigned Minor,
unsigned Update,
243 VersionTuple SDKVersion) {
248void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
249 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
250 VersionTuple SDKVersion) {
252 Minor, Update, SDKVersion);
255void MCMachOStreamer::emitTargetTriple(StringRef TargetTriple) {
256 getWriter().setTargetTriple(TargetTriple);
259bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
261 auto *
Symbol =
static_cast<MCSymbolMachO *
>(Sym);
268 getWriter().getIndirectSymbols().push_back(
269 {
Symbol, getCurrentSectionOnly()});
276 getAssembler().registerSymbol(*Symbol);
309 Symbol->setExternal(
true);
316 Symbol->setReferenceTypeUndefinedLazy(
false);
322 if (
Symbol->isUndefined())
323 Symbol->setReferenceTypeUndefinedLazy(
true);
334 Symbol->setSymbolResolver();
342 Symbol->setExternal(
true);
343 Symbol->setPrivateExtern(
true);
348 if (
Symbol->isUndefined())
349 Symbol->setWeakReference();
355 Symbol->setWeakDefinition();
359 Symbol->setWeakDefinition();
360 Symbol->setWeakReference();
371void MCMachOStreamer::emitSymbolDesc(MCSymbol *Symbol,
unsigned DescValue) {
373 getAssembler().registerSymbol(*Symbol);
374 static_cast<MCSymbolMachO *
>(
Symbol)->setDesc(DescValue);
377void MCMachOStreamer::emitCommonSymbol(MCSymbol *Symbol,
uint64_t Size,
378 Align ByteAlignment) {
379 auto &Sym =
static_cast<MCSymbolMachO &
>(*Symbol);
381 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
383 getAssembler().registerSymbol(Sym);
384 Sym.setExternal(
true);
388void MCMachOStreamer::emitLocalCommonSymbol(MCSymbol *Symbol,
uint64_t Size,
389 Align ByteAlignment) {
391 return emitZerofill(
getContext().getObjectFileInfo()->getDataBSSSection(),
392 Symbol,
Size, ByteAlignment);
395void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
401 if (!
Section->isBssSection()) {
403 Loc,
"The usage of .zerofill is restricted to sections of "
404 "ZEROFILL type. Use .zero or .space instead.");
410 switchSection(Section);
414 emitValueToAlignment(ByteAlignment, 0, 1, 0);
423void MCMachOStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
425 emitZerofill(Section, Symbol,
Size, ByteAlignment);
428void MCMachOStreamer::finishImpl() {
436 DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
437 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
438 auto &Sym =
static_cast<const MCSymbolMachO &
>(
Symbol);
443 "Invalid offset in atom defining symbol!");
450 for (MCSection &Sec : getAssembler()) {
451 static_cast<MCSectionMachO &
>(Sec).allocAtoms();
452 const MCSymbol *CurrentAtom =
nullptr;
454 for (MCFragment &Frag : Sec) {
455 if (
const MCSymbol *Symbol = DefiningSymbolMap.
lookup(&Frag))
457 static_cast<MCSectionMachO &
>(Sec).setAtom(
I++, CurrentAtom);
463 createAddrSigSection();
467void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
470 if (getAssembler().registerSymbol(*S))
471 S->setExternal(
true);
474void MCMachOStreamer::finalizeCGProfile() {
475 MCAssembler &
Asm = getAssembler();
476 MCObjectWriter &
W = getWriter();
477 if (
W.getCGProfile().empty())
479 for (
auto &
E :
W.getCGProfile()) {
480 finalizeCGProfileEntry(
E.From);
481 finalizeCGProfileEntry(
E.To);
486 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
491 size_t SectionBytes =
492 W.getCGProfile().size() * (2 *
sizeof(uint32_t) +
sizeof(
uint64_t));
493 (*CGProfileSection->
begin())
494 .setVarContents(std::vector<char>(SectionBytes, 0));
498 std::unique_ptr<MCAsmBackend> &&MAB,
499 std::unique_ptr<MCObjectWriter> &&OW,
500 std::unique_ptr<MCCodeEmitter> &&CE,
501 bool DWARFMustBeAtTheEnd,
502 bool LabelSections) {
503 return new MCMachOStreamer(
Context, std::move(MAB), std::move(OW),
504 std::move(CE), LabelSections);
513void MCMachOStreamer::createAddrSigSection() {
516 if (!
writer.getEmitAddrsigSection())
521 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
530 constexpr char zero[8] = {};
531 Frag->setVarContents(
zero);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
dxil container DXContainer Global Emitter
This file defines the DenseMap class.
static bool isSymbolLinkerVisible(const MCSymbol &Symbol)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file defines the SmallVector class.
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
Context object for machine code objects.
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...
Instances of this class represent a uniqued identifier for a section in the current translation unit.
FragList * curFragList() const
Streaming machine code generation interface.
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()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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
MCLOHType
Linker Optimization Hint Type.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
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)