43#define DEBUG_TYPE "WinCOFFStreamer"
53 : SectionSymbol(SectionSymbol_), Writer(Writer_) {}
64 SectionSymbol.print(
OS, MAI);
70 assert(sectionNumber != 0 &&
71 "Containing section was not assigned a number");
81 return SectionSymbol.getFragment();
100 Symbol.print(
OS, MAI);
106 if (!Asm->getSymbolOffset(Symbol, CallsiteOffset)) {
118 return Symbol.getFragment();
123 std::unique_ptr<MCAsmBackend> MAB,
124 std::unique_ptr<MCCodeEmitter> CE,
125 std::unique_ptr<MCObjectWriter> OW)
128 auto *TO =
Context.getTargetOptions();
129 if (TO && TO->MCIncrementalLinkerCompatible)
160 static_cast<const MCSectionCOFF *
>(Section)->getCOMDATSymbol())
175 default:
return false;
179 Symbol->setExternal(
true);
183 Symbol->setExternal(
true);
184 Symbol->setIsWeakExternal(
true);
187 Symbol->setExternal(
true);
202 Error(
"starting a new symbol definition without completing the "
209 Error(
"storage class specified outside of symbol definition");
225 Error(
"symbol type specified outside of a symbol definition");
229 if (
Type & ~0xffff) {
240 Error(
"ending symbol definition without starting one");
250 auto *CSymbol =
static_cast<const MCSymbolCOFF *
>(Symbol);
251 if (CSymbol->isSafeSEH())
259 newSpecialFragment<MCSymbolIdFragment>(Symbol);
261 CSymbol->setIsSafeSEH();
274 newSpecialFragment<MCSymbolIdFragment>(Symbol);
340 Align ByteAlignment) {
344 if (
T.isWindowsMSVCEnvironment()) {
345 if (ByteAlignment > 32)
349 Size = std::max(
Size, ByteAlignment.value());
353 Symbol->setExternal(
true);
354 Symbol->setCommon(
Size, ByteAlignment);
356 if (!
T.isWindowsMSVCEnvironment() && ByteAlignment > 1) {
361 OS <<
" -aligncomm:\"" << Symbol->getName() <<
"\","
372 Align ByteAlignment) {
380 Symbol->setExternal(
false);
390 Alias->setIsWeakExternal(
true);
416 static_cast<const MCSymbolCOFF *
>(S)->setExternal(
true);
422 if (Asm.getWriter().getEmitAddrsigSection()) {
424 switchSection(Asm.getContext().getCOFFSection(
".llvm_addrsig",
427 if (!Asm.getWriter().getCGProfile().empty()) {
428 for (
auto &E : Asm.getWriter().getCGProfile()) {
432 switchSection(Asm.getContext().getCOFFSection(
".llvm.call-graph-profile",
439void MCWinCOFFStreamer::Error(
const Twine &Msg)
const {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
BlockVerifier::State From
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 printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
static MCCOFFSectionNumberTargetExpr * create(const MCSymbol &SectionSymbol, const WinCOFFObjectWriter &Writer, MCContext &Ctx)
void visitUsedExpr(MCStreamer &Streamer) const override
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) 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 printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) const override
void visitUsedExpr(MCStreamer &Streamer) const override
Lightweight error class with error context and mandatory checking.
This class is intended to be used as a base class for asm properties and features specific to the tar...
MCObjectWriter & getWriter() const
LLVM_ABI bool registerSymbol(const MCSymbol &Symbol)
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
const MCObjectFileInfo * getObjectFileInfo() const
LLVM_ABI CodeViewContext & getCVContext()
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
const Triple & getTargetTriple() const
Base class for the full range of assembler expressions which are needed for parsing.
MCSection * getSXDataSection() const
MCSection * getBSSSection() const
MCSection * getDrectveSection() const
Streaming object file generation interface.
void emitValueToAlignment(Align Alignment, int64_t Fill=0, uint8_t FillLen=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
MCAssembler & getAssembler()
void appendContents(ArrayRef< char > Contents)
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
void addFixup(const MCExpr *Value, MCFixupKind Kind)
void visitUsedSymbol(const MCSymbol &Sym) override
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void finishImpl() override
Streamer specific finalization.
void changeSection(MCSection *Section, uint32_t Subsection=0) override
This is called by popSection and switchSection, if the current section changes.
void emitCodeAlignment(Align ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
void ensureHeadroom(size_t Headroom)
SmallVector< CGProfileEntry, 0 > & getCGProfile()
This represents a section on Windows.
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.
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Extension point for target-specific MCExpr subclasses to implement.
static MCValue get(const MCSymbol *SymA, const MCSymbol *SymB=nullptr, int64_t Val=0, uint32_t Specifier=0)
void emitCOFFSectionIndex(MCSymbol const *Symbol) override
Emits a COFF section index.
void finalizeCGProfileEntry(const MCSymbolRefExpr *&S)
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 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 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.
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 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...
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.
@ 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.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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.