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 if (Ctx.getTargetTriple().isLFI())
59 emitLFIBundleAlign(*this, Ctx);
60}
61
63 auto *Symbol = static_cast<MCSymbolELF *>(S);
65
66 const MCSectionELF &Section =
67 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
68 if (Section.getFlags() & ELF::SHF_TLS)
69 Symbol->setType(ELF::STT_TLS);
70}
71
73 uint64_t Offset) {
74 auto *Symbol = static_cast<MCSymbolELF *>(S);
76
77 const MCSectionELF &Section =
78 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
79 if (Section.getFlags() & ELF::SHF_TLS)
80 Symbol->setType(ELF::STT_TLS);
81}
82
85 if (isBundleLocked()) {
87 getStartTokLoc(), "unterminated .bundle_lock when changing a section");
88 // Clean up bundle state to allow continuing.
89 BundleLocked = false;
90 BundleBA = nullptr;
91 }
92 auto *SectionELF = static_cast<const MCSectionELF *>(Section);
93 const MCSymbol *Grp = SectionELF->getGroup();
94 if (Grp)
95 Asm.registerSymbol(*Grp);
96 if (SectionELF->getFlags() & ELF::SHF_GNU_RETAIN)
98
99 MCObjectStreamer::changeSection(Section, Subsection);
100 auto *Sym = static_cast<MCSymbolELF *>(Section->getBeginSymbol());
102 Sym->setType(ELF::STT_SECTION);
103}
104
106 auto *A = static_cast<MCSymbolELF *>(Alias);
107 if (A->isDefined()) {
108 getContext().reportError(getStartTokLoc(), "symbol '" + A->getName() +
109 "' is already defined");
110 return;
111 }
112 A->setVariableValue(MCSymbolRefExpr::create(Target, getContext()));
113 A->setIsWeakref();
114 getWriter().Weakrefs.push_back(A);
115}
116
117// When GNU as encounters more than one .type declaration for an object it seems
118// to use a mechanism similar to the one below to decide which type is actually
119// used in the object file. The greater of T1 and T2 is selected based on the
120// following ordering:
121// STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
122// If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
123// provided type).
124static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
127 if (T1 == Type)
128 return T2;
129 if (T2 == Type)
130 return T1;
131 }
132
133 return T2;
134}
135
137 auto *Symbol = static_cast<MCSymbolELF *>(S);
138
139 // Adding a symbol attribute always introduces the symbol, note that an
140 // important side effect of calling registerSymbol here is to register
141 // the symbol with the assembler.
142 getAssembler().registerSymbol(*Symbol);
143
144 // The implementation of symbol attributes is designed to match 'as', but it
145 // leaves much to desired. It doesn't really make sense to arbitrarily add and
146 // remove flags, but 'as' allows this (in particular, see .desc).
147 //
148 // In the future it might be worth trying to make these operations more well
149 // defined.
150 switch (Attribute) {
151 case MCSA_Cold:
152 case MCSA_Extern:
154 case MCSA_Reference:
159 case MCSA_Invalid:
161 case MCSA_Exported:
162 case MCSA_WeakAntiDep:
163 case MCSA_OSLinkage:
164 case MCSA_XPLinkage:
165 return false;
166
167 case MCSA_NoDeadStrip:
168 // Ignore for now.
169 break;
170
172 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
173 Symbol->setBinding(ELF::STB_GNU_UNIQUE);
175 break;
176
177 case MCSA_Global:
178 // For `.weak x; .global x`, GNU as sets the binding to STB_WEAK while we
179 // traditionally set the binding to STB_GLOBAL. This is error-prone, so we
180 // error on such cases. Note, we also disallow changed binding from .local.
181 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_GLOBAL)
183 Symbol->getName() +
184 " changed binding to STB_GLOBAL");
185 Symbol->setBinding(ELF::STB_GLOBAL);
186 break;
187
189 case MCSA_Weak:
190 // For `.global x; .weak x`, both MC and GNU as set the binding to STB_WEAK.
191 // We emit a warning for now but may switch to an error in the future.
192 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_WEAK)
194 getStartTokLoc(), Symbol->getName() + " changed binding to STB_WEAK");
195 Symbol->setBinding(ELF::STB_WEAK);
196 break;
197
198 case MCSA_Local:
199 if (Symbol->isBindingSet() && Symbol->getBinding() != ELF::STB_LOCAL)
201 Symbol->getName() +
202 " changed binding to STB_LOCAL");
203 Symbol->setBinding(ELF::STB_LOCAL);
204 break;
205
207 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
208 break;
209
211 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
213 break;
214
216 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
217 break;
218
219 case MCSA_ELF_TypeTLS:
220 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
221 break;
222
224 // TODO: Emit these as a common symbol.
225 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
226 break;
227
229 Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
230 break;
231
232 case MCSA_Protected:
233 Symbol->setVisibility(ELF::STV_PROTECTED);
234 break;
235
236 case MCSA_Memtag:
237 Symbol->setMemtag(true);
238 break;
239
240 case MCSA_Hidden:
241 Symbol->setVisibility(ELF::STV_HIDDEN);
242 break;
243
244 case MCSA_Internal:
245 Symbol->setVisibility(ELF::STV_INTERNAL);
246 break;
247
248 case MCSA_AltEntry:
249 llvm_unreachable("ELF doesn't support the .alt_entry attribute");
250
251 case MCSA_LGlobal:
252 llvm_unreachable("ELF doesn't support the .lglobl attribute");
253 }
254
255 return true;
256}
257
259 Align ByteAlignment) {
260 auto *Symbol = static_cast<MCSymbolELF *>(S);
261 getAssembler().registerSymbol(*Symbol);
262
263 if (!Symbol->isBindingSet())
264 Symbol->setBinding(ELF::STB_GLOBAL);
265
266 Symbol->setType(ELF::STT_OBJECT);
267
268 if (Symbol->getBinding() == ELF::STB_LOCAL) {
272 switchSection(&Section);
273
274 emitValueToAlignment(ByteAlignment, 0, 1, 0);
275 emitLabel(Symbol);
277
278 switchSection(P.first, P.second);
279 } else {
280 if (Symbol->declareCommon(Size, ByteAlignment))
281 report_fatal_error(Twine("Symbol: ") + Symbol->getName() +
282 " redeclared as different type");
283 }
284
285 Symbol->setSize(MCConstantExpr::create(Size, getContext()));
286}
287
289 static_cast<MCSymbolELF *>(Symbol)->setSize(Value);
290}
291
293 StringRef Name,
294 bool KeepOriginalSym) {
296 getStartTokLoc(), OriginalSym, Name, KeepOriginalSym});
297}
298
300 Align ByteAlignment) {
301 auto *Symbol = static_cast<MCSymbolELF *>(S);
302 // FIXME: Should this be caught and done earlier?
303 getAssembler().registerSymbol(*Symbol);
304 Symbol->setBinding(ELF::STB_LOCAL);
305 emitCommonSymbol(Symbol, Size, ByteAlignment);
306}
307
309 const MCSymbolRefExpr *To,
310 uint64_t Count) {
311 getWriter().getCGProfile().push_back({From, To, Count});
312}
313
317 pushSection();
318 switchSection(Comment);
319 if (!SeenIdent) {
320 emitInt8(0);
321 SeenIdent = true;
322 }
323 emitBytes(IdentString);
324 emitInt8(0);
325 popSection();
326}
327
329 MCAssembler &Asm = getAssembler();
331
332 if (!Asm.getBackend().allowBundling())
333 return getContext().reportError(
334 Loc, "aligned bundling is not supported by this target");
335 if (Asm.isBundlingEnabled()) {
336 if (Asm.getBundleAlign() != Alignment)
338 ".bundle_align_mode cannot be changed once set");
339 return;
340 }
341 // Enable bundling even after the error, to avoid cascading diagnostics from
342 // later .bundle_lock directives.
343 if (Asm.getBackend().allowAutoPadding())
345 Loc, ".bundle_align_mode is incompatible with branch alignment");
346
348 Asm.setBundleAlign(Alignment);
349}
350
351void MCELFStreamer::emitBundleLock(bool AlignToEnd,
352 const MCSubtargetInfo &STI) {
353 MCAssembler &Asm = getAssembler();
355
356 if (!Asm.isBundlingEnabled())
357 return getContext().reportError(
358 Loc, ".bundle_lock forbidden when bundling is disabled");
359 if (isBundleLocked())
360 return getContext().reportError(Loc, "nested .bundle_lock is not allowed");
361 // Padding a group is only meaningful where nops are instructions.
362 if (!getCurrentSectionOnly()->isText())
363 return getContext().reportError(
364 Loc, ".bundle_lock is only allowed in an executable section");
365
366 BundleLocked = true;
367 BundleBA =
368 newSpecialFragment<MCBoundaryAlignFragment>(Asm.getBundleAlign(), STI);
369 BundleBA->setAlignToEnd(AlignToEnd);
370}
371
373 MCAssembler &Asm = getAssembler();
375
376 if (!Asm.isBundlingEnabled())
377 return getContext().reportError(
378 Loc, ".bundle_unlock forbidden when bundling is disabled");
379 if (!isBundleLocked())
380 return getContext().reportError(Loc,
381 ".bundle_unlock without matching lock");
382
383 BundleLocked = false;
385 BundleBA->setLastFragment(CF);
386
387 uint64_t GroupSize = 0;
388 for (const MCFragment *F = BundleBA->getNext();; F = F->getNext()) {
389 if (F->getKind() == MCFragment::FT_Align ||
390 F->getKind() == MCFragment::FT_Org) {
391 getContext().reportError(Loc, "alignment and .org directives are not "
392 "supported inside a .bundle_lock group");
393 break;
394 }
395 GroupSize += Asm.computeFragmentSize(*F);
396 if (F == BundleBA->getLastFragment())
397 break;
398 }
399 BundleBA = nullptr;
400
401 if (GroupSize > Asm.getBundleAlign().value())
403 Loc, ".bundle_lock group is larger than the bundle size");
404
405 newFragment();
406
407 CF->getParent()->ensureMinAlignment(Asm.getBundleAlign());
408}
409
410void MCELFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *Sym,
411 uint64_t Offset,
412 const MCSymbolRefExpr *&SRE) {
413 const MCSymbol *S = &SRE->getSymbol();
414 if (S->isTemporary()) {
415 if (!S->isInSection()) {
417 SRE->getLoc(), Twine("Reference to undefined temporary symbol ") +
418 "`" + S->getName() + "`");
419 return;
420 }
421 S = S->getSection().getBeginSymbol();
422 S->setUsedInReloc();
423 SRE = MCSymbolRefExpr::create(S, getContext(), SRE->getLoc());
424 }
427 MCObjectStreamer::emitRelocDirective(*O, "BFD_RELOC_NONE", SRE);
428}
429
430void MCELFStreamer::finalizeCGProfile() {
431 ELFObjectWriter &W = getWriter();
432 if (W.getCGProfile().empty())
433 return;
434 MCSection *CGProfile = getAssembler().getContext().getELFSection(
435 ".llvm.call-graph-profile", ELF::SHT_LLVM_CALL_GRAPH_PROFILE,
436 ELF::SHF_EXCLUDE, /*sizeof(Elf_CGProfile_Impl<>)=*/8);
437 pushSection();
438 switchSection(CGProfile);
439 uint64_t Offset = 0;
440 auto *Sym =
442 for (auto &E : W.getCGProfile()) {
443 finalizeCGProfileEntry(Sym, Offset, E.From);
444 finalizeCGProfileEntry(Sym, Offset, E.To);
445 emitIntValue(E.Count, sizeof(uint64_t));
446 Offset += sizeof(uint64_t);
447 }
448 popSection();
449}
450
452 if (isBundleLocked())
453 getContext().reportError(getStartTokLoc(), "unterminated .bundle_lock");
454
455 // Emit .note.GNU-stack, similar to AsmPrinter::doFinalization.
456 MCContext &Ctx = getContext();
457 auto *StackSec = Ctx.getAsmInfo().getStackSection(Ctx,
458 /*Exec=*/false);
459 if (StackSec && Ctx.getTargetOptions().MCNoExecStack)
460 switchSection(StackSec);
461
462 // Emit the .gnu attributes section if any attributes have been added.
463 if (!GNUAttributes.empty()) {
464 MCSection *DummyAttributeSection = nullptr;
465 createAttributesSection("gnu", ".gnu.attributes", ELF::SHT_GNU_ATTRIBUTES,
466 DummyAttributeSection, GNUAttributes);
467 }
468
469 if (Ctx.getTargetTriple().isLFI())
470 emitLFINoteSection(*this, Ctx);
471
472 finalizeCGProfile();
473 emitFrames();
474
476}
477
479 bool OverwriteExisting) {
480 // Look for existing attribute item
481 if (AttributeItem *Item = getAttributeItem(Attribute)) {
482 if (!OverwriteExisting)
483 return;
485 Item->IntValue = Value;
486 return;
487 }
488
489 // Create new attribute item
491 std::string(StringRef(""))};
492 Contents.push_back(Item);
493}
494
496 bool OverwriteExisting) {
497 // Look for existing attribute item
498 if (AttributeItem *Item = getAttributeItem(Attribute)) {
499 if (!OverwriteExisting)
500 return;
501 Item->Type = AttributeItem::TextAttribute;
502 Item->StringValue = std::string(Value);
503 return;
504 }
505
506 // Create new attribute item
508 std::string(Value)};
509 Contents.push_back(Item);
510}
511
512void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue,
513 StringRef StringValue,
514 bool OverwriteExisting) {
515 // Look for existing attribute item
516 if (AttributeItem *Item = getAttributeItem(Attribute)) {
517 if (!OverwriteExisting)
518 return;
520 Item->IntValue = IntValue;
521 Item->StringValue = std::string(StringValue);
522 return;
523 }
524
525 // Create new attribute item
527 IntValue, std::string(StringValue)};
528 Contents.push_back(Item);
529}
530
532MCELFStreamer::getAttributeItem(unsigned Attribute) {
533 for (AttributeItem &Item : Contents)
534 if (Item.Tag == Attribute)
535 return &Item;
536 return nullptr;
537}
538
539size_t MCELFStreamer::calculateContentSize(
540 SmallVector<AttributeItem, 64> &AttrsVec) const {
541 size_t Result = 0;
542 for (const AttributeItem &Item : AttrsVec) {
543 switch (Item.Type) {
545 break;
547 Result += getULEB128Size(Item.Tag);
548 Result += getULEB128Size(Item.IntValue);
549 break;
551 Result += getULEB128Size(Item.Tag);
552 Result += Item.StringValue.size() + 1; // string + '\0'
553 break;
555 Result += getULEB128Size(Item.Tag);
556 Result += getULEB128Size(Item.IntValue);
557 Result += Item.StringValue.size() + 1; // string + '\0';
558 break;
559 }
560 }
561 return Result;
562}
563
564void MCELFStreamer::createAttributesSection(
565 StringRef Vendor, const Twine &Section, unsigned Type,
566 MCSection *&AttributeSection, SmallVector<AttributeItem, 64> &AttrsVec) {
567 // <format-version>
568 // [ <section-length> "vendor-name"
569 // [ <file-tag> <size> <attribute>*
570 // | <section-tag> <size> <section-number>* 0 <attribute>*
571 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
572 // ]+
573 // ]*
574
575 // Switch section to AttributeSection or get/create the section.
576 if (AttributeSection) {
577 switchSection(AttributeSection);
578 } else {
579 AttributeSection = getContext().getELFSection(Section, Type, 0);
580 switchSection(AttributeSection);
581
582 // Format version
583 emitInt8(0x41);
584 }
585
586 // Vendor size + Vendor name + '\0'
587 const size_t VendorHeaderSize = 4 + Vendor.size() + 1;
588
589 // Tag + Tag Size
590 const size_t TagHeaderSize = 1 + 4;
591
592 const size_t ContentsSize = calculateContentSize(AttrsVec);
593
594 emitInt32(VendorHeaderSize + TagHeaderSize + ContentsSize);
595 emitBytes(Vendor);
596 emitInt8(0); // '\0'
597
599 emitInt32(TagHeaderSize + ContentsSize);
600
601 // Size should have been accounted for already, now
602 // emit each field as its type (ULEB or String)
603 for (const AttributeItem &Item : AttrsVec) {
604 emitULEB128IntValue(Item.Tag);
605 switch (Item.Type) {
606 default:
607 llvm_unreachable("Invalid attribute type");
609 emitULEB128IntValue(Item.IntValue);
610 break;
612 emitBytes(Item.StringValue);
613 emitInt8(0); // '\0'
614 break;
616 emitULEB128IntValue(Item.IntValue);
617 emitBytes(Item.StringValue);
618 emitInt8(0); // '\0'
619 break;
620 }
621 }
622
623 AttrsVec.clear();
624}
625
626void MCELFStreamer::createAttributesWithSubsection(
627 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
629 // <format-version: 'A'>
630 // [ <uint32: subsection-length> NTBS: vendor-name
631 // <bytes: vendor-data>
632 // ]*
633 // vendor-data expends to:
634 // <uint8: optional> <uint8: parameter type> <attribute>*
635 if (0 == SubSectionVec.size()) {
636 return;
637 }
638
639 // Switch section to AttributeSection or get/create the section.
640 if (AttributeSection) {
641 switchSection(AttributeSection);
642 } else {
643 AttributeSection = getContext().getELFSection(Section, Type, 0);
644 switchSection(AttributeSection);
645
646 // Format version
647 emitInt8(0x41);
648 }
649
650 for (AttributeSubSection &SubSection : SubSectionVec) {
651 // subsection-length + vendor-name + '\0'
652 const size_t VendorHeaderSize = 4 + SubSection.VendorName.size() + 1;
653 // optional + parameter-type
654 const size_t VendorParameters = 1 + 1;
655 const size_t ContentsSize = calculateContentSize(SubSection.Content);
656
657 emitInt32(VendorHeaderSize + VendorParameters + ContentsSize);
658 emitBytes(SubSection.VendorName);
659 emitInt8(0); // '\0'
660 emitInt8(SubSection.IsOptional);
661 emitInt8(SubSection.ParameterType);
662
663 for (AttributeItem &Item : SubSection.Content) {
664 emitULEB128IntValue(Item.Tag);
665 switch (Item.Type) {
666 default:
667 assert(0 && "Invalid attribute type");
668 break;
670 emitULEB128IntValue(Item.IntValue);
671 break;
673 emitBytes(Item.StringValue);
674 emitInt8(0); // '\0'
675 break;
677 emitULEB128IntValue(Item.IntValue);
678 emitBytes(Item.StringValue);
679 emitInt8(0); // '\0'
680 break;
681 }
682 }
683 }
684 SubSectionVec.clear();
685}
686
688 std::unique_ptr<MCAsmBackend> &&MAB,
689 std::unique_ptr<MCObjectWriter> &&OW,
690 std::unique_ptr<MCCodeEmitter> &&CE) {
691 MCELFStreamer *S =
692 new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
693 return S;
694}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
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:63
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
LLVM_ABI void emitLFIBundleAlign(MCStreamer &Streamer, MCContext &Ctx)
Definition MCLFI.cpp:55
@ 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.