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