xref: /freebsd/contrib/llvm-project/llvm/lib/MC/MCMachOStreamer.cpp (revision 3078531de10dcae44b253a35125c949ff4235284)
1 //===- MCMachOStreamer.cpp - MachO Streamer -------------------------------===//
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 #include "llvm/ADT/DenseMap.h"
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/ADT/SmallVector.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/ADT/Triple.h"
14 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCAssembler.h"
16 #include "llvm/MC/MCCodeEmitter.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCDirectives.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCFixup.h"
21 #include "llvm/MC/MCFragment.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCLinkerOptimizationHint.h"
24 #include "llvm/MC/MCObjectFileInfo.h"
25 #include "llvm/MC/MCObjectStreamer.h"
26 #include "llvm/MC/MCObjectWriter.h"
27 #include "llvm/MC/MCSection.h"
28 #include "llvm/MC/MCSectionMachO.h"
29 #include "llvm/MC/MCStreamer.h"
30 #include "llvm/MC/MCSymbol.h"
31 #include "llvm/MC/MCSymbolMachO.h"
32 #include "llvm/MC/MCValue.h"
33 #include "llvm/MC/TargetRegistry.h"
34 #include "llvm/Support/Casting.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include "llvm/Support/raw_ostream.h"
37 #include <cassert>
38 #include <vector>
39 
40 using namespace llvm;
41 
42 namespace {
43 
44 class MCMachOStreamer : public MCObjectStreamer {
45 private:
46   /// LabelSections - true if each section change should emit a linker local
47   /// label for use in relocations for assembler local references. Obviates the
48   /// need for local relocations. False by default.
49   bool LabelSections;
50 
51   bool DWARFMustBeAtTheEnd;
52   bool CreatedADWARFSection;
53 
54   /// HasSectionLabel - map of which sections have already had a non-local
55   /// label emitted to them. Used so we don't emit extraneous linker local
56   /// labels in the middle of the section.
57   DenseMap<const MCSection*, bool> HasSectionLabel;
58 
59   void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) override;
60 
61   void emitDataRegion(DataRegionData::KindTy Kind);
62   void emitDataRegionEnd();
63 
64 public:
65   MCMachOStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
66                   std::unique_ptr<MCObjectWriter> OW,
67                   std::unique_ptr<MCCodeEmitter> Emitter,
68                   bool DWARFMustBeAtTheEnd, bool label)
69       : MCObjectStreamer(Context, std::move(MAB), std::move(OW),
70                          std::move(Emitter)),
71         LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd),
72         CreatedADWARFSection(false) {}
73 
74   /// state management
75   void reset() override {
76     CreatedADWARFSection = false;
77     HasSectionLabel.clear();
78     MCObjectStreamer::reset();
79   }
80 
81   /// @name MCStreamer Interface
82   /// @{
83 
84   void changeSection(MCSection *Sect, const MCExpr *Subsect) override;
85   void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
86   void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
87   void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
88   void emitAssemblerFlag(MCAssemblerFlag Flag) override;
89   void emitLinkerOptions(ArrayRef<std::string> Options) override;
90   void emitDataRegion(MCDataRegionType Kind) override;
91   void emitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
92                       unsigned Update, VersionTuple SDKVersion) override;
93   void emitBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
94                         unsigned Update, VersionTuple SDKVersion) override;
95   void emitDarwinTargetVariantBuildVersion(unsigned Platform, unsigned Major,
96                                            unsigned Minor, unsigned Update,
97                                            VersionTuple SDKVersion) override;
98   void emitThumbFunc(MCSymbol *Func) override;
99   bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
100   void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
101   void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
102                         unsigned ByteAlignment) override;
103 
104   void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
105                              unsigned ByteAlignment) override;
106   void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
107                     uint64_t Size = 0, unsigned ByteAlignment = 0,
108                     SMLoc Loc = SMLoc()) override;
109   void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
110                       unsigned ByteAlignment = 0) override;
111 
112   void emitIdent(StringRef IdentString) override {
113     llvm_unreachable("macho doesn't support this directive");
114   }
115 
116   void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override {
117     getAssembler().getLOHContainer().addDirective(Kind, Args);
118   }
119   void emitCGProfileEntry(const MCSymbolRefExpr *From,
120                           const MCSymbolRefExpr *To, uint64_t Count) override {
121     if (!From->getSymbol().isTemporary() && !To->getSymbol().isTemporary())
122       getAssembler().CGProfile.push_back({From, To, Count});
123   }
124 
125   void finishImpl() override;
126 
127   void finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE);
128   void finalizeCGProfile();
129 };
130 
131 } // end anonymous namespace.
132 
133 static bool canGoAfterDWARF(const MCSectionMachO &MSec) {
134   // These sections are created by the assembler itself after the end of
135   // the .s file.
136   StringRef SegName = MSec.getSegmentName();
137   StringRef SecName = MSec.getName();
138 
139   if (SegName == "__LD" && SecName == "__compact_unwind")
140     return true;
141 
142   if (SegName == "__IMPORT") {
143     if (SecName == "__jump_table")
144       return true;
145 
146     if (SecName == "__pointers")
147       return true;
148   }
149 
150   if (SegName == "__TEXT" && SecName == "__eh_frame")
151     return true;
152 
153   if (SegName == "__DATA" && (SecName == "__nl_symbol_ptr" ||
154                               SecName == "__thread_ptr"))
155     return true;
156   if (SegName == "__LLVM" && SecName == "__cg_profile")
157     return true;
158   return false;
159 }
160 
161 void MCMachOStreamer::changeSection(MCSection *Section,
162                                     const MCExpr *Subsection) {
163   // Change the section normally.
164   bool Created = changeSectionImpl(Section, Subsection);
165   const MCSectionMachO &MSec = *cast<MCSectionMachO>(Section);
166   StringRef SegName = MSec.getSegmentName();
167   if (SegName == "__DWARF")
168     CreatedADWARFSection = true;
169   else if (Created && DWARFMustBeAtTheEnd && !canGoAfterDWARF(MSec))
170     assert((!CreatedADWARFSection ||
171             Section == getContext().getObjectFileInfo()->getStackMapSection())
172            && "Creating regular section after DWARF");
173 
174   // Output a linker-local symbol so we don't need section-relative local
175   // relocations. The linker hates us when we do that.
176   if (LabelSections && !HasSectionLabel[Section] &&
177       !Section->getBeginSymbol()) {
178     MCSymbol *Label = getContext().createLinkerPrivateTempSymbol();
179     Section->setBeginSymbol(Label);
180     HasSectionLabel[Section] = true;
181   }
182 }
183 
184 void MCMachOStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
185                                           MCSymbol *EHSymbol) {
186   getAssembler().registerSymbol(*Symbol);
187   if (Symbol->isExternal())
188     emitSymbolAttribute(EHSymbol, MCSA_Global);
189   if (cast<MCSymbolMachO>(Symbol)->isWeakDefinition())
190     emitSymbolAttribute(EHSymbol, MCSA_WeakDefinition);
191   if (Symbol->isPrivateExtern())
192     emitSymbolAttribute(EHSymbol, MCSA_PrivateExtern);
193 }
194 
195 void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
196   // We have to create a new fragment if this is an atom defining symbol,
197   // fragments cannot span atoms.
198   if (getAssembler().isSymbolLinkerVisible(*Symbol))
199     insert(new MCDataFragment());
200 
201   MCObjectStreamer::emitLabel(Symbol, Loc);
202 
203   // This causes the reference type flag to be cleared. Darwin 'as' was "trying"
204   // to clear the weak reference and weak definition bits too, but the
205   // implementation was buggy. For now we just try to match 'as', for
206   // diffability.
207   //
208   // FIXME: Cleanup this code, these bits should be emitted based on semantic
209   // properties, not on the order of definition, etc.
210   cast<MCSymbolMachO>(Symbol)->clearReferenceType();
211 }
212 
213 void MCMachOStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
214   MCValue Res;
215 
216   if (Value->evaluateAsRelocatable(Res, nullptr, nullptr)) {
217     if (const MCSymbolRefExpr *SymAExpr = Res.getSymA()) {
218       const MCSymbol &SymA = SymAExpr->getSymbol();
219       if (!Res.getSymB() && (SymA.getName() == "" || Res.getConstant() != 0))
220         cast<MCSymbolMachO>(Symbol)->setAltEntry();
221     }
222   }
223   MCObjectStreamer::emitAssignment(Symbol, Value);
224 }
225 
226 void MCMachOStreamer::emitDataRegion(DataRegionData::KindTy Kind) {
227   // Create a temporary label to mark the start of the data region.
228   MCSymbol *Start = getContext().createTempSymbol();
229   emitLabel(Start);
230   // Record the region for the object writer to use.
231   DataRegionData Data = { Kind, Start, nullptr };
232   std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
233   Regions.push_back(Data);
234 }
235 
236 void MCMachOStreamer::emitDataRegionEnd() {
237   std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
238   assert(!Regions.empty() && "Mismatched .end_data_region!");
239   DataRegionData &Data = Regions.back();
240   assert(!Data.End && "Mismatched .end_data_region!");
241   // Create a temporary label to mark the end of the data region.
242   Data.End = getContext().createTempSymbol();
243   emitLabel(Data.End);
244 }
245 
246 void MCMachOStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
247   // Let the target do whatever target specific stuff it needs to do.
248   getAssembler().getBackend().handleAssemblerFlag(Flag);
249   // Do any generic stuff we need to do.
250   switch (Flag) {
251   case MCAF_SyntaxUnified: return; // no-op here.
252   case MCAF_Code16: return; // Change parsing mode; no-op here.
253   case MCAF_Code32: return; // Change parsing mode; no-op here.
254   case MCAF_Code64: return; // Change parsing mode; no-op here.
255   case MCAF_SubsectionsViaSymbols:
256     getAssembler().setSubsectionsViaSymbols(true);
257     return;
258   }
259 }
260 
261 void MCMachOStreamer::emitLinkerOptions(ArrayRef<std::string> Options) {
262   getAssembler().getLinkerOptions().push_back(Options);
263 }
264 
265 void MCMachOStreamer::emitDataRegion(MCDataRegionType Kind) {
266   switch (Kind) {
267   case MCDR_DataRegion:
268     emitDataRegion(DataRegionData::Data);
269     return;
270   case MCDR_DataRegionJT8:
271     emitDataRegion(DataRegionData::JumpTable8);
272     return;
273   case MCDR_DataRegionJT16:
274     emitDataRegion(DataRegionData::JumpTable16);
275     return;
276   case MCDR_DataRegionJT32:
277     emitDataRegion(DataRegionData::JumpTable32);
278     return;
279   case MCDR_DataRegionEnd:
280     emitDataRegionEnd();
281     return;
282   }
283 }
284 
285 void MCMachOStreamer::emitVersionMin(MCVersionMinType Kind, unsigned Major,
286                                      unsigned Minor, unsigned Update,
287                                      VersionTuple SDKVersion) {
288   getAssembler().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
289 }
290 
291 void MCMachOStreamer::emitBuildVersion(unsigned Platform, unsigned Major,
292                                        unsigned Minor, unsigned Update,
293                                        VersionTuple SDKVersion) {
294   getAssembler().setBuildVersion((MachO::PlatformType)Platform, Major, Minor,
295                                  Update, SDKVersion);
296 }
297 
298 void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
299     unsigned Platform, unsigned Major, unsigned Minor, unsigned Update,
300     VersionTuple SDKVersion) {
301   getAssembler().setDarwinTargetVariantBuildVersion(
302       (MachO::PlatformType)Platform, Major, Minor, Update, SDKVersion);
303 }
304 
305 void MCMachOStreamer::emitThumbFunc(MCSymbol *Symbol) {
306   // Remember that the function is a thumb function. Fixup and relocation
307   // values will need adjusted.
308   getAssembler().setIsThumbFunc(Symbol);
309   cast<MCSymbolMachO>(Symbol)->setThumbFunc();
310 }
311 
312 bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
313                                           MCSymbolAttr Attribute) {
314   MCSymbolMachO *Symbol = cast<MCSymbolMachO>(Sym);
315 
316   // Indirect symbols are handled differently, to match how 'as' handles
317   // them. This makes writing matching .o files easier.
318   if (Attribute == MCSA_IndirectSymbol) {
319     // Note that we intentionally cannot use the symbol data here; this is
320     // important for matching the string table that 'as' generates.
321     IndirectSymbolData ISD;
322     ISD.Symbol = Symbol;
323     ISD.Section = getCurrentSectionOnly();
324     getAssembler().getIndirectSymbols().push_back(ISD);
325     return true;
326   }
327 
328   // Adding a symbol attribute always introduces the symbol, note that an
329   // important side effect of calling registerSymbol here is to register
330   // the symbol with the assembler.
331   getAssembler().registerSymbol(*Symbol);
332 
333   // The implementation of symbol attributes is designed to match 'as', but it
334   // leaves much to desired. It doesn't really make sense to arbitrarily add and
335   // remove flags, but 'as' allows this (in particular, see .desc).
336   //
337   // In the future it might be worth trying to make these operations more well
338   // defined.
339   switch (Attribute) {
340   case MCSA_Invalid:
341   case MCSA_ELF_TypeFunction:
342   case MCSA_ELF_TypeIndFunction:
343   case MCSA_ELF_TypeObject:
344   case MCSA_ELF_TypeTLS:
345   case MCSA_ELF_TypeCommon:
346   case MCSA_ELF_TypeNoType:
347   case MCSA_ELF_TypeGnuUniqueObject:
348   case MCSA_Extern:
349   case MCSA_Hidden:
350   case MCSA_IndirectSymbol:
351   case MCSA_Internal:
352   case MCSA_Protected:
353   case MCSA_Weak:
354   case MCSA_Local:
355   case MCSA_LGlobal:
356     return false;
357 
358   case MCSA_Global:
359     Symbol->setExternal(true);
360     // This effectively clears the undefined lazy bit, in Darwin 'as', although
361     // it isn't very consistent because it implements this as part of symbol
362     // lookup.
363     //
364     // FIXME: Cleanup this code, these bits should be emitted based on semantic
365     // properties, not on the order of definition, etc.
366     Symbol->setReferenceTypeUndefinedLazy(false);
367     break;
368 
369   case MCSA_LazyReference:
370     // FIXME: This requires -dynamic.
371     Symbol->setNoDeadStrip();
372     if (Symbol->isUndefined())
373       Symbol->setReferenceTypeUndefinedLazy(true);
374     break;
375 
376     // Since .reference sets the no dead strip bit, it is equivalent to
377     // .no_dead_strip in practice.
378   case MCSA_Reference:
379   case MCSA_NoDeadStrip:
380     Symbol->setNoDeadStrip();
381     break;
382 
383   case MCSA_SymbolResolver:
384     Symbol->setSymbolResolver();
385     break;
386 
387   case MCSA_AltEntry:
388     Symbol->setAltEntry();
389     break;
390 
391   case MCSA_PrivateExtern:
392     Symbol->setExternal(true);
393     Symbol->setPrivateExtern(true);
394     break;
395 
396   case MCSA_WeakReference:
397     // FIXME: This requires -dynamic.
398     if (Symbol->isUndefined())
399       Symbol->setWeakReference();
400     break;
401 
402   case MCSA_WeakDefinition:
403     // FIXME: 'as' enforces that this is defined and global. The manual claims
404     // it has to be in a coalesced section, but this isn't enforced.
405     Symbol->setWeakDefinition();
406     break;
407 
408   case MCSA_WeakDefAutoPrivate:
409     Symbol->setWeakDefinition();
410     Symbol->setWeakReference();
411     break;
412 
413   case MCSA_Cold:
414     Symbol->setCold();
415     break;
416   }
417 
418   return true;
419 }
420 
421 void MCMachOStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
422   // Encode the 'desc' value into the lowest implementation defined bits.
423   getAssembler().registerSymbol(*Symbol);
424   cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
425 }
426 
427 void MCMachOStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
428                                        unsigned ByteAlignment) {
429   // FIXME: Darwin 'as' does appear to allow redef of a .comm by itself.
430   assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
431 
432   getAssembler().registerSymbol(*Symbol);
433   Symbol->setExternal(true);
434   Symbol->setCommon(Size, ByteAlignment);
435 }
436 
437 void MCMachOStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
438                                             unsigned ByteAlignment) {
439   // '.lcomm' is equivalent to '.zerofill'.
440   return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
441                       Symbol, Size, ByteAlignment);
442 }
443 
444 void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
445                                    uint64_t Size, unsigned ByteAlignment,
446                                    SMLoc Loc) {
447   // On darwin all virtual sections have zerofill type. Disallow the usage of
448   // .zerofill in non-virtual functions. If something similar is needed, use
449   // .space or .zero.
450   if (!Section->isVirtualSection()) {
451     getContext().reportError(
452         Loc, "The usage of .zerofill is restricted to sections of "
453              "ZEROFILL type. Use .zero or .space instead.");
454     return; // Early returning here shouldn't harm. EmitZeros should work on any
455             // section.
456   }
457 
458   PushSection();
459   SwitchSection(Section);
460 
461   // The symbol may not be present, which only creates the section.
462   if (Symbol) {
463     emitValueToAlignment(ByteAlignment, 0, 1, 0);
464     emitLabel(Symbol);
465     emitZeros(Size);
466   }
467   PopSection();
468 }
469 
470 // This should always be called with the thread local bss section.  Like the
471 // .zerofill directive this doesn't actually switch sections on us.
472 void MCMachOStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
473                                      uint64_t Size, unsigned ByteAlignment) {
474   emitZerofill(Section, Symbol, Size, ByteAlignment);
475 }
476 
477 void MCMachOStreamer::emitInstToData(const MCInst &Inst,
478                                      const MCSubtargetInfo &STI) {
479   MCDataFragment *DF = getOrCreateDataFragment();
480 
481   SmallVector<MCFixup, 4> Fixups;
482   SmallString<256> Code;
483   raw_svector_ostream VecOS(Code);
484   getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
485 
486   // Add the fixups and data.
487   for (MCFixup &Fixup : Fixups) {
488     Fixup.setOffset(Fixup.getOffset() + DF->getContents().size());
489     DF->getFixups().push_back(Fixup);
490   }
491   DF->setHasInstructions(STI);
492   DF->getContents().append(Code.begin(), Code.end());
493 }
494 
495 void MCMachOStreamer::finishImpl() {
496   emitFrames(&getAssembler().getBackend());
497 
498   // We have to set the fragment atom associations so we can relax properly for
499   // Mach-O.
500 
501   // First, scan the symbol table to build a lookup table from fragments to
502   // defining symbols.
503   DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
504   for (const MCSymbol &Symbol : getAssembler().symbols()) {
505     if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() &&
506         !Symbol.isVariable()) {
507       // An atom defining symbol should never be internal to a fragment.
508       assert(Symbol.getOffset() == 0 &&
509              "Invalid offset in atom defining symbol!");
510       DefiningSymbolMap[Symbol.getFragment()] = &Symbol;
511     }
512   }
513 
514   // Set the fragment atom associations by tracking the last seen atom defining
515   // symbol.
516   for (MCSection &Sec : getAssembler()) {
517     const MCSymbol *CurrentAtom = nullptr;
518     for (MCFragment &Frag : Sec) {
519       if (const MCSymbol *Symbol = DefiningSymbolMap.lookup(&Frag))
520         CurrentAtom = Symbol;
521       Frag.setAtom(CurrentAtom);
522     }
523   }
524 
525   finalizeCGProfile();
526 
527   this->MCObjectStreamer::finishImpl();
528 }
529 
530 void MCMachOStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE) {
531   const MCSymbol *S = &SRE->getSymbol();
532   bool Created;
533   getAssembler().registerSymbol(*S, &Created);
534   if (Created)
535     S->setExternal(true);
536 }
537 
538 void MCMachOStreamer::finalizeCGProfile() {
539   MCAssembler &Asm = getAssembler();
540   if (Asm.CGProfile.empty())
541     return;
542   for (MCAssembler::CGProfileEntry &E : Asm.CGProfile) {
543     finalizeCGProfileEntry(E.From);
544     finalizeCGProfileEntry(E.To);
545   }
546   // We can't write the section out until symbol indices are finalized which
547   // doesn't happen until after section layout. We need to create the section
548   // and set its size now so that it's accounted for in layout.
549   MCSection *CGProfileSection = Asm.getContext().getMachOSection(
550       "__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
551   Asm.registerSection(*CGProfileSection);
552   auto *Frag = new MCDataFragment(CGProfileSection);
553   // For each entry, reserve space for 2 32-bit indices and a 64-bit count.
554   size_t SectionBytes =
555       Asm.CGProfile.size() * (2 * sizeof(uint32_t) + sizeof(uint64_t));
556   Frag->getContents().resize(SectionBytes);
557 }
558 
559 MCStreamer *llvm::createMachOStreamer(MCContext &Context,
560                                       std::unique_ptr<MCAsmBackend> &&MAB,
561                                       std::unique_ptr<MCObjectWriter> &&OW,
562                                       std::unique_ptr<MCCodeEmitter> &&CE,
563                                       bool RelaxAll, bool DWARFMustBeAtTheEnd,
564                                       bool LabelSections) {
565   MCMachOStreamer *S =
566       new MCMachOStreamer(Context, std::move(MAB), std::move(OW), std::move(CE),
567                           DWARFMustBeAtTheEnd, LabelSections);
568   const Triple &Target = Context.getTargetTriple();
569   S->emitVersionForTarget(
570       Target, Context.getObjectFileInfo()->getSDKVersion(),
571       Context.getObjectFileInfo()->getDarwinTargetVariantTriple(),
572       Context.getObjectFileInfo()->getDarwinTargetVariantSDKVersion());
573   if (RelaxAll)
574     S->getAssembler().setRelaxAll(true);
575   return S;
576 }
577