LLVM 23.0.0git
MCELFStreamer.cpp
Go to the documentation of this file.
1//===- lib/MC/MCELFStreamer.cpp - ELF Object Output -----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file assembles .s files and emits ELF .o object files.
10//
11//===----------------------------------------------------------------------===//
12
17#include "llvm/MC/MCAsmInfo.h"
18#include "llvm/MC/MCAssembler.h"
20#include "llvm/MC/MCContext.h"
23#include "llvm/MC/MCExpr.h"
24#include "llvm/MC/MCFixup.h"
27#include "llvm/MC/MCSection.h"
29#include "llvm/MC/MCStreamer.h"
30#include "llvm/MC/MCSymbol.h"
31#include "llvm/MC/MCSymbolELF.h"
35#include "llvm/Support/LEB128.h"
36#include <cassert>
37#include <cstdint>
38
39using namespace llvm;
40
42 std::unique_ptr<MCAsmBackend> TAB,
43 std::unique_ptr<MCObjectWriter> OW,
44 std::unique_ptr<MCCodeEmitter> Emitter)
45 : MCObjectStreamer(Context, std::move(TAB), std::move(OW),
46 std::move(Emitter)) {}
47
51
53 MCContext &Ctx = getContext();
54 switchSection(Ctx.getObjectFileInfo()->getTextSection());
55 emitCodeAlignment(Align(Ctx.getObjectFileInfo()->getTextSectionAlignment()),
56 &STI);
57}
58
60 auto *Symbol = static_cast<MCSymbolELF *>(S);
62
63 const MCSectionELF &Section =
64 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
65 if (Section.getFlags() & ELF::SHF_TLS)
66 Symbol->setType(ELF::STT_TLS);
67}
68
71 auto *Symbol = static_cast<MCSymbolELF *>(S);
73
74 const MCSectionELF &Section =
75 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
76 if (Section.getFlags() & ELF::SHF_TLS)
77 Symbol->setType(ELF::STT_TLS);
78}
79
82 auto *SectionELF = static_cast<const MCSectionELF *>(Section);
83 const MCSymbol *Grp = SectionELF->getGroup();
84 if (Grp)
85 Asm.registerSymbol(*Grp);
86 if (SectionELF->getFlags() & ELF::SHF_GNU_RETAIN)
88
89 MCObjectStreamer::changeSection(Section, Subsection);
90 auto *Sym = static_cast<MCSymbolELF *>(Section->getBeginSymbol());
92 Sym->setType(ELF::STT_SECTION);
93}
94
96 auto *A = static_cast<MCSymbolELF *>(Alias);
97 if (A->isDefined()) {
98 getContext().reportError(getStartTokLoc(), "symbol '" + A->getName() +
99 "' is already defined");
100 return;
101 }
102 A->setVariableValue(MCSymbolRefExpr::create(Target, getContext()));
103 A->setIsWeakref();
104 getWriter().Weakrefs.push_back(A);
105}
106
107// When GNU as encounters more than one .type declaration for an object it seems
108// to use a mechanism similar to the one below to decide which type is actually
109// used in the object file. The greater of T1 and T2 is selected based on the
110// following ordering:
111// STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
112// If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
113// provided type).
114static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
117 if (T1 == Type)
118 return T2;
119 if (T2 == Type)
120 return T1;
121 }
122
123 return T2;
124}
125
127 auto *Symbol = static_cast<MCSymbolELF *>(S);
128
129 // Adding a symbol attribute always introduces the symbol, note that an
130 // important side effect of calling registerSymbol here is to register
131 // the symbol with the assembler.
132 getAssembler().registerSymbol(*Symbol);
133
134 // The implementation of symbol attributes is designed to match 'as', but it
135 // leaves much to desired. It doesn't really make sense to arbitrarily add and
136 // remove flags, but 'as' allows this (in particular, see .desc).
137 //
138 // In the future it might be worth trying to make these operations more well
139 // defined.
140 switch (Attribute) {
141 case MCSA_Cold:
142 case MCSA_Extern:
144 case MCSA_Reference:
149 case MCSA_Invalid:
151 case MCSA_Exported:
152 case MCSA_WeakAntiDep:
153 case MCSA_OSLinkage:
154 case MCSA_XPLinkage:
155 return false;
156
157 case MCSA_NoDeadStrip:
158 // Ignore for now.
159 break;
160
162 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
163 Symbol->setBinding(ELF::STB_GNU_UNIQUE);
165 break;
166
167 case MCSA_Global:
168 // For `.weak x; .global x`, GNU as sets the binding to STB_WEAK while we
169 // traditionally set the binding to STB_GLOBAL. This is error-prone, so we
170 // error on such cases. Note, we also disallow changed binding from .local.
171 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_GLOBAL)
173 Symbol->getName() +
174 " changed binding to STB_GLOBAL");
175 Symbol->setBinding(ELF::STB_GLOBAL);
176 break;
177
179 case MCSA_Weak:
180 // For `.global x; .weak x`, both MC and GNU as set the binding to STB_WEAK.
181 // We emit a warning for now but may switch to an error in the future.
182 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_WEAK)
184 getStartTokLoc(), Symbol->getName() + " changed binding to STB_WEAK");
185 Symbol->setBinding(ELF::STB_WEAK);
186 break;
187
188 case MCSA_Local:
189 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_LOCAL)
191 Symbol->getName() +
192 " changed binding to STB_LOCAL");
193 Symbol->setBinding(ELF::STB_LOCAL);
194 break;
195
197 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
198 break;
199
201 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
203 break;
204
206 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
207 break;
208
209 case MCSA_ELF_TypeTLS:
210 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
211 break;
212
214 // TODO: Emit these as a common symbol.
215 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
216 break;
217
219 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
220 break;
221
222 case MCSA_Protected:
223 Symbol->setVisibility(ELF::STV_PROTECTED);
224 break;
225
226 case MCSA_Memtag:
227 Symbol->setMemtag(true);
228 break;
229
230 case MCSA_Hidden:
231 Symbol->setVisibility(ELF::STV_HIDDEN);
232 break;
233
234 case MCSA_Internal:
235 Symbol->setVisibility(ELF::STV_INTERNAL);
236 break;
237
238 case MCSA_AltEntry:
239 llvm_unreachable("ELF doesn't support the .alt_entry attribute");
240
241 case MCSA_LGlobal:
242 llvm_unreachable("ELF doesn't support the .lglobl attribute");
243 }
244
245 return true;
246}
247
249 Align ByteAlignment) {
250 auto *Symbol = static_cast<MCSymbolELF *>(S);
251 getAssembler().registerSymbol(*Symbol);
252
253 if (!Symbol->isBindingSet())
254 Symbol->setBinding(ELF::STB_GLOBAL);
255
256 Symbol->setType(ELF::STT_OBJECT);
257
258 if (Symbol->getBinding() == ELF::STB_LOCAL) {
262 switchSection(&Section);
263
264 emitValueToAlignment(ByteAlignment, 0, 1, 0);
265 emitLabel(Symbol);
267
268 switchSection(P.first, P.second);
269 } else {
270 if (Symbol->declareCommon(Size, ByteAlignment))
271 report_fatal_error(Twine("Symbol: ") + Symbol->getName() +
272 " redeclared as different type");
273 }
274
275 Symbol->setSize(MCConstantExpr::create(Size, getContext()));
276}
277
279 static_cast<MCSymbolELF *>(Symbol)->setSize(Value);
280}
281
283 StringRef Name,
284 bool KeepOriginalSym) {
286 getStartTokLoc(), OriginalSym, Name, KeepOriginalSym});
287}
288
290 Align ByteAlignment) {
291 auto *Symbol = static_cast<MCSymbolELF *>(S);
292 // FIXME: Should this be caught and done earlier?
293 getAssembler().registerSymbol(*Symbol);
294 Symbol->setBinding(ELF::STB_LOCAL);
295 emitCommonSymbol(Symbol, Size, ByteAlignment);
296}
297
299 const MCSymbolRefExpr *To,
300 uint64_t Count) {
301 getWriter().getCGProfile().push_back({From, To, Count});
302}
303
307 pushSection();
308 switchSection(Comment);
309 if (!SeenIdent) {
310 emitInt8(0);
311 SeenIdent = true;
312 }
313 emitBytes(IdentString);
314 emitInt8(0);
315 popSection();
316}
317
318void MCELFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *Sym,
320 const MCSymbolRefExpr *&SRE) {
321 const MCSymbol *S = &SRE->getSymbol();
322 if (S->isTemporary()) {
323 if (!S->isInSection()) {
325 SRE->getLoc(), Twine("Reference to undefined temporary symbol ") +
326 "`" + S->getName() + "`");
327 return;
328 }
329 S = S->getSection().getBeginSymbol();
330 S->setUsedInReloc();
331 SRE = MCSymbolRefExpr::create(S, getContext(), SRE->getLoc());
332 }
335 MCObjectStreamer::emitRelocDirective(*O, "BFD_RELOC_NONE", SRE);
336}
337
338void MCELFStreamer::finalizeCGProfile() {
339 ELFObjectWriter &W = getWriter();
340 if (W.getCGProfile().empty())
341 return;
342 MCSection *CGProfile = getAssembler().getContext().getELFSection(
343 ".llvm.call-graph-profile", ELF::SHT_LLVM_CALL_GRAPH_PROFILE,
344 ELF::SHF_EXCLUDE, /*sizeof(Elf_CGProfile_Impl<>)=*/8);
345 pushSection();
346 switchSection(CGProfile);
347 uint64_t Offset = 0;
348 auto *Sym =
350 for (auto &E : W.getCGProfile()) {
351 finalizeCGProfileEntry(Sym, Offset, E.From);
352 finalizeCGProfileEntry(Sym, Offset, E.To);
353 emitIntValue(E.Count, sizeof(uint64_t));
354 Offset += sizeof(uint64_t);
355 }
356 popSection();
357}
358
360 // Emit .note.GNU-stack, similar to AsmPrinter::doFinalization.
361 MCContext &Ctx = getContext();
362 if (const MCTargetOptions *TO = Ctx.getTargetOptions()) {
363 auto *StackSec = Ctx.getAsmInfo()->getStackSection(Ctx,
364 /*Exec=*/false);
365 if (StackSec && TO->MCNoExecStack)
366 switchSection(StackSec);
367 }
368
369 // Emit the .gnu attributes section if any attributes have been added.
370 if (!GNUAttributes.empty()) {
371 MCSection *DummyAttributeSection = nullptr;
372 createAttributesSection("gnu", ".gnu.attributes", ELF::SHT_GNU_ATTRIBUTES,
373 DummyAttributeSection, GNUAttributes);
374 }
375
376 finalizeCGProfile();
377 emitFrames();
378
380}
381
383 bool OverwriteExisting) {
384 // Look for existing attribute item
385 if (AttributeItem *Item = getAttributeItem(Attribute)) {
386 if (!OverwriteExisting)
387 return;
389 Item->IntValue = Value;
390 return;
391 }
392
393 // Create new attribute item
395 std::string(StringRef(""))};
396 Contents.push_back(Item);
397}
398
400 bool OverwriteExisting) {
401 // Look for existing attribute item
402 if (AttributeItem *Item = getAttributeItem(Attribute)) {
403 if (!OverwriteExisting)
404 return;
405 Item->Type = AttributeItem::TextAttribute;
406 Item->StringValue = std::string(Value);
407 return;
408 }
409
410 // Create new attribute item
412 std::string(Value)};
413 Contents.push_back(Item);
414}
415
416void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue,
417 StringRef StringValue,
418 bool OverwriteExisting) {
419 // Look for existing attribute item
420 if (AttributeItem *Item = getAttributeItem(Attribute)) {
421 if (!OverwriteExisting)
422 return;
424 Item->IntValue = IntValue;
425 Item->StringValue = std::string(StringValue);
426 return;
427 }
428
429 // Create new attribute item
431 IntValue, std::string(StringValue)};
432 Contents.push_back(Item);
433}
434
436MCELFStreamer::getAttributeItem(unsigned Attribute) {
437 for (AttributeItem &Item : Contents)
438 if (Item.Tag == Attribute)
439 return &Item;
440 return nullptr;
441}
442
443size_t MCELFStreamer::calculateContentSize(
444 SmallVector<AttributeItem, 64> &AttrsVec) const {
445 size_t Result = 0;
446 for (const AttributeItem &Item : AttrsVec) {
447 switch (Item.Type) {
449 break;
451 Result += getULEB128Size(Item.Tag);
452 Result += getULEB128Size(Item.IntValue);
453 break;
455 Result += getULEB128Size(Item.Tag);
456 Result += Item.StringValue.size() + 1; // string + '\0'
457 break;
459 Result += getULEB128Size(Item.Tag);
460 Result += getULEB128Size(Item.IntValue);
461 Result += Item.StringValue.size() + 1; // string + '\0';
462 break;
463 }
464 }
465 return Result;
466}
467
468void MCELFStreamer::createAttributesSection(
469 StringRef Vendor, const Twine &Section, unsigned Type,
470 MCSection *&AttributeSection, SmallVector<AttributeItem, 64> &AttrsVec) {
471 // <format-version>
472 // [ <section-length> "vendor-name"
473 // [ <file-tag> <size> <attribute>*
474 // | <section-tag> <size> <section-number>* 0 <attribute>*
475 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
476 // ]+
477 // ]*
478
479 // Switch section to AttributeSection or get/create the section.
480 if (AttributeSection) {
481 switchSection(AttributeSection);
482 } else {
483 AttributeSection = getContext().getELFSection(Section, Type, 0);
484 switchSection(AttributeSection);
485
486 // Format version
487 emitInt8(0x41);
488 }
489
490 // Vendor size + Vendor name + '\0'
491 const size_t VendorHeaderSize = 4 + Vendor.size() + 1;
492
493 // Tag + Tag Size
494 const size_t TagHeaderSize = 1 + 4;
495
496 const size_t ContentsSize = calculateContentSize(AttrsVec);
497
498 emitInt32(VendorHeaderSize + TagHeaderSize + ContentsSize);
499 emitBytes(Vendor);
500 emitInt8(0); // '\0'
501
503 emitInt32(TagHeaderSize + ContentsSize);
504
505 // Size should have been accounted for already, now
506 // emit each field as its type (ULEB or String)
507 for (const AttributeItem &Item : AttrsVec) {
508 emitULEB128IntValue(Item.Tag);
509 switch (Item.Type) {
510 default:
511 llvm_unreachable("Invalid attribute type");
513 emitULEB128IntValue(Item.IntValue);
514 break;
516 emitBytes(Item.StringValue);
517 emitInt8(0); // '\0'
518 break;
520 emitULEB128IntValue(Item.IntValue);
521 emitBytes(Item.StringValue);
522 emitInt8(0); // '\0'
523 break;
524 }
525 }
526
527 AttrsVec.clear();
528}
529
530void MCELFStreamer::createAttributesWithSubsection(
531 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
533 // <format-version: 'A'>
534 // [ <uint32: subsection-length> NTBS: vendor-name
535 // <bytes: vendor-data>
536 // ]*
537 // vendor-data expends to:
538 // <uint8: optional> <uint8: parameter type> <attribute>*
539 if (0 == SubSectionVec.size()) {
540 return;
541 }
542
543 // Switch section to AttributeSection or get/create the section.
544 if (AttributeSection) {
545 switchSection(AttributeSection);
546 } else {
547 AttributeSection = getContext().getELFSection(Section, Type, 0);
548 switchSection(AttributeSection);
549
550 // Format version
551 emitInt8(0x41);
552 }
553
554 for (AttributeSubSection &SubSection : SubSectionVec) {
555 // subsection-length + vendor-name + '\0'
556 const size_t VendorHeaderSize = 4 + SubSection.VendorName.size() + 1;
557 // optional + parameter-type
558 const size_t VendorParameters = 1 + 1;
559 const size_t ContentsSize = calculateContentSize(SubSection.Content);
560
561 emitInt32(VendorHeaderSize + VendorParameters + ContentsSize);
562 emitBytes(SubSection.VendorName);
563 emitInt8(0); // '\0'
564 emitInt8(SubSection.IsOptional);
565 emitInt8(SubSection.ParameterType);
566
567 for (AttributeItem &Item : SubSection.Content) {
568 emitULEB128IntValue(Item.Tag);
569 switch (Item.Type) {
570 default:
571 assert(0 && "Invalid attribute type");
572 break;
574 emitULEB128IntValue(Item.IntValue);
575 break;
577 emitBytes(Item.StringValue);
578 emitInt8(0); // '\0'
579 break;
581 emitULEB128IntValue(Item.IntValue);
582 emitBytes(Item.StringValue);
583 emitInt8(0); // '\0'
584 break;
585 }
586 }
587 }
588 SubSectionVec.clear();
589}
590
592 std::unique_ptr<MCAsmBackend> &&MAB,
593 std::unique_ptr<MCObjectWriter> &&OW,
594 std::unique_ptr<MCCodeEmitter> &&CE) {
595 MCELFStreamer *S =
596 new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
597 return S;
598}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
dxil DXContainer Global Emitter
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2)
#define F(x, y, z)
Definition MD5.cpp:54
#define T1
#define P(N)
This file defines the SmallVector class.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
SmallVector< const MCSymbolELF *, 0 > Weakrefs
SmallVector< Symver, 0 > Symvers
MCContext & getContext() const
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())
Definition MCExpr.h:343
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:83
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition MCContext.h:553
LLVM_ABI void reportWarning(SMLoc L, const Twine &Msg)
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
SmallVector< AttributeItem, 64 > Contents
void changeSection(MCSection *Section, uint32_t Subsection=0) override
This is called by popSection and switchSection, if the current section changes.
void emitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
void setAttributeItems(unsigned Attribute, unsigned IntValue, StringRef StringValue, bool OverwriteExisting)
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a common symbol.
void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a local common (.lcomm) symbol.
void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Target) override
Emit an weak reference from Alias to Symbol.
void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name, bool KeepOriginalSym) override
Emit an ELF .symver directive.
void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count) override
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment &F, uint64_t Offset) override
ELFObjectWriter & getWriter()
void setAttributeItem(unsigned Attribute, unsigned Value, bool OverwriteExisting)
void finishImpl() final
Streamer specific finalization.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override
Create the default sections and set the initial one.
MCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
SMLoc getLoc() const
Definition MCExpr.h:86
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 emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc={}) override
Record a relocation described by the .reloc directive.
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment &F, uint64_t Offset)
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.
SmallVector< CGProfileEntry, 0 > & getCGProfile()
This represents a section on linux, lots of unix variants and some bare metal systems.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:516
MCSymbol * getBeginSymbol()
Definition MCSection.h:589
Streaming machine code generation interface.
Definition MCStreamer.h:221
virtual bool popSection()
Restore the current and previous section from the section stack.
MCContext & getContext() const
Definition MCStreamer.h:322
SMLoc getStartTokLoc() const
Definition MCStreamer.h:310
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
void pushSection()
Save the current and previous section on the section stack.
Definition MCStreamer.h:449
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
void emitInt32(uint64_t Value)
Definition MCStreamer.h:756
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition MCStreamer.h:422
MCSection * getCurrentSectionOnly() const
Definition MCStreamer.h:427
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
void emitInt8(uint64_t Value)
Definition MCStreamer.h:754
Generic base class for all target subtargets.
void setBinding(unsigned Binding) const
Represent a reference to a symbol from inside an expression.
Definition MCExpr.h:190
const MCSymbol & getSymbol() const
Definition MCExpr.h:227
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
Definition MCSymbol.h:237
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
void setUsedInReloc() const
Definition MCSymbol.h:198
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition MCSymbol.h:251
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition MCSymbol.h:205
Represents a location in source code.
Definition SMLoc.h:22
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.
Definition StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:143
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ SHF_MERGE
Definition ELF.h:1253
@ SHF_STRINGS
Definition ELF.h:1256
@ SHF_EXCLUDE
Definition ELF.h:1281
@ SHF_ALLOC
Definition ELF.h:1247
@ SHF_GNU_RETAIN
Definition ELF.h:1278
@ SHF_WRITE
Definition ELF.h:1244
@ SHF_TLS
Definition ELF.h:1272
@ SHT_PROGBITS
Definition ELF.h:1146
@ SHT_LLVM_CALL_GRAPH_PROFILE
Definition ELF.h:1183
@ SHT_NOBITS
Definition ELF.h:1153
@ SHT_GNU_ATTRIBUTES
Definition ELF.h:1194
@ STB_GLOBAL
Definition ELF.h:1404
@ STB_LOCAL
Definition ELF.h:1403
@ STB_GNU_UNIQUE
Definition ELF.h:1406
@ STB_WEAK
Definition ELF.h:1405
@ STT_FUNC
Definition ELF.h:1417
@ STT_NOTYPE
Definition ELF.h:1415
@ STT_SECTION
Definition ELF.h:1418
@ STT_GNU_IFUNC
Definition ELF.h:1422
@ STT_OBJECT
Definition ELF.h:1416
@ STT_TLS
Definition ELF.h:1421
@ STV_INTERNAL
Definition ELF.h:1434
@ STV_HIDDEN
Definition ELF.h:1435
@ STV_PROTECTED
Definition ELF.h:1436
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
LLVM_ABI MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition LEB128.cpp:19
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
std::pair< MCSection *, uint32_t > MCSectionSubPair
Definition MCStreamer.h:67
@ MCSA_Local
.local (ELF)
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_Protected
.protected (ELF)
@ MCSA_OSLinkage
symbol uses OS linkage (GOFF)
@ MCSA_Exported
.globl _foo, exported (XCOFF)
@ MCSA_PrivateExtern
.private_extern (MachO)
@ MCSA_Internal
.internal (ELF)
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_AltEntry
.alt_entry (MachO)
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
@ MCSA_LazyReference
.lazy_reference (MachO)
@ MCSA_ELF_TypeNoType
.type _foo, STT_NOTYPE # aka @notype
@ MCSA_Reference
.reference (MachO)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
@ MCSA_Weak
.weak
@ MCSA_ELF_TypeTLS
.type _foo, STT_TLS # aka @tls_object
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_ELF_TypeCommon
.type _foo, STT_COMMON # aka @common
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
@ MCSA_XPLinkage
symbol uses XP linkage (GOFF)
@ MCSA_Extern
.extern (XCOFF)
@ MCSA_Cold
.cold (MachO)
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
@ MCSA_ELF_TypeGnuUniqueObject
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
@ MCSA_Hidden
.hidden (ELF)
@ MCSA_LGlobal
.lglobl (XCOFF)
@ MCSA_Invalid
Not a valid directive.
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
ELF object attributes section emission support.
ELF object attributes subsection support.