LLVM: lib/MC/MCWinCOFFStreamer.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
38#include
39#include
40
41using namespace llvm;
42
43#define DEBUG_TYPE "WinCOFFStreamer"
44
45
46
47class MCCOFFSectionNumberTargetExpr final : public MCTargetExpr {
48 const MCSymbol &SectionSymbol;
50
51 MCCOFFSectionNumberTargetExpr(const MCSymbol &SectionSymbol_,
53 : SectionSymbol(SectionSymbol_), Writer(Writer_) {}
54
55public:
56 static MCCOFFSectionNumberTargetExpr *
59 return new (Ctx) MCCOFFSectionNumberTargetExpr(SectionSymbol, Writer);
60 }
61
63 OS << ":secnum:";
64 SectionSymbol.print(OS, MAI);
65 }
66
69 auto sectionNumber = Writer.getSectionNumber(SectionSymbol.getSection());
70 assert(sectionNumber != 0 &&
71 "Containing section was not assigned a number");
73 return true;
74 }
75
79
81 return SectionSymbol.getFragment();
82 }
83};
84
85
86
87class MCCOFFSectionOffsetTargetExpr final : public MCTargetExpr {
89
90 MCCOFFSectionOffsetTargetExpr(const MCSymbol &Symbol_) : Symbol(Symbol_) {}
91
92public:
93 static MCCOFFSectionOffsetTargetExpr *create(const MCSymbol &Symbol,
95 return new (Ctx) MCCOFFSectionOffsetTargetExpr(Symbol);
96 }
97
99 OS << ":secoffset:";
100 Symbol.print(OS, MAI);
101 }
102
106 if (!Asm->getSymbolOffset(Symbol, CallsiteOffset)) {
107 return true;
108 }
110 return true;
111 }
112
116
118 return Symbol.getFragment();
119 }
120};
121
123 std::unique_ptr MAB,
124 std::unique_ptr CE,
125 std::unique_ptr OW)
128 auto *TO = Context.getTargetOptions();
129 if (TO && TO->MCIncrementalLinkerCompatible)
130 getWriter().setIncrementalLinkerCompatible(true);
131}
132
136
139
140
141
144
147
150
152}
153
156
157
159 if (auto *Sym =
160 static_cast<const MCSectionCOFF *>(Section)->getCOMDATSymbol())
162}
163
168
171 auto *Symbol = static_cast<MCSymbolCOFF *>(S);
173
175 default: return false;
179 Symbol->setExternal(true);
180 break;
183 Symbol->setExternal(true);
184 Symbol->setIsWeakExternal(true);
185 break;
187 Symbol->setExternal(true);
188 break;
190 llvm_unreachable("COFF doesn't support the .alt_entry attribute");
191 }
192
193 return true;
194}
195
199
202 Error("starting a new symbol definition without completing the "
203 "previous one");
205}
206
209 Error("storage class specified outside of symbol definition");
210 return;
211 }
212
215 "' out of range");
216 return;
217 }
218
221}
222
225 Error("symbol type specified outside of a symbol definition");
226 return;
227 }
228
229 if (Type & ~0xffff) {
230 Error("type value '" + Twine(Type) + "' out of range");
231 return;
232 }
233
236}
237
240 Error("ending symbol definition without starting one");
242}
243
245
246
248 return;
249
250 auto *CSymbol = static_cast<const MCSymbolCOFF *>(Symbol);
251 if (CSymbol->isSafeSEH())
252 return;
253
258
261 CSymbol->setIsSafeSEH();
262
263
264
268}
269
277
285
300
316
327
338
340 Align ByteAlignment) {
341 auto *Symbol = static_cast<MCSymbolCOFF *>(S);
342
344 if (T.isWindowsMSVCEnvironment()) {
345 if (ByteAlignment > 32)
347
348
349 Size = std::max(Size, ByteAlignment.value());
350 }
351
353 Symbol->setExternal(true);
354 Symbol->setCommon(Size, ByteAlignment);
355
356 if (.isWindowsMSVCEnvironment() && ByteAlignment > 1) {
360
361 OS << " -aligncomm:\"" << Symbol->getName() << "\","
363
368 }
369}
370
372 Align ByteAlignment) {
373 auto *Symbol = static_cast<MCSymbolCOFF *>(S);
374
380 Symbol->setExternal(false);
383}
384
385
388 auto *Alias = static_cast<MCSymbolCOFF *>(AliasS);
390 Alias->setIsWeakExternal(true);
391
394}
395
396
400
404
412
416 static_cast<const MCSymbolCOFF *>(S)->setExternal(true);
417}
418
422 if (Asm.getWriter().getEmitAddrsigSection()) {
423
424 switchSection(Asm.getContext().getCOFFSection(".llvm_addrsig",
426 }
427 if (!Asm.getWriter().getCGProfile().empty()) {
428 for (auto &E : Asm.getWriter().getCGProfile()) {
431 }
432 switchSection(Asm.getContext().getCOFFSection(".llvm.call-graph-profile",
434 }
435
437}
438
439void MCWinCOFFStreamer::Error(const Twine &Msg) const {
441}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the SmallString class.
This file defines the SmallVector class.
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition MCWinCOFFStreamer.cpp:62
static MCCOFFSectionNumberTargetExpr * create(const MCSymbol &SectionSymbol, const WinCOFFObjectWriter &Writer, MCContext &Ctx)
Definition MCWinCOFFStreamer.cpp:57
void visitUsedExpr(MCStreamer &Streamer) const override
Definition MCWinCOFFStreamer.cpp:76
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) const override
Definition MCWinCOFFStreamer.cpp:67
MCFragment * findAssociatedFragment() const override
Definition MCWinCOFFStreamer.cpp:80
MCFragment * findAssociatedFragment() const override
Definition MCWinCOFFStreamer.cpp:117
static MCCOFFSectionOffsetTargetExpr * create(const MCSymbol &Symbol, MCContext &Ctx)
Definition MCWinCOFFStreamer.cpp:93
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition MCWinCOFFStreamer.cpp:98
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) const override
Definition MCWinCOFFStreamer.cpp:103
void visitUsedExpr(MCStreamer &Streamer) const override
Definition MCWinCOFFStreamer.cpp:113
Functions, function parameters, and return types can have attributes to indicate how they should be t...
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
FT * newSpecialFragment(Args &&...args)
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.
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
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.
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.
Definition MCWinCOFFStreamer.cpp:278
void finalizeCGProfileEntry(const MCSymbolRefExpr *&S)
Definition MCWinCOFFStreamer.cpp:413
void emitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) override
Emits a COFF image relative relocation.
Definition MCWinCOFFStreamer.cpp:301
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Definition MCWinCOFFStreamer.cpp:164
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
Definition MCWinCOFFStreamer.cpp:386
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override
Create the default sections and set the initial one.
Definition MCWinCOFFStreamer.cpp:137
void emitCOFFSafeSEH(MCSymbol const *Symbol) override
Definition MCWinCOFFStreamer.cpp:244
void emitCOFFSecOffset(MCSymbol const *Symbol) override
Emits the offset of the symbol from the beginning of the section during object writing (i....
Definition MCWinCOFFStreamer.cpp:328
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a common symbol.
Definition MCWinCOFFStreamer.cpp:339
void endCOFFSymbolDef() override
Marks the end of the symbol definition.
Definition MCWinCOFFStreamer.cpp:238
MCWinCOFFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCObjectWriter > OW)
Definition MCWinCOFFStreamer.cpp:122
void changeSection(MCSection *Section, uint32_t Subsection=0) override
This is called by popSection and switchSection, if the current section changes.
Definition MCWinCOFFStreamer.cpp:154
void emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override
Emits a COFF section relative relocation.
Definition MCWinCOFFStreamer.cpp:286
void finishImpl() override
Streamer specific finalization.
Definition MCWinCOFFStreamer.cpp:419
void emitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
Definition MCWinCOFFStreamer.cpp:397
void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count) override
Definition MCWinCOFFStreamer.cpp:405
void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a local common (.lcomm) symbol.
Definition MCWinCOFFStreamer.cpp:371
WinCOFFObjectWriter & getWriter()
Definition MCWinCOFFStreamer.cpp:133
void emitCOFFSymbolType(int Type) override
Emit the type of the symbol.
Definition MCWinCOFFStreamer.cpp:223
void emitCOFFSecNumber(MCSymbol const *Symbol) override
Emits the physical number of the section containing the given symbol as assigned during object writin...
Definition MCWinCOFFStreamer.cpp:317
void emitWinEHHandlerData(SMLoc Loc) override
Definition MCWinCOFFStreamer.cpp:401
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override
Set the DescValue for the Symbol.
Definition MCWinCOFFStreamer.cpp:196
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
Definition MCWinCOFFStreamer.cpp:169
void emitCOFFSymbolIndex(MCSymbol const *Symbol) override
Emits the symbol table index of a Symbol into the current section.
Definition MCWinCOFFStreamer.cpp:270
void beginCOFFSymbolDef(MCSymbol const *Symbol) override
Start emitting COFF symbol definition.
Definition MCWinCOFFStreamer.cpp:200
void emitCOFFSymbolStorageClass(int StorageClass) override
Emit the storage class of the symbol.
Definition MCWinCOFFStreamer.cpp:207
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.
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.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionAddr VTableAddr Count
@ 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.
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.