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 if (Ctx.getAsmInfo().emitELFStackSection() &&
458 Ctx.getTargetOptions().MCNoExecStack)
459 switchSection(Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS, 0U));
460
461 // Emit the .gnu attributes section if any attributes have been added.
462 if (!GNUAttributes.empty()) {
463 MCSection *DummyAttributeSection = nullptr;
464 createAttributesSection("gnu", ".gnu.attributes", ELF::SHT_GNU_ATTRIBUTES,
465 DummyAttributeSection, GNUAttributes);
466 }
467
468 if (Ctx.getTargetTriple().isLFI())
469 emitLFINoteSection(*this, Ctx);
470
471 finalizeCGProfile();
472 emitFrames();
473
475}
476
478 bool OverwriteExisting) {
479 // Look for existing attribute item
480 if (AttributeItem *Item = getAttributeItem(Attribute)) {
481 if (!OverwriteExisting)
482 return;
484 Item->IntValue = Value;
485 return;
486 }
487
488 // Create new attribute item
490 std::string(StringRef(""))};
491 Contents.push_back(Item);
492}
493
495 bool OverwriteExisting) {
496 // Look for existing attribute item
497 if (AttributeItem *Item = getAttributeItem(Attribute)) {
498 if (!OverwriteExisting)
499 return;
500 Item->Type = AttributeItem::TextAttribute;
501 Item->StringValue = std::string(Value);
502 return;
503 }
504
505 // Create new attribute item
507 std::string(Value)};
508 Contents.push_back(Item);
509}
510
511void MCELFStreamer::setAttributeItems(unsigned Attribute, uint64_t IntValue,
512 StringRef StringValue,
513 bool OverwriteExisting) {
514 // Look for existing attribute item
515 if (AttributeItem *Item = getAttributeItem(Attribute)) {
516 if (!OverwriteExisting)
517 return;
519 Item->IntValue = IntValue;
520 Item->StringValue = std::string(StringValue);
521 return;
522 }
523
524 // Create new attribute item
526 IntValue, std::string(StringValue)};
527 Contents.push_back(Item);
528}
529
531MCELFStreamer::getAttributeItem(unsigned Attribute) {
532 for (AttributeItem &Item : Contents)
533 if (Item.Tag == Attribute)
534 return &Item;
535 return nullptr;
536}
537
538size_t MCELFStreamer::calculateContentSize(
539 SmallVector<AttributeItem, 64> &AttrsVec) const {
540 size_t Result = 0;
541 for (const AttributeItem &Item : AttrsVec) {
542 switch (Item.Type) {
544 break;
546 Result += getULEB128Size(Item.Tag);
547 Result += getULEB128Size(Item.IntValue);
548 break;
550 Result += getULEB128Size(Item.Tag);
551 Result += Item.StringValue.size() + 1; // string + '\0'
552 break;
554 Result += getULEB128Size(Item.Tag);
555 Result += getULEB128Size(Item.IntValue);
556 Result += Item.StringValue.size() + 1; // string + '\0';
557 break;
558 }
559 }
560 return Result;
561}
562
563void MCELFStreamer::createAttributesSection(
564 StringRef Vendor, const Twine &Section, unsigned Type,
565 MCSection *&AttributeSection, SmallVector<AttributeItem, 64> &AttrsVec) {
566 // <format-version>
567 // [ <section-length> "vendor-name"
568 // [ <file-tag> <size> <attribute>*
569 // | <section-tag> <size> <section-number>* 0 <attribute>*
570 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
571 // ]+
572 // ]*
573
574 // Switch section to AttributeSection or get/create the section.
575 if (AttributeSection) {
576 switchSection(AttributeSection);
577 } else {
578 AttributeSection = getContext().getELFSection(Section, Type, 0);
579 switchSection(AttributeSection);
580
581 // Format version
582 emitInt8(0x41);
583 }
584
585 // Vendor size + Vendor name + '\0'
586 const size_t VendorHeaderSize = 4 + Vendor.size() + 1;
587
588 // Tag + Tag Size
589 const size_t TagHeaderSize = 1 + 4;
590
591 const size_t ContentsSize = calculateContentSize(AttrsVec);
592
593 emitInt32(VendorHeaderSize + TagHeaderSize + ContentsSize);
594 emitBytes(Vendor);
595 emitInt8(0); // '\0'
596
598 emitInt32(TagHeaderSize + ContentsSize);
599
600 // Size should have been accounted for already, now
601 // emit each field as its type (ULEB or String)
602 for (const AttributeItem &Item : AttrsVec) {
603 emitULEB128IntValue(Item.Tag);
604 switch (Item.Type) {
605 default:
606 llvm_unreachable("Invalid attribute type");
608 emitULEB128IntValue(Item.IntValue);
609 break;
611 emitBytes(Item.StringValue);
612 emitInt8(0); // '\0'
613 break;
615 emitULEB128IntValue(Item.IntValue);
616 emitBytes(Item.StringValue);
617 emitInt8(0); // '\0'
618 break;
619 }
620 }
621
622 AttrsVec.clear();
623}
624
625void MCELFStreamer::createAttributesWithSubsection(
626 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
628 // <format-version: 'A'>
629 // [ <uint32: subsection-length> NTBS: vendor-name
630 // <bytes: vendor-data>
631 // ]*
632 // vendor-data expends to:
633 // <uint8: optional> <uint8: parameter type> <attribute>*
634 if (0 == SubSectionVec.size()) {
635 return;
636 }
637
638 // Switch section to AttributeSection or get/create the section.
639 if (AttributeSection) {
640 switchSection(AttributeSection);
641 } else {
642 AttributeSection = getContext().getELFSection(Section, Type, 0);
643 switchSection(AttributeSection);
644
645 // Format version
646 emitInt8(0x41);
647 }
648
649 for (AttributeSubSection &SubSection : SubSectionVec) {
650 // subsection-length + vendor-name + '\0'
651 const size_t VendorHeaderSize = 4 + SubSection.VendorName.size() + 1;
652 // optional + parameter-type
653 const size_t VendorParameters = 1 + 1;
654 const size_t ContentsSize = calculateContentSize(SubSection.Content);
655
656 emitInt32(VendorHeaderSize + VendorParameters + ContentsSize);
657 emitBytes(SubSection.VendorName);
658 emitInt8(0); // '\0'
659 emitInt8(SubSection.IsOptional);
660 emitInt8(SubSection.ParameterType);
661
662 for (AttributeItem &Item : SubSection.Content) {
663 emitULEB128IntValue(Item.Tag);
664 switch (Item.Type) {
665 default:
666 assert(0 && "Invalid attribute type");
667 break;
669 emitULEB128IntValue(Item.IntValue);
670 break;
672 emitBytes(Item.StringValue);
673 emitInt8(0); // '\0'
674 break;
676 emitULEB128IntValue(Item.IntValue);
677 emitBytes(Item.StringValue);
678 emitInt8(0); // '\0'
679 break;
680 }
681 }
682 }
683 SubSectionVec.clear();
684}
685
687 std::unique_ptr<MCAsmBackend> &&MAB,
688 std::unique_ptr<MCObjectWriter> &&OW,
689 std::unique_ptr<MCCodeEmitter> &&CE) {
690 MCELFStreamer *S =
691 new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
692 return S;
693}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
dxil container 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:106
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:339
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:84
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 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 setAttributeItems(unsigned Attribute, uint64_t IntValue, StringRef StringValue, bool OverwriteExisting)
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 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.
void setAttributeItem(unsigned Attribute, uint64_t Value, bool OverwriteExisting)
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:31
SMLoc getLoc() const
Definition MCExpr.h:83
MCSection * getParent() const
Definition MCSection.h:178
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:577
void ensureMinAlignment(Align MinAlignment)
Makes sure that Alignment is at least MinAlignment.
Definition MCSection.h:665
MCSymbol * getBeginSymbol()
Definition MCSection.h:650
Streaming machine code generation interface.
Definition MCStreamer.h:221
virtual bool popSection()
Restore the current and previous section from the section stack.
MCFragment * getCurrentFragment() const
Definition MCStreamer.h:448
MCContext & getContext() const
Definition MCStreamer.h:325
SMLoc getStartTokLoc() const
Definition MCStreamer.h:313
void setAllowAutoPadding(bool v)
Definition MCStreamer.h:339
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:459
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:768
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition MCStreamer.h:432
MCSection * getCurrentSectionOnly() const
Definition MCStreamer.h:437
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
void emitInt8(uint64_t Value)
Definition MCStreamer.h:766
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:187
const MCSymbol & getSymbol() const
Definition MCExpr.h:223
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:210
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.
@ STT_FUNC
Definition ELF.h:1274
@ STT_NOTYPE
Definition ELF.h:1272
@ STT_SECTION
Definition ELF.h:1275
@ STT_GNU_IFUNC
Definition ELF.h:1279
@ STT_OBJECT
Definition ELF.h:1273
@ STT_TLS
Definition ELF.h:1278
@ STV_INTERNAL
Definition ELF.h:1294
@ STV_HIDDEN
Definition ELF.h:1295
@ STV_PROTECTED
Definition ELF.h:1296
@ SHF_MERGE
Definition ELF.h:1104
@ SHF_STRINGS
Definition ELF.h:1107
@ SHF_EXCLUDE
Definition ELF.h:1132
@ SHF_ALLOC
Definition ELF.h:1098
@ SHF_GNU_RETAIN
Definition ELF.h:1129
@ SHF_WRITE
Definition ELF.h:1095
@ SHF_TLS
Definition ELF.h:1123
@ SHT_PROGBITS
Definition ELF.h:996
@ SHT_LLVM_CALL_GRAPH_PROFILE
Definition ELF.h:1033
@ SHT_NOBITS
Definition ELF.h:1003
@ SHT_GNU_ATTRIBUTES
Definition ELF.h:1045
@ STB_GLOBAL
Definition ELF.h:1261
@ STB_LOCAL
Definition ELF.h:1260
@ STB_GNU_UNIQUE
Definition ELF.h:1263
@ STB_WEAK
Definition ELF.h:1262
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
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:58
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:1933
std::pair< MCSection *, uint32_t > MCSectionSubPair
Definition MCStreamer.h:67
LLVM_ABI void emitLFIBundleAlign(MCStreamer &Streamer, MCContext &Ctx)
Definition MCLFI.cpp:51
@ 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:879
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.