LLVM 22.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"
22#include "llvm/MC/MCExpr.h"
23#include "llvm/MC/MCFixup.h"
26#include "llvm/MC/MCSection.h"
28#include "llvm/MC/MCStreamer.h"
29#include "llvm/MC/MCSymbol.h"
30#include "llvm/MC/MCSymbolELF.h"
33#include "llvm/Support/LEB128.h"
34#include <cassert>
35#include <cstdint>
36
37using namespace llvm;
38
40 std::unique_ptr<MCAsmBackend> TAB,
41 std::unique_ptr<MCObjectWriter> OW,
42 std::unique_ptr<MCCodeEmitter> Emitter)
43 : MCObjectStreamer(Context, std::move(TAB), std::move(OW),
44 std::move(Emitter)) {}
45
47 return static_cast<ELFObjectWriter &>(getAssembler().getWriter());
48}
49
50void MCELFStreamer::initSections(bool NoExecStack, const MCSubtargetInfo &STI) {
51 MCContext &Ctx = getContext();
54 &STI);
55
56 if (NoExecStack)
58}
59
61 auto *Symbol = static_cast<MCSymbolELF *>(S);
62 MCObjectStreamer::emitLabel(Symbol, Loc);
63
64 const MCSectionELF &Section =
65 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
66 if (Section.getFlags() & ELF::SHF_TLS)
67 Symbol->setType(ELF::STT_TLS);
68}
69
72 auto *Symbol = static_cast<MCSymbolELF *>(S);
74
75 const MCSectionELF &Section =
76 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
77 if (Section.getFlags() & ELF::SHF_TLS)
78 Symbol->setType(ELF::STT_TLS);
79}
80
83 auto *SectionELF = static_cast<const MCSectionELF *>(Section);
84 const MCSymbol *Grp = SectionELF->getGroup();
85 if (Grp)
86 Asm.registerSymbol(*Grp);
87 if (SectionELF->getFlags() & ELF::SHF_GNU_RETAIN)
89
90 MCObjectStreamer::changeSection(Section, Subsection);
91 auto *Sym = static_cast<MCSymbolELF *>(Section->getBeginSymbol());
92 Sym->setBinding(ELF::STB_LOCAL);
93 Sym->setType(ELF::STT_SECTION);
94}
95
97 auto *A = static_cast<MCSymbolELF *>(Alias);
98 if (A->isDefined()) {
99 getContext().reportError(getStartTokLoc(), "symbol '" + A->getName() +
100 "' is already defined");
101 return;
102 }
103 A->setVariableValue(MCSymbolRefExpr::create(Target, getContext()));
104 A->setIsWeakref();
105 getWriter().Weakrefs.push_back(A);
106}
107
108// When GNU as encounters more than one .type declaration for an object it seems
109// to use a mechanism similar to the one below to decide which type is actually
110// used in the object file. The greater of T1 and T2 is selected based on the
111// following ordering:
112// STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
113// If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
114// provided type).
115static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
118 if (T1 == Type)
119 return T2;
120 if (T2 == Type)
121 return T1;
122 }
123
124 return T2;
125}
126
128 auto *Symbol = static_cast<MCSymbolELF *>(S);
129
130 // Adding a symbol attribute always introduces the symbol, note that an
131 // important side effect of calling registerSymbol here is to register
132 // the symbol with the assembler.
133 getAssembler().registerSymbol(*Symbol);
134
135 // The implementation of symbol attributes is designed to match 'as', but it
136 // leaves much to desired. It doesn't really make sense to arbitrarily add and
137 // remove flags, but 'as' allows this (in particular, see .desc).
138 //
139 // In the future it might be worth trying to make these operations more well
140 // defined.
141 switch (Attribute) {
142 case MCSA_Cold:
143 case MCSA_Extern:
145 case MCSA_Reference:
150 case MCSA_Invalid:
152 case MCSA_Exported:
153 case MCSA_WeakAntiDep:
154 return false;
155
156 case MCSA_NoDeadStrip:
157 // Ignore for now.
158 break;
159
161 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
162 Symbol->setBinding(ELF::STB_GNU_UNIQUE);
164 break;
165
166 case MCSA_Global:
167 // For `.weak x; .global x`, GNU as sets the binding to STB_WEAK while we
168 // traditionally set the binding to STB_GLOBAL. This is error-prone, so we
169 // error on such cases. Note, we also disallow changed binding from .local.
170 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_GLOBAL)
172 Symbol->getName() +
173 " changed binding to STB_GLOBAL");
174 Symbol->setBinding(ELF::STB_GLOBAL);
175 break;
176
178 case MCSA_Weak:
179 // For `.global x; .weak x`, both MC and GNU as set the binding to STB_WEAK.
180 // We emit a warning for now but may switch to an error in the future.
181 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_WEAK)
183 getStartTokLoc(), Symbol->getName() + " changed binding to STB_WEAK");
184 Symbol->setBinding(ELF::STB_WEAK);
185 break;
186
187 case MCSA_Local:
188 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_LOCAL)
190 Symbol->getName() +
191 " changed binding to STB_LOCAL");
192 Symbol->setBinding(ELF::STB_LOCAL);
193 break;
194
196 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
197 break;
198
200 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
202 break;
203
205 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
206 break;
207
208 case MCSA_ELF_TypeTLS:
209 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
210 break;
211
213 // TODO: Emit these as a common symbol.
214 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
215 break;
216
218 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
219 break;
220
221 case MCSA_Protected:
222 Symbol->setVisibility(ELF::STV_PROTECTED);
223 break;
224
225 case MCSA_Memtag:
226 Symbol->setMemtag(true);
227 break;
228
229 case MCSA_Hidden:
230 Symbol->setVisibility(ELF::STV_HIDDEN);
231 break;
232
233 case MCSA_Internal:
234 Symbol->setVisibility(ELF::STV_INTERNAL);
235 break;
236
237 case MCSA_AltEntry:
238 llvm_unreachable("ELF doesn't support the .alt_entry attribute");
239
240 case MCSA_LGlobal:
241 llvm_unreachable("ELF doesn't support the .lglobl attribute");
242 }
243
244 return true;
245}
246
248 Align ByteAlignment) {
249 auto *Symbol = static_cast<MCSymbolELF *>(S);
250 getAssembler().registerSymbol(*Symbol);
251
252 if (!Symbol->isBindingSet())
253 Symbol->setBinding(ELF::STB_GLOBAL);
254
255 Symbol->setType(ELF::STT_OBJECT);
256
257 if (Symbol->getBinding() == ELF::STB_LOCAL) {
261 switchSection(&Section);
262
263 emitValueToAlignment(ByteAlignment, 0, 1, 0);
264 emitLabel(Symbol);
266
267 switchSection(P.first, P.second);
268 } else {
269 if (Symbol->declareCommon(Size, ByteAlignment))
270 report_fatal_error(Twine("Symbol: ") + Symbol->getName() +
271 " redeclared as different type");
272 }
273
274 static_cast<MCSymbolELF *>(Symbol)->setSize(
276}
277
279 static_cast<MCSymbolELF *>(Symbol)->setSize(Value);
280}
281
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() {
340 if (W.getCGProfile().empty())
341 return;
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 the .gnu attributes section if any attributes have been added.
361 if (!GNUAttributes.empty()) {
362 MCSection *DummyAttributeSection = nullptr;
363 createAttributesSection("gnu", ".gnu.attributes", ELF::SHT_GNU_ATTRIBUTES,
364 DummyAttributeSection, GNUAttributes);
365 }
366
367 finalizeCGProfile();
368 emitFrames(nullptr);
369
371}
372
374 bool OverwriteExisting) {
375 // Look for existing attribute item
376 if (AttributeItem *Item = getAttributeItem(Attribute)) {
377 if (!OverwriteExisting)
378 return;
380 Item->IntValue = Value;
381 return;
382 }
383
384 // Create new attribute item
386 std::string(StringRef(""))};
387 Contents.push_back(Item);
388}
389
391 bool OverwriteExisting) {
392 // Look for existing attribute item
393 if (AttributeItem *Item = getAttributeItem(Attribute)) {
394 if (!OverwriteExisting)
395 return;
396 Item->Type = AttributeItem::TextAttribute;
397 Item->StringValue = std::string(Value);
398 return;
399 }
400
401 // Create new attribute item
403 std::string(Value)};
404 Contents.push_back(Item);
405}
406
407void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue,
408 StringRef StringValue,
409 bool OverwriteExisting) {
410 // Look for existing attribute item
411 if (AttributeItem *Item = getAttributeItem(Attribute)) {
412 if (!OverwriteExisting)
413 return;
415 Item->IntValue = IntValue;
416 Item->StringValue = std::string(StringValue);
417 return;
418 }
419
420 // Create new attribute item
422 IntValue, std::string(StringValue)};
423 Contents.push_back(Item);
424}
425
427MCELFStreamer::getAttributeItem(unsigned Attribute) {
428 for (AttributeItem &Item : Contents)
429 if (Item.Tag == Attribute)
430 return &Item;
431 return nullptr;
432}
433
434size_t MCELFStreamer::calculateContentSize(
435 SmallVector<AttributeItem, 64> &AttrsVec) const {
436 size_t Result = 0;
437 for (const AttributeItem &Item : AttrsVec) {
438 switch (Item.Type) {
440 break;
442 Result += getULEB128Size(Item.Tag);
443 Result += getULEB128Size(Item.IntValue);
444 break;
446 Result += getULEB128Size(Item.Tag);
447 Result += Item.StringValue.size() + 1; // string + '\0'
448 break;
450 Result += getULEB128Size(Item.Tag);
451 Result += getULEB128Size(Item.IntValue);
452 Result += Item.StringValue.size() + 1; // string + '\0';
453 break;
454 }
455 }
456 return Result;
457}
458
459void MCELFStreamer::createAttributesSection(
460 StringRef Vendor, const Twine &Section, unsigned Type,
461 MCSection *&AttributeSection, SmallVector<AttributeItem, 64> &AttrsVec) {
462 // <format-version>
463 // [ <section-length> "vendor-name"
464 // [ <file-tag> <size> <attribute>*
465 // | <section-tag> <size> <section-number>* 0 <attribute>*
466 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
467 // ]+
468 // ]*
469
470 // Switch section to AttributeSection or get/create the section.
471 if (AttributeSection) {
472 switchSection(AttributeSection);
473 } else {
474 AttributeSection = getContext().getELFSection(Section, Type, 0);
475 switchSection(AttributeSection);
476
477 // Format version
478 emitInt8(0x41);
479 }
480
481 // Vendor size + Vendor name + '\0'
482 const size_t VendorHeaderSize = 4 + Vendor.size() + 1;
483
484 // Tag + Tag Size
485 const size_t TagHeaderSize = 1 + 4;
486
487 const size_t ContentsSize = calculateContentSize(AttrsVec);
488
489 emitInt32(VendorHeaderSize + TagHeaderSize + ContentsSize);
490 emitBytes(Vendor);
491 emitInt8(0); // '\0'
492
494 emitInt32(TagHeaderSize + ContentsSize);
495
496 // Size should have been accounted for already, now
497 // emit each field as its type (ULEB or String)
498 for (const AttributeItem &Item : AttrsVec) {
499 emitULEB128IntValue(Item.Tag);
500 switch (Item.Type) {
501 default:
502 llvm_unreachable("Invalid attribute type");
504 emitULEB128IntValue(Item.IntValue);
505 break;
507 emitBytes(Item.StringValue);
508 emitInt8(0); // '\0'
509 break;
511 emitULEB128IntValue(Item.IntValue);
512 emitBytes(Item.StringValue);
513 emitInt8(0); // '\0'
514 break;
515 }
516 }
517
518 AttrsVec.clear();
519}
520
521void MCELFStreamer::createAttributesWithSubsection(
522 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
524 // <format-version: 'A'>
525 // [ <uint32: subsection-length> NTBS: vendor-name
526 // <bytes: vendor-data>
527 // ]*
528 // vendor-data expends to:
529 // <uint8: optional> <uint8: parameter type> <attribute>*
530 if (0 == SubSectionVec.size()) {
531 return;
532 }
533
534 // Switch section to AttributeSection or get/create the section.
535 if (AttributeSection) {
536 switchSection(AttributeSection);
537 } else {
538 AttributeSection = getContext().getELFSection(Section, Type, 0);
539 switchSection(AttributeSection);
540
541 // Format version
542 emitInt8(0x41);
543 }
544
545 for (AttributeSubSection &SubSection : SubSectionVec) {
546 // subsection-length + vendor-name + '\0'
547 const size_t VendorHeaderSize = 4 + SubSection.VendorName.size() + 1;
548 // optional + parameter-type
549 const size_t VendorParameters = 1 + 1;
550 const size_t ContentsSize = calculateContentSize(SubSection.Content);
551
552 emitInt32(VendorHeaderSize + VendorParameters + ContentsSize);
553 emitBytes(SubSection.VendorName);
554 emitInt8(0); // '\0'
555 emitInt8(SubSection.IsOptional);
556 emitInt8(SubSection.ParameterType);
557
558 for (AttributeItem &Item : SubSection.Content) {
559 emitULEB128IntValue(Item.Tag);
560 switch (Item.Type) {
561 default:
562 assert(0 && "Invalid attribute type");
563 break;
565 emitULEB128IntValue(Item.IntValue);
566 break;
568 emitBytes(Item.StringValue);
569 emitInt8(0); // '\0'
570 break;
572 emitULEB128IntValue(Item.IntValue);
573 emitBytes(Item.StringValue);
574 emitInt8(0); // '\0'
575 break;
576 }
577 }
578 }
579 SubSectionVec.clear();
580}
581
583 std::unique_ptr<MCAsmBackend> &&MAB,
584 std::unique_ptr<MCObjectWriter> &&OW,
585 std::unique_ptr<MCCodeEmitter> &&CE) {
586 MCELFStreamer *S =
587 new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
588 return S;
589}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
BlockVerifier::State From
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
dxil DXContainer Global Emitter
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2)
#define F(x, y, z)
Definition: MD5.cpp:55
#define T1
#define P(N)
This file defines the SmallVector class.
SmallVector< const MCSymbolELF *, 0 > Weakrefs
SmallVector< Symver, 0 > Symvers
virtual MCSection * getNonexecutableStackSection(MCContext &Ctx) const
Targets can implement this method to specify a section to switch to if the translation unit doesn't h...
Definition: MCAsmInfo.h:470
MCContext & getContext() const
Definition: MCAssembler.h:169
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:179
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
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:416
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:549
LLVM_ABI void reportWarning(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1122
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:412
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1115
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
virtual unsigned getTextSectionAlignment() const
MCSection * getTextSection() 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 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.
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 emitFrames(MCAsmBackend *MAB)
SmallVector< CGProfileEntry, 0 > & getCGProfile()
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:27
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
MCSymbol * getBeginSymbol()
Definition: MCSection.h:568
Streaming machine code generation interface.
Definition: MCStreamer.h:220
virtual bool popSection()
Restore the current and previous section from the section stack.
MCContext & getContext() const
Definition: MCStreamer.h:314
SMLoc getStartTokLoc() const
Definition: MCStreamer.h:306
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.
Definition: MCStreamer.cpp:132
void pushSection()
Save the current and previous section on the section stack.
Definition: MCStreamer.h:443
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...
Definition: MCStreamer.cpp:160
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:750
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition: MCStreamer.h:416
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:421
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Definition: MCStreamer.cpp:204
void emitInt8(uint64_t Value)
Definition: MCStreamer.h:748
Generic base class for all target subtargets.
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:23
bool empty() const
Definition: SmallVector.h:82
size_t size() const
Definition: SmallVector.h:79
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
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:154
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:45
LLVM Value Representation.
Definition: Value.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ STV_INTERNAL
Definition: ELF.h:1427
@ STV_HIDDEN
Definition: ELF.h:1428
@ STV_PROTECTED
Definition: ELF.h:1429
@ SHT_PROGBITS
Definition: ELF.h:1140
@ SHT_LLVM_CALL_GRAPH_PROFILE
Definition: ELF.h:1177
@ SHT_NOBITS
Definition: ELF.h:1147
@ SHT_GNU_ATTRIBUTES
Definition: ELF.h:1187
@ STB_GLOBAL
Definition: ELF.h:1397
@ STB_LOCAL
Definition: ELF.h:1396
@ STB_GNU_UNIQUE
Definition: ELF.h:1399
@ STB_WEAK
Definition: ELF.h:1398
@ SHF_MERGE
Definition: ELF.h:1246
@ SHF_STRINGS
Definition: ELF.h:1249
@ SHF_EXCLUDE
Definition: ELF.h:1274
@ SHF_ALLOC
Definition: ELF.h:1240
@ SHF_GNU_RETAIN
Definition: ELF.h:1271
@ SHF_WRITE
Definition: ELF.h:1237
@ SHF_TLS
Definition: ELF.h:1265
@ STT_FUNC
Definition: ELF.h:1410
@ STT_NOTYPE
Definition: ELF.h:1408
@ STT_SECTION
Definition: ELF.h:1411
@ STT_GNU_IFUNC
Definition: ELF.h:1415
@ STT_OBJECT
Definition: ELF.h:1409
@ STT_TLS
Definition: ELF.h:1414
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
LLVM_ABI MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
std::pair< MCSection *, uint32_t > MCSectionSubPair
Definition: MCStreamer.h:66
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
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:1886
MCSymbolAttr
Definition: MCDirectives.h:18
@ MCSA_Local
.local (ELF)
Definition: MCDirectives.h:38
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
Definition: MCDirectives.h:48
@ MCSA_Memtag
.memtag (ELF)
Definition: MCDirectives.h:50
@ MCSA_Protected
.protected (ELF)
Definition: MCDirectives.h:43
@ MCSA_Exported
.globl _foo, exported (XCOFF)
Definition: MCDirectives.h:34
@ MCSA_PrivateExtern
.private_extern (MachO)
Definition: MCDirectives.h:42
@ MCSA_Internal
.internal (ELF)
Definition: MCDirectives.h:36
@ MCSA_WeakReference
.weak_reference (MachO)
Definition: MCDirectives.h:47
@ MCSA_AltEntry
.alt_entry (MachO)
Definition: MCDirectives.h:41
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
Definition: MCDirectives.h:24
@ MCSA_LazyReference
.lazy_reference (MachO)
Definition: MCDirectives.h:37
@ MCSA_ELF_TypeNoType
.type _foo, STT_NOTYPE # aka @notype
Definition: MCDirectives.h:28
@ MCSA_Reference
.reference (MachO)
Definition: MCDirectives.h:44
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
Definition: MCDirectives.h:40
@ MCSA_Weak
.weak
Definition: MCDirectives.h:45
@ MCSA_ELF_TypeTLS
.type _foo, STT_TLS # aka @tls_object
Definition: MCDirectives.h:26
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
Definition: MCDirectives.h:35
@ MCSA_WeakDefinition
.weak_definition (MachO)
Definition: MCDirectives.h:46
@ MCSA_ELF_TypeCommon
.type _foo, STT_COMMON # aka @common
Definition: MCDirectives.h:27
@ MCSA_Global
.type _foo, @gnu_unique_object
Definition: MCDirectives.h:30
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
Definition: MCDirectives.h:49
@ MCSA_Extern
.extern (XCOFF)
Definition: MCDirectives.h:32
@ MCSA_Cold
.cold (MachO)
Definition: MCDirectives.h:22
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
Definition: MCDirectives.h:25
@ MCSA_ELF_TypeGnuUniqueObject
Definition: MCDirectives.h:29
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
Definition: MCDirectives.h:23
@ MCSA_Hidden
.hidden (ELF)
Definition: MCDirectives.h:33
@ MCSA_LGlobal
.lglobl (XCOFF)
Definition: MCDirectives.h:31
@ MCSA_Invalid
Not a valid directive.
Definition: MCDirectives.h:19
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
Definition: MCDirectives.h:39
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
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.
Definition: MCELFStreamer.h:77