43#define DEBUG_TYPE "WinCOFFStreamer"
46 std::unique_ptr<MCAsmBackend> MAB,
47 std::unique_ptr<MCCodeEmitter> CE,
48 std::unique_ptr<MCObjectWriter> OW)
52 if (TO && TO->MCIncrementalLinkerCompatible)
69 for (
unsigned i = 0, e = Fixups.size(); i != e; ++i) {
70 Fixups[i].setOffset(Fixups[i].
getOffset() +
DF->getContents().size());
71 DF->getFixups().push_back(Fixups[i]);
73 DF->setHasInstructions(STI);
74 DF->getContents().append(Code.begin(), Code.end());
99 if (
auto *
Sym = cast<MCSectionCOFF>(Section)->getCOMDATSymbol())
104 auto *Symbol = cast<MCSymbolCOFF>(S);
130 auto *Symbol = cast<MCSymbolCOFF>(S);
134 default:
return false;
138 Symbol->setExternal(
true);
142 Symbol->setExternal(
true);
143 Symbol->setIsWeakExternal(
true);
146 Symbol->setExternal(
true);
160 auto *Symbol = cast<MCSymbolCOFF>(S);
162 Error(
"starting a new symbol definition without completing the "
169 Error(
"storage class specified outside of symbol definition");
185 Error(
"symbol type specified outside of a symbol definition");
189 if (
Type & ~0xffff) {
200 Error(
"ending symbol definition without starting one");
210 const MCSymbolCOFF *CSymbol = cast<MCSymbolCOFF>(Symbol);
241 DF->getFixups().push_back(
Fixup);
242 DF->getContents().resize(
DF->getContents().size() + 2, 0);
258 DF->getFixups().push_back(
Fixup);
260 DF->getContents().resize(
DF->getContents().size() + 4, 0);
277 DF->getFixups().push_back(
Fixup);
279 DF->getContents().resize(
DF->getContents().size() + 4, 0);
283 Align ByteAlignment) {
284 auto *Symbol = cast<MCSymbolCOFF>(S);
287 if (
T.isWindowsMSVCEnvironment()) {
288 if (ByteAlignment > 32)
292 Size = std::max(
Size, ByteAlignment.value());
296 Symbol->setExternal(
true);
297 Symbol->setCommon(
Size, ByteAlignment);
299 if (!
T.isWindowsMSVCEnvironment() && ByteAlignment > 1) {
304 OS <<
" -aligncomm:\"" << Symbol->getName() <<
"\","
315 Align ByteAlignment) {
316 auto *Symbol = cast<MCSymbolCOFF>(S);
323 Symbol->setExternal(
false);
330 auto *Alias = cast<MCSymbolCOFF>(AliasS);
374 if (Asm.getWriter().getEmitAddrsigSection()) {
376 switchSection(Asm.getContext().getCOFFSection(
".llvm_addrsig",
379 if (!Asm.getWriter().getCGProfile().empty()) {
380 for (
auto &E : Asm.getWriter().getCGProfile()) {
384 switchSection(Asm.getContext().getCOFFSection(
".llvm.call-graph-profile",
391void 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
This file defines the SmallString class.
This file defines the SmallVector class.
Lightweight error class with error context and mandatory checking.
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
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
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.
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.
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 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 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.
void setIncrementalLinkerCompatible(bool Value)
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.