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