45#define DEBUG_TYPE "WinCOFFStreamer"
55 : SectionSymbol(SectionSymbol_), Writer(Writer_) {}
66 SectionSymbol.print(
OS, MAI);
72 assert(sectionNumber != 0 &&
73 "Containing section was not assigned a number");
83 return SectionSymbol.getFragment();
106 Symbol.print(
OS, MAI);
112 if (!Asm->getSymbolOffset(Symbol, CallsiteOffset)) {
124 return Symbol.getFragment();
133 std::unique_ptr<MCAsmBackend> MAB,
134 std::unique_ptr<MCCodeEmitter> CE,
135 std::unique_ptr<MCObjectWriter> OW)
139 if (TO && TO->MCIncrementalLinkerCompatible)
156 for (
unsigned i = 0, e = Fixups.size(); i != e; ++i) {
157 Fixups[i].setOffset(Fixups[i].
getOffset() +
DF->getContents().size());
158 DF->getFixups().push_back(Fixups[i]);
160 DF->setHasInstructions(STI);
161 DF->appendContents(Code);
186 if (
auto *
Sym = cast<MCSectionCOFF>(Section)->getCOMDATSymbol())
191 auto *Symbol = cast<MCSymbolCOFF>(S);
217 auto *Symbol = cast<MCSymbolCOFF>(S);
221 default:
return false;
225 Symbol->setExternal(
true);
229 Symbol->setExternal(
true);
230 Symbol->setIsWeakExternal(
true);
233 Symbol->setExternal(
true);
247 auto *Symbol = cast<MCSymbolCOFF>(S);
249 Error(
"starting a new symbol definition without completing the "
256 Error(
"storage class specified outside of symbol definition");
272 Error(
"symbol type specified outside of a symbol definition");
276 if (
Type & ~0xffff) {
287 Error(
"ending symbol definition without starting one");
297 const MCSymbolCOFF *CSymbol = cast<MCSymbolCOFF>(Symbol);
328 DF->getFixups().push_back(
Fixup);
329 DF->appendContents(2, 0);
345 DF->getFixups().push_back(
Fixup);
347 DF->appendContents(4, 0);
364 DF->getFixups().push_back(
Fixup);
366 DF->appendContents(4, 0);
378 DF->getFixups().push_back(
Fixup);
380 DF->appendContents(4, 0);
392 DF->getFixups().push_back(
Fixup);
394 DF->appendContents(4, 0);
398 Align ByteAlignment) {
399 auto *Symbol = cast<MCSymbolCOFF>(S);
402 if (
T.isWindowsMSVCEnvironment()) {
403 if (ByteAlignment > 32)
407 Size = std::max(
Size, ByteAlignment.value());
411 Symbol->setExternal(
true);
412 Symbol->setCommon(
Size, ByteAlignment);
414 if (!
T.isWindowsMSVCEnvironment() && ByteAlignment > 1) {
419 OS <<
" -aligncomm:\"" << Symbol->getName() <<
"\","
430 Align ByteAlignment) {
431 auto *Symbol = cast<MCSymbolCOFF>(S);
438 Symbol->setExternal(
false);
445 auto *Alias = cast<MCSymbolCOFF>(AliasS);
490 if (Asm.getWriter().getEmitAddrsigSection()) {
492 switchSection(Asm.getContext().getCOFFSection(
".llvm_addrsig",
495 if (!Asm.getWriter().getCGProfile().empty()) {
496 for (
auto &E : Asm.getWriter().getCGProfile()) {
500 switchSection(Asm.getContext().getCOFFSection(
".llvm.call-graph-profile",
507void MCWinCOFFStreamer::Error(
const Twine &Msg)
const {
BlockVerifier::State From
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This file defines the SmallVector class.
MCExpr that represents the physical number for the sections that contains a symbol.
void fixELFSymbolsInTLSFixups(MCAssembler &) const override
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
static MCCOFFSectionNumberTargetExpr * create(const MCSymbol &SectionSymbol, const WinCOFFObjectWriter &Writer, MCContext &Ctx)
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override
void visitUsedExpr(MCStreamer &Streamer) const override
MCFragment * findAssociatedFragment() const override
MCExpr that represents the offset to a symbol from the beginning of its section.
MCFragment * findAssociatedFragment() const override
static MCCOFFSectionOffsetTargetExpr * create(const MCSymbol &Symbol, MCContext &Ctx)
void fixELFSymbolsInTLSFixups(MCAssembler &) const override
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override
void visitUsedExpr(MCStreamer &Streamer) const override
Lightweight error class with error context and mandatory checking.
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
This class is intended to be used as a base class for asm properties and features specific to the tar...
MCObjectWriter & getWriter() const
MCCodeEmitter & getEmitter() const
MCAsmBackend & getBackend() const
bool registerSymbol(const MCSymbol &Symbol)
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
Encode the given Inst to bytes and append to CB.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
const MCObjectFileInfo * getObjectFileInfo() const
CodeViewContext & getCVContext()
void reportError(SMLoc L, const Twine &Msg)
const MCTargetOptions * getTargetOptions() const
const Triple & getTargetTriple() const
Fragment for data and encoded instructions.
Base class for the full range of assembler expressions which are needed for parsing.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Instances of this class represent a single low-level machine instruction.
MCSection * getSXDataSection() const
MCSection * getBSSSection() const
MCSection * getDrectveSection() const
Streaming object file generation interface.
void emitValueToAlignment(Align Alignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
MCDataFragment * getOrCreateDataFragment(const MCSubtargetInfo *STI=nullptr)
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment.
MCAssembler & getAssembler()
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
bool changeSectionImpl(MCSection *Section, uint32_t Subsection)
void visitUsedSymbol(const MCSymbol &Sym) override
void insert(MCFragment *F)
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void finishImpl() override
Streamer specific finalization.
void emitCodeAlignment(Align ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
SmallVector< CGProfileEntry, 0 > & getCGProfile()
Instances of this class represent a uniqued identifier for a section in the current translation unit.
void ensureMinAlignment(Align MinAlignment)
Makes sure that Alignment is at least MinAlignment.
Streaming machine code generation interface.
virtual bool popSection()
Restore the current and previous section from the section stack.
MCContext & getContext() const
void pushSection()
Save the current and previous section on the section stack.
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
MCSection * getCurrentSectionOnly() const
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Generic base class for all target subtargets.
void setIsSafeSEH() const
void setType(uint16_t Ty) const
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void setExternal(bool Value) const
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
This is an extension point for target-specific MCExpr subclasses to implement.
This represents an "assembler immediate".
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
void emitCOFFSectionIndex(MCSymbol const *Symbol) override
Emits a COFF section index.
void emitAssemblerFlag(MCAssemblerFlag Flag) override
Note in the output the specified Flag.
void finalizeCGProfileEntry(const MCSymbolRefExpr *&S)
void emitThumbFunc(MCSymbol *Func) override
Note in the output that the specified Func is a Thumb mode function (ARM target only).
void emitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) override
Emits a COFF image relative relocation.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void emitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size, Align ByteAlignment, SMLoc Loc=SMLoc()) override
Emit the zerofill section and an optional symbol.
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override
Create the default sections and set the initial one.
void emitCOFFSafeSEH(MCSymbol const *Symbol) override
void emitCOFFSecOffset(MCSymbol const *Symbol) override
Emits the offset of the symbol from the beginning of the section during object writing (i....
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a common symbol.
void endCOFFSymbolDef() override
Marks the end of the symbol definition.
MCWinCOFFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCObjectWriter > OW)
void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a thread local bss (.tbss) symbol.
void changeSection(MCSection *Section, uint32_t Subsection=0) override
This is called by popSection and switchSection, if the current section changes.
void emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override
Emits a COFF section relative relocation.
void finishImpl() override
Streamer specific finalization.
void emitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count) override
void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a local common (.lcomm) symbol.
WinCOFFObjectWriter & getWriter()
void emitCOFFSymbolType(int Type) override
Emit the type of the symbol.
void emitCOFFSecNumber(MCSymbol const *Symbol) override
Emits the physical number of the section containing the given symbol as assigned during object writin...
void emitWinEHHandlerData(SMLoc Loc) override
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override
Set the DescValue for the Symbol.
const MCSymbol * CurSymbol
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void emitCOFFSymbolIndex(MCSymbol const *Symbol) override
Emits the symbol table index of a Symbol into the current section.
void beginCOFFSymbolDef(MCSymbol const *Symbol) override
Start emitting COFF symbol definition.
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) override
void emitCOFFSymbolStorageClass(int StorageClass) override
Emit the storage class of the symbol.
Represents a location in source code.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
int getSectionNumber(const MCSection &Section) const
void setIncrementalLinkerCompatible(bool Value)
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_WEAK_EXTERN_SEARCH_ALIAS
@ IMAGE_WEAK_EXTERN_ANTI_DEPENDENCY
@ IMAGE_SYM_DTYPE_FUNCTION
A function that returns a base type.
@ SCT_COMPLEX_TYPE_SHIFT
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
This is an optimization pass for GlobalISel generic memory operations.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
@ FK_SecRel_2
A two-byte section relative fixup.
@ FK_Data_4
A four-byte fixup.
@ FK_SecRel_4
A four-byte section relative fixup.
@ MCAF_SyntaxUnified
.syntax (ARM/ELF)
@ MCAF_Code64
.code64 (X86)
@ MCAF_Code16
.code16 (X86) / .code 16 (ARM)
@ MCAF_Code32
.code32 (X86) / .code 32 (ARM)
@ MCAF_SubsectionsViaSymbols
.subsections_via_symbols (MachO)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_AltEntry
.alt_entry (MachO)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.