LLVM 17.0.0git
MCMachOStreamer.cpp
Go to the documentation of this file.
1//===- MCMachOStreamer.cpp - MachO Streamer -------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/ADT/DenseMap.h"
12#include "llvm/ADT/StringRef.h"
14#include "llvm/MC/MCAssembler.h"
16#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCFixup.h"
20#include "llvm/MC/MCFragment.h"
25#include "llvm/MC/MCSection.h"
27#include "llvm/MC/MCSymbol.h"
29#include "llvm/MC/MCValue.h"
30#include "llvm/MC/SectionKind.h"
35#include <cassert>
36#include <vector>
37
38namespace llvm {
39class MCInst;
40class MCStreamer;
41class MCSubtargetInfo;
42class Triple;
43} // namespace llvm
44
45using namespace llvm;
46
47namespace {
48
49class MCMachOStreamer : public MCObjectStreamer {
50private:
51 /// LabelSections - true if each section change should emit a linker local
52 /// label for use in relocations for assembler local references. Obviates the
53 /// need for local relocations. False by default.
54 bool LabelSections;
55
56 bool DWARFMustBeAtTheEnd;
57 bool CreatedADWARFSection;
58
59 /// HasSectionLabel - map of which sections have already had a non-local
60 /// label emitted to them. Used so we don't emit extraneous linker local
61 /// labels in the middle of the section.
63
64 void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) override;
65
66 void emitDataRegion(DataRegionData::KindTy Kind);
67 void emitDataRegionEnd();
68
69public:
70 MCMachOStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
71 std::unique_ptr<MCObjectWriter> OW,
72 std::unique_ptr<MCCodeEmitter> Emitter,
73 bool DWARFMustBeAtTheEnd, bool label)
74 : MCObjectStreamer(Context, std::move(MAB), std::move(OW),
75 std::move(Emitter)),
76 LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd),
77 CreatedADWARFSection(false) {}
78
79 /// state management
80 void reset() override {
81 CreatedADWARFSection = false;
82 HasSectionLabel.clear();
84 }
85
86 /// @name MCStreamer Interface
87 /// @{
88
89 void changeSection(MCSection *Sect, const MCExpr *Subsect) override;
90 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
91 void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
92 void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
93 void emitAssemblerFlag(MCAssemblerFlag Flag) override;
94 void emitLinkerOptions(ArrayRef<std::string> Options) override;
95 void emitDataRegion(MCDataRegionType Kind) override;
96 void emitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
97 unsigned Update, VersionTuple SDKVersion) override;
98 void emitBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
99 unsigned Update, VersionTuple SDKVersion) override;
100 void emitDarwinTargetVariantBuildVersion(unsigned Platform, unsigned Major,
101 unsigned Minor, unsigned Update,
102 VersionTuple SDKVersion) override;
103 void emitThumbFunc(MCSymbol *Func) override;
104 bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
105 void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
106 void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
107 Align ByteAlignment) override;
108
109 void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
110 Align ByteAlignment) override;
111 void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
112 uint64_t Size = 0, Align ByteAlignment = Align(1),
113 SMLoc Loc = SMLoc()) override;
114 void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
115 Align ByteAlignment = Align(1)) override;
116
117 void emitIdent(StringRef IdentString) override {
118 llvm_unreachable("macho doesn't support this directive");
119 }
120
121 void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override {
122 getAssembler().getLOHContainer().addDirective(Kind, Args);
123 }
124 void emitCGProfileEntry(const MCSymbolRefExpr *From,
125 const MCSymbolRefExpr *To, uint64_t Count) override {
126 if (!From->getSymbol().isTemporary() && !To->getSymbol().isTemporary())
127 getAssembler().CGProfile.push_back({From, To, Count});
128 }
129
130 void finishImpl() override;
131
132 void finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE);
133 void finalizeCGProfile();
134 void createAddrSigSection();
135};
136
137} // end anonymous namespace.
138
139static bool canGoAfterDWARF(const MCSectionMachO &MSec) {
140 // These sections are created by the assembler itself after the end of
141 // the .s file.
142 StringRef SegName = MSec.getSegmentName();
143 StringRef SecName = MSec.getName();
144
145 if (SegName == "__LD" && SecName == "__compact_unwind")
146 return true;
147
148 if (SegName == "__IMPORT") {
149 if (SecName == "__jump_table")
150 return true;
151
152 if (SecName == "__pointers")
153 return true;
154 }
155
156 if (SegName == "__TEXT" && SecName == "__eh_frame")
157 return true;
158
159 if (SegName == "__DATA" && (SecName == "__nl_symbol_ptr" ||
160 SecName == "__thread_ptr"))
161 return true;
162 if (SegName == "__LLVM" && SecName == "__cg_profile")
163 return true;
164 return false;
165}
166
167void MCMachOStreamer::changeSection(MCSection *Section,
168 const MCExpr *Subsection) {
169 // Change the section normally.
170 bool Created = changeSectionImpl(Section, Subsection);
171 const MCSectionMachO &MSec = *cast<MCSectionMachO>(Section);
172 StringRef SegName = MSec.getSegmentName();
173 if (SegName == "__DWARF")
174 CreatedADWARFSection = true;
175 else if (Created && DWARFMustBeAtTheEnd && !canGoAfterDWARF(MSec))
176 assert(!CreatedADWARFSection && "Creating regular section after DWARF");
177
178 // Output a linker-local symbol so we don't need section-relative local
179 // relocations. The linker hates us when we do that.
180 if (LabelSections && !HasSectionLabel[Section] &&
181 !Section->getBeginSymbol()) {
182 MCSymbol *Label = getContext().createLinkerPrivateTempSymbol();
183 Section->setBeginSymbol(Label);
184 HasSectionLabel[Section] = true;
185 }
186}
187
188void MCMachOStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
189 MCSymbol *EHSymbol) {
190 getAssembler().registerSymbol(*Symbol);
191 if (Symbol->isExternal())
192 emitSymbolAttribute(EHSymbol, MCSA_Global);
193 if (cast<MCSymbolMachO>(Symbol)->isWeakDefinition())
194 emitSymbolAttribute(EHSymbol, MCSA_WeakDefinition);
195 if (Symbol->isPrivateExtern())
196 emitSymbolAttribute(EHSymbol, MCSA_PrivateExtern);
197}
198
199void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
200 // We have to create a new fragment if this is an atom defining symbol,
201 // fragments cannot span atoms.
202 if (getAssembler().isSymbolLinkerVisible(*Symbol))
203 insert(new MCDataFragment());
204
205 MCObjectStreamer::emitLabel(Symbol, Loc);
206
207 // This causes the reference type flag to be cleared. Darwin 'as' was "trying"
208 // to clear the weak reference and weak definition bits too, but the
209 // implementation was buggy. For now we just try to match 'as', for
210 // diffability.
211 //
212 // FIXME: Cleanup this code, these bits should be emitted based on semantic
213 // properties, not on the order of definition, etc.
214 cast<MCSymbolMachO>(Symbol)->clearReferenceType();
215}
216
217void MCMachOStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
218 MCValue Res;
219
220 if (Value->evaluateAsRelocatable(Res, nullptr, nullptr)) {
221 if (const MCSymbolRefExpr *SymAExpr = Res.getSymA()) {
222 const MCSymbol &SymA = SymAExpr->getSymbol();
223 if (!Res.getSymB() && (SymA.getName() == "" || Res.getConstant() != 0))
224 cast<MCSymbolMachO>(Symbol)->setAltEntry();
225 }
226 }
228}
229
230void MCMachOStreamer::emitDataRegion(DataRegionData::KindTy Kind) {
231 // Create a temporary label to mark the start of the data region.
232 MCSymbol *Start = getContext().createTempSymbol();
233 emitLabel(Start);
234 // Record the region for the object writer to use.
235 DataRegionData Data = { Kind, Start, nullptr };
236 std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
237 Regions.push_back(Data);
238}
239
240void MCMachOStreamer::emitDataRegionEnd() {
241 std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
242 assert(!Regions.empty() && "Mismatched .end_data_region!");
243 DataRegionData &Data = Regions.back();
244 assert(!Data.End && "Mismatched .end_data_region!");
245 // Create a temporary label to mark the end of the data region.
246 Data.End = getContext().createTempSymbol();
247 emitLabel(Data.End);
248}
249
250void MCMachOStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
251 // Let the target do whatever target specific stuff it needs to do.
252 getAssembler().getBackend().handleAssemblerFlag(Flag);
253 // Do any generic stuff we need to do.
254 switch (Flag) {
255 case MCAF_SyntaxUnified: return; // no-op here.
256 case MCAF_Code16: return; // Change parsing mode; no-op here.
257 case MCAF_Code32: return; // Change parsing mode; no-op here.
258 case MCAF_Code64: return; // Change parsing mode; no-op here.
260 getAssembler().setSubsectionsViaSymbols(true);
261 return;
262 }
263}
264
265void MCMachOStreamer::emitLinkerOptions(ArrayRef<std::string> Options) {
266 getAssembler().getLinkerOptions().push_back(Options);
267}
268
269void MCMachOStreamer::emitDataRegion(MCDataRegionType Kind) {
270 switch (Kind) {
271 case MCDR_DataRegion:
272 emitDataRegion(DataRegionData::Data);
273 return;
275 emitDataRegion(DataRegionData::JumpTable8);
276 return;
278 emitDataRegion(DataRegionData::JumpTable16);
279 return;
281 emitDataRegion(DataRegionData::JumpTable32);
282 return;
284 emitDataRegionEnd();
285 return;
286 }
287}
288
289void MCMachOStreamer::emitVersionMin(MCVersionMinType Kind, unsigned Major,
290 unsigned Minor, unsigned Update,
291 VersionTuple SDKVersion) {
292 getAssembler().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
293}
294
295void MCMachOStreamer::emitBuildVersion(unsigned Platform, unsigned Major,
296 unsigned Minor, unsigned Update,
297 VersionTuple SDKVersion) {
298 getAssembler().setBuildVersion((MachO::PlatformType)Platform, Major, Minor,
299 Update, SDKVersion);
300}
301
302void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
303 unsigned Platform, unsigned Major, unsigned Minor, unsigned Update,
304 VersionTuple SDKVersion) {
305 getAssembler().setDarwinTargetVariantBuildVersion(
306 (MachO::PlatformType)Platform, Major, Minor, Update, SDKVersion);
307}
308
309void MCMachOStreamer::emitThumbFunc(MCSymbol *Symbol) {
310 // Remember that the function is a thumb function. Fixup and relocation
311 // values will need adjusted.
312 getAssembler().setIsThumbFunc(Symbol);
313 cast<MCSymbolMachO>(Symbol)->setThumbFunc();
314}
315
316bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
318 MCSymbolMachO *Symbol = cast<MCSymbolMachO>(Sym);
319
320 // Indirect symbols are handled differently, to match how 'as' handles
321 // them. This makes writing matching .o files easier.
323 // Note that we intentionally cannot use the symbol data here; this is
324 // important for matching the string table that 'as' generates.
326 ISD.Symbol = Symbol;
327 ISD.Section = getCurrentSectionOnly();
328 getAssembler().getIndirectSymbols().push_back(ISD);
329 return true;
330 }
331
332 // Adding a symbol attribute always introduces the symbol, note that an
333 // important side effect of calling registerSymbol here is to register
334 // the symbol with the assembler.
335 getAssembler().registerSymbol(*Symbol);
336
337 // The implementation of symbol attributes is designed to match 'as', but it
338 // leaves much to desired. It doesn't really make sense to arbitrarily add and
339 // remove flags, but 'as' allows this (in particular, see .desc).
340 //
341 // In the future it might be worth trying to make these operations more well
342 // defined.
343 switch (Attribute) {
344 case MCSA_Invalid:
348 case MCSA_ELF_TypeTLS:
352 case MCSA_Extern:
353 case MCSA_Hidden:
355 case MCSA_Internal:
356 case MCSA_Protected:
357 case MCSA_Weak:
358 case MCSA_Local:
359 case MCSA_LGlobal:
360 case MCSA_Exported:
361 case MCSA_Memtag:
362 return false;
363
364 case MCSA_Global:
365 Symbol->setExternal(true);
366 // This effectively clears the undefined lazy bit, in Darwin 'as', although
367 // it isn't very consistent because it implements this as part of symbol
368 // lookup.
369 //
370 // FIXME: Cleanup this code, these bits should be emitted based on semantic
371 // properties, not on the order of definition, etc.
372 Symbol->setReferenceTypeUndefinedLazy(false);
373 break;
374
376 // FIXME: This requires -dynamic.
377 Symbol->setNoDeadStrip();
378 if (Symbol->isUndefined())
379 Symbol->setReferenceTypeUndefinedLazy(true);
380 break;
381
382 // Since .reference sets the no dead strip bit, it is equivalent to
383 // .no_dead_strip in practice.
384 case MCSA_Reference:
385 case MCSA_NoDeadStrip:
386 Symbol->setNoDeadStrip();
387 break;
388
390 Symbol->setSymbolResolver();
391 break;
392
393 case MCSA_AltEntry:
394 Symbol->setAltEntry();
395 break;
396
398 Symbol->setExternal(true);
399 Symbol->setPrivateExtern(true);
400 break;
401
403 // FIXME: This requires -dynamic.
404 if (Symbol->isUndefined())
405 Symbol->setWeakReference();
406 break;
407
409 // FIXME: 'as' enforces that this is defined and global. The manual claims
410 // it has to be in a coalesced section, but this isn't enforced.
411 Symbol->setWeakDefinition();
412 break;
413
415 Symbol->setWeakDefinition();
416 Symbol->setWeakReference();
417 break;
418
419 case MCSA_Cold:
420 Symbol->setCold();
421 break;
422 }
423
424 return true;
425}
426
427void MCMachOStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
428 // Encode the 'desc' value into the lowest implementation defined bits.
429 getAssembler().registerSymbol(*Symbol);
430 cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
431}
432
433void MCMachOStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
434 Align ByteAlignment) {
435 // FIXME: Darwin 'as' does appear to allow redef of a .comm by itself.
436 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
437
438 getAssembler().registerSymbol(*Symbol);
439 Symbol->setExternal(true);
440 Symbol->setCommon(Size, ByteAlignment);
441}
442
443void MCMachOStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
444 Align ByteAlignment) {
445 // '.lcomm' is equivalent to '.zerofill'.
446 return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
447 Symbol, Size, ByteAlignment);
448}
449
450void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
451 uint64_t Size, Align ByteAlignment,
452 SMLoc Loc) {
453 // On darwin all virtual sections have zerofill type. Disallow the usage of
454 // .zerofill in non-virtual functions. If something similar is needed, use
455 // .space or .zero.
456 if (!Section->isVirtualSection()) {
457 getContext().reportError(
458 Loc, "The usage of .zerofill is restricted to sections of "
459 "ZEROFILL type. Use .zero or .space instead.");
460 return; // Early returning here shouldn't harm. EmitZeros should work on any
461 // section.
462 }
463
464 pushSection();
465 switchSection(Section);
466
467 // The symbol may not be present, which only creates the section.
468 if (Symbol) {
469 emitValueToAlignment(ByteAlignment, 0, 1, 0);
470 emitLabel(Symbol);
471 emitZeros(Size);
472 }
473 popSection();
474}
475
476// This should always be called with the thread local bss section. Like the
477// .zerofill directive this doesn't actually switch sections on us.
478void MCMachOStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
479 uint64_t Size, Align ByteAlignment) {
480 emitZerofill(Section, Symbol, Size, ByteAlignment);
481}
482
483void MCMachOStreamer::emitInstToData(const MCInst &Inst,
484 const MCSubtargetInfo &STI) {
485 MCDataFragment *DF = getOrCreateDataFragment();
486
489 raw_svector_ostream VecOS(Code);
490 getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
491
492 // Add the fixups and data.
493 for (MCFixup &Fixup : Fixups) {
494 Fixup.setOffset(Fixup.getOffset() + DF->getContents().size());
495 DF->getFixups().push_back(Fixup);
496 }
497 DF->setHasInstructions(STI);
498 DF->getContents().append(Code.begin(), Code.end());
499}
500
501void MCMachOStreamer::finishImpl() {
502 emitFrames(&getAssembler().getBackend());
503
504 // We have to set the fragment atom associations so we can relax properly for
505 // Mach-O.
506
507 // First, scan the symbol table to build a lookup table from fragments to
508 // defining symbols.
510 for (const MCSymbol &Symbol : getAssembler().symbols()) {
511 if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() &&
512 !Symbol.isVariable()) {
513 // An atom defining symbol should never be internal to a fragment.
514 assert(Symbol.getOffset() == 0 &&
515 "Invalid offset in atom defining symbol!");
516 DefiningSymbolMap[Symbol.getFragment()] = &Symbol;
517 }
518 }
519
520 // Set the fragment atom associations by tracking the last seen atom defining
521 // symbol.
522 for (MCSection &Sec : getAssembler()) {
523 const MCSymbol *CurrentAtom = nullptr;
524 for (MCFragment &Frag : Sec) {
525 if (const MCSymbol *Symbol = DefiningSymbolMap.lookup(&Frag))
526 CurrentAtom = Symbol;
527 Frag.setAtom(CurrentAtom);
528 }
529 }
530
531 finalizeCGProfile();
532
533 createAddrSigSection();
535}
536
537void MCMachOStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE) {
538 const MCSymbol *S = &SRE->getSymbol();
539 bool Created;
540 getAssembler().registerSymbol(*S, &Created);
541 if (Created)
542 S->setExternal(true);
543}
544
545void MCMachOStreamer::finalizeCGProfile() {
546 MCAssembler &Asm = getAssembler();
547 if (Asm.CGProfile.empty())
548 return;
549 for (MCAssembler::CGProfileEntry &E : Asm.CGProfile) {
550 finalizeCGProfileEntry(E.From);
551 finalizeCGProfileEntry(E.To);
552 }
553 // We can't write the section out until symbol indices are finalized which
554 // doesn't happen until after section layout. We need to create the section
555 // and set its size now so that it's accounted for in layout.
556 MCSection *CGProfileSection = Asm.getContext().getMachOSection(
557 "__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
558 Asm.registerSection(*CGProfileSection);
559 auto *Frag = new MCDataFragment(CGProfileSection);
560 // For each entry, reserve space for 2 32-bit indices and a 64-bit count.
561 size_t SectionBytes =
562 Asm.CGProfile.size() * (2 * sizeof(uint32_t) + sizeof(uint64_t));
563 Frag->getContents().resize(SectionBytes);
564}
565
567 std::unique_ptr<MCAsmBackend> &&MAB,
568 std::unique_ptr<MCObjectWriter> &&OW,
569 std::unique_ptr<MCCodeEmitter> &&CE,
570 bool RelaxAll, bool DWARFMustBeAtTheEnd,
571 bool LabelSections) {
572 MCMachOStreamer *S =
573 new MCMachOStreamer(Context, std::move(MAB), std::move(OW), std::move(CE),
574 DWARFMustBeAtTheEnd, LabelSections);
575 const Triple &Target = Context.getTargetTriple();
576 S->emitVersionForTarget(
577 Target, Context.getObjectFileInfo()->getSDKVersion(),
578 Context.getObjectFileInfo()->getDarwinTargetVariantTriple(),
579 Context.getObjectFileInfo()->getDarwinTargetVariantSDKVersion());
580 if (RelaxAll)
581 S->getAssembler().setRelaxAll(true);
582 return S;
583}
584
585// The AddrSig section uses a series of relocations to refer to the symbols that
586// should be considered address-significant. The only interesting content of
587// these relocations is their symbol; the type, length etc will be ignored by
588// the linker. The reason we are not referring to the symbol indices directly is
589// that those indices will be invalidated by tools that update the symbol table.
590// Symbol relocations OTOH will have their indices updated by e.g. llvm-strip.
591void MCMachOStreamer::createAddrSigSection() {
592 MCAssembler &Asm = getAssembler();
593 MCObjectWriter &writer = Asm.getWriter();
594 if (!writer.getEmitAddrsigSection())
595 return;
596 // Create the AddrSig section and first data fragment here as its layout needs
597 // to be computed immediately after in order for it to be exported correctly.
598 MCSection *AddrSigSection =
599 Asm.getContext().getObjectFileInfo()->getAddrSigSection();
600 Asm.registerSection(*AddrSigSection);
601 auto *Frag = new MCDataFragment(AddrSigSection);
602 // We will generate a series of pointer-sized symbol relocations at offset
603 // 0x0. Set the section size to be large enough to contain a single pointer
604 // (instead of emitting a zero-sized section) so these relocations are
605 // technically valid, even though we don't expect these relocations to
606 // actually be applied by the linker.
607 Frag->getContents().resize(8);
608}
BlockVerifier::State From
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
dxil DXContainer Global Emitter
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
This file defines the DenseMap class.
uint64_t Size
static LVOptions Options
Definition: LVOptions.cpp:25
static bool canGoAfterDWARF(const MCSectionMachO &MSec)
LLVMContext & Context
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
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...
Definition: DenseMap.h:202
Context object for machine code objects.
Definition: MCContext.h:76
Fragment for data and encoded instructions.
Definition: MCFragment.h:241
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
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.
Defines the object file and target independent interfaces used by the assembler backend to write nati...
This represents a section on a Mach-O system (used by Mac OS X).
StringRef getSegmentName() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
StringRef getName() const
Definition: MCSection.h:124
Streaming machine code generation interface.
Definition: MCStreamer.h:212
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
const MCSymbol & getSymbol() const
Definition: MCExpr.h:399
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
void setExternal(bool Value) const
Definition: MCSymbol.h:405
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:220
This represents an "assembler immediate".
Definition: MCValue.h:36
int64_t getConstant() const
Definition: MCValue.h:43
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:45
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:44
Represents a location in source code.
Definition: SMLoc.h:23
static SectionKind getMetadata()
Definition: SectionKind.h:188
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
LLVM Value Representation.
Definition: Value.h:74
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:31
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:672
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
PlatformType
Definition: MachO.h:497
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCDataRegionType
Definition: MCDirectives.h:60
@ MCDR_DataRegionEnd
.end_data_region
Definition: MCDirectives.h:65
@ MCDR_DataRegion
.data_region
Definition: MCDirectives.h:61
@ MCDR_DataRegionJT8
.data_region jt8
Definition: MCDirectives.h:62
@ MCDR_DataRegionJT32
.data_region jt32
Definition: MCDirectives.h:64
@ MCDR_DataRegionJT16
.data_region jt16
Definition: MCDirectives.h:63
MCVersionMinType
Definition: MCDirectives.h:68
MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
MCAssemblerFlag
Definition: MCDirectives.h:52
@ MCAF_SyntaxUnified
.syntax (ARM/ELF)
Definition: MCDirectives.h:53
@ MCAF_Code64
.code64 (X86)
Definition: MCDirectives.h:57
@ MCAF_Code16
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:55
@ MCAF_Code32
.code32 (X86) / .code 32 (ARM)
Definition: MCDirectives.h:56
@ MCAF_SubsectionsViaSymbols
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:54
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.
Definition: STLExtras.h:1946
MCSymbolAttr
Definition: MCDirectives.h:18
@ MCSA_Local
.local (ELF)
Definition: MCDirectives.h:38
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
Definition: MCDirectives.h:48
@ MCSA_Memtag
.memtag (ELF)
Definition: MCDirectives.h:49
@ MCSA_Protected
.protected (ELF)
Definition: MCDirectives.h:43
@ MCSA_Exported
.globl _foo, exported (XCOFF)
Definition: MCDirectives.h:34
@ MCSA_PrivateExtern
.private_extern (MachO)
Definition: MCDirectives.h:42
@ MCSA_Internal
.internal (ELF)
Definition: MCDirectives.h:36
@ MCSA_WeakReference
.weak_reference (MachO)
Definition: MCDirectives.h:47
@ MCSA_AltEntry
.alt_entry (MachO)
Definition: MCDirectives.h:41
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
Definition: MCDirectives.h:24
@ MCSA_LazyReference
.lazy_reference (MachO)
Definition: MCDirectives.h:37
@ MCSA_ELF_TypeNoType
.type _foo, STT_NOTYPE # aka @notype
Definition: MCDirectives.h:28
@ MCSA_Reference
.reference (MachO)
Definition: MCDirectives.h:44
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
Definition: MCDirectives.h:40
@ MCSA_Weak
.weak
Definition: MCDirectives.h:45
@ MCSA_ELF_TypeTLS
.type _foo, STT_TLS # aka @tls_object
Definition: MCDirectives.h:26
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
Definition: MCDirectives.h:35
@ MCSA_WeakDefinition
.weak_definition (MachO)
Definition: MCDirectives.h:46
@ MCSA_ELF_TypeCommon
.type _foo, STT_COMMON # aka @common
Definition: MCDirectives.h:27
@ MCSA_Global
.type _foo, @gnu_unique_object
Definition: MCDirectives.h:30
@ MCSA_Extern
.extern (XCOFF)
Definition: MCDirectives.h:32
@ MCSA_Cold
.cold (MachO)
Definition: MCDirectives.h:22
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
Definition: MCDirectives.h:25
@ MCSA_ELF_TypeGnuUniqueObject
Definition: MCDirectives.h:29
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
Definition: MCDirectives.h:23
@ MCSA_Hidden
.hidden (ELF)
Definition: MCDirectives.h:33
@ MCSA_LGlobal
.lglobl (XCOFF)
Definition: MCDirectives.h:31
@ MCSA_Invalid
Not a valid directive.
Definition: MCDirectives.h:19
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
Definition: MCDirectives.h:39
Definition: BitVector.h:858
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39