1 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
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 // This file declares the MCStreamer class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_MC_MCSTREAMER_H
14 #define LLVM_MC_MCSTREAMER_H
15 
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/MC/MCDirectives.h"
21 #include "llvm/MC/MCDwarf.h"
22 #include "llvm/MC/MCLinkerOptimizationHint.h"
23 #include "llvm/MC/MCPseudoProbe.h"
24 #include "llvm/MC/MCWinEH.h"
25 #include "llvm/Support/Error.h"
26 #include "llvm/Support/MD5.h"
27 #include "llvm/Support/SMLoc.h"
28 #include "llvm/Support/VersionTuple.h"
29 #include "llvm/TargetParser/ARMTargetParser.h"
30 #include <cassert>
31 #include <cstdint>
32 #include <memory>
33 #include <optional>
34 #include <string>
35 #include <utility>
36 #include <vector>
37 
38 namespace llvm {
39 
40 class APInt;
41 class AssemblerConstantPools;
42 class MCAsmBackend;
43 class MCAssembler;
44 class MCContext;
45 class MCExpr;
46 class MCFragment;
47 class MCInst;
48 class MCInstPrinter;
49 class MCRegister;
50 class MCSection;
51 class MCStreamer;
52 class MCSubtargetInfo;
53 class MCSymbol;
54 class MCSymbolRefExpr;
55 class Triple;
56 class Twine;
57 class raw_ostream;
58 
59 namespace codeview {
60 struct DefRangeRegisterRelHeader;
61 struct DefRangeSubfieldRegisterHeader;
62 struct DefRangeRegisterHeader;
63 struct DefRangeFramePointerRelHeader;
64 }
65 
66 using MCSectionSubPair = std::pair<MCSection *, const MCExpr *>;
67 
68 /// Target specific streamer interface. This is used so that targets can
69 /// implement support for target specific assembly directives.
70 ///
71 /// If target foo wants to use this, it should implement 3 classes:
72 /// * FooTargetStreamer : public MCTargetStreamer
73 /// * FooTargetAsmStreamer : public FooTargetStreamer
74 /// * FooTargetELFStreamer : public FooTargetStreamer
75 ///
76 /// FooTargetStreamer should have a pure virtual method for each directive. For
77 /// example, for a ".bar symbol_name" directive, it should have
78 /// virtual emitBar(const MCSymbol &Symbol) = 0;
79 ///
80 /// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
81 /// method. The assembly streamer just prints ".bar symbol_name". The object
82 /// streamer does whatever is needed to implement .bar in the object file.
83 ///
84 /// In the assembly printer and parser the target streamer can be used by
85 /// calling getTargetStreamer and casting it to FooTargetStreamer:
86 ///
87 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
88 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
89 ///
90 /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
91 /// *never* be treated differently. Callers should always talk to a
92 /// FooTargetStreamer.
93 class MCTargetStreamer {
94 protected:
95   MCStreamer &Streamer;
96 
97 public:
98   MCTargetStreamer(MCStreamer &S);
99   virtual ~MCTargetStreamer();
100 
101   MCStreamer &getStreamer() { return Streamer; }
102 
103   // Allow a target to add behavior to the EmitLabel of MCStreamer.
104   virtual void emitLabel(MCSymbol *Symbol);
105   // Allow a target to add behavior to the emitAssignment of MCStreamer.
106   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
107 
108   virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
109                               const MCInst &Inst, const MCSubtargetInfo &STI,
110                               raw_ostream &OS);
111 
112   virtual void emitDwarfFileDirective(StringRef Directive);
113 
114   /// Update streamer for a new active section.
115   ///
116   /// This is called by popSection and switchSection, if the current
117   /// section changes.
118   virtual void changeSection(const MCSection *CurSection, MCSection *Section,
119                              const MCExpr *SubSection, raw_ostream &OS);
120 
121   virtual void emitValue(const MCExpr *Value);
122 
123   /// Emit the bytes in \p Data into the output.
124   ///
125   /// This is used to emit bytes in \p Data as sequence of .byte directives.
126   virtual void emitRawBytes(StringRef Data);
127 
128   virtual void emitConstantPools();
129 
130   virtual void finish();
131 };
132 
133 // FIXME: declared here because it is used from
134 // lib/CodeGen/AsmPrinter/ARMException.cpp.
135 class ARMTargetStreamer : public MCTargetStreamer {
136 public:
137   ARMTargetStreamer(MCStreamer &S);
138   ~ARMTargetStreamer() override;
139 
140   virtual void emitFnStart();
141   virtual void emitFnEnd();
142   virtual void emitCantUnwind();
143   virtual void emitPersonality(const MCSymbol *Personality);
144   virtual void emitPersonalityIndex(unsigned Index);
145   virtual void emitHandlerData();
146   virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
147                          int64_t Offset = 0);
148   virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
149   virtual void emitPad(int64_t Offset);
150   virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
151                            bool isVector);
152   virtual void emitUnwindRaw(int64_t StackOffset,
153                              const SmallVectorImpl<uint8_t> &Opcodes);
154 
155   virtual void switchVendor(StringRef Vendor);
156   virtual void emitAttribute(unsigned Attribute, unsigned Value);
157   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
158   virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
159                                     StringRef StringValue = "");
160   virtual void emitFPU(ARM::FPUKind FPU);
161   virtual void emitArch(ARM::ArchKind Arch);
162   virtual void emitArchExtension(uint64_t ArchExt);
163   virtual void emitObjectArch(ARM::ArchKind Arch);
164   void emitTargetAttributes(const MCSubtargetInfo &STI);
165   virtual void finishAttributeSection();
166   virtual void emitInst(uint32_t Inst, char Suffix = '\0');
167 
168   virtual void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
169 
170   virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
171 
172   void emitConstantPools() override;
173 
174   virtual void emitARMWinCFIAllocStack(unsigned Size, bool Wide);
175   virtual void emitARMWinCFISaveRegMask(unsigned Mask, bool Wide);
176   virtual void emitARMWinCFISaveSP(unsigned Reg);
177   virtual void emitARMWinCFISaveFRegs(unsigned First, unsigned Last);
178   virtual void emitARMWinCFISaveLR(unsigned Offset);
179   virtual void emitARMWinCFIPrologEnd(bool Fragment);
180   virtual void emitARMWinCFINop(bool Wide);
181   virtual void emitARMWinCFIEpilogStart(unsigned Condition);
182   virtual void emitARMWinCFIEpilogEnd();
183   virtual void emitARMWinCFICustom(unsigned Opcode);
184 
185   /// Reset any state between object emissions, i.e. the equivalent of
186   /// MCStreamer's reset method.
187   virtual void reset();
188 
189   /// Callback used to implement the ldr= pseudo.
190   /// Add a new entry to the constant pool for the current section and return an
191   /// MCExpr that can be used to refer to the constant pool location.
192   const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc);
193 
194   /// Callback used to implement the .ltorg directive.
195   /// Emit contents of constant pool for the current section.
196   void emitCurrentConstantPool();
197 
198 private:
199   std::unique_ptr<AssemblerConstantPools> ConstantPools;
200 };
201 
202 /// Streaming machine code generation interface.
203 ///
204 /// This interface is intended to provide a programmatic interface that is very
205 /// similar to the level that an assembler .s file provides.  It has callbacks
206 /// to emit bytes, handle directives, etc.  The implementation of this interface
207 /// retains state to know what the current section is etc.
208 ///
209 /// There are multiple implementations of this interface: one for writing out
210 /// a .s file, and implementations that write out .o files of various formats.
211 ///
212 class MCStreamer {
213   MCContext &Context;
214   std::unique_ptr<MCTargetStreamer> TargetStreamer;
215 
216   std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
217   // This is a pair of index into DwarfFrameInfos and the MCSection associated
218   // with the frame. Note, we use an index instead of an iterator because they
219   // can be invalidated in std::vector.
220   SmallVector<std::pair<size_t, MCSection *>, 1> FrameInfoStack;
221   MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
222 
223   /// Similar to DwarfFrameInfos, but for SEH unwind info. Chained frames may
224   /// refer to each other, so use std::unique_ptr to provide pointer stability.
225   std::vector<std::unique_ptr<WinEH::FrameInfo>> WinFrameInfos;
226 
227   WinEH::FrameInfo *CurrentWinFrameInfo;
228   size_t CurrentProcWinFrameInfoStartIndex;
229 
230   /// Tracks an index to represent the order a symbol was emitted in.
231   /// Zero means we did not emit that symbol.
232   DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
233 
234   /// This is stack of current and previous section values saved by
235   /// pushSection.
236   SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
237 
238   /// Pointer to the parser's SMLoc if available. This is used to provide
239   /// locations for diagnostics.
240   const SMLoc *StartTokLocPtr = nullptr;
241 
242   /// The next unique ID to use when creating a WinCFI-related section (.pdata
243   /// or .xdata). This ID ensures that we have a one-to-one mapping from
244   /// code section to unwind info section, which MSVC's incremental linker
245   /// requires.
246   unsigned NextWinCFIID = 0;
247 
248   bool UseAssemblerInfoForParsing;
249 
250   /// Is the assembler allowed to insert padding automatically?  For
251   /// correctness reasons, we sometimes need to ensure instructions aren't
252   /// separated in unexpected ways.  At the moment, this feature is only
253   /// useable from an integrated assembler, but assembly syntax is under
254   /// discussion for future inclusion.
255   bool AllowAutoPadding = false;
256 
257 protected:
258   MCStreamer(MCContext &Ctx);
259 
260   virtual void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
261   virtual void emitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
262 
263   WinEH::FrameInfo *getCurrentWinFrameInfo() {
264     return CurrentWinFrameInfo;
265   }
266 
267   virtual void emitWindowsUnwindTables(WinEH::FrameInfo *Frame);
268 
269   virtual void emitWindowsUnwindTables();
270 
271   virtual void emitRawTextImpl(StringRef String);
272 
273   /// Returns true if the the .cv_loc directive is in the right section.
274   bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc);
275 
276 public:
277   MCStreamer(const MCStreamer &) = delete;
278   MCStreamer &operator=(const MCStreamer &) = delete;
279   virtual ~MCStreamer();
280 
281   void visitUsedExpr(const MCExpr &Expr);
282   virtual void visitUsedSymbol(const MCSymbol &Sym);
283 
284   void setTargetStreamer(MCTargetStreamer *TS) {
285     TargetStreamer.reset(TS);
286   }
287 
288   void setStartTokLocPtr(const SMLoc *Loc) { StartTokLocPtr = Loc; }
289   SMLoc getStartTokLoc() const {
290     return StartTokLocPtr ? *StartTokLocPtr : SMLoc();
291   }
292 
293   /// State management
294   ///
295   virtual void reset();
296 
297   MCContext &getContext() const { return Context; }
298 
299   virtual MCAssembler *getAssemblerPtr() { return nullptr; }
300 
301   void setUseAssemblerInfoForParsing(bool v) { UseAssemblerInfoForParsing = v; }
302   bool getUseAssemblerInfoForParsing() { return UseAssemblerInfoForParsing; }
303 
304   MCTargetStreamer *getTargetStreamer() {
305     return TargetStreamer.get();
306   }
307 
308   void setAllowAutoPadding(bool v) { AllowAutoPadding = v; }
309   bool getAllowAutoPadding() const { return AllowAutoPadding; }
310 
311   /// When emitting an object file, create and emit a real label. When emitting
312   /// textual assembly, this should do nothing to avoid polluting our output.
313   virtual MCSymbol *emitCFILabel();
314 
315   /// Retrieve the current frame info if one is available and it is not yet
316   /// closed. Otherwise, issue an error and return null.
317   WinEH::FrameInfo *EnsureValidWinFrameInfo(SMLoc Loc);
318 
319   unsigned getNumFrameInfos();
320   ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const;
321 
322   bool hasUnfinishedDwarfFrameInfo();
323 
324   unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
325   ArrayRef<std::unique_ptr<WinEH::FrameInfo>> getWinFrameInfos() const {
326     return WinFrameInfos;
327   }
328 
329   void generateCompactUnwindEncodings(MCAsmBackend *MAB);
330 
331   /// \name Assembly File Formatting.
332   /// @{
333 
334   /// Return true if this streamer supports verbose assembly and if it is
335   /// enabled.
336   virtual bool isVerboseAsm() const { return false; }
337 
338   /// Return true if this asm streamer supports emitting unformatted text
339   /// to the .s file with EmitRawText.
340   virtual bool hasRawTextSupport() const { return false; }
341 
342   /// Is the integrated assembler required for this streamer to function
343   /// correctly?
344   virtual bool isIntegratedAssemblerRequired() const { return false; }
345 
346   /// Add a textual comment.
347   ///
348   /// Typically for comments that can be emitted to the generated .s
349   /// file if applicable as a QoI issue to make the output of the compiler
350   /// more readable.  This only affects the MCAsmStreamer, and only when
351   /// verbose assembly output is enabled.
352   ///
353   /// If the comment includes embedded \n's, they will each get the comment
354   /// prefix as appropriate.  The added comment should not end with a \n.
355   /// By default, each comment is terminated with an end of line, i.e. the
356   /// EOL param is set to true by default. If one prefers not to end the
357   /// comment with a new line then the EOL param should be passed
358   /// with a false value.
359   virtual void AddComment(const Twine &T, bool EOL = true) {}
360 
361   /// Return a raw_ostream that comments can be written to. Unlike
362   /// AddComment, you are required to terminate comments with \n if you use this
363   /// method.
364   virtual raw_ostream &getCommentOS();
365 
366   /// Print T and prefix it with the comment string (normally #) and
367   /// optionally a tab. This prints the comment immediately, not at the end of
368   /// the current line. It is basically a safe version of EmitRawText: since it
369   /// only prints comments, the object streamer ignores it instead of asserting.
370   virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
371 
372   /// Add explicit comment T. T is required to be a valid
373   /// comment in the output and does not need to be escaped.
374   virtual void addExplicitComment(const Twine &T);
375 
376   /// Emit added explicit comments.
377   virtual void emitExplicitComments();
378 
379   /// Emit a blank line to a .s file to pretty it up.
380   virtual void addBlankLine() {}
381 
382   /// @}
383 
384   /// \name Symbol & Section Management
385   /// @{
386 
387   /// Return the current section that the streamer is emitting code to.
388   MCSectionSubPair getCurrentSection() const {
389     if (!SectionStack.empty())
390       return SectionStack.back().first;
391     return MCSectionSubPair();
392   }
393   MCSection *getCurrentSectionOnly() const { return getCurrentSection().first; }
394 
395   /// Return the previous section that the streamer is emitting code to.
396   MCSectionSubPair getPreviousSection() const {
397     if (!SectionStack.empty())
398       return SectionStack.back().second;
399     return MCSectionSubPair();
400   }
401 
402   /// Returns an index to represent the order a symbol was emitted in.
403   /// (zero if we did not emit that symbol)
404   unsigned getSymbolOrder(const MCSymbol *Sym) const {
405     return SymbolOrdering.lookup(Sym);
406   }
407 
408   /// Update streamer for a new active section.
409   ///
410   /// This is called by popSection and switchSection, if the current
411   /// section changes.
412   virtual void changeSection(MCSection *, const MCExpr *);
413 
414   /// Save the current and previous section on the section stack.
415   void pushSection() {
416     SectionStack.push_back(
417         std::make_pair(getCurrentSection(), getPreviousSection()));
418   }
419 
420   /// Restore the current and previous section from the section stack.
421   /// Calls changeSection as needed.
422   ///
423   /// Returns false if the stack was empty.
424   bool popSection() {
425     if (SectionStack.size() <= 1)
426       return false;
427     auto I = SectionStack.end();
428     --I;
429     MCSectionSubPair OldSection = I->first;
430     --I;
431     MCSectionSubPair NewSection = I->first;
432 
433     if (NewSection.first && OldSection != NewSection)
434       changeSection(NewSection.first, NewSection.second);
435     SectionStack.pop_back();
436     return true;
437   }
438 
439   bool subSection(const MCExpr *Subsection) {
440     if (SectionStack.empty())
441       return false;
442 
443     switchSection(SectionStack.back().first.first, Subsection);
444     return true;
445   }
446 
447   /// Set the current section where code is being emitted to \p Section.  This
448   /// is required to update CurSection.
449   ///
450   /// This corresponds to assembler directives like .section, .text, etc.
451   virtual void switchSection(MCSection *Section,
452                              const MCExpr *Subsection = nullptr);
453 
454   /// Set the current section where code is being emitted to \p Section.
455   /// This is required to update CurSection. This version does not call
456   /// changeSection.
457   void switchSectionNoChange(MCSection *Section,
458                              const MCExpr *Subsection = nullptr) {
459     assert(Section && "Cannot switch to a null section!");
460     MCSectionSubPair curSection = SectionStack.back().first;
461     SectionStack.back().second = curSection;
462     if (MCSectionSubPair(Section, Subsection) != curSection)
463       SectionStack.back().first = MCSectionSubPair(Section, Subsection);
464   }
465 
466   /// Create the default sections and set the initial one.
467   virtual void initSections(bool NoExecStack, const MCSubtargetInfo &STI);
468 
469   MCSymbol *endSection(MCSection *Section);
470 
471   /// Sets the symbol's section.
472   ///
473   /// Each emitted symbol will be tracked in the ordering table,
474   /// so we can sort on them later.
475   void assignFragment(MCSymbol *Symbol, MCFragment *Fragment);
476 
477   /// Returns the mnemonic for \p MI, if the streamer has access to a
478   /// instruction printer and returns an empty string otherwise.
479   virtual StringRef getMnemonic(MCInst &MI) { return ""; }
480 
481   /// Emit a label for \p Symbol into the current section.
482   ///
483   /// This corresponds to an assembler statement such as:
484   ///   foo:
485   ///
486   /// \param Symbol - The symbol to emit. A given symbol should only be
487   /// emitted as a label once, and symbols emitted as a label should never be
488   /// used in an assignment.
489   // FIXME: These emission are non-const because we mutate the symbol to
490   // add the section we're emitting it to later.
491   virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc());
492 
493   virtual void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
494 
495   /// Note in the output the specified \p Flag.
496   virtual void emitAssemblerFlag(MCAssemblerFlag Flag);
497 
498   /// Emit the given list \p Options of strings as linker
499   /// options into the output.
500   virtual void emitLinkerOptions(ArrayRef<std::string> Kind) {}
501 
502   /// Note in the output the specified region \p Kind.
503   virtual void emitDataRegion(MCDataRegionType Kind) {}
504 
505   /// Specify the Mach-O minimum deployment target version.
506   virtual void emitVersionMin(MCVersionMinType Type, unsigned Major,
507                               unsigned Minor, unsigned Update,
508                               VersionTuple SDKVersion) {}
509 
510   /// Emit/Specify Mach-O build version command.
511   /// \p Platform should be one of MachO::PlatformType.
512   virtual void emitBuildVersion(unsigned Platform, unsigned Major,
513                                 unsigned Minor, unsigned Update,
514                                 VersionTuple SDKVersion) {}
515 
516   virtual void emitDarwinTargetVariantBuildVersion(unsigned Platform,
517                                                    unsigned Major,
518                                                    unsigned Minor,
519                                                    unsigned Update,
520                                                    VersionTuple SDKVersion) {}
521 
522   void emitVersionForTarget(const Triple &Target,
523                             const VersionTuple &SDKVersion,
524                             const Triple *DarwinTargetVariantTriple,
525                             const VersionTuple &DarwinTargetVariantSDKVersion);
526 
527   /// Note in the output that the specified \p Func is a Thumb mode
528   /// function (ARM target only).
529   virtual void emitThumbFunc(MCSymbol *Func);
530 
531   /// Emit an assignment of \p Value to \p Symbol.
532   ///
533   /// This corresponds to an assembler statement such as:
534   ///  symbol = value
535   ///
536   /// The assignment generates no code, but has the side effect of binding the
537   /// value in the current context. For the assembly streamer, this prints the
538   /// binding into the .s file.
539   ///
540   /// \param Symbol - The symbol being assigned to.
541   /// \param Value - The value for the symbol.
542   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
543 
544   /// Emit an assignment of \p Value to \p Symbol, but only if \p Value is also
545   /// emitted.
546   virtual void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value);
547 
548   /// Emit an weak reference from \p Alias to \p Symbol.
549   ///
550   /// This corresponds to an assembler statement such as:
551   ///  .weakref alias, symbol
552   ///
553   /// \param Alias - The alias that is being created.
554   /// \param Symbol - The symbol being aliased.
555   virtual void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
556 
557   /// Add the given \p Attribute to \p Symbol.
558   virtual bool emitSymbolAttribute(MCSymbol *Symbol,
559                                    MCSymbolAttr Attribute) = 0;
560 
561   /// Set the \p DescValue for the \p Symbol.
562   ///
563   /// \param Symbol - The symbol to have its n_desc field set.
564   /// \param DescValue - The value to set into the n_desc field.
565   virtual void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
566 
567   /// Start emitting COFF symbol definition
568   ///
569   /// \param Symbol - The symbol to have its External & Type fields set.
570   virtual void beginCOFFSymbolDef(const MCSymbol *Symbol);
571 
572   /// Emit the storage class of the symbol.
573   ///
574   /// \param StorageClass - The storage class the symbol should have.
575   virtual void emitCOFFSymbolStorageClass(int StorageClass);
576 
577   /// Emit the type of the symbol.
578   ///
579   /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
580   virtual void emitCOFFSymbolType(int Type);
581 
582   /// Marks the end of the symbol definition.
583   virtual void endCOFFSymbolDef();
584 
585   virtual void emitCOFFSafeSEH(MCSymbol const *Symbol);
586 
587   /// Emits the symbol table index of a Symbol into the current section.
588   virtual void emitCOFFSymbolIndex(MCSymbol const *Symbol);
589 
590   /// Emits a COFF section index.
591   ///
592   /// \param Symbol - Symbol the section number relocation should point to.
593   virtual void emitCOFFSectionIndex(MCSymbol const *Symbol);
594 
595   /// Emits a COFF section relative relocation.
596   ///
597   /// \param Symbol - Symbol the section relative relocation should point to.
598   virtual void emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset);
599 
600   /// Emits a COFF image relative relocation.
601   ///
602   /// \param Symbol - Symbol the image relative relocation should point to.
603   virtual void emitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset);
604 
605   /// Emits an lcomm directive with XCOFF csect information.
606   ///
607   /// \param LabelSym - Label on the block of storage.
608   /// \param Size - The size of the block of storage.
609   /// \param CsectSym - Csect name for the block of storage.
610   /// \param Alignment - The alignment of the symbol in bytes.
611   virtual void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
612                                           MCSymbol *CsectSym, Align Alignment);
613 
614   /// Emit a symbol's linkage and visibility with a linkage directive for XCOFF.
615   ///
616   /// \param Symbol - The symbol to emit.
617   /// \param Linkage - The linkage of the symbol to emit.
618   /// \param Visibility - The visibility of the symbol to emit or MCSA_Invalid
619   /// if the symbol does not have an explicit visibility.
620   virtual void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
621                                                     MCSymbolAttr Linkage,
622                                                     MCSymbolAttr Visibility);
623 
624   /// Emit a XCOFF .rename directive which creates a synonym for an illegal or
625   /// undesirable name.
626   ///
627   /// \param Name - The name used internally in the assembly for references to
628   /// the symbol.
629   /// \param Rename - The value to which the Name parameter is
630   /// changed at the end of assembly.
631   virtual void emitXCOFFRenameDirective(const MCSymbol *Name, StringRef Rename);
632 
633   /// Emit an XCOFF .except directive which adds information about
634   /// a trap instruction to the object file exception section
635   ///
636   /// \param Symbol - The function containing the trap.
637   /// \param Lang - The language code for the exception entry.
638   /// \param Reason - The reason code for the exception entry.
639   virtual void emitXCOFFExceptDirective(const MCSymbol *Symbol,
640                                         const MCSymbol *Trap,
641                                         unsigned Lang, unsigned Reason,
642                                         unsigned FunctionSize, bool hasDebug);
643 
644   /// Emit a XCOFF .ref directive which creates R_REF type entry in the
645   /// relocation table for one or more symbols.
646   ///
647   /// \param Sym - The symbol on the .ref directive.
648   virtual void emitXCOFFRefDirective(const MCSymbol *Symbol);
649 
650   /// Emit a C_INFO symbol with XCOFF embedded metadata to the .info section.
651   ///
652   /// \param Name - The embedded metadata name
653   /// \param Metadata - The embedded metadata
654   virtual void emitXCOFFCInfoSym(StringRef Name, StringRef Metadata);
655 
656   /// Emit an ELF .size directive.
657   ///
658   /// This corresponds to an assembler statement such as:
659   ///  .size symbol, expression
660   virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value);
661 
662   /// Emit an ELF .symver directive.
663   ///
664   /// This corresponds to an assembler statement such as:
665   ///  .symver _start, foo@@SOME_VERSION
666   virtual void emitELFSymverDirective(const MCSymbol *OriginalSym,
667                                       StringRef Name, bool KeepOriginalSym);
668 
669   /// Emit a Linker Optimization Hint (LOH) directive.
670   /// \param Args - Arguments of the LOH.
671   virtual void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
672 
673   /// Emit a .gnu_attribute directive.
674   virtual void emitGNUAttribute(unsigned Tag, unsigned Value) {}
675 
676   /// Emit a common symbol.
677   ///
678   /// \param Symbol - The common symbol to emit.
679   /// \param Size - The size of the common symbol.
680   /// \param ByteAlignment - The alignment of the symbol.
681   virtual void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
682                                 Align ByteAlignment) = 0;
683 
684   /// Emit a local common (.lcomm) symbol.
685   ///
686   /// \param Symbol - The common symbol to emit.
687   /// \param Size - The size of the common symbol.
688   /// \param ByteAlignment - The alignment of the common symbol in bytes.
689   virtual void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
690                                      Align ByteAlignment);
691 
692   /// Emit the zerofill section and an optional symbol.
693   ///
694   /// \param Section - The zerofill section to create and or to put the symbol
695   /// \param Symbol - The zerofill symbol to emit, if non-NULL.
696   /// \param Size - The size of the zerofill symbol.
697   /// \param ByteAlignment - The alignment of the zerofill symbol.
698   virtual void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
699                             uint64_t Size = 0, Align ByteAlignment = Align(1),
700                             SMLoc Loc = SMLoc()) = 0;
701 
702   /// Emit a thread local bss (.tbss) symbol.
703   ///
704   /// \param Section - The thread local common section.
705   /// \param Symbol - The thread local common symbol to emit.
706   /// \param Size - The size of the symbol.
707   /// \param ByteAlignment - The alignment of the thread local common symbol.
708   virtual void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
709                               uint64_t Size, Align ByteAlignment = Align(1));
710 
711   /// @}
712   /// \name Generating Data
713   /// @{
714 
715   /// Emit the bytes in \p Data into the output.
716   ///
717   /// This is used to implement assembler directives such as .byte, .ascii,
718   /// etc.
719   virtual void emitBytes(StringRef Data);
720 
721   /// Functionally identical to EmitBytes. When emitting textual assembly, this
722   /// method uses .byte directives instead of .ascii or .asciz for readability.
723   virtual void emitBinaryData(StringRef Data);
724 
725   /// Emit the expression \p Value into the output as a native
726   /// integer of the given \p Size bytes.
727   ///
728   /// This is used to implement assembler directives such as .word, .quad,
729   /// etc.
730   ///
731   /// \param Value - The value to emit.
732   /// \param Size - The size of the integer (in bytes) to emit. This must
733   /// match a native machine width.
734   /// \param Loc - The location of the expression for error reporting.
735   virtual void emitValueImpl(const MCExpr *Value, unsigned Size,
736                              SMLoc Loc = SMLoc());
737 
738   void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
739 
740   /// Special case of EmitValue that avoids the client having
741   /// to pass in a MCExpr for constant integers.
742   virtual void emitIntValue(uint64_t Value, unsigned Size);
743   virtual void emitIntValue(APInt Value);
744 
745   /// Special case of EmitValue that avoids the client having to pass
746   /// in a MCExpr for constant integers & prints in Hex format for certain
747   /// modes.
748   virtual void emitIntValueInHex(uint64_t Value, unsigned Size) {
749     emitIntValue(Value, Size);
750   }
751 
752   void emitInt8(uint64_t Value) { emitIntValue(Value, 1); }
753   void emitInt16(uint64_t Value) { emitIntValue(Value, 2); }
754   void emitInt32(uint64_t Value) { emitIntValue(Value, 4); }
755   void emitInt64(uint64_t Value) { emitIntValue(Value, 8); }
756 
757   /// Special case of EmitValue that avoids the client having to pass
758   /// in a MCExpr for constant integers & prints in Hex format for certain
759   /// modes, pads the field with leading zeros to Size width
760   virtual void emitIntValueInHexWithPadding(uint64_t Value, unsigned Size) {
761     emitIntValue(Value, Size);
762   }
763 
764   virtual void emitULEB128Value(const MCExpr *Value);
765 
766   virtual void emitSLEB128Value(const MCExpr *Value);
767 
768   /// Special case of EmitULEB128Value that avoids the client having to
769   /// pass in a MCExpr for constant integers.
770   unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo = 0);
771 
772   /// Special case of EmitSLEB128Value that avoids the client having to
773   /// pass in a MCExpr for constant integers.
774   unsigned emitSLEB128IntValue(int64_t Value);
775 
776   /// Special case of EmitValue that avoids the client having to pass in
777   /// a MCExpr for MCSymbols.
778   void emitSymbolValue(const MCSymbol *Sym, unsigned Size,
779                        bool IsSectionRelative = false);
780 
781   /// Emit the expression \p Value into the output as a dtprel
782   /// (64-bit DTP relative) value.
783   ///
784   /// This is used to implement assembler directives such as .dtpreldword on
785   /// targets that support them.
786   virtual void emitDTPRel64Value(const MCExpr *Value);
787 
788   /// Emit the expression \p Value into the output as a dtprel
789   /// (32-bit DTP relative) value.
790   ///
791   /// This is used to implement assembler directives such as .dtprelword on
792   /// targets that support them.
793   virtual void emitDTPRel32Value(const MCExpr *Value);
794 
795   /// Emit the expression \p Value into the output as a tprel
796   /// (64-bit TP relative) value.
797   ///
798   /// This is used to implement assembler directives such as .tpreldword on
799   /// targets that support them.
800   virtual void emitTPRel64Value(const MCExpr *Value);
801 
802   /// Emit the expression \p Value into the output as a tprel
803   /// (32-bit TP relative) value.
804   ///
805   /// This is used to implement assembler directives such as .tprelword on
806   /// targets that support them.
807   virtual void emitTPRel32Value(const MCExpr *Value);
808 
809   /// Emit the expression \p Value into the output as a gprel64 (64-bit
810   /// GP relative) value.
811   ///
812   /// This is used to implement assembler directives such as .gpdword on
813   /// targets that support them.
814   virtual void emitGPRel64Value(const MCExpr *Value);
815 
816   /// Emit the expression \p Value into the output as a gprel32 (32-bit
817   /// GP relative) value.
818   ///
819   /// This is used to implement assembler directives such as .gprel32 on
820   /// targets that support them.
821   virtual void emitGPRel32Value(const MCExpr *Value);
822 
823   /// Emit NumBytes bytes worth of the value specified by FillValue.
824   /// This implements directives such as '.space'.
825   void emitFill(uint64_t NumBytes, uint8_t FillValue);
826 
827   /// Emit \p Size bytes worth of the value specified by \p FillValue.
828   ///
829   /// This is used to implement assembler directives such as .space or .skip.
830   ///
831   /// \param NumBytes - The number of bytes to emit.
832   /// \param FillValue - The value to use when filling bytes.
833   /// \param Loc - The location of the expression for error reporting.
834   virtual void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
835                         SMLoc Loc = SMLoc());
836 
837   /// Emit \p NumValues copies of \p Size bytes. Each \p Size bytes is
838   /// taken from the lowest order 4 bytes of \p Expr expression.
839   ///
840   /// This is used to implement assembler directives such as .fill.
841   ///
842   /// \param NumValues - The number of copies of \p Size bytes to emit.
843   /// \param Size - The size (in bytes) of each repeated value.
844   /// \param Expr - The expression from which \p Size bytes are used.
845   virtual void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
846                         SMLoc Loc = SMLoc());
847 
848   virtual void emitNops(int64_t NumBytes, int64_t ControlledNopLength,
849                         SMLoc Loc, const MCSubtargetInfo& STI);
850 
851   /// Emit NumBytes worth of zeros.
852   /// This function properly handles data in virtual sections.
853   void emitZeros(uint64_t NumBytes);
854 
855   /// Emit some number of copies of \p Value until the byte alignment \p
856   /// ByteAlignment is reached.
857   ///
858   /// If the number of bytes need to emit for the alignment is not a multiple
859   /// of \p ValueSize, then the contents of the emitted fill bytes is
860   /// undefined.
861   ///
862   /// This used to implement the .align assembler directive.
863   ///
864   /// \param Alignment - The alignment to reach.
865   /// \param Value - The value to use when filling bytes.
866   /// \param ValueSize - The size of the integer (in bytes) to emit for
867   /// \p Value. This must match a native machine width.
868   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
869   /// the alignment cannot be reached in this many bytes, no bytes are
870   /// emitted.
871   virtual void emitValueToAlignment(Align Alignment, int64_t Value = 0,
872                                     unsigned ValueSize = 1,
873                                     unsigned MaxBytesToEmit = 0);
874 
875   /// Emit nops until the byte alignment \p ByteAlignment is reached.
876   ///
877   /// This used to align code where the alignment bytes may be executed.  This
878   /// can emit different bytes for different sizes to optimize execution.
879   ///
880   /// \param Alignment - The alignment to reach.
881   /// \param STI - The MCSubtargetInfo in operation when padding is emitted.
882   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
883   /// the alignment cannot be reached in this many bytes, no bytes are
884   /// emitted.
885   virtual void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI,
886                                  unsigned MaxBytesToEmit = 0);
887 
888   /// Emit some number of copies of \p Value until the byte offset \p
889   /// Offset is reached.
890   ///
891   /// This is used to implement assembler directives such as .org.
892   ///
893   /// \param Offset - The offset to reach. This may be an expression, but the
894   /// expression must be associated with the current section.
895   /// \param Value - The value to use when filling bytes.
896   virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
897                                  SMLoc Loc);
898 
899   /// @}
900 
901   /// Switch to a new logical file.  This is used to implement the '.file
902   /// "foo.c"' assembler directive.
903   virtual void emitFileDirective(StringRef Filename);
904 
905   /// Emit ".file assembler diretive with additioal info.
906   virtual void emitFileDirective(StringRef Filename, StringRef CompilerVerion,
907                                  StringRef TimeStamp, StringRef Description);
908 
909   /// Emit the "identifiers" directive.  This implements the
910   /// '.ident "version foo"' assembler directive.
911   virtual void emitIdent(StringRef IdentString) {}
912 
913   /// Associate a filename with a specified logical file number.  This
914   /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
915   unsigned emitDwarfFileDirective(
916       unsigned FileNo, StringRef Directory, StringRef Filename,
917       std::optional<MD5::MD5Result> Checksum = std::nullopt,
918       std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0) {
919     return cantFail(
920         tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum,
921                                   Source, CUID));
922   }
923 
924   /// Associate a filename with a specified logical file number.
925   /// Also associate a directory, optional checksum, and optional source
926   /// text with the logical file.  This implements the DWARF2
927   /// '.file 4 "dir/foo.c"' assembler directive, and the DWARF5
928   /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive.
929   virtual Expected<unsigned> tryEmitDwarfFileDirective(
930       unsigned FileNo, StringRef Directory, StringRef Filename,
931       std::optional<MD5::MD5Result> Checksum = std::nullopt,
932       std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0);
933 
934   /// Specify the "root" file of the compilation, using the ".file 0" extension.
935   virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
936                                        std::optional<MD5::MD5Result> Checksum,
937                                        std::optional<StringRef> Source,
938                                        unsigned CUID = 0);
939 
940   virtual void emitCFIBKeyFrame();
941   virtual void emitCFIMTETaggedFrame();
942 
943   /// This implements the DWARF2 '.loc fileno lineno ...' assembler
944   /// directive.
945   virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line,
946                                      unsigned Column, unsigned Flags,
947                                      unsigned Isa, unsigned Discriminator,
948                                      StringRef FileName);
949 
950   /// Associate a filename with a specified logical file number, and also
951   /// specify that file's checksum information.  This implements the '.cv_file 4
952   /// "foo.c"' assembler directive. Returns true on success.
953   virtual bool emitCVFileDirective(unsigned FileNo, StringRef Filename,
954                                    ArrayRef<uint8_t> Checksum,
955                                    unsigned ChecksumKind);
956 
957   /// Introduces a function id for use with .cv_loc.
958   virtual bool emitCVFuncIdDirective(unsigned FunctionId);
959 
960   /// Introduces an inline call site id for use with .cv_loc. Includes
961   /// extra information for inline line table generation.
962   virtual bool emitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
963                                            unsigned IAFile, unsigned IALine,
964                                            unsigned IACol, SMLoc Loc);
965 
966   /// This implements the CodeView '.cv_loc' assembler directive.
967   virtual void emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
968                                   unsigned Line, unsigned Column,
969                                   bool PrologueEnd, bool IsStmt,
970                                   StringRef FileName, SMLoc Loc);
971 
972   /// This implements the CodeView '.cv_linetable' assembler directive.
973   virtual void emitCVLinetableDirective(unsigned FunctionId,
974                                         const MCSymbol *FnStart,
975                                         const MCSymbol *FnEnd);
976 
977   /// This implements the CodeView '.cv_inline_linetable' assembler
978   /// directive.
979   virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
980                                               unsigned SourceFileId,
981                                               unsigned SourceLineNum,
982                                               const MCSymbol *FnStartSym,
983                                               const MCSymbol *FnEndSym);
984 
985   /// This implements the CodeView '.cv_def_range' assembler
986   /// directive.
987   virtual void emitCVDefRangeDirective(
988       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
989       StringRef FixedSizePortion);
990 
991   virtual void emitCVDefRangeDirective(
992       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
993       codeview::DefRangeRegisterRelHeader DRHdr);
994 
995   virtual void emitCVDefRangeDirective(
996       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
997       codeview::DefRangeSubfieldRegisterHeader DRHdr);
998 
999   virtual void emitCVDefRangeDirective(
1000       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1001       codeview::DefRangeRegisterHeader DRHdr);
1002 
1003   virtual void emitCVDefRangeDirective(
1004       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1005       codeview::DefRangeFramePointerRelHeader DRHdr);
1006 
1007   /// This implements the CodeView '.cv_stringtable' assembler directive.
1008   virtual void emitCVStringTableDirective() {}
1009 
1010   /// This implements the CodeView '.cv_filechecksums' assembler directive.
1011   virtual void emitCVFileChecksumsDirective() {}
1012 
1013   /// This implements the CodeView '.cv_filechecksumoffset' assembler
1014   /// directive.
1015   virtual void emitCVFileChecksumOffsetDirective(unsigned FileNo) {}
1016 
1017   /// This implements the CodeView '.cv_fpo_data' assembler directive.
1018   virtual void emitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc = {}) {}
1019 
1020   /// Emit the absolute difference between two symbols.
1021   ///
1022   /// \pre Offset of \c Hi is greater than the offset \c Lo.
1023   virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
1024                                       unsigned Size);
1025 
1026   /// Emit the absolute difference between two symbols encoded with ULEB128.
1027   virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
1028                                                const MCSymbol *Lo);
1029 
1030   virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
1031   virtual void emitCFISections(bool EH, bool Debug);
1032   void emitCFIStartProc(bool IsSimple, SMLoc Loc = SMLoc());
1033   void emitCFIEndProc();
1034   virtual void emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc = {});
1035   virtual void emitCFIDefCfaOffset(int64_t Offset, SMLoc Loc = {});
1036   virtual void emitCFIDefCfaRegister(int64_t Register, SMLoc Loc = {});
1037   virtual void emitCFILLVMDefAspaceCfa(int64_t Register, int64_t Offset,
1038                                        int64_t AddressSpace, SMLoc Loc = {});
1039   virtual void emitCFIOffset(int64_t Register, int64_t Offset, SMLoc Loc = {});
1040   virtual void emitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
1041   virtual void emitCFILsda(const MCSymbol *Sym, unsigned Encoding);
1042   virtual void emitCFIRememberState(SMLoc Loc);
1043   virtual void emitCFIRestoreState(SMLoc Loc);
1044   virtual void emitCFISameValue(int64_t Register, SMLoc Loc = {});
1045   virtual void emitCFIRestore(int64_t Register, SMLoc Loc = {});
1046   virtual void emitCFIRelOffset(int64_t Register, int64_t Offset, SMLoc Loc);
1047   virtual void emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc = {});
1048   virtual void emitCFIEscape(StringRef Values, SMLoc Loc = {});
1049   virtual void emitCFIReturnColumn(int64_t Register);
1050   virtual void emitCFIGnuArgsSize(int64_t Size, SMLoc Loc = {});
1051   virtual void emitCFISignalFrame();
1052   virtual void emitCFIUndefined(int64_t Register, SMLoc Loc = {});
1053   virtual void emitCFIRegister(int64_t Register1, int64_t Register2,
1054                                SMLoc Loc = {});
1055   virtual void emitCFIWindowSave(SMLoc Loc = {});
1056   virtual void emitCFINegateRAState(SMLoc Loc = {});
1057 
1058   virtual void emitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc());
1059   virtual void emitWinCFIEndProc(SMLoc Loc = SMLoc());
1060   /// This is used on platforms, such as Windows on ARM64, that require function
1061   /// or funclet sizes to be emitted in .xdata before the End marker is emitted
1062   /// for the frame.  We cannot use the End marker, as it is not set at the
1063   /// point of emitting .xdata, in order to indicate that the frame is active.
1064   virtual void emitWinCFIFuncletOrFuncEnd(SMLoc Loc = SMLoc());
1065   virtual void emitWinCFIStartChained(SMLoc Loc = SMLoc());
1066   virtual void emitWinCFIEndChained(SMLoc Loc = SMLoc());
1067   virtual void emitWinCFIPushReg(MCRegister Register, SMLoc Loc = SMLoc());
1068   virtual void emitWinCFISetFrame(MCRegister Register, unsigned Offset,
1069                                   SMLoc Loc = SMLoc());
1070   virtual void emitWinCFIAllocStack(unsigned Size, SMLoc Loc = SMLoc());
1071   virtual void emitWinCFISaveReg(MCRegister Register, unsigned Offset,
1072                                  SMLoc Loc = SMLoc());
1073   virtual void emitWinCFISaveXMM(MCRegister Register, unsigned Offset,
1074                                  SMLoc Loc = SMLoc());
1075   virtual void emitWinCFIPushFrame(bool Code, SMLoc Loc = SMLoc());
1076   virtual void emitWinCFIEndProlog(SMLoc Loc = SMLoc());
1077   virtual void emitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
1078                                 SMLoc Loc = SMLoc());
1079   virtual void emitWinEHHandlerData(SMLoc Loc = SMLoc());
1080 
1081   virtual void emitCGProfileEntry(const MCSymbolRefExpr *From,
1082                                   const MCSymbolRefExpr *To, uint64_t Count);
1083 
1084   /// Get the .pdata section used for the given section. Typically the given
1085   /// section is either the main .text section or some other COMDAT .text
1086   /// section, but it may be any section containing code.
1087   MCSection *getAssociatedPDataSection(const MCSection *TextSec);
1088 
1089   /// Get the .xdata section used for the given section.
1090   MCSection *getAssociatedXDataSection(const MCSection *TextSec);
1091 
1092   virtual void emitSyntaxDirective();
1093 
1094   /// Record a relocation described by the .reloc directive. Return std::nullopt
1095   /// if succeeded. Otherwise, return a pair (Name is invalid, error message).
1096   virtual std::optional<std::pair<bool, std::string>>
1097   emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
1098                      SMLoc Loc, const MCSubtargetInfo &STI) {
1099     return std::nullopt;
1100   }
1101 
1102   virtual void emitAddrsig() {}
1103   virtual void emitAddrsigSym(const MCSymbol *Sym) {}
1104 
1105   /// Emit the given \p Instruction into the current section.
1106   virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
1107 
1108   /// Emit the a pseudo probe into the current section.
1109   virtual void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
1110                                uint64_t Attr, uint64_t Discriminator,
1111                                const MCPseudoProbeInlineStack &InlineStack,
1112                                MCSymbol *FnSym);
1113 
1114   /// Set the bundle alignment mode from now on in the section.
1115   /// The value 1 means turn the bundle alignment off.
1116   virtual void emitBundleAlignMode(Align Alignment);
1117 
1118   /// The following instructions are a bundle-locked group.
1119   ///
1120   /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
1121   ///                     the end of a bundle.
1122   virtual void emitBundleLock(bool AlignToEnd);
1123 
1124   /// Ends a bundle-locked group.
1125   virtual void emitBundleUnlock();
1126 
1127   /// If this file is backed by a assembly streamer, this dumps the
1128   /// specified string in the output .s file.  This capability is indicated by
1129   /// the hasRawTextSupport() predicate.  By default this aborts.
1130   void emitRawText(const Twine &String);
1131 
1132   /// Streamer specific finalization.
1133   virtual void finishImpl();
1134   /// Finish emission of machine code.
1135   void finish(SMLoc EndLoc = SMLoc());
1136 
1137   virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
1138 
1139   /// Emit a special value of 0xffffffff if producing 64-bit debugging info.
1140   void maybeEmitDwarf64Mark();
1141 
1142   /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
1143   /// according to the settings.
1144   virtual void emitDwarfUnitLength(uint64_t Length, const Twine &Comment);
1145 
1146   /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
1147   /// according to the settings.
1148   /// Return the end symbol generated inside, the caller needs to emit it.
1149   virtual MCSymbol *emitDwarfUnitLength(const Twine &Prefix,
1150                                         const Twine &Comment);
1151 
1152   /// Emit the debug line start label.
1153   virtual void emitDwarfLineStartLabel(MCSymbol *StartSym);
1154 
1155   /// Emit the debug line end entry.
1156   virtual void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel) {}
1157 
1158   /// If targets does not support representing debug line section by .loc/.file
1159   /// directives in assembly output, we need to populate debug line section with
1160   /// raw debug line contents.
1161   virtual void emitDwarfAdvanceLineAddr(int64_t LineDelta,
1162                                         const MCSymbol *LastLabel,
1163                                         const MCSymbol *Label,
1164                                         unsigned PointerSize) {}
1165 
1166   /// Do finalization for the streamer at the end of a section.
1167   virtual void doFinalizationAtSectionEnd(MCSection *Section) {}
1168 };
1169 
1170 /// Create a dummy machine code streamer, which does nothing. This is useful for
1171 /// timing the assembler front end.
1172 MCStreamer *createNullStreamer(MCContext &Ctx);
1173 
1174 } // end namespace llvm
1175 
1176 #endif // LLVM_MC_MCSTREAMER_H
1177