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
13#include "llvm/MC/MCELFStreamer.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/BinaryFormat/ELF.h"
16#include "llvm/MC/MCAsmBackend.h"
17#include "llvm/MC/MCAsmInfo.h"
18#include "llvm/MC/MCAssembler.h"
19#include "llvm/MC/MCCodeEmitter.h"
20#include "llvm/MC/MCContext.h"
21#include "llvm/MC/MCDirectives.h"
22#include "llvm/MC/MCELFObjectWriter.h"
23#include "llvm/MC/MCExpr.h"
24#include "llvm/MC/MCFixup.h"
25#include "llvm/MC/MCLFI.h"
26#include "llvm/MC/MCObjectFileInfo.h"
27#include "llvm/MC/MCObjectWriter.h"
28#include "llvm/MC/MCSection.h"
29#include "llvm/MC/MCSectionELF.h"
30#include "llvm/MC/MCStreamer.h"
31#include "llvm/MC/MCSymbol.h"
32#include "llvm/MC/MCSymbolELF.h"
33#include "llvm/MC/MCTargetOptions.h"
34#include "llvm/MC/TargetRegistry.h"
35#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/LEB128.h"
37#include <cassert>
38#include <cstdint>
39
40using namespace llvm;
41
42MCELFStreamer::MCELFStreamer(MCContext &Context,
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
49ELFObjectWriter &MCELFStreamer::getWriter() {
50 return static_cast<ELFObjectWriter &>(getAssembler().getWriter());
51}
52
53void MCELFStreamer::initSections(const MCSubtargetInfo &STI) {
54 MCContext &Ctx = getContext();
55 switchSection(Section: Ctx.getObjectFileInfo()->getTextSection());
56 emitCodeAlignment(ByteAlignment: Align(Ctx.getObjectFileInfo()->getTextSectionAlignment()),
57 STI);
58}
59
60void MCELFStreamer::emitLabel(MCSymbol *S, SMLoc Loc) {
61 auto *Symbol = static_cast<MCSymbolELF *>(S);
62 MCObjectStreamer::emitLabel(Symbol, Loc);
63
64 const MCSectionELF &Section =
65 static_cast<const MCSectionELF &>(*getCurrentSectionOnly());
66 if (Section.getFlags() & ELF::SHF_TLS)
67 Symbol->setType(ELF::STT_TLS);
68}
69
70void MCELFStreamer::emitLabelAtPos(MCSymbol *S, SMLoc Loc, MCFragment &F,
71 uint64_t Offset) {
72 auto *Symbol = static_cast<MCSymbolELF *>(S);
73 MCObjectStreamer::emitLabelAtPos(Symbol, Loc, F, Offset);
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
81void MCELFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
82 MCAssembler &Asm = getAssembler();
83 auto *SectionELF = static_cast<const MCSectionELF *>(Section);
84 const MCSymbol *Grp = SectionELF->getGroup();
85 if (Grp)
86 Asm.registerSymbol(Symbol: *Grp);
87 if (SectionELF->getFlags() & ELF::SHF_GNU_RETAIN)
88 getWriter().markGnuAbi();
89
90 MCObjectStreamer::changeSection(Section, Subsection);
91 auto *Sym = static_cast<MCSymbolELF *>(Section->getBeginSymbol());
92 Sym->setBinding(ELF::STB_LOCAL);
93 Sym->setType(ELF::STT_SECTION);
94}
95
96void MCELFStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Target) {
97 auto *A = static_cast<MCSymbolELF *>(Alias);
98 if (A->isDefined()) {
99 getContext().reportError(L: getStartTokLoc(), Msg: "symbol '" + A->getName() +
100 "' is already defined");
101 return;
102 }
103 A->setVariableValue(MCSymbolRefExpr::create(Symbol: Target, Ctx&: getContext()));
104 A->setIsWeakref();
105 getWriter().Weakrefs.push_back(Elt: 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) {
116 for (unsigned Type : {ELF::STT_NOTYPE, ELF::STT_OBJECT, ELF::STT_FUNC,
117 ELF::STT_GNU_IFUNC, ELF::STT_TLS}) {
118 if (T1 == Type)
119 return T2;
120 if (T2 == Type)
121 return T1;
122 }
123
124 return T2;
125}
126
127bool MCELFStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
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: *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:
144 case MCSA_LazyReference:
145 case MCSA_Reference:
146 case MCSA_SymbolResolver:
147 case MCSA_PrivateExtern:
148 case MCSA_WeakDefinition:
149 case MCSA_WeakDefAutoPrivate:
150 case MCSA_Invalid:
151 case MCSA_IndirectSymbol:
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
162 case MCSA_ELF_TypeGnuUniqueObject:
163 Symbol->setType(CombineSymbolTypes(T1: Symbol->getType(), T2: ELF::STT_OBJECT));
164 Symbol->setBinding(ELF::STB_GNU_UNIQUE);
165 getWriter().markGnuAbi();
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)
173 getContext().reportError(L: getStartTokLoc(),
174 Msg: Symbol->getName() +
175 " changed binding to STB_GLOBAL");
176 Symbol->setBinding(ELF::STB_GLOBAL);
177 break;
178
179 case MCSA_WeakReference:
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)
184 getContext().reportWarning(
185 L: getStartTokLoc(), Msg: 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)
191 getContext().reportError(L: getStartTokLoc(),
192 Msg: Symbol->getName() +
193 " changed binding to STB_LOCAL");
194 Symbol->setBinding(ELF::STB_LOCAL);
195 break;
196
197 case MCSA_ELF_TypeFunction:
198 Symbol->setType(CombineSymbolTypes(T1: Symbol->getType(), T2: ELF::STT_FUNC));
199 break;
200
201 case MCSA_ELF_TypeIndFunction:
202 Symbol->setType(CombineSymbolTypes(T1: Symbol->getType(), T2: ELF::STT_GNU_IFUNC));
203 getWriter().markGnuAbi();
204 break;
205
206 case MCSA_ELF_TypeObject:
207 Symbol->setType(CombineSymbolTypes(T1: Symbol->getType(), T2: ELF::STT_OBJECT));
208 break;
209
210 case MCSA_ELF_TypeTLS:
211 Symbol->setType(CombineSymbolTypes(T1: Symbol->getType(), T2: ELF::STT_TLS));
212 break;
213
214 case MCSA_ELF_TypeCommon:
215 // TODO: Emit these as a common symbol.
216 Symbol->setType(CombineSymbolTypes(T1: Symbol->getType(), T2: ELF::STT_OBJECT));
217 break;
218
219 case MCSA_ELF_TypeNoType:
220 Symbol->setType(CombineSymbolTypes(T1: Symbol->getType(), T2: 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
249void MCELFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
250 Align ByteAlignment) {
251 auto *Symbol = static_cast<MCSymbolELF *>(S);
252 getAssembler().registerSymbol(Symbol: *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) {
260 MCSection &Section = *getAssembler().getContext().getELFSection(
261 Section: ".bss", Type: ELF::SHT_NOBITS, Flags: ELF::SHF_WRITE | ELF::SHF_ALLOC);
262 MCSectionSubPair P = getCurrentSection();
263 switchSection(Section: &Section);
264
265 emitValueToAlignment(Alignment: ByteAlignment, Fill: 0, FillLen: 1, MaxBytesToEmit: 0);
266 emitLabel(S: Symbol);
267 emitZeros(NumBytes: Size);
268
269 switchSection(Section: P.first, Subsec: P.second);
270 } else {
271 if (Symbol->declareCommon(Size, Alignment: ByteAlignment))
272 report_fatal_error(reason: Twine("Symbol: ") + Symbol->getName() +
273 " redeclared as different type");
274 }
275
276 Symbol->setSize(MCConstantExpr::create(Value: Size, Ctx&: getContext()));
277}
278
279void MCELFStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
280 static_cast<MCSymbolELF *>(Symbol)->setSize(Value);
281}
282
283void MCELFStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym,
284 StringRef Name,
285 bool KeepOriginalSym) {
286 getWriter().Symvers.push_back(Elt: ELFObjectWriter::Symver{
287 .Loc: getStartTokLoc(), .Sym: OriginalSym, .Name: Name, .KeepOriginalSym: KeepOriginalSym});
288}
289
290void MCELFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
291 Align ByteAlignment) {
292 auto *Symbol = static_cast<MCSymbolELF *>(S);
293 // FIXME: Should this be caught and done earlier?
294 getAssembler().registerSymbol(Symbol: *Symbol);
295 Symbol->setBinding(ELF::STB_LOCAL);
296 emitCommonSymbol(S: Symbol, Size, ByteAlignment);
297}
298
299void MCELFStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
300 const MCSymbolRefExpr *To,
301 uint64_t Count) {
302 getWriter().getCGProfile().push_back(Elt: {.From: From, .To: To, .Count: Count});
303}
304
305void MCELFStreamer::emitIdent(StringRef IdentString) {
306 MCSection *Comment = getAssembler().getContext().getELFSection(
307 Section: ".comment", Type: ELF::SHT_PROGBITS, Flags: ELF::SHF_MERGE | ELF::SHF_STRINGS, EntrySize: 1);
308 pushSection();
309 switchSection(Section: Comment);
310 if (!SeenIdent) {
311 emitInt8(Value: 0);
312 SeenIdent = true;
313 }
314 emitBytes(Data: IdentString);
315 emitInt8(Value: 0);
316 popSection();
317}
318
319void MCELFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *Sym,
320 uint64_t Offset,
321 const MCSymbolRefExpr *&SRE) {
322 const MCSymbol *S = &SRE->getSymbol();
323 if (S->isTemporary()) {
324 if (!S->isInSection()) {
325 getContext().reportError(
326 L: SRE->getLoc(), Msg: Twine("Reference to undefined temporary symbol ") +
327 "`" + S->getName() + "`");
328 return;
329 }
330 S = S->getSection().getBeginSymbol();
331 S->setUsedInReloc();
332 SRE = MCSymbolRefExpr::create(Symbol: S, Ctx&: getContext(), Loc: SRE->getLoc());
333 }
334 auto *O = MCBinaryExpr::createAdd(
335 LHS: Sym, RHS: MCConstantExpr::create(Value: Offset, Ctx&: getContext()), Ctx&: getContext());
336 MCObjectStreamer::emitRelocDirective(Offset: *O, Name: "BFD_RELOC_NONE", Expr: SRE);
337}
338
339void MCELFStreamer::finalizeCGProfile() {
340 ELFObjectWriter &W = getWriter();
341 if (W.getCGProfile().empty())
342 return;
343 MCSection *CGProfile = getAssembler().getContext().getELFSection(
344 Section: ".llvm.call-graph-profile", Type: ELF::SHT_LLVM_CALL_GRAPH_PROFILE,
345 Flags: ELF::SHF_EXCLUDE, /*sizeof(Elf_CGProfile_Impl<>)=*/EntrySize: 8);
346 pushSection();
347 switchSection(Section: CGProfile);
348 uint64_t Offset = 0;
349 auto *Sym =
350 MCSymbolRefExpr::create(Symbol: CGProfile->getBeginSymbol(), Ctx&: getContext());
351 for (auto &E : W.getCGProfile()) {
352 finalizeCGProfileEntry(Sym, Offset, SRE&: E.From);
353 finalizeCGProfileEntry(Sym, Offset, SRE&: E.To);
354 emitIntValue(Value: E.Count, Size: sizeof(uint64_t));
355 Offset += sizeof(uint64_t);
356 }
357 popSection();
358}
359
360void MCELFStreamer::finishImpl() {
361 // Emit .note.GNU-stack, similar to AsmPrinter::doFinalization.
362 MCContext &Ctx = getContext();
363 auto *StackSec = Ctx.getAsmInfo().getStackSection(Ctx,
364 /*Exec=*/false);
365 if (StackSec && Ctx.getTargetOptions().MCNoExecStack)
366 switchSection(Section: StackSec);
367
368 // Emit the .gnu attributes section if any attributes have been added.
369 if (!GNUAttributes.empty()) {
370 MCSection *DummyAttributeSection = nullptr;
371 createAttributesSection(Vendor: "gnu", Section: ".gnu.attributes", Type: ELF::SHT_GNU_ATTRIBUTES,
372 AttributeSection&: DummyAttributeSection, AttrsVec&: GNUAttributes);
373 }
374
375 if (Ctx.getTargetTriple().isLFI())
376 emitLFINoteSection(Streamer&: *this, Ctx);
377
378 finalizeCGProfile();
379 emitFrames();
380
381 this->MCObjectStreamer::finishImpl();
382}
383
384void MCELFStreamer::setAttributeItem(unsigned Attribute, unsigned Value,
385 bool OverwriteExisting) {
386 // Look for existing attribute item
387 if (AttributeItem *Item = getAttributeItem(Attribute)) {
388 if (!OverwriteExisting)
389 return;
390 Item->Type = AttributeItem::NumericAttribute;
391 Item->IntValue = Value;
392 return;
393 }
394
395 // Create new attribute item
396 AttributeItem Item = {AttributeItem::NumericAttribute, Attribute, Value,
397 std::string(StringRef(""))};
398 Contents.push_back(Elt: Item);
399}
400
401void MCELFStreamer::setAttributeItem(unsigned Attribute, StringRef Value,
402 bool OverwriteExisting) {
403 // Look for existing attribute item
404 if (AttributeItem *Item = getAttributeItem(Attribute)) {
405 if (!OverwriteExisting)
406 return;
407 Item->Type = AttributeItem::TextAttribute;
408 Item->StringValue = std::string(Value);
409 return;
410 }
411
412 // Create new attribute item
413 AttributeItem Item = {AttributeItem::TextAttribute, Attribute, 0,
414 std::string(Value)};
415 Contents.push_back(Elt: Item);
416}
417
418void MCELFStreamer::setAttributeItems(unsigned Attribute, unsigned IntValue,
419 StringRef StringValue,
420 bool OverwriteExisting) {
421 // Look for existing attribute item
422 if (AttributeItem *Item = getAttributeItem(Attribute)) {
423 if (!OverwriteExisting)
424 return;
425 Item->Type = AttributeItem::NumericAndTextAttributes;
426 Item->IntValue = IntValue;
427 Item->StringValue = std::string(StringValue);
428 return;
429 }
430
431 // Create new attribute item
432 AttributeItem Item = {AttributeItem::NumericAndTextAttributes, Attribute,
433 IntValue, std::string(StringValue)};
434 Contents.push_back(Elt: Item);
435}
436
437MCELFStreamer::AttributeItem *
438MCELFStreamer::getAttributeItem(unsigned Attribute) {
439 for (AttributeItem &Item : Contents)
440 if (Item.Tag == Attribute)
441 return &Item;
442 return nullptr;
443}
444
445size_t MCELFStreamer::calculateContentSize(
446 SmallVector<AttributeItem, 64> &AttrsVec) const {
447 size_t Result = 0;
448 for (const AttributeItem &Item : AttrsVec) {
449 switch (Item.Type) {
450 case AttributeItem::HiddenAttribute:
451 break;
452 case AttributeItem::NumericAttribute:
453 Result += getULEB128Size(Value: Item.Tag);
454 Result += getULEB128Size(Value: Item.IntValue);
455 break;
456 case AttributeItem::TextAttribute:
457 Result += getULEB128Size(Value: Item.Tag);
458 Result += Item.StringValue.size() + 1; // string + '\0'
459 break;
460 case AttributeItem::NumericAndTextAttributes:
461 Result += getULEB128Size(Value: Item.Tag);
462 Result += getULEB128Size(Value: Item.IntValue);
463 Result += Item.StringValue.size() + 1; // string + '\0';
464 break;
465 }
466 }
467 return Result;
468}
469
470void MCELFStreamer::createAttributesSection(
471 StringRef Vendor, const Twine &Section, unsigned Type,
472 MCSection *&AttributeSection, SmallVector<AttributeItem, 64> &AttrsVec) {
473 // <format-version>
474 // [ <section-length> "vendor-name"
475 // [ <file-tag> <size> <attribute>*
476 // | <section-tag> <size> <section-number>* 0 <attribute>*
477 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
478 // ]+
479 // ]*
480
481 // Switch section to AttributeSection or get/create the section.
482 if (AttributeSection) {
483 switchSection(Section: AttributeSection);
484 } else {
485 AttributeSection = getContext().getELFSection(Section, Type, Flags: 0);
486 switchSection(Section: AttributeSection);
487
488 // Format version
489 emitInt8(Value: 0x41);
490 }
491
492 // Vendor size + Vendor name + '\0'
493 const size_t VendorHeaderSize = 4 + Vendor.size() + 1;
494
495 // Tag + Tag Size
496 const size_t TagHeaderSize = 1 + 4;
497
498 const size_t ContentsSize = calculateContentSize(AttrsVec);
499
500 emitInt32(Value: VendorHeaderSize + TagHeaderSize + ContentsSize);
501 emitBytes(Data: Vendor);
502 emitInt8(Value: 0); // '\0'
503
504 emitInt8(Value: ARMBuildAttrs::File);
505 emitInt32(Value: TagHeaderSize + ContentsSize);
506
507 // Size should have been accounted for already, now
508 // emit each field as its type (ULEB or String)
509 for (const AttributeItem &Item : AttrsVec) {
510 emitULEB128IntValue(Value: Item.Tag);
511 switch (Item.Type) {
512 default:
513 llvm_unreachable("Invalid attribute type");
514 case AttributeItem::NumericAttribute:
515 emitULEB128IntValue(Value: Item.IntValue);
516 break;
517 case AttributeItem::TextAttribute:
518 emitBytes(Data: Item.StringValue);
519 emitInt8(Value: 0); // '\0'
520 break;
521 case AttributeItem::NumericAndTextAttributes:
522 emitULEB128IntValue(Value: Item.IntValue);
523 emitBytes(Data: Item.StringValue);
524 emitInt8(Value: 0); // '\0'
525 break;
526 }
527 }
528
529 AttrsVec.clear();
530}
531
532void MCELFStreamer::createAttributesWithSubsection(
533 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
534 SmallVector<AttributeSubSection, 64> &SubSectionVec) {
535 // <format-version: 'A'>
536 // [ <uint32: subsection-length> NTBS: vendor-name
537 // <bytes: vendor-data>
538 // ]*
539 // vendor-data expends to:
540 // <uint8: optional> <uint8: parameter type> <attribute>*
541 if (0 == SubSectionVec.size()) {
542 return;
543 }
544
545 // Switch section to AttributeSection or get/create the section.
546 if (AttributeSection) {
547 switchSection(Section: AttributeSection);
548 } else {
549 AttributeSection = getContext().getELFSection(Section, Type, Flags: 0);
550 switchSection(Section: AttributeSection);
551
552 // Format version
553 emitInt8(Value: 0x41);
554 }
555
556 for (AttributeSubSection &SubSection : SubSectionVec) {
557 // subsection-length + vendor-name + '\0'
558 const size_t VendorHeaderSize = 4 + SubSection.VendorName.size() + 1;
559 // optional + parameter-type
560 const size_t VendorParameters = 1 + 1;
561 const size_t ContentsSize = calculateContentSize(AttrsVec&: SubSection.Content);
562
563 emitInt32(Value: VendorHeaderSize + VendorParameters + ContentsSize);
564 emitBytes(Data: SubSection.VendorName);
565 emitInt8(Value: 0); // '\0'
566 emitInt8(Value: SubSection.IsOptional);
567 emitInt8(Value: SubSection.ParameterType);
568
569 for (AttributeItem &Item : SubSection.Content) {
570 emitULEB128IntValue(Value: Item.Tag);
571 switch (Item.Type) {
572 default:
573 assert(0 && "Invalid attribute type");
574 break;
575 case AttributeItem::NumericAttribute:
576 emitULEB128IntValue(Value: Item.IntValue);
577 break;
578 case AttributeItem::TextAttribute:
579 emitBytes(Data: Item.StringValue);
580 emitInt8(Value: 0); // '\0'
581 break;
582 case AttributeItem::NumericAndTextAttributes:
583 emitULEB128IntValue(Value: Item.IntValue);
584 emitBytes(Data: Item.StringValue);
585 emitInt8(Value: 0); // '\0'
586 break;
587 }
588 }
589 }
590 SubSectionVec.clear();
591}
592
593MCStreamer *llvm::createELFStreamer(MCContext &Context,
594 std::unique_ptr<MCAsmBackend> &&MAB,
595 std::unique_ptr<MCObjectWriter> &&OW,
596 std::unique_ptr<MCCodeEmitter> &&CE) {
597 MCELFStreamer *S =
598 new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
599 return S;
600}
601