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;
98 void emitTargetTriple(StringRef TargetTriple)
override;
100 void emitSymbolDesc(MCSymbol *Symbol,
unsigned DescValue)
override;
101 void emitCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
102 Align ByteAlignment)
override;
104 void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
105 Align ByteAlignment)
override;
106 void emitZerofill(MCSection *Section, MCSymbol *Symbol =
nullptr,
107 uint64_t
Size = 0, Align ByteAlignment =
Align(1),
108 SMLoc Loc = SMLoc())
override;
109 void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t
Size,
110 Align ByteAlignment =
Align(1))
override;
112 void emitIdent(StringRef IdentString)
override {
117 getWriter().getLOHContainer().addDirective(Kind, Args);
119 void emitCGProfileEntry(
const MCSymbolRefExpr *From,
120 const MCSymbolRefExpr *To, uint64_t
Count)
override {
122 getWriter().getCGProfile().push_back({From, To,
Count});
125 void finishImpl()
override;
127 void finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE);
128 void finalizeCGProfile();
129 void createAddrSigSection();
139 if (LabelSections && !HasSectionLabel[Section] &&
142 Section->setBeginSymbol(Label);
143 HasSectionLabel[
Section] =
true;
144 if (!
Label->isInSection())
149void MCMachOStreamer::emitEHSymAttributes(
const MCSymbol *Symbol,
150 MCSymbol *EHSymbol) {
151 auto *Sym =
static_cast<const MCSymbolMachO *
>(
Symbol);
152 getAssembler().registerSymbol(*Symbol);
153 if (Sym->isExternal())
155 if (Sym->isWeakDefinition())
157 if (Sym->isPrivateExtern())
161void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
176 static_cast<MCSymbolMachO *
>(
Symbol)->clearReferenceType();
179void MCMachOStreamer::emitAssignment(MCSymbol *Symbol,
const MCExpr *
Value) {
182 if (
Value->evaluateAsRelocatable(Res,
nullptr)) {
183 if (
const auto *SymA = Res.
getAddSym()) {
185 (SymA->getName().empty() || Res.
getConstant() != 0))
186 static_cast<MCSymbolMachO *
>(
Symbol)->setAltEntry();
197 getWriter().getDataRegions().push_back({
Kind,
Start,
nullptr});
200void MCMachOStreamer::emitDataRegionEnd() {
201 auto &Regions = getWriter().getDataRegions();
202 assert(!Regions.empty() &&
"Mismatched .end_data_region!");
203 auto &
Data = Regions.back();
204 assert(!
Data.End &&
"Mismatched .end_data_region!");
210void MCMachOStreamer::emitSubsectionsViaSymbols() {
211 getWriter().setSubsectionsViaSymbols(
true);
214void MCMachOStreamer::emitLinkerOptions(ArrayRef<std::string>
Options) {
215 getWriter().getLinkerOptions().push_back(
Options);
221 emitDataRegion(MachO::DataRegionType::DICE_KIND_DATA);
224 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE8);
227 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE16);
230 emitDataRegion(MachO::DataRegionType::DICE_KIND_JUMP_TABLE32);
239 unsigned Minor,
unsigned Update,
240 VersionTuple SDKVersion) {
241 getWriter().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
244void MCMachOStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
245 unsigned Minor,
unsigned Update,
246 VersionTuple SDKVersion) {
251void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
252 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
253 VersionTuple SDKVersion) {
255 Minor, Update, SDKVersion);
258void MCMachOStreamer::emitTargetTriple(StringRef TargetTriple) {
259 getWriter().setTargetTriple(TargetTriple);
262bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
264 auto *
Symbol =
static_cast<MCSymbolMachO *
>(Sym);
271 getWriter().getIndirectSymbols().push_back(
272 {
Symbol, getCurrentSectionOnly()});
279 getAssembler().registerSymbol(*Symbol);
312 Symbol->setExternal(
true);
319 Symbol->setReferenceTypeUndefinedLazy(
false);
325 if (
Symbol->isUndefined())
326 Symbol->setReferenceTypeUndefinedLazy(
true);
337 Symbol->setSymbolResolver();
345 Symbol->setExternal(
true);
346 Symbol->setPrivateExtern(
true);
351 if (
Symbol->isUndefined())
352 Symbol->setWeakReference();
358 Symbol->setWeakDefinition();
362 Symbol->setWeakDefinition();
363 Symbol->setWeakReference();
374void MCMachOStreamer::emitSymbolDesc(MCSymbol *Symbol,
unsigned DescValue) {
376 getAssembler().registerSymbol(*Symbol);
377 static_cast<MCSymbolMachO *
>(
Symbol)->setDesc(DescValue);
380void MCMachOStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
381 Align ByteAlignment) {
382 auto &Sym =
static_cast<MCSymbolMachO &
>(*Symbol);
384 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
386 getAssembler().registerSymbol(Sym);
387 Sym.setExternal(
true);
391void MCMachOStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
392 Align ByteAlignment) {
394 return emitZerofill(
getContext().getObjectFileInfo()->getDataBSSSection(),
395 Symbol,
Size, ByteAlignment);
398void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
399 uint64_t
Size, Align ByteAlignment,
404 if (!
Section->isBssSection()) {
406 Loc,
"The usage of .zerofill is restricted to sections of "
407 "ZEROFILL type. Use .zero or .space instead.");
413 switchSection(Section);
417 emitValueToAlignment(ByteAlignment, 0, 1, 0);
426void MCMachOStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
427 uint64_t
Size, Align ByteAlignment) {
428 emitZerofill(Section, Symbol,
Size, ByteAlignment);
431void MCMachOStreamer::finishImpl() {
439 DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
440 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
441 auto &Sym =
static_cast<const MCSymbolMachO &
>(
Symbol);
446 "Invalid offset in atom defining symbol!");
453 for (MCSection &Sec : getAssembler()) {
454 static_cast<MCSectionMachO &
>(Sec).allocAtoms();
455 const MCSymbol *CurrentAtom =
nullptr;
457 for (MCFragment &Frag : Sec) {
458 if (
const MCSymbol *Symbol = DefiningSymbolMap.
lookup(&Frag))
460 static_cast<MCSectionMachO &
>(Sec).setAtom(
I++, CurrentAtom);
466 createAddrSigSection();
470void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
473 if (getAssembler().registerSymbol(*S))
474 S->setExternal(
true);
477void MCMachOStreamer::finalizeCGProfile() {
478 MCAssembler &
Asm = getAssembler();
479 MCObjectWriter &
W = getWriter();
480 if (
W.getCGProfile().empty())
482 for (
auto &
E :
W.getCGProfile()) {
483 finalizeCGProfileEntry(
E.From);
484 finalizeCGProfileEntry(
E.To);
489 MCSection *CGProfileSection =
Asm.getContext().getMachOSection(
494 size_t SectionBytes =
495 W.getCGProfile().size() * (2 *
sizeof(uint32_t) +
sizeof(uint64_t));
496 (*CGProfileSection->
begin())
497 .setVarContents(std::vector<char>(SectionBytes, 0));
501 std::unique_ptr<MCAsmBackend> &&MAB,
502 std::unique_ptr<MCObjectWriter> &&OW,
503 std::unique_ptr<MCCodeEmitter> &&CE,
504 bool DWARFMustBeAtTheEnd,
505 bool LabelSections) {
506 return new MCMachOStreamer(Context, std::move(MAB), std::move(OW),
507 std::move(CE), LabelSections);
516void MCMachOStreamer::createAddrSigSection() {
524 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
533 constexpr char zero[8] = {};
534 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)
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.
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.
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)