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"
25#include "llvm/MC/MCLFI.h"
28#include "llvm/MC/MCSection.h"
30#include "llvm/MC/MCStreamer.h"
31#include "llvm/MC/MCSymbol.h"
32#include "llvm/MC/MCSymbolELF.h"
36#include "llvm/Support/LEB128.h"
37#include <cassert>
38#include <cstdint>
39
40using namespace llvm;
41
43 std::unique_ptr<MCAsmBackend> TAB,
44 std::unique_ptr<MCObjectWriter> OW,
45 std::unique_ptr<MCCodeEmitter> Emitter)
46 : MCObjectStreamer(Context, std::move(TAB), std::move(OW),
47 std::move(Emitter)) {}
48
52
54 MCContext &Ctx = getContext();
55 switchSection(Ctx.getObjectFileInfo()->getTextSection());
56 emitCodeAlignment(Align(Ctx.getObjectFileInfo()->getTextSectionAlignment()),
57 &STI);
58}
59
61 auto *Symbol = static_cast<MCSymbolELF *>(S);
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());
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 case MCSA_OSLinkage:
155 case MCSA_XPLinkage:
156 return false;
157
158 case MCSA_NoDeadStrip:
159 // Ignore for now.
160 break;
161
163 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
164 Symbol->setBinding(ELF::STB_GNU_UNIQUE);
166 break;
167
168 case MCSA_Global:
169 // For `.weak x; .global x`, GNU as sets the binding to STB_WEAK while we
170 // traditionally set the binding to STB_GLOBAL. This is error-prone, so we
171 // error on such cases. Note, we also disallow changed binding from .local.
172 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_GLOBAL)
174 Symbol->getName() +
175 " changed binding to STB_GLOBAL");
176 Symbol->setBinding(ELF::STB_GLOBAL);
177 break;
178
180 case MCSA_Weak:
181 // For `.global x; .weak x`, both MC and GNU as set the binding to STB_WEAK.
182 // We emit a warning for now but may switch to an error in the future.
183 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_WEAK)
185 getStartTokLoc(), Symbol->getName() + " changed binding to STB_WEAK");
186 Symbol->setBinding(ELF::STB_WEAK);
187 break;
188
189 case MCSA_Local:
190 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_LOCAL)
192 Symbol->getName() +
193 " changed binding to STB_LOCAL");
194 Symbol->setBinding(ELF::STB_LOCAL);
195 break;
196
198 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
199 break;
200
202 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
204 break;
205
207 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
208 break;
209
210 case MCSA_ELF_TypeTLS:
211 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
212 break;
213
215 // TODO: Emit these as a common symbol.
216 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
217 break;
218
220 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
221 break;
222
223 case MCSA_Protected:
224 Symbol->setVisibility(ELF::STV_PROTECTED);
225 break;
226
227 case MCSA_Memtag:
228 Symbol->setMemtag(true);
229 break;
230
231 case MCSA_Hidden:
232 Symbol->setVisibility(ELF::STV_HIDDEN);
233 break;
234
235 case MCSA_Internal:
236 Symbol->setVisibility(ELF::STV_INTERNAL);
237 break;
238
239 case MCSA_AltEntry:
240 llvm_unreachable("ELF doesn't support the .alt_entry attribute");
241
242 case MCSA_LGlobal:
243 llvm_unreachable("ELF doesn't support the .lglobl attribute");
244 }
245
246 return true;
247}
248
250 Align ByteAlignment) {
251 auto *Symbol = static_cast<MCSymbolELF *>(S);
252 getAssembler().registerSymbol(*Symbol);
253
254 if (!Symbol->isBindingSet())
255 Symbol->setBinding(ELF::STB_GLOBAL);
256
257 Symbol->setType(ELF::STT_OBJECT);
258
259 if (Symbol->getBinding() == ELF::STB_LOCAL) {
263 switchSection(&Section);
264
265 emitValueToAlignment(ByteAlignment, 0, 1, 0);
266 emitLabel(Symbol);
268
269 switchSection(P.first, P.second);
270 } else {
271 if (Symbol->declareCommon(Size, ByteAlignment))
272 report_fatal_error(Twine("Symbol: ") + Symbol->getName() +
273 " redeclared as different type");
274 }
275
276 Symbol->setSize(MCConstantExpr::create(Size, getContext()));
277}
278
280 static_cast<MCSymbolELF *>(Symbol)->setSize(Value);
281}
282
284 StringRef Name,
285 bool KeepOriginalSym) {
287 getStartTokLoc(), OriginalSym, Name, KeepOriginalSym});
288}
289
291 Align ByteAlignment) {
292 auto *Symbol = static_cast<MCSymbolELF *>(S);
293 // FIXME: Should this be caught and done earlier?
294 getAssembler().registerSymbol(*Symbol);
295 Symbol->setBinding(ELF::STB_LOCAL);
296 emitCommonSymbol(Symbol, Size, ByteAlignment);
297}
298
300 const MCSymbolRefExpr *To,
301 uint64_t Count) {
302 getWriter().getCGProfile().push_back({From, To, Count});
303}
304
308 pushSection();
309 switchSection(Comment);
310 if (!SeenIdent) {
311 emitInt8(0);
312 SeenIdent = true;
313 }
314 emitBytes(IdentString);
315 emitInt8(0);
316 popSection();
317}
318
319void MCELFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *Sym,
321 const MCSymbolRefExpr *&SRE) {
322 const MCSymbol *S = &SRE->getSymbol();
323 if (S->isTemporary()) {
324 if (!S->isInSection()) {
326 SRE->getLoc(), Twine("Reference to undefined temporary symbol ") +
327 "`" + S->getName() + "`");
328 return;
329 }
330 S = S->getSection().getBeginSymbol();
331 S->setUsedInReloc();
332 SRE = MCSymbolRefExpr::create(S, getContext(), SRE->getLoc());
333 }
336 MCObjectStreamer::emitRelocDirective(*O, "BFD_RELOC_NONE", SRE);
337}
338
339void MCELFStreamer::finalizeCGProfile() {
340 ELFObjectWriter &W = getWriter();
341 if (W.getCGProfile().empty())
342 return;
343 MCSection *CGProfile = getAssembler().getContext().getELFSection(
344 ".llvm.call-graph-profile", ELF::SHT_LLVM_CALL_GRAPH_PROFILE,
345 ELF::SHF_EXCLUDE, /*sizeof(Elf_CGProfile_Impl<>)=*/8);
346 pushSection();
347 switchSection(CGProfile);
348 uint64_t Offset = 0;
349 auto *Sym =
351 for (auto &E : W.getCGProfile()) {
352 finalizeCGProfileEntry(Sym, Offset, E.From);
353 finalizeCGProfileEntry(Sym, Offset, E.To);
354 emitIntValue(E.Count, sizeof(uint64_t));
355 Offset += sizeof(uint64_t);
356 }
357 popSection();
358}
359
361 // Emit .note.GNU-stack, similar to AsmPrinter::doFinalization.
362 MCContext &Ctx = getContext();
363 if (const MCTargetOptions *TO = Ctx.getTargetOptions()) {
364 auto *StackSec = Ctx.getAsmInfo()->getStackSection(Ctx,
365 /*Exec=*/false);
366 if (StackSec && TO->MCNoExecStack)
367 switchSection(StackSec);
368 }
369
370 // Emit the .gnu attributes section if any attributes have been added.
371 if (!GNUAttributes.empty()) {
372 MCSection *DummyAttributeSection = nullptr;
373 createAttributesSection("gnu", ".gnu.attributes", ELF::SHT_GNU_ATTRIBUTES,
374 DummyAttributeSection, GNUAttributes);
375 }
376
377 if (Ctx.getTargetTriple().isLFI())
378 emitLFINoteSection(*this, Ctx);
379
380 finalizeCGProfile();
381 emitFrames();
382
384}
385
387 bool OverwriteExisting) {
388 // Look for existing attribute item
389 if (AttributeItem *Item = getAttributeItem(Attribute)) {
390 if (!OverwriteExisting)
391 return;
393 Item->IntValue = Value;
394 return;
395 }
396
397 // Create new attribute item
399 std::string(StringRef(""))};
400 Contents.push_back(Item);
401}
402
404 bool OverwriteExisting) {
405 // Look for existing attribute item
406 if (AttributeItem *Item = getAttributeItem(Attribute)) {
407 if (!OverwriteExisting)
408 return;
409 Item->Type = AttributeItem::TextAttribute;
410 Item->StringValue = std::string(Value);
411 return;
412 }
413
414 // Create new attribute item
416 std::string(Value)};
417 Contents.push_back(Item);
418}
419
420void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue,
421 StringRef StringValue,
422 bool OverwriteExisting) {
423 // Look for existing attribute item
424 if (AttributeItem *Item = getAttributeItem(Attribute)) {
425 if (!OverwriteExisting)
426 return;
428 Item->IntValue = IntValue;
429 Item->StringValue = std::string(StringValue);
430 return;
431 }
432
433 // Create new attribute item
435 IntValue, std::string(StringValue)};
436 Contents.push_back(Item);
437}
438
440MCELFStreamer::getAttributeItem(unsigned Attribute) {
441 for (AttributeItem &Item : Contents)
442 if (Item.Tag == Attribute)
443 return &Item;
444 return nullptr;
445}
446
447size_t MCELFStreamer::calculateContentSize(
448 SmallVector<AttributeItem, 64> &AttrsVec) const {
449 size_t Result = 0;
450 for (const AttributeItem &Item : AttrsVec) {
451 switch (Item.Type) {
453 break;
455 Result += getULEB128Size(Item.Tag);
456 Result += getULEB128Size(Item.IntValue);
457 break;
459 Result += getULEB128Size(Item.Tag);
460 Result += Item.StringValue.size() + 1; // string + '\0'
461 break;
463 Result += getULEB128Size(Item.Tag);
464 Result += getULEB128Size(Item.IntValue);
465 Result += Item.StringValue.size() + 1; // string + '\0';
466 break;
467 }
468 }
469 return Result;
470}
471
472void MCELFStreamer::createAttributesSection(
473 StringRef Vendor, const Twine &Section, unsigned Type,
474 MCSection *&AttributeSection, SmallVector<AttributeItem, 64> &AttrsVec) {
475 // <format-version>
476 // [ <section-length> "vendor-name"
477 // [ <file-tag> <size> <attribute>*
478 // | <section-tag> <size> <section-number>* 0 <attribute>*
479 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
480 // ]+
481 // ]*
482
483 // Switch section to AttributeSection or get/create the section.
484 if (AttributeSection) {
485 switchSection(AttributeSection);
486 } else {
487 AttributeSection = getContext().getELFSection(Section, Type, 0);
488 switchSection(AttributeSection);
489
490 // Format version
491 emitInt8(0x41);
492 }
493
494 // Vendor size + Vendor name + '\0'
495 const size_t VendorHeaderSize = 4 + Vendor.size() + 1;
496
497 // Tag + Tag Size
498 const size_t TagHeaderSize = 1 + 4;
499
500 const size_t ContentsSize = calculateContentSize(AttrsVec);
501
502 emitInt32(VendorHeaderSize + TagHeaderSize + ContentsSize);
503 emitBytes(Vendor);
504 emitInt8(0); // '\0'
505
507 emitInt32(TagHeaderSize + ContentsSize);
508
509 // Size should have been accounted for already, now
510 // emit each field as its type (ULEB or String)
511 for (const AttributeItem &Item : AttrsVec) {
512 emitULEB128IntValue(Item.Tag);
513 switch (Item.Type) {
514 default:
515 llvm_unreachable("Invalid attribute type");
517 emitULEB128IntValue(Item.IntValue);
518 break;
520 emitBytes(Item.StringValue);
521 emitInt8(0); // '\0'
522 break;
524 emitULEB128IntValue(Item.IntValue);
525 emitBytes(Item.StringValue);
526 emitInt8(0); // '\0'
527 break;
528 }
529 }
530
531 AttrsVec.clear();
532}
533
534void MCELFStreamer::createAttributesWithSubsection(
535 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
537 // <format-version: 'A'>
538 // [ <uint32: subsection-length> NTBS: vendor-name
539 // <bytes: vendor-data>
540 // ]*
541 // vendor-data expends to:
542 // <uint8: optional> <uint8: parameter type> <attribute>*
543 if (0 == SubSectionVec.size()) {
544 return;
545 }
546
547 // Switch section to AttributeSection or get/create the section.
548 if (AttributeSection) {
549 switchSection(AttributeSection);
550 } else {
551 AttributeSection = getContext().getELFSection(Section, Type, 0);
552 switchSection(AttributeSection);
553
554 // Format version
555 emitInt8(0x41);
556 }
557
558 for (AttributeSubSection &SubSection : SubSectionVec) {
559 // subsection-length + vendor-name + '\0'
560 const size_t VendorHeaderSize = 4 + SubSection.VendorName.size() + 1;
561 // optional + parameter-type
562 const size_t VendorParameters = 1 + 1;
563 const size_t ContentsSize = calculateContentSize(SubSection.Content);
564
565 emitInt32(VendorHeaderSize + VendorParameters + ContentsSize);
566 emitBytes(SubSection.VendorName);
567 emitInt8(0); // '\0'
568 emitInt8(SubSection.IsOptional);
569 emitInt8(SubSection.ParameterType);
570
571 for (AttributeItem &Item : SubSection.Content) {
572 emitULEB128IntValue(Item.Tag);
573 switch (Item.Type) {
574 default:
575 assert(0 && "Invalid attribute type");
576 break;
578 emitULEB128IntValue(Item.IntValue);
579 break;
581 emitBytes(Item.StringValue);
582 emitInt8(0); // '\0'
583 break;
585 emitULEB128IntValue(Item.IntValue);
586 emitBytes(Item.StringValue);
587 emitInt8(0); // '\0'
588 break;
589 }
590 }
591 }
592 SubSectionVec.clear();
593}
594
596 std::unique_ptr<MCAsmBackend> &&MAB,
597 std::unique_ptr<MCObjectWriter> &&OW,
598 std::unique_ptr<MCCodeEmitter> &&CE) {
599 MCELFStreamer *S =
600 new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
601 return S;
602}
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)
LFI-specific code for MC.
#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:550
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 initSections(const MCSubtargetInfo &STI) override
Create the default sections and set the initial one.
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.
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:569
MCSymbol * getBeginSymbol()
Definition MCSection.h:642
Streaming machine code generation interface.
Definition MCStreamer.h:222
virtual bool popSection()
Restore the current and previous section from the section stack.
MCContext & getContext() const
Definition MCStreamer.h:323
SMLoc getStartTokLoc() const
Definition MCStreamer.h:311
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:450
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:757
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition MCStreamer.h:423
MCSection * getCurrentSectionOnly() const
Definition MCStreamer.h:428
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
void emitInt8(uint64_t Value)
Definition MCStreamer.h:755
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:1255
@ SHF_STRINGS
Definition ELF.h:1258
@ SHF_EXCLUDE
Definition ELF.h:1283
@ SHF_ALLOC
Definition ELF.h:1249
@ SHF_GNU_RETAIN
Definition ELF.h:1280
@ SHF_WRITE
Definition ELF.h:1246
@ SHF_TLS
Definition ELF.h:1274
@ SHT_PROGBITS
Definition ELF.h:1148
@ SHT_LLVM_CALL_GRAPH_PROFILE
Definition ELF.h:1185
@ SHT_NOBITS
Definition ELF.h:1155
@ SHT_GNU_ATTRIBUTES
Definition ELF.h:1196
@ STB_GLOBAL
Definition ELF.h:1406
@ STB_LOCAL
Definition ELF.h:1405
@ STB_GNU_UNIQUE
Definition ELF.h:1408
@ STB_WEAK
Definition ELF.h:1407
@ STT_FUNC
Definition ELF.h:1419
@ STT_NOTYPE
Definition ELF.h:1417
@ STT_SECTION
Definition ELF.h:1420
@ STT_GNU_IFUNC
Definition ELF.h:1424
@ STT_OBJECT
Definition ELF.h:1418
@ STT_TLS
Definition ELF.h:1423
@ STV_INTERNAL
Definition ELF.h:1436
@ STV_HIDDEN
Definition ELF.h:1437
@ STV_PROTECTED
Definition ELF.h:1438
This is an optimization pass for GlobalISel generic memory operations.
@ 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 emitLFINoteSection(MCStreamer &Streamer, MCContext &Ctx)
Definition MCLFI.cpp:53
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:68
@ 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.