LLVM 24.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 if (isBundleLocked()) {
85 getStartTokLoc(), "unterminated .bundle_lock when changing a section");
86 // Clean up bundle state to allow continuing.
87 BundleLocked = false;
88 BundleBA = nullptr;
89 }
90 auto *SectionELF = static_cast<const MCSectionELF *>(Section);
91 const MCSymbol *Grp = SectionELF->getGroup();
92 if (Grp)
93 Asm.registerSymbol(*Grp);
94 if (SectionELF->getFlags() & ELF::SHF_GNU_RETAIN)
96
97 MCObjectStreamer::changeSection(Section, Subsection);
98 auto *Sym = static_cast<MCSymbolELF *>(Section->getBeginSymbol());
100 Sym->setType(ELF::STT_SECTION);
101}
102
104 auto *A = static_cast<MCSymbolELF *>(Alias);
105 if (A->isDefined()) {
106 getContext().reportError(getStartTokLoc(), "symbol '" + A->getName() +
107 "' is already defined");
108 return;
109 }
110 A->setVariableValue(MCSymbolRefExpr::create(Target, getContext()));
111 A->setIsWeakref();
112 getWriter().Weakrefs.push_back(A);
113}
114
115// When GNU as encounters more than one .type declaration for an object it seems
116// to use a mechanism similar to the one below to decide which type is actually
117// used in the object file. The greater of T1 and T2 is selected based on the
118// following ordering:
119// STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
120// If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
121// provided type).
122static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
125 if (T1 == Type)
126 return T2;
127 if (T2 == Type)
128 return T1;
129 }
130
131 return T2;
132}
133
135 auto *Symbol = static_cast<MCSymbolELF *>(S);
136
137 // Adding a symbol attribute always introduces the symbol, note that an
138 // important side effect of calling registerSymbol here is to register
139 // the symbol with the assembler.
140 getAssembler().registerSymbol(*Symbol);
141
142 // The implementation of symbol attributes is designed to match 'as', but it
143 // leaves much to desired. It doesn't really make sense to arbitrarily add and
144 // remove flags, but 'as' allows this (in particular, see .desc).
145 //
146 // In the future it might be worth trying to make these operations more well
147 // defined.
148 switch (Attribute) {
149 case MCSA_Cold:
150 case MCSA_Extern:
152 case MCSA_Reference:
157 case MCSA_Invalid:
159 case MCSA_Exported:
160 case MCSA_WeakAntiDep:
161 case MCSA_OSLinkage:
162 case MCSA_XPLinkage:
163 return false;
164
165 case MCSA_NoDeadStrip:
166 // Ignore for now.
167 break;
168
170 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
171 Symbol->setBinding(ELF::STB_GNU_UNIQUE);
173 break;
174
175 case MCSA_Global:
176 // For `.weak x; .global x`, GNU as sets the binding to STB_WEAK while we
177 // traditionally set the binding to STB_GLOBAL. This is error-prone, so we
178 // error on such cases. Note, we also disallow changed binding from .local.
179 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_GLOBAL)
181 Symbol->getName() +
182 " changed binding to STB_GLOBAL");
183 Symbol->setBinding(ELF::STB_GLOBAL);
184 break;
185
187 case MCSA_Weak:
188 // For `.global x; .weak x`, both MC and GNU as set the binding to STB_WEAK.
189 // We emit a warning for now but may switch to an error in the future.
190 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_WEAK)
192 getStartTokLoc(), Symbol->getName() + " changed binding to STB_WEAK");
193 Symbol->setBinding(ELF::STB_WEAK);
194 break;
195
196 case MCSA_Local:
197 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_LOCAL)
199 Symbol->getName() +
200 " changed binding to STB_LOCAL");
201 Symbol->setBinding(ELF::STB_LOCAL);
202 break;
203
205 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
206 break;
207
209 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
211 break;
212
214 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
215 break;
216
217 case MCSA_ELF_TypeTLS:
218 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
219 break;
220
222 // TODO: Emit these as a common symbol.
223 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
224 break;
225
227 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
228 break;
229
230 case MCSA_Protected:
231 Symbol->setVisibility(ELF::STV_PROTECTED);
232 break;
233
234 case MCSA_Memtag:
235 Symbol->setMemtag(true);
236 break;
237
238 case MCSA_Hidden:
239 Symbol->setVisibility(ELF::STV_HIDDEN);
240 break;
241
242 case MCSA_Internal:
243 Symbol->setVisibility(ELF::STV_INTERNAL);
244 break;
245
246 case MCSA_AltEntry:
247 llvm_unreachable("ELF doesn't support the .alt_entry attribute");
248
249 case MCSA_LGlobal:
250 llvm_unreachable("ELF doesn't support the .lglobl attribute");
251 }
252
253 return true;
254}
255
257 Align ByteAlignment) {
258 auto *Symbol = static_cast<MCSymbolELF *>(S);
259 getAssembler().registerSymbol(*Symbol);
260
261 if (!Symbol->isBindingSet())
262 Symbol->setBinding(ELF::STB_GLOBAL);
263
264 Symbol->setType(ELF::STT_OBJECT);
265
266 if (Symbol->getBinding() == ELF::STB_LOCAL) {
270 switchSection(&Section);
271
272 emitValueToAlignment(ByteAlignment, 0, 1, 0);
273 emitLabel(Symbol);
275
276 switchSection(P.first, P.second);
277 } else {
278 if (Symbol->declareCommon(Size, ByteAlignment))
279 report_fatal_error(Twine("Symbol: ") + Symbol->getName() +
280 " redeclared as different type");
281 }
282
283 Symbol->setSize(MCConstantExpr::create(Size, getContext()));
284}
285
287 static_cast<MCSymbolELF *>(Symbol)->setSize(Value);
288}
289
291 StringRef Name,
292 bool KeepOriginalSym) {
294 getStartTokLoc(), OriginalSym, Name, KeepOriginalSym});
295}
296
298 Align ByteAlignment) {
299 auto *Symbol = static_cast<MCSymbolELF *>(S);
300 // FIXME: Should this be caught and done earlier?
301 getAssembler().registerSymbol(*Symbol);
302 Symbol->setBinding(ELF::STB_LOCAL);
303 emitCommonSymbol(Symbol, Size, ByteAlignment);
304}
305
307 const MCSymbolRefExpr *To,
308 uint64_t Count) {
309 getWriter().getCGProfile().push_back({From, To, Count});
310}
311
315 pushSection();
316 switchSection(Comment);
317 if (!SeenIdent) {
318 emitInt8(0);
319 SeenIdent = true;
320 }
321 emitBytes(IdentString);
322 emitInt8(0);
323 popSection();
324}
325
327 MCAssembler &Asm = getAssembler();
329
330 if (!Asm.getBackend().allowBundling())
331 return getContext().reportError(
332 Loc, "aligned bundling is not supported by this target");
333 if (Asm.isBundlingEnabled()) {
334 if (Asm.getBundleAlign() != Alignment)
336 ".bundle_align_mode cannot be changed once set");
337 return;
338 }
339 // Enable bundling even after the error, to avoid cascading diagnostics from
340 // later .bundle_lock directives.
341 if (Asm.getBackend().allowAutoPadding())
343 Loc, ".bundle_align_mode is incompatible with branch alignment");
344
346 Asm.setBundleAlign(Alignment);
347}
348
349void MCELFStreamer::emitBundleLock(bool AlignToEnd,
350 const MCSubtargetInfo &STI) {
351 MCAssembler &Asm = getAssembler();
353
354 if (!Asm.isBundlingEnabled())
355 return getContext().reportError(
356 Loc, ".bundle_lock forbidden when bundling is disabled");
357 if (isBundleLocked())
358 return getContext().reportError(Loc, "nested .bundle_lock is not allowed");
359 // Padding a group is only meaningful where nops are instructions.
360 if (!getCurrentSectionOnly()->isText())
361 return getContext().reportError(
362 Loc, ".bundle_lock is only allowed in an executable section");
363
364 BundleLocked = true;
365 BundleBA =
366 newSpecialFragment<MCBoundaryAlignFragment>(Asm.getBundleAlign(), STI);
367 BundleBA->setAlignToEnd(AlignToEnd);
368}
369
371 MCAssembler &Asm = getAssembler();
373
374 if (!Asm.isBundlingEnabled())
375 return getContext().reportError(
376 Loc, ".bundle_unlock forbidden when bundling is disabled");
377 if (!isBundleLocked())
378 return getContext().reportError(Loc,
379 ".bundle_unlock without matching lock");
380
381 BundleLocked = false;
383 BundleBA->setLastFragment(CF);
384
385 uint64_t GroupSize = 0;
386 for (const MCFragment *F = BundleBA->getNext();; F = F->getNext()) {
387 if (F->getKind() == MCFragment::FT_Align ||
388 F->getKind() == MCFragment::FT_Org) {
389 getContext().reportError(Loc, "alignment and .org directives are not "
390 "supported inside a .bundle_lock group");
391 break;
392 }
393 GroupSize += Asm.computeFragmentSize(*F);
394 if (F == BundleBA->getLastFragment())
395 break;
396 }
397 BundleBA = nullptr;
398
399 if (GroupSize > Asm.getBundleAlign().value())
401 Loc, ".bundle_lock group is larger than the bundle size");
402
403 newFragment();
404
405 CF->getParent()->ensureMinAlignment(Asm.getBundleAlign());
406}
407
408void MCELFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *Sym,
410 const MCSymbolRefExpr *&SRE) {
411 const MCSymbol *S = &SRE->getSymbol();
412 if (S->isTemporary()) {
413 if (!S->isInSection()) {
415 SRE->getLoc(), Twine("Reference to undefined temporary symbol ") +
416 "`" + S->getName() + "`");
417 return;
418 }
419 S = S->getSection().getBeginSymbol();
420 S->setUsedInReloc();
421 SRE = MCSymbolRefExpr::create(S, getContext(), SRE->getLoc());
422 }
425 MCObjectStreamer::emitRelocDirective(*O, "BFD_RELOC_NONE", SRE);
426}
427
428void MCELFStreamer::finalizeCGProfile() {
429 ELFObjectWriter &W = getWriter();
430 if (W.getCGProfile().empty())
431 return;
432 MCSection *CGProfile = getAssembler().getContext().getELFSection(
433 ".llvm.call-graph-profile", ELF::SHT_LLVM_CALL_GRAPH_PROFILE,
434 ELF::SHF_EXCLUDE, /*sizeof(Elf_CGProfile_Impl<>)=*/8);
435 pushSection();
436 switchSection(CGProfile);
437 uint64_t Offset = 0;
438 auto *Sym =
440 for (auto &E : W.getCGProfile()) {
441 finalizeCGProfileEntry(Sym, Offset, E.From);
442 finalizeCGProfileEntry(Sym, Offset, E.To);
443 emitIntValue(E.Count, sizeof(uint64_t));
444 Offset += sizeof(uint64_t);
445 }
446 popSection();
447}
448
450 if (isBundleLocked())
451 getContext().reportError(getStartTokLoc(), "unterminated .bundle_lock");
452
453 // Emit .note.GNU-stack, similar to AsmPrinter::doFinalization.
454 MCContext &Ctx = getContext();
455 auto *StackSec = Ctx.getAsmInfo().getStackSection(Ctx,
456 /*Exec=*/false);
457 if (StackSec && Ctx.getTargetOptions().MCNoExecStack)
458 switchSection(StackSec);
459
460 // Emit the .gnu attributes section if any attributes have been added.
461 if (!GNUAttributes.empty()) {
462 MCSection *DummyAttributeSection = nullptr;
463 createAttributesSection("gnu", ".gnu.attributes", ELF::SHT_GNU_ATTRIBUTES,
464 DummyAttributeSection, GNUAttributes);
465 }
466
467 if (Ctx.getTargetTriple().isLFI())
468 emitLFINoteSection(*this, Ctx);
469
470 finalizeCGProfile();
471 emitFrames();
472
474}
475
477 bool OverwriteExisting) {
478 // Look for existing attribute item
479 if (AttributeItem *Item = getAttributeItem(Attribute)) {
480 if (!OverwriteExisting)
481 return;
483 Item->IntValue = Value;
484 return;
485 }
486
487 // Create new attribute item
489 std::string(StringRef(""))};
490 Contents.push_back(Item);
491}
492
494 bool OverwriteExisting) {
495 // Look for existing attribute item
496 if (AttributeItem *Item = getAttributeItem(Attribute)) {
497 if (!OverwriteExisting)
498 return;
499 Item->Type = AttributeItem::TextAttribute;
500 Item->StringValue = std::string(Value);
501 return;
502 }
503
504 // Create new attribute item
506 std::string(Value)};
507 Contents.push_back(Item);
508}
509
510void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue,
511 StringRef StringValue,
512 bool OverwriteExisting) {
513 // Look for existing attribute item
514 if (AttributeItem *Item = getAttributeItem(Attribute)) {
515 if (!OverwriteExisting)
516 return;
518 Item->IntValue = IntValue;
519 Item->StringValue = std::string(StringValue);
520 return;
521 }
522
523 // Create new attribute item
525 IntValue, std::string(StringValue)};
526 Contents.push_back(Item);
527}
528
530MCELFStreamer::getAttributeItem(unsigned Attribute) {
531 for (AttributeItem &Item : Contents)
532 if (Item.Tag == Attribute)
533 return &Item;
534 return nullptr;
535}
536
537size_t MCELFStreamer::calculateContentSize(
538 SmallVector<AttributeItem, 64> &AttrsVec) const {
539 size_t Result = 0;
540 for (const AttributeItem &Item : AttrsVec) {
541 switch (Item.Type) {
543 break;
545 Result += getULEB128Size(Item.Tag);
546 Result += getULEB128Size(Item.IntValue);
547 break;
549 Result += getULEB128Size(Item.Tag);
550 Result += Item.StringValue.size() + 1; // string + '\0'
551 break;
553 Result += getULEB128Size(Item.Tag);
554 Result += getULEB128Size(Item.IntValue);
555 Result += Item.StringValue.size() + 1; // string + '\0';
556 break;
557 }
558 }
559 return Result;
560}
561
562void MCELFStreamer::createAttributesSection(
563 StringRef Vendor, const Twine &Section, unsigned Type,
564 MCSection *&AttributeSection, SmallVector<AttributeItem, 64> &AttrsVec) {
565 // <format-version>
566 // [ <section-length> "vendor-name"
567 // [ <file-tag> <size> <attribute>*
568 // | <section-tag> <size> <section-number>* 0 <attribute>*
569 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
570 // ]+
571 // ]*
572
573 // Switch section to AttributeSection or get/create the section.
574 if (AttributeSection) {
575 switchSection(AttributeSection);
576 } else {
577 AttributeSection = getContext().getELFSection(Section, Type, 0);
578 switchSection(AttributeSection);
579
580 // Format version
581 emitInt8(0x41);
582 }
583
584 // Vendor size + Vendor name + '\0'
585 const size_t VendorHeaderSize = 4 + Vendor.size() + 1;
586
587 // Tag + Tag Size
588 const size_t TagHeaderSize = 1 + 4;
589
590 const size_t ContentsSize = calculateContentSize(AttrsVec);
591
592 emitInt32(VendorHeaderSize + TagHeaderSize + ContentsSize);
593 emitBytes(Vendor);
594 emitInt8(0); // '\0'
595
597 emitInt32(TagHeaderSize + ContentsSize);
598
599 // Size should have been accounted for already, now
600 // emit each field as its type (ULEB or String)
601 for (const AttributeItem &Item : AttrsVec) {
602 emitULEB128IntValue(Item.Tag);
603 switch (Item.Type) {
604 default:
605 llvm_unreachable("Invalid attribute type");
607 emitULEB128IntValue(Item.IntValue);
608 break;
610 emitBytes(Item.StringValue);
611 emitInt8(0); // '\0'
612 break;
614 emitULEB128IntValue(Item.IntValue);
615 emitBytes(Item.StringValue);
616 emitInt8(0); // '\0'
617 break;
618 }
619 }
620
621 AttrsVec.clear();
622}
623
624void MCELFStreamer::createAttributesWithSubsection(
625 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
627 // <format-version: 'A'>
628 // [ <uint32: subsection-length> NTBS: vendor-name
629 // <bytes: vendor-data>
630 // ]*
631 // vendor-data expends to:
632 // <uint8: optional> <uint8: parameter type> <attribute>*
633 if (0 == SubSectionVec.size()) {
634 return;
635 }
636
637 // Switch section to AttributeSection or get/create the section.
638 if (AttributeSection) {
639 switchSection(AttributeSection);
640 } else {
641 AttributeSection = getContext().getELFSection(Section, Type, 0);
642 switchSection(AttributeSection);
643
644 // Format version
645 emitInt8(0x41);
646 }
647
648 for (AttributeSubSection &SubSection : SubSectionVec) {
649 // subsection-length + vendor-name + '\0'
650 const size_t VendorHeaderSize = 4 + SubSection.VendorName.size() + 1;
651 // optional + parameter-type
652 const size_t VendorParameters = 1 + 1;
653 const size_t ContentsSize = calculateContentSize(SubSection.Content);
654
655 emitInt32(VendorHeaderSize + VendorParameters + ContentsSize);
656 emitBytes(SubSection.VendorName);
657 emitInt8(0); // '\0'
658 emitInt8(SubSection.IsOptional);
659 emitInt8(SubSection.ParameterType);
660
661 for (AttributeItem &Item : SubSection.Content) {
662 emitULEB128IntValue(Item.Tag);
663 switch (Item.Type) {
664 default:
665 assert(0 && "Invalid attribute type");
666 break;
668 emitULEB128IntValue(Item.IntValue);
669 break;
671 emitBytes(Item.StringValue);
672 emitInt8(0); // '\0'
673 break;
675 emitULEB128IntValue(Item.IntValue);
676 emitBytes(Item.StringValue);
677 emitInt8(0); // '\0'
678 break;
679 }
680 }
681 }
682 SubSectionVec.clear();
683}
684
686 std::unique_ptr<MCAsmBackend> &&MAB,
687 std::unique_ptr<MCObjectWriter> &&OW,
688 std::unique_ptr<MCCodeEmitter> &&CE) {
689 MCELFStreamer *S =
690 new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
691 return S;
692}
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:342
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 emitBundleUnlock(const MCSubtargetInfo &STI) override
Ends a bundle-locked group.
void setAttributeItem(unsigned Attribute, unsigned Value, bool OverwriteExisting)
void finishImpl() final
Streamer specific finalization.
void emitBundleLock(bool AlignToEnd, const MCSubtargetInfo &STI) override
The following instructions are a bundle-locked group.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void emitBundleAlignMode(Align Alignment) override
Enable aligned instruction bundling with the given bundle size, from this point onward.
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
MCSection * getParent() const
Definition MCSection.h:181
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 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.
void emitCodeAlignment(Align ByteAlignment, const MCSubtargetInfo &STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
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.
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:580
void ensureMinAlignment(Align MinAlignment)
Makes sure that Alignment is at least MinAlignment.
Definition MCSection.h:668
MCSymbol * getBeginSymbol()
Definition MCSection.h:653
Streaming machine code generation interface.
Definition MCStreamer.h:222
virtual bool popSection()
Restore the current and previous section from the section stack.
MCFragment * getCurrentFragment() const
Definition MCStreamer.h:449
MCContext & getContext() const
Definition MCStreamer.h:326
SMLoc getStartTokLoc() const
Definition MCStreamer.h:314
void setAllowAutoPadding(bool v)
Definition MCStreamer.h:340
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:460
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:769
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition MCStreamer.h:433
MCSection * getCurrentSectionOnly() const
Definition MCStreamer.h:438
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
void emitInt8(uint64_t Value)
Definition MCStreamer.h:767
Generic base class for all target subtargets.
LLVM_ABI 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:226
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:213
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
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:1264
@ SHF_STRINGS
Definition ELF.h:1267
@ SHF_EXCLUDE
Definition ELF.h:1292
@ SHF_ALLOC
Definition ELF.h:1258
@ SHF_GNU_RETAIN
Definition ELF.h:1289
@ SHF_WRITE
Definition ELF.h:1255
@ SHF_TLS
Definition ELF.h:1283
@ SHT_PROGBITS
Definition ELF.h:1156
@ SHT_LLVM_CALL_GRAPH_PROFILE
Definition ELF.h:1193
@ SHT_NOBITS
Definition ELF.h:1163
@ SHT_GNU_ATTRIBUTES
Definition ELF.h:1205
@ STB_GLOBAL
Definition ELF.h:1415
@ STB_LOCAL
Definition ELF.h:1414
@ STB_GNU_UNIQUE
Definition ELF.h:1417
@ STB_WEAK
Definition ELF.h:1416
@ STT_FUNC
Definition ELF.h:1428
@ STT_NOTYPE
Definition ELF.h:1426
@ STT_SECTION
Definition ELF.h:1429
@ STT_GNU_IFUNC
Definition ELF.h:1433
@ STT_OBJECT
Definition ELF.h:1427
@ STT_TLS
Definition ELF.h:1432
@ STV_INTERNAL
Definition ELF.h:1445
@ STV_HIDDEN
Definition ELF.h:1446
@ STV_PROTECTED
Definition ELF.h:1447
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
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
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition LEB128.cpp:19
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
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:878
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.