#include "llvm/MC/MCStreamer.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCCodeView.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCPseudoProbe.h"
#include "llvm/MC/MCRegister.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCWin64EH.h"
#include "llvm/MC/MCWinEH.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <optional>
#include <utility>
usingnamespacellvm;
MCTargetStreamer::MCTargetStreamer(MCStreamer &S) : … { … }
MCTargetStreamer::~MCTargetStreamer() = default;
void MCTargetStreamer::emitLabel(MCSymbol *Symbol) { … }
void MCTargetStreamer::finish() { … }
void MCTargetStreamer::emitConstantPools() { … }
void MCTargetStreamer::changeSection(const MCSection *CurSection,
MCSection *Section, uint32_t Subsection,
raw_ostream &OS) { … }
void MCTargetStreamer::emitDwarfFileDirective(StringRef Directive) { … }
void MCTargetStreamer::emitValue(const MCExpr *Value) { … }
void MCTargetStreamer::emitRawBytes(StringRef Data) { … }
void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) { … }
MCStreamer::MCStreamer(MCContext &Ctx)
: … { … }
MCStreamer::~MCStreamer() = default;
void MCStreamer::reset() { … }
raw_ostream &MCStreamer::getCommentOS() { … }
unsigned MCStreamer::getNumFrameInfos() { … }
ArrayRef<MCDwarfFrameInfo> MCStreamer::getDwarfFrameInfos() const { … }
void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) { … }
void MCStreamer::addExplicitComment(const Twine &T) { … }
void MCStreamer::emitExplicitComments() { … }
void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) { … }
void MCStreamer::emitIntValue(uint64_t Value, unsigned Size) { … }
void MCStreamer::emitIntValue(const APInt &Value) { … }
unsigned MCStreamer::emitULEB128IntValue(uint64_t Value, unsigned PadTo) { … }
unsigned MCStreamer::emitSLEB128IntValue(int64_t Value) { … }
void MCStreamer::emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc) { … }
void MCStreamer::emitSymbolValue(const MCSymbol *Sym, unsigned Size,
bool IsSectionRelative) { … }
void MCStreamer::emitDTPRel64Value(const MCExpr *Value) { … }
void MCStreamer::emitDTPRel32Value(const MCExpr *Value) { … }
void MCStreamer::emitTPRel64Value(const MCExpr *Value) { … }
void MCStreamer::emitTPRel32Value(const MCExpr *Value) { … }
void MCStreamer::emitGPRel64Value(const MCExpr *Value) { … }
void MCStreamer::emitGPRel32Value(const MCExpr *Value) { … }
void MCStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) { … }
void llvm::MCStreamer::emitNops(int64_t NumBytes, int64_t ControlledNopLen,
llvm::SMLoc, const MCSubtargetInfo& STI) { … }
void MCStreamer::emitZeros(uint64_t NumBytes) { … }
Expected<unsigned> MCStreamer::tryEmitDwarfFileDirective(
unsigned FileNo, StringRef Directory, StringRef Filename,
std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
unsigned CUID) { … }
void MCStreamer::emitDwarfFile0Directive(StringRef Directory,
StringRef Filename,
std::optional<MD5::MD5Result> Checksum,
std::optional<StringRef> Source,
unsigned CUID) { … }
void MCStreamer::emitCFIBKeyFrame() { … }
void MCStreamer::emitCFIMTETaggedFrame() { … }
void MCStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa, unsigned Discriminator,
StringRef FileName) { … }
void MCStreamer::emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name) { … }
MCSymbol *MCStreamer::getDwarfLineTableSymbol(unsigned CUID) { … }
bool MCStreamer::hasUnfinishedDwarfFrameInfo() { … }
MCDwarfFrameInfo *MCStreamer::getCurrentDwarfFrameInfo() { … }
bool MCStreamer::emitCVFileDirective(unsigned FileNo, StringRef Filename,
ArrayRef<uint8_t> Checksum,
unsigned ChecksumKind) { … }
bool MCStreamer::emitCVFuncIdDirective(unsigned FunctionId) { … }
bool MCStreamer::emitCVInlineSiteIdDirective(unsigned FunctionId,
unsigned IAFunc, unsigned IAFile,
unsigned IALine, unsigned IACol,
SMLoc Loc) { … }
void MCStreamer::emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
unsigned Line, unsigned Column,
bool PrologueEnd, bool IsStmt,
StringRef FileName, SMLoc Loc) { … }
bool MCStreamer::checkCVLocSection(unsigned FuncId, unsigned FileNo,
SMLoc Loc) { … }
void MCStreamer::emitCVLinetableDirective(unsigned FunctionId,
const MCSymbol *Begin,
const MCSymbol *End) { … }
void MCStreamer::emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
unsigned SourceFileId,
unsigned SourceLineNum,
const MCSymbol *FnStartSym,
const MCSymbol *FnEndSym) { … }
template <typename T>
static void copyBytesForDefRange(SmallString<20> &BytePrefix,
codeview::SymbolKind SymKind,
const T &DefRangeHeader) { … }
void MCStreamer::emitCVDefRangeDirective(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
StringRef FixedSizePortion) { … }
void MCStreamer::emitCVDefRangeDirective(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
codeview::DefRangeRegisterRelHeader DRHdr) { … }
void MCStreamer::emitCVDefRangeDirective(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
codeview::DefRangeSubfieldRegisterHeader DRHdr) { … }
void MCStreamer::emitCVDefRangeDirective(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
codeview::DefRangeRegisterHeader DRHdr) { … }
void MCStreamer::emitCVDefRangeDirective(
ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
codeview::DefRangeFramePointerRelHeader DRHdr) { … }
void MCStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
MCSymbol *EHSymbol) { … }
void MCStreamer::initSections(bool NoExecStack, const MCSubtargetInfo &STI) { … }
void MCStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) { … }
void MCStreamer::emitConditionalAssignment(MCSymbol *Symbol,
const MCExpr *Value) { … }
void MCStreamer::emitCFISections(bool EH, bool Debug) { … }
void MCStreamer::emitCFIStartProc(bool IsSimple, SMLoc Loc) { … }
void MCStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) { … }
void MCStreamer::emitCFIEndProc() { … }
void MCStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) { … }
MCSymbol *MCStreamer::emitCFILabel() { … }
void MCStreamer::emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc) { … }
void MCStreamer::emitCFIDefCfaOffset(int64_t Offset, SMLoc Loc) { … }
void MCStreamer::emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc) { … }
void MCStreamer::emitCFIDefCfaRegister(int64_t Register, SMLoc Loc) { … }
void MCStreamer::emitCFILLVMDefAspaceCfa(int64_t Register, int64_t Offset,
int64_t AddressSpace, SMLoc Loc) { … }
void MCStreamer::emitCFIOffset(int64_t Register, int64_t Offset, SMLoc Loc) { … }
void MCStreamer::emitCFIRelOffset(int64_t Register, int64_t Offset, SMLoc Loc) { … }
void MCStreamer::emitCFIPersonality(const MCSymbol *Sym,
unsigned Encoding) { … }
void MCStreamer::emitCFILsda(const MCSymbol *Sym, unsigned Encoding) { … }
void MCStreamer::emitCFIRememberState(SMLoc Loc) { … }
void MCStreamer::emitCFIRestoreState(SMLoc Loc) { … }
void MCStreamer::emitCFISameValue(int64_t Register, SMLoc Loc) { … }
void MCStreamer::emitCFIRestore(int64_t Register, SMLoc Loc) { … }
void MCStreamer::emitCFIEscape(StringRef Values, SMLoc Loc) { … }
void MCStreamer::emitCFIGnuArgsSize(int64_t Size, SMLoc Loc) { … }
void MCStreamer::emitCFISignalFrame() { … }
void MCStreamer::emitCFIUndefined(int64_t Register, SMLoc Loc) { … }
void MCStreamer::emitCFIRegister(int64_t Register1, int64_t Register2,
SMLoc Loc) { … }
void MCStreamer::emitCFIWindowSave(SMLoc Loc) { … }
void MCStreamer::emitCFINegateRAState(SMLoc Loc) { … }
void MCStreamer::emitCFIReturnColumn(int64_t Register) { … }
void MCStreamer::emitCFILabelDirective(SMLoc Loc, StringRef Name) { … }
WinEH::FrameInfo *MCStreamer::EnsureValidWinFrameInfo(SMLoc Loc) { … }
void MCStreamer::emitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc) { … }
void MCStreamer::emitWinCFIEndProc(SMLoc Loc) { … }
void MCStreamer::emitWinCFIFuncletOrFuncEnd(SMLoc Loc) { … }
void MCStreamer::emitWinCFIStartChained(SMLoc Loc) { … }
void MCStreamer::emitWinCFIEndChained(SMLoc Loc) { … }
void MCStreamer::emitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
SMLoc Loc) { … }
void MCStreamer::emitWinEHHandlerData(SMLoc Loc) { … }
void MCStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
const MCSymbolRefExpr *To, uint64_t Count) { … }
static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID,
MCSection *MainCFISec,
const MCSection *TextSec) { … }
MCSection *MCStreamer::getAssociatedPDataSection(const MCSection *TextSec) { … }
MCSection *MCStreamer::getAssociatedXDataSection(const MCSection *TextSec) { … }
void MCStreamer::emitSyntaxDirective() { … }
static unsigned encodeSEHRegNum(MCContext &Ctx, MCRegister Reg) { … }
void MCStreamer::emitWinCFIPushReg(MCRegister Register, SMLoc Loc) { … }
void MCStreamer::emitWinCFISetFrame(MCRegister Register, unsigned Offset,
SMLoc Loc) { … }
void MCStreamer::emitWinCFIAllocStack(unsigned Size, SMLoc Loc) { … }
void MCStreamer::emitWinCFISaveReg(MCRegister Register, unsigned Offset,
SMLoc Loc) { … }
void MCStreamer::emitWinCFISaveXMM(MCRegister Register, unsigned Offset,
SMLoc Loc) { … }
void MCStreamer::emitWinCFIPushFrame(bool Code, SMLoc Loc) { … }
void MCStreamer::emitWinCFIEndProlog(SMLoc Loc) { … }
void MCStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) { … }
void MCStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) { … }
void MCStreamer::emitCOFFSectionIndex(MCSymbol const *Symbol) { … }
void MCStreamer::emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) { … }
void MCStreamer::emitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) { … }
void MCStreamer::emitRawTextImpl(StringRef String) { … }
void MCStreamer::emitRawText(const Twine &T) { … }
void MCStreamer::emitWindowsUnwindTables() { … }
void MCStreamer::emitWindowsUnwindTables(WinEH::FrameInfo *Frame) { … }
void MCStreamer::finish(SMLoc EndLoc) { … }
void MCStreamer::maybeEmitDwarf64Mark() { … }
void MCStreamer::emitDwarfUnitLength(uint64_t Length, const Twine &Comment) { … }
MCSymbol *MCStreamer::emitDwarfUnitLength(const Twine &Prefix,
const Twine &Comment) { … }
void MCStreamer::emitDwarfLineStartLabel(MCSymbol *StartSym) { … }
void MCStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) { … }
void MCTargetStreamer::prettyPrintAsm(MCInstPrinter &InstPrinter,
uint64_t Address, const MCInst &Inst,
const MCSubtargetInfo &STI,
raw_ostream &OS) { … }
void MCStreamer::visitUsedSymbol(const MCSymbol &Sym) { … }
void MCStreamer::visitUsedExpr(const MCExpr &Expr) { … }
void MCStreamer::emitInstruction(const MCInst &Inst, const MCSubtargetInfo &) { … }
void MCStreamer::emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
uint64_t Attr, uint64_t Discriminator,
const MCPseudoProbeInlineStack &InlineStack,
MCSymbol *FnSym) { … }
void MCStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
unsigned Size) { … }
void MCStreamer::emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
const MCSymbol *Lo) { … }
void MCStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) { … }
void MCStreamer::emitThumbFunc(MCSymbol *Func) { … }
void MCStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) { … }
void MCStreamer::beginCOFFSymbolDef(const MCSymbol *Symbol) { … }
void MCStreamer::endCOFFSymbolDef() { … }
void MCStreamer::emitFileDirective(StringRef Filename) { … }
void MCStreamer::emitFileDirective(StringRef Filename,
StringRef CompilerVersion,
StringRef TimeStamp, StringRef Description) { … }
void MCStreamer::emitCOFFSymbolStorageClass(int StorageClass) { … }
void MCStreamer::emitCOFFSymbolType(int Type) { … }
void MCStreamer::emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
MCSymbol *CsectSym,
Align Alignment) { … }
void MCStreamer::emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
MCSymbolAttr Linkage,
MCSymbolAttr Visibility) { … }
void MCStreamer::emitXCOFFRenameDirective(const MCSymbol *Name,
StringRef Rename) { … }
void MCStreamer::emitXCOFFRefDirective(const MCSymbol *Symbol) { … }
void MCStreamer::emitXCOFFExceptDirective(const MCSymbol *Symbol,
const MCSymbol *Trap,
unsigned Lang, unsigned Reason,
unsigned FunctionSize,
bool hasDebug) { … }
void MCStreamer::emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) { … }
void MCStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) { … }
void MCStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym,
StringRef Name, bool KeepOriginalSym) { … }
void MCStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Align ByteAlignment) { … }
void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, Align ByteAlignment) { … }
void MCStreamer::changeSection(MCSection *Section, uint32_t) { … }
void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) { … }
void MCStreamer::emitBytes(StringRef Data) { … }
void MCStreamer::emitBinaryData(StringRef Data) { … }
void MCStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) { … }
void MCStreamer::emitULEB128Value(const MCExpr *Value) { … }
void MCStreamer::emitSLEB128Value(const MCExpr *Value) { … }
void MCStreamer::emitFill(const MCExpr &NumBytes, uint64_t Value, SMLoc Loc) { … }
void MCStreamer::emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
SMLoc Loc) { … }
void MCStreamer::emitValueToAlignment(Align Alignment, int64_t Value,
unsigned ValueSize,
unsigned MaxBytesToEmit) { … }
void MCStreamer::emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI,
unsigned MaxBytesToEmit) { … }
void MCStreamer::emitValueToOffset(const MCExpr *Offset, unsigned char Value,
SMLoc Loc) { … }
void MCStreamer::emitBundleAlignMode(Align Alignment) { … }
void MCStreamer::emitBundleLock(bool AlignToEnd) { … }
void MCStreamer::finishImpl() { … }
void MCStreamer::emitBundleUnlock() { … }
bool MCStreamer::popSection() { … }
void MCStreamer::switchSection(MCSection *Section, uint32_t Subsection) { … }
bool MCStreamer::switchSection(MCSection *Section, const MCExpr *SubsecExpr) { … }
void MCStreamer::switchSectionNoPrint(MCSection *Section) { … }
MCSymbol *MCStreamer::endSection(MCSection *Section) { … }
static VersionTuple
targetVersionOrMinimumSupportedOSVersion(const Triple &Target,
VersionTuple TargetVersion) { … }
static MCVersionMinType
getMachoVersionMinLoadCommandType(const Triple &Target) { … }
static VersionTuple getMachoBuildVersionSupportedOS(const Triple &Target) { … }
static MachO::PlatformType
getMachoBuildVersionPlatformType(const Triple &Target) { … }
void MCStreamer::emitVersionForTarget(
const Triple &Target, const VersionTuple &SDKVersion,
const Triple *DarwinTargetVariantTriple,
const VersionTuple &DarwinTargetVariantSDKVersion) { … }