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();
87 void emitEHSymAttributes(
const MCSymbol *Symbol,
MCSymbol *EHSymbol)
override;
88 void emitSubsectionsViaSymbols()
override;
93 void emitBuildVersion(
unsigned Platform,
unsigned Major,
unsigned Minor,
95 void emitDarwinTargetVariantBuildVersion(
unsigned Platform,
unsigned Major,
96 unsigned Minor,
unsigned Update,
99 void emitSymbolDesc(
MCSymbol *Symbol,
unsigned DescValue)
override;
101 Align ByteAlignment)
override;
104 Align ByteAlignment)
override;
111 void emitIdent(
StringRef IdentString)
override {
116 getWriter().getLOHContainer().addDirective(Kind, Args);
121 getWriter().getCGProfile().push_back({
From, To, Count});
124 void finishImpl()
override;
127 void finalizeCGProfile();
128 void createAddrSigSection();
138 if (LabelSections && !HasSectionLabel[Section] &&
140 MCSymbol *
Label = getContext().createLinkerPrivateTempSymbol();
141 Section->setBeginSymbol(Label);
142 HasSectionLabel[
Section] =
true;
143 if (!
Label->isInSection())
148void MCMachOStreamer::emitEHSymAttributes(
const MCSymbol *Symbol,
151 getAssembler().registerSymbol(*Symbol);
152 if (
Sym->isExternal())
154 if (
Sym->isWeakDefinition())
156 if (
Sym->isPrivateExtern())
160void MCMachOStreamer::emitLabel(
MCSymbol *Symbol,
SMLoc Loc) {
181 if (
Value->evaluateAsRelocatable(Res,
nullptr)) {
182 if (
const auto *SymA = Res.
getAddSym()) {
184 (SymA->getName().empty() || Res.
getConstant() != 0))
193 MCSymbol *Start = getContext().createTempSymbol();
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!");
205 Data.End = getContext().createTempSymbol();
209void MCMachOStreamer::emitSubsectionsViaSymbols() {
210 getWriter().setSubsectionsViaSymbols(
true);
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,
240 getWriter().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
243void MCMachOStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
244 unsigned Minor,
unsigned Update,
250void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
251 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
254 Minor, Update, SDKVersion);
257bool MCMachOStreamer::emitSymbolAttribute(
MCSymbol *
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);
374 Align ByteAlignment) {
377 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
379 getAssembler().registerSymbol(
Sym);
380 Sym.setExternal(
true);
381 Sym.setCommon(
Size, ByteAlignment);
385 Align ByteAlignment) {
387 return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
388 Symbol,
Size, ByteAlignment);
397 if (!
Section->isBssSection()) {
398 getContext().reportError(
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);
421 emitZerofill(Section, Symbol,
Size, ByteAlignment);
424void MCMachOStreamer::finishImpl() {
425 emitFrames(&getAssembler().getBackend());
433 for (
const MCSymbol &Symbol : getAssembler().symbols()) {
435 if (
Sym.isSymbolLinkerVisible() &&
Sym.isInSection() && !
Sym.isVariable() &&
439 "Invalid offset in atom defining symbol!");
448 const MCSymbol *CurrentAtom =
nullptr;
452 CurrentAtom = Symbol;
459 createAddrSigSection();
463void MCMachOStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
466 if (getAssembler().registerSymbol(*S))
470void MCMachOStreamer::finalizeCGProfile() {
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 =
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!")
BlockVerifier::State From
dxil DXContainer Global Emitter
This file defines the DenseMap class.
static bool isSymbolLinkerVisible(const MCSymbol &Symbol)
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.
Base class for the full range of assembler expressions which are needed for parsing.
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.
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()
This represents a section on a Mach-O system (used by Mac OS X).
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.
void setExternal(bool Value) const
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 ...
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
const MCSymbol * getAddSym() const
int64_t getConstant() const
const MCSymbol * getSubSym() const
Represents a location in source code.
static SectionKind getMetadata()
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
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
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)
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.