ARM IAS: support .personalityindex
[oota-llvm.git] / lib / Target / ARM / MCTargetDesc / ARMELFStreamer.cpp
1 //===- lib/MC/ARMELFStreamer.cpp - ELF Object Output for ARM --------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file assembles .s files and emits ARM ELF .o object files. Different
11 // from generic ELF streamer in emitting mapping symbols ($a, $t and $d) to
12 // delimit regions of data and code.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "ARMArchName.h"
17 #include "ARMFPUName.h"
18 #include "ARMRegisterInfo.h"
19 #include "ARMUnwindOpAsm.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/StringExtras.h"
22 #include "llvm/ADT/Twine.h"
23 #include "llvm/MC/MCAsmBackend.h"
24 #include "llvm/MC/MCAsmInfo.h"
25 #include "llvm/MC/MCAssembler.h"
26 #include "llvm/MC/MCCodeEmitter.h"
27 #include "llvm/MC/MCContext.h"
28 #include "llvm/MC/MCELF.h"
29 #include "llvm/MC/MCELFStreamer.h"
30 #include "llvm/MC/MCELFSymbolFlags.h"
31 #include "llvm/MC/MCExpr.h"
32 #include "llvm/MC/MCInst.h"
33 #include "llvm/MC/MCInstPrinter.h"
34 #include "llvm/MC/MCObjectStreamer.h"
35 #include "llvm/MC/MCRegisterInfo.h"
36 #include "llvm/MC/MCSection.h"
37 #include "llvm/MC/MCSectionELF.h"
38 #include "llvm/MC/MCStreamer.h"
39 #include "llvm/MC/MCSymbol.h"
40 #include "llvm/MC/MCValue.h"
41 #include "llvm/Support/ARMBuildAttributes.h"
42 #include "llvm/Support/ARMEHABI.h"
43 #include "llvm/Support/Debug.h"
44 #include "llvm/Support/ELF.h"
45 #include "llvm/Support/FormattedStream.h"
46 #include "llvm/Support/raw_ostream.h"
47 #include <algorithm>
48
49 using namespace llvm;
50
51 static std::string GetAEABIUnwindPersonalityName(unsigned Index) {
52   assert(Index < ARM::EHABI::NUM_PERSONALITY_INDEX &&
53          "Invalid personality index");
54   return (Twine("__aeabi_unwind_cpp_pr") + Twine(Index)).str();
55 }
56
57 static const char *GetFPUName(unsigned ID) {
58   switch (ID) {
59   default:
60     llvm_unreachable("Unknown FPU kind");
61     break;
62 #define ARM_FPU_NAME(NAME, ID) case ARM::ID: return NAME;
63 #include "ARMFPUName.def"
64   }
65   return NULL;
66 }
67
68 static const char *GetArchName(unsigned ID) {
69   switch (ID) {
70   default:
71     llvm_unreachable("Unknown ARCH kind");
72     break;
73 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
74   case ARM::ID: return NAME;
75 #define ARM_ARCH_ALIAS(NAME, ID) /* empty */
76 #include "ARMArchName.def"
77   }
78   return NULL;
79 }
80
81 static const char *GetArchDefaultCPUName(unsigned ID) {
82   switch (ID) {
83   default:
84     llvm_unreachable("Unknown ARCH kind");
85     break;
86 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
87   case ARM::ID: return DEFAULT_CPU_NAME;
88 #define ARM_ARCH_ALIAS(NAME, ID) /* empty */
89 #include "ARMArchName.def"
90   }
91   return NULL;
92 }
93
94 static unsigned GetArchDefaultCPUArch(unsigned ID) {
95   switch (ID) {
96   default:
97     llvm_unreachable("Unknown ARCH kind");
98     break;
99 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
100   case ARM::ID: return ARMBuildAttrs::DEFAULT_CPU_ARCH;
101 #define ARM_ARCH_ALIAS(NAME, ID) /* empty */
102 #include "ARMArchName.def"
103   }
104   return 0;
105 }
106
107 namespace {
108
109 class ARMELFStreamer;
110
111 class ARMTargetAsmStreamer : public ARMTargetStreamer {
112   formatted_raw_ostream &OS;
113   MCInstPrinter &InstPrinter;
114   bool IsVerboseAsm;
115
116   virtual void emitFnStart();
117   virtual void emitFnEnd();
118   virtual void emitCantUnwind();
119   virtual void emitPersonality(const MCSymbol *Personality);
120   virtual void emitPersonalityIndex(unsigned Index);
121   virtual void emitHandlerData();
122   virtual void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
123   virtual void emitPad(int64_t Offset);
124   virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
125                            bool isVector);
126
127   virtual void switchVendor(StringRef Vendor);
128   virtual void emitAttribute(unsigned Attribute, unsigned Value);
129   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
130   virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
131                                     StringRef StrinValue);
132   virtual void emitArch(unsigned Arch);
133   virtual void emitFPU(unsigned FPU);
134   virtual void emitInst(uint32_t Inst, char Suffix = '\0');
135   virtual void finishAttributeSection();
136
137 public:
138   ARMTargetAsmStreamer(formatted_raw_ostream &OS, MCInstPrinter &InstPrinter,
139                        bool VerboseAsm);
140 };
141
142 ARMTargetAsmStreamer::ARMTargetAsmStreamer(formatted_raw_ostream &OS,
143                                            MCInstPrinter &InstPrinter,
144                                            bool VerboseAsm)
145     : OS(OS), InstPrinter(InstPrinter), IsVerboseAsm(VerboseAsm) {}
146 void ARMTargetAsmStreamer::emitFnStart() { OS << "\t.fnstart\n"; }
147 void ARMTargetAsmStreamer::emitFnEnd() { OS << "\t.fnend\n"; }
148 void ARMTargetAsmStreamer::emitCantUnwind() { OS << "\t.cantunwind\n"; }
149 void ARMTargetAsmStreamer::emitPersonality(const MCSymbol *Personality) {
150   OS << "\t.personality " << Personality->getName() << '\n';
151 }
152 void ARMTargetAsmStreamer::emitPersonalityIndex(unsigned Index) {
153   OS << "\t.personalityindex " << Index << '\n';
154 }
155 void ARMTargetAsmStreamer::emitHandlerData() { OS << "\t.handlerdata\n"; }
156 void ARMTargetAsmStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
157                                      int64_t Offset) {
158   OS << "\t.setfp\t";
159   InstPrinter.printRegName(OS, FpReg);
160   OS << ", ";
161   InstPrinter.printRegName(OS, SpReg);
162   if (Offset)
163     OS << ", #" << Offset;
164   OS << '\n';
165 }
166 void ARMTargetAsmStreamer::emitPad(int64_t Offset) {
167   OS << "\t.pad\t#" << Offset << '\n';
168 }
169 void ARMTargetAsmStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
170                                        bool isVector) {
171   assert(RegList.size() && "RegList should not be empty");
172   if (isVector)
173     OS << "\t.vsave\t{";
174   else
175     OS << "\t.save\t{";
176
177   InstPrinter.printRegName(OS, RegList[0]);
178
179   for (unsigned i = 1, e = RegList.size(); i != e; ++i) {
180     OS << ", ";
181     InstPrinter.printRegName(OS, RegList[i]);
182   }
183
184   OS << "}\n";
185 }
186 void ARMTargetAsmStreamer::switchVendor(StringRef Vendor) {
187 }
188 void ARMTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
189   OS << "\t.eabi_attribute\t" << Attribute << ", " << Twine(Value);
190   if (IsVerboseAsm) {
191     StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute);
192     if (!Name.empty())
193       OS << "\t@ " << Name;
194   }
195   OS << "\n";
196 }
197 void ARMTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
198                                              StringRef String) {
199   switch (Attribute) {
200   case ARMBuildAttrs::CPU_name:
201     OS << "\t.cpu\t" << String.lower();
202     break;
203   default:
204     OS << "\t.eabi_attribute\t" << Attribute << ", \"" << String << "\"";
205     if (IsVerboseAsm) {
206       StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute);
207       if (!Name.empty())
208         OS << "\t@ " << Name;
209     }
210     break;
211   }
212   OS << "\n";
213 }
214 void ARMTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
215                                                 unsigned IntValue,
216                                                 StringRef StringValue) {
217   switch (Attribute) {
218   default: llvm_unreachable("unsupported multi-value attribute in asm mode");
219   case ARMBuildAttrs::compatibility:
220     OS << "\t.eabi_attribute\t" << Attribute << ", " << IntValue;
221     if (!StringValue.empty())
222       OS << ", \"" << StringValue << "\"";
223     if (IsVerboseAsm)
224       OS << "\t@ " << ARMBuildAttrs::AttrTypeAsString(Attribute);
225     break;
226   }
227   OS << "\n";
228 }
229 void ARMTargetAsmStreamer::emitArch(unsigned Arch) {
230   OS << "\t.arch\t" << GetArchName(Arch) << "\n";
231 }
232 void ARMTargetAsmStreamer::emitFPU(unsigned FPU) {
233   OS << "\t.fpu\t" << GetFPUName(FPU) << "\n";
234 }
235 void ARMTargetAsmStreamer::finishAttributeSection() {
236 }
237
238 void ARMTargetAsmStreamer::emitInst(uint32_t Inst, char Suffix) {
239   OS << "\t.inst";
240   if (Suffix)
241     OS << "." << Suffix;
242   OS << "\t0x" << utohexstr(Inst) << "\n";
243 }
244
245 class ARMTargetELFStreamer : public ARMTargetStreamer {
246 private:
247   // This structure holds all attributes, accounting for
248   // their string/numeric value, so we can later emmit them
249   // in declaration order, keeping all in the same vector
250   struct AttributeItem {
251     enum {
252       HiddenAttribute = 0,
253       NumericAttribute,
254       TextAttribute,
255       NumericAndTextAttributes
256     } Type;
257     unsigned Tag;
258     unsigned IntValue;
259     StringRef StringValue;
260
261     static bool LessTag(const AttributeItem &LHS, const AttributeItem &RHS) {
262       return (LHS.Tag < RHS.Tag);
263     }
264   };
265
266   StringRef CurrentVendor;
267   unsigned FPU;
268   unsigned Arch;
269   SmallVector<AttributeItem, 64> Contents;
270
271   const MCSection *AttributeSection;
272
273   // FIXME: this should be in a more generic place, but
274   // getULEBSize() is in MCAsmInfo and will be moved to MCDwarf
275   static size_t getULEBSize(int Value) {
276     size_t Size = 0;
277     do {
278       Value >>= 7;
279       Size += sizeof(int8_t); // Is this really necessary?
280     } while (Value);
281     return Size;
282   }
283
284   AttributeItem *getAttributeItem(unsigned Attribute) {
285     for (size_t i = 0; i < Contents.size(); ++i)
286       if (Contents[i].Tag == Attribute)
287         return &Contents[i];
288     return 0;
289   }
290
291   void setAttributeItem(unsigned Attribute, unsigned Value,
292                         bool OverwriteExisting) {
293     // Look for existing attribute item
294     if (AttributeItem *Item = getAttributeItem(Attribute)) {
295       if (!OverwriteExisting)
296         return;
297       Item->Type = AttributeItem::NumericAttribute;
298       Item->IntValue = Value;
299       return;
300     }
301
302     // Create new attribute item
303     AttributeItem Item = {
304       AttributeItem::NumericAttribute,
305       Attribute,
306       Value,
307       StringRef("")
308     };
309     Contents.push_back(Item);
310   }
311
312   void setAttributeItem(unsigned Attribute, StringRef Value,
313                         bool OverwriteExisting) {
314     // Look for existing attribute item
315     if (AttributeItem *Item = getAttributeItem(Attribute)) {
316       if (!OverwriteExisting)
317         return;
318       Item->Type = AttributeItem::TextAttribute;
319       Item->StringValue = Value;
320       return;
321     }
322
323     // Create new attribute item
324     AttributeItem Item = {
325       AttributeItem::TextAttribute,
326       Attribute,
327       0,
328       Value
329     };
330     Contents.push_back(Item);
331   }
332
333   void setAttributeItems(unsigned Attribute, unsigned IntValue,
334                          StringRef StringValue, bool OverwriteExisting) {
335     // Look for existing attribute item
336     if (AttributeItem *Item = getAttributeItem(Attribute)) {
337       if (!OverwriteExisting)
338         return;
339       Item->Type = AttributeItem::NumericAndTextAttributes;
340       Item->IntValue = IntValue;
341       Item->StringValue = StringValue;
342       return;
343     }
344
345     // Create new attribute item
346     AttributeItem Item = {
347       AttributeItem::NumericAndTextAttributes,
348       Attribute,
349       IntValue,
350       StringValue
351     };
352     Contents.push_back(Item);
353   }
354
355   void emitArchDefaultAttributes();
356   void emitFPUDefaultAttributes();
357
358   ARMELFStreamer &getStreamer();
359
360   virtual void emitFnStart();
361   virtual void emitFnEnd();
362   virtual void emitCantUnwind();
363   virtual void emitPersonality(const MCSymbol *Personality);
364   virtual void emitPersonalityIndex(unsigned Index);
365   virtual void emitHandlerData();
366   virtual void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
367   virtual void emitPad(int64_t Offset);
368   virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
369                            bool isVector);
370
371   virtual void switchVendor(StringRef Vendor);
372   virtual void emitAttribute(unsigned Attribute, unsigned Value);
373   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
374   virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
375                                     StringRef StringValue);
376   virtual void emitArch(unsigned Arch);
377   virtual void emitFPU(unsigned FPU);
378   virtual void emitInst(uint32_t Inst, char Suffix = '\0');
379   virtual void finishAttributeSection();
380
381   size_t calculateContentSize() const;
382
383 public:
384   ARMTargetELFStreamer()
385     : ARMTargetStreamer(), CurrentVendor("aeabi"), FPU(ARM::INVALID_FPU),
386       Arch(ARM::INVALID_ARCH), AttributeSection(0) {
387   }
388 };
389
390 /// Extend the generic ELFStreamer class so that it can emit mapping symbols at
391 /// the appropriate points in the object files. These symbols are defined in the
392 /// ARM ELF ABI: infocenter.arm.com/help/topic/com.arm.../IHI0044D_aaelf.pdf.
393 ///
394 /// In brief: $a, $t or $d should be emitted at the start of each contiguous
395 /// region of ARM code, Thumb code or data in a section. In practice, this
396 /// emission does not rely on explicit assembler directives but on inherent
397 /// properties of the directives doing the emission (e.g. ".byte" is data, "add
398 /// r0, r0, r0" an instruction).
399 ///
400 /// As a result this system is orthogonal to the DataRegion infrastructure used
401 /// by MachO. Beware!
402 class ARMELFStreamer : public MCELFStreamer {
403 public:
404   friend class ARMTargetELFStreamer;
405
406   ARMELFStreamer(MCContext &Context, MCTargetStreamer *TargetStreamer,
407                  MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *Emitter,
408                  bool IsThumb)
409       : MCELFStreamer(Context, TargetStreamer, TAB, OS, Emitter),
410         IsThumb(IsThumb), MappingSymbolCounter(0), LastEMS(EMS_None) {
411     Reset();
412   }
413
414   ~ARMELFStreamer() {}
415
416   virtual void FinishImpl();
417
418   // ARM exception handling directives
419   void emitFnStart();
420   void emitFnEnd();
421   void emitCantUnwind();
422   void emitPersonality(const MCSymbol *Per);
423   void emitPersonalityIndex(unsigned index);
424   void emitHandlerData();
425   void emitSetFP(unsigned NewFpReg, unsigned NewSpReg, int64_t Offset = 0);
426   void emitPad(int64_t Offset);
427   void emitRegSave(const SmallVectorImpl<unsigned> &RegList, bool isVector);
428
429   virtual void ChangeSection(const MCSection *Section,
430                              const MCExpr *Subsection) {
431     // We have to keep track of the mapping symbol state of any sections we
432     // use. Each one should start off as EMS_None, which is provided as the
433     // default constructor by DenseMap::lookup.
434     LastMappingSymbols[getPreviousSection().first] = LastEMS;
435     LastEMS = LastMappingSymbols.lookup(Section);
436
437     MCELFStreamer::ChangeSection(Section, Subsection);
438   }
439
440   /// This function is the one used to emit instruction data into the ELF
441   /// streamer. We override it to add the appropriate mapping symbol if
442   /// necessary.
443   virtual void EmitInstruction(const MCInst& Inst) {
444     if (IsThumb)
445       EmitThumbMappingSymbol();
446     else
447       EmitARMMappingSymbol();
448
449     MCELFStreamer::EmitInstruction(Inst);
450   }
451
452   virtual void emitInst(uint32_t Inst, char Suffix) {
453     unsigned Size;
454     char Buffer[4];
455     const bool LittleEndian = getContext().getAsmInfo()->isLittleEndian();
456
457     switch (Suffix) {
458     case '\0':
459       Size = 4;
460
461       assert(!IsThumb);
462       EmitARMMappingSymbol();
463       for (unsigned II = 0, IE = Size; II != IE; II++) {
464         const unsigned I = LittleEndian ? (Size - II - 1) : II;
465         Buffer[Size - II - 1] = uint8_t(Inst >> I * CHAR_BIT);
466       }
467
468       break;
469     case 'n':
470     case 'w':
471       Size = (Suffix == 'n' ? 2 : 4);
472
473       assert(IsThumb);
474       EmitThumbMappingSymbol();
475       for (unsigned II = 0, IE = Size; II != IE; II = II + 2) {
476         const unsigned I0 = LittleEndian ? II + 0 : (Size - II - 1);
477         const unsigned I1 = LittleEndian ? II + 1 : (Size - II - 2);
478         Buffer[Size - II - 2] = uint8_t(Inst >> I0 * CHAR_BIT);
479         Buffer[Size - II - 1] = uint8_t(Inst >> I1 * CHAR_BIT);
480       }
481
482       break;
483     default:
484       llvm_unreachable("Invalid Suffix");
485     }
486
487     MCELFStreamer::EmitBytes(StringRef(Buffer, Size));
488   }
489
490   /// This is one of the functions used to emit data into an ELF section, so the
491   /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
492   /// necessary.
493   virtual void EmitBytes(StringRef Data) {
494     EmitDataMappingSymbol();
495     MCELFStreamer::EmitBytes(Data);
496   }
497
498   /// This is one of the functions used to emit data into an ELF section, so the
499   /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
500   /// necessary.
501   virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) {
502     EmitDataMappingSymbol();
503     MCELFStreamer::EmitValueImpl(Value, Size);
504   }
505
506   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {
507     MCELFStreamer::EmitAssemblerFlag(Flag);
508
509     switch (Flag) {
510     case MCAF_SyntaxUnified:
511       return; // no-op here.
512     case MCAF_Code16:
513       IsThumb = true;
514       return; // Change to Thumb mode
515     case MCAF_Code32:
516       IsThumb = false;
517       return; // Change to ARM mode
518     case MCAF_Code64:
519       return;
520     case MCAF_SubsectionsViaSymbols:
521       return;
522     }
523   }
524
525 private:
526   enum ElfMappingSymbol {
527     EMS_None,
528     EMS_ARM,
529     EMS_Thumb,
530     EMS_Data
531   };
532
533   void EmitDataMappingSymbol() {
534     if (LastEMS == EMS_Data) return;
535     EmitMappingSymbol("$d");
536     LastEMS = EMS_Data;
537   }
538
539   void EmitThumbMappingSymbol() {
540     if (LastEMS == EMS_Thumb) return;
541     EmitMappingSymbol("$t");
542     LastEMS = EMS_Thumb;
543   }
544
545   void EmitARMMappingSymbol() {
546     if (LastEMS == EMS_ARM) return;
547     EmitMappingSymbol("$a");
548     LastEMS = EMS_ARM;
549   }
550
551   void EmitMappingSymbol(StringRef Name) {
552     MCSymbol *Start = getContext().CreateTempSymbol();
553     EmitLabel(Start);
554
555     MCSymbol *Symbol =
556       getContext().GetOrCreateSymbol(Name + "." +
557                                      Twine(MappingSymbolCounter++));
558
559     MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
560     MCELF::SetType(SD, ELF::STT_NOTYPE);
561     MCELF::SetBinding(SD, ELF::STB_LOCAL);
562     SD.setExternal(false);
563     AssignSection(Symbol, getCurrentSection().first);
564
565     const MCExpr *Value = MCSymbolRefExpr::Create(Start, getContext());
566     Symbol->setVariableValue(Value);
567   }
568
569   void EmitThumbFunc(MCSymbol *Func) {
570     // FIXME: Anything needed here to flag the function as thumb?
571
572     getAssembler().setIsThumbFunc(Func);
573
574     MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Func);
575     SD.setFlags(SD.getFlags() | ELF_Other_ThumbFunc);
576   }
577
578   // Helper functions for ARM exception handling directives
579   void Reset();
580
581   void EmitPersonalityFixup(StringRef Name);
582   void FlushPendingOffset();
583   void FlushUnwindOpcodes(bool NoHandlerData);
584
585   void SwitchToEHSection(const char *Prefix, unsigned Type, unsigned Flags,
586                          SectionKind Kind, const MCSymbol &Fn);
587   void SwitchToExTabSection(const MCSymbol &FnStart);
588   void SwitchToExIdxSection(const MCSymbol &FnStart);
589
590   bool IsThumb;
591   int64_t MappingSymbolCounter;
592
593   DenseMap<const MCSection *, ElfMappingSymbol> LastMappingSymbols;
594   ElfMappingSymbol LastEMS;
595
596   // ARM Exception Handling Frame Information
597   MCSymbol *ExTab;
598   MCSymbol *FnStart;
599   const MCSymbol *Personality;
600   unsigned PersonalityIndex;
601   unsigned FPReg; // Frame pointer register
602   int64_t FPOffset; // Offset: (final frame pointer) - (initial $sp)
603   int64_t SPOffset; // Offset: (final $sp) - (initial $sp)
604   int64_t PendingOffset; // Offset: (final $sp) - (emitted $sp)
605   bool UsedFP;
606   bool CantUnwind;
607   SmallVector<uint8_t, 64> Opcodes;
608   UnwindOpcodeAssembler UnwindOpAsm;
609 };
610 } // end anonymous namespace
611
612 ARMELFStreamer &ARMTargetELFStreamer::getStreamer() {
613   ARMELFStreamer *S = static_cast<ARMELFStreamer *>(Streamer);
614   return *S;
615 }
616
617 void ARMTargetELFStreamer::emitFnStart() { getStreamer().emitFnStart(); }
618 void ARMTargetELFStreamer::emitFnEnd() { getStreamer().emitFnEnd(); }
619 void ARMTargetELFStreamer::emitCantUnwind() { getStreamer().emitCantUnwind(); }
620 void ARMTargetELFStreamer::emitPersonality(const MCSymbol *Personality) {
621   getStreamer().emitPersonality(Personality);
622 }
623 void ARMTargetELFStreamer::emitPersonalityIndex(unsigned Index) {
624   getStreamer().emitPersonalityIndex(Index);
625 }
626 void ARMTargetELFStreamer::emitHandlerData() {
627   getStreamer().emitHandlerData();
628 }
629 void ARMTargetELFStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
630                                      int64_t Offset) {
631   getStreamer().emitSetFP(FpReg, SpReg, Offset);
632 }
633 void ARMTargetELFStreamer::emitPad(int64_t Offset) {
634   getStreamer().emitPad(Offset);
635 }
636 void ARMTargetELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
637                                        bool isVector) {
638   getStreamer().emitRegSave(RegList, isVector);
639 }
640 void ARMTargetELFStreamer::switchVendor(StringRef Vendor) {
641   assert(!Vendor.empty() && "Vendor cannot be empty.");
642
643   if (CurrentVendor == Vendor)
644     return;
645
646   if (!CurrentVendor.empty())
647     finishAttributeSection();
648
649   assert(Contents.empty() &&
650          ".ARM.attributes should be flushed before changing vendor");
651   CurrentVendor = Vendor;
652
653 }
654 void ARMTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
655   setAttributeItem(Attribute, Value, /* OverwriteExisting= */ true);
656 }
657 void ARMTargetELFStreamer::emitTextAttribute(unsigned Attribute,
658                                              StringRef Value) {
659   setAttributeItem(Attribute, Value, /* OverwriteExisting= */ true);
660 }
661 void ARMTargetELFStreamer::emitIntTextAttribute(unsigned Attribute,
662                                                 unsigned IntValue,
663                                                 StringRef StringValue) {
664   setAttributeItems(Attribute, IntValue, StringValue,
665                     /* OverwriteExisting= */ true);
666 }
667 void ARMTargetELFStreamer::emitArch(unsigned Value) {
668   Arch = Value;
669 }
670 void ARMTargetELFStreamer::emitArchDefaultAttributes() {
671   using namespace ARMBuildAttrs;
672   setAttributeItem(CPU_name, GetArchDefaultCPUName(Arch), false);
673   setAttributeItem(CPU_arch, GetArchDefaultCPUArch(Arch), false);
674
675   switch (Arch) {
676   case ARM::ARMV2:
677   case ARM::ARMV2A:
678   case ARM::ARMV3:
679   case ARM::ARMV3M:
680   case ARM::ARMV4:
681   case ARM::ARMV5:
682     setAttributeItem(ARM_ISA_use, Allowed, false);
683     break;
684
685   case ARM::ARMV4T:
686   case ARM::ARMV5T:
687   case ARM::ARMV5TE:
688   case ARM::ARMV6:
689   case ARM::ARMV6J:
690     setAttributeItem(ARM_ISA_use, Allowed, false);
691     setAttributeItem(THUMB_ISA_use, Allowed, false);
692     break;
693
694   case ARM::ARMV6T2:
695     setAttributeItem(ARM_ISA_use, Allowed, false);
696     setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
697     break;
698
699   case ARM::ARMV6Z:
700   case ARM::ARMV6ZK:
701     setAttributeItem(ARM_ISA_use, Allowed, false);
702     setAttributeItem(THUMB_ISA_use, Allowed, false);
703     setAttributeItem(Virtualization_use, AllowTZ, false);
704     break;
705
706   case ARM::ARMV6M:
707     setAttributeItem(THUMB_ISA_use, Allowed, false);
708     break;
709
710   case ARM::ARMV7:
711     setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
712     break;
713
714   case ARM::ARMV7A:
715     setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
716     setAttributeItem(ARM_ISA_use, Allowed, false);
717     setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
718     break;
719
720   case ARM::ARMV7R:
721     setAttributeItem(CPU_arch_profile, RealTimeProfile, false);
722     setAttributeItem(ARM_ISA_use, Allowed, false);
723     setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
724     break;
725
726   case ARM::ARMV7M:
727     setAttributeItem(CPU_arch_profile, MicroControllerProfile, false);
728     setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
729     break;
730
731   case ARM::ARMV8A:
732     setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
733     setAttributeItem(ARM_ISA_use, Allowed, false);
734     setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
735     setAttributeItem(MPextension_use, Allowed, false);
736     setAttributeItem(Virtualization_use, AllowTZVirtualization, false);
737     break;
738
739   case ARM::IWMMXT:
740     setAttributeItem(ARM_ISA_use, Allowed, false);
741     setAttributeItem(THUMB_ISA_use, Allowed, false);
742     setAttributeItem(WMMX_arch, AllowWMMXv1, false);
743     break;
744
745   case ARM::IWMMXT2:
746     setAttributeItem(ARM_ISA_use, Allowed, false);
747     setAttributeItem(THUMB_ISA_use, Allowed, false);
748     setAttributeItem(WMMX_arch, AllowWMMXv2, false);
749     break;
750
751   default:
752     report_fatal_error("Unknown Arch: " + Twine(Arch));
753     break;
754   }
755 }
756 void ARMTargetELFStreamer::emitFPU(unsigned Value) {
757   FPU = Value;
758 }
759 void ARMTargetELFStreamer::emitFPUDefaultAttributes() {
760   switch (FPU) {
761   case ARM::VFP:
762   case ARM::VFPV2:
763     setAttributeItem(ARMBuildAttrs::FP_arch,
764                      ARMBuildAttrs::AllowFPv2,
765                      /* OverwriteExisting= */ false);
766     break;
767
768   case ARM::VFPV3:
769     setAttributeItem(ARMBuildAttrs::FP_arch,
770                      ARMBuildAttrs::AllowFPv3A,
771                      /* OverwriteExisting= */ false);
772     break;
773
774   case ARM::VFPV3_D16:
775     setAttributeItem(ARMBuildAttrs::FP_arch,
776                      ARMBuildAttrs::AllowFPv3B,
777                      /* OverwriteExisting= */ false);
778     break;
779
780   case ARM::VFPV4:
781     setAttributeItem(ARMBuildAttrs::FP_arch,
782                      ARMBuildAttrs::AllowFPv4A,
783                      /* OverwriteExisting= */ false);
784     break;
785
786   case ARM::VFPV4_D16:
787     setAttributeItem(ARMBuildAttrs::FP_arch,
788                      ARMBuildAttrs::AllowFPv4B,
789                      /* OverwriteExisting= */ false);
790     break;
791
792   case ARM::FP_ARMV8:
793     setAttributeItem(ARMBuildAttrs::FP_arch,
794                      ARMBuildAttrs::AllowFPARMv8A,
795                      /* OverwriteExisting= */ false);
796     break;
797
798   case ARM::NEON:
799     setAttributeItem(ARMBuildAttrs::FP_arch,
800                      ARMBuildAttrs::AllowFPv3A,
801                      /* OverwriteExisting= */ false);
802     setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
803                      ARMBuildAttrs::AllowNeon,
804                      /* OverwriteExisting= */ false);
805     break;
806
807   case ARM::NEON_VFPV4:
808     setAttributeItem(ARMBuildAttrs::FP_arch,
809                      ARMBuildAttrs::AllowFPv4A,
810                      /* OverwriteExisting= */ false);
811     setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
812                      ARMBuildAttrs::AllowNeon2,
813                      /* OverwriteExisting= */ false);
814     break;
815
816   case ARM::NEON_FP_ARMV8:
817   case ARM::CRYPTO_NEON_FP_ARMV8:
818     setAttributeItem(ARMBuildAttrs::FP_arch,
819                      ARMBuildAttrs::AllowFPARMv8A,
820                      /* OverwriteExisting= */ false);
821     setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
822                      ARMBuildAttrs::AllowNeonARMv8,
823                      /* OverwriteExisting= */ false);
824     break;
825
826   case ARM::SOFTVFP:
827     break;
828
829   default:
830     report_fatal_error("Unknown FPU: " + Twine(FPU));
831     break;
832   }
833 }
834 size_t ARMTargetELFStreamer::calculateContentSize() const {
835   size_t Result = 0;
836   for (size_t i = 0; i < Contents.size(); ++i) {
837     AttributeItem item = Contents[i];
838     switch (item.Type) {
839     case AttributeItem::HiddenAttribute:
840       break;
841     case AttributeItem::NumericAttribute:
842       Result += getULEBSize(item.Tag);
843       Result += getULEBSize(item.IntValue);
844       break;
845     case AttributeItem::TextAttribute:
846       Result += getULEBSize(item.Tag);
847       Result += item.StringValue.size() + 1; // string + '\0'
848       break;
849     case AttributeItem::NumericAndTextAttributes:
850       Result += getULEBSize(item.Tag);
851       Result += getULEBSize(item.IntValue);
852       Result += item.StringValue.size() + 1; // string + '\0';
853       break;
854     }
855   }
856   return Result;
857 }
858 void ARMTargetELFStreamer::finishAttributeSection() {
859   // <format-version>
860   // [ <section-length> "vendor-name"
861   // [ <file-tag> <size> <attribute>*
862   //   | <section-tag> <size> <section-number>* 0 <attribute>*
863   //   | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
864   //   ]+
865   // ]*
866
867   if (FPU != ARM::INVALID_FPU)
868     emitFPUDefaultAttributes();
869
870   if (Arch != ARM::INVALID_ARCH)
871     emitArchDefaultAttributes();
872
873   if (Contents.empty())
874     return;
875
876   std::sort(Contents.begin(), Contents.end(), AttributeItem::LessTag);
877
878   ARMELFStreamer &Streamer = getStreamer();
879
880   // Switch to .ARM.attributes section
881   if (AttributeSection) {
882     Streamer.SwitchSection(AttributeSection);
883   } else {
884     AttributeSection =
885       Streamer.getContext().getELFSection(".ARM.attributes",
886                                           ELF::SHT_ARM_ATTRIBUTES,
887                                           0,
888                                           SectionKind::getMetadata());
889     Streamer.SwitchSection(AttributeSection);
890
891     // Format version
892     Streamer.EmitIntValue(0x41, 1);
893   }
894
895   // Vendor size + Vendor name + '\0'
896   const size_t VendorHeaderSize = 4 + CurrentVendor.size() + 1;
897
898   // Tag + Tag Size
899   const size_t TagHeaderSize = 1 + 4;
900
901   const size_t ContentsSize = calculateContentSize();
902
903   Streamer.EmitIntValue(VendorHeaderSize + TagHeaderSize + ContentsSize, 4);
904   Streamer.EmitBytes(CurrentVendor);
905   Streamer.EmitIntValue(0, 1); // '\0'
906
907   Streamer.EmitIntValue(ARMBuildAttrs::File, 1);
908   Streamer.EmitIntValue(TagHeaderSize + ContentsSize, 4);
909
910   // Size should have been accounted for already, now
911   // emit each field as its type (ULEB or String)
912   for (size_t i = 0; i < Contents.size(); ++i) {
913     AttributeItem item = Contents[i];
914     Streamer.EmitULEB128IntValue(item.Tag);
915     switch (item.Type) {
916     default: llvm_unreachable("Invalid attribute type");
917     case AttributeItem::NumericAttribute:
918       Streamer.EmitULEB128IntValue(item.IntValue);
919       break;
920     case AttributeItem::TextAttribute:
921       Streamer.EmitBytes(item.StringValue.upper());
922       Streamer.EmitIntValue(0, 1); // '\0'
923       break;
924     case AttributeItem::NumericAndTextAttributes:
925       Streamer.EmitULEB128IntValue(item.IntValue);
926       Streamer.EmitBytes(item.StringValue.upper());
927       Streamer.EmitIntValue(0, 1); // '\0'
928       break;
929     }
930   }
931
932   Contents.clear();
933   FPU = ARM::INVALID_FPU;
934 }
935 void ARMTargetELFStreamer::emitInst(uint32_t Inst, char Suffix) {
936   getStreamer().emitInst(Inst, Suffix);
937 }
938
939 void ARMELFStreamer::FinishImpl() {
940   MCTargetStreamer &TS = *getTargetStreamer();
941   ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
942   ATS.finishAttributeSection();
943
944   MCELFStreamer::FinishImpl();
945 }
946
947 inline void ARMELFStreamer::SwitchToEHSection(const char *Prefix,
948                                               unsigned Type,
949                                               unsigned Flags,
950                                               SectionKind Kind,
951                                               const MCSymbol &Fn) {
952   const MCSectionELF &FnSection =
953     static_cast<const MCSectionELF &>(Fn.getSection());
954
955   // Create the name for new section
956   StringRef FnSecName(FnSection.getSectionName());
957   SmallString<128> EHSecName(Prefix);
958   if (FnSecName != ".text") {
959     EHSecName += FnSecName;
960   }
961
962   // Get .ARM.extab or .ARM.exidx section
963   const MCSectionELF *EHSection = NULL;
964   if (const MCSymbol *Group = FnSection.getGroup()) {
965     EHSection = getContext().getELFSection(
966       EHSecName, Type, Flags | ELF::SHF_GROUP, Kind,
967       FnSection.getEntrySize(), Group->getName());
968   } else {
969     EHSection = getContext().getELFSection(EHSecName, Type, Flags, Kind);
970   }
971   assert(EHSection && "Failed to get the required EH section");
972
973   // Switch to .ARM.extab or .ARM.exidx section
974   SwitchSection(EHSection);
975   EmitCodeAlignment(4, 0);
976 }
977
978 inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) {
979   SwitchToEHSection(".ARM.extab",
980                     ELF::SHT_PROGBITS,
981                     ELF::SHF_ALLOC,
982                     SectionKind::getDataRel(),
983                     FnStart);
984 }
985
986 inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {
987   SwitchToEHSection(".ARM.exidx",
988                     ELF::SHT_ARM_EXIDX,
989                     ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER,
990                     SectionKind::getDataRel(),
991                     FnStart);
992 }
993
994 void ARMELFStreamer::Reset() {
995   ExTab = NULL;
996   FnStart = NULL;
997   Personality = NULL;
998   PersonalityIndex = ARM::EHABI::NUM_PERSONALITY_INDEX;
999   FPReg = ARM::SP;
1000   FPOffset = 0;
1001   SPOffset = 0;
1002   PendingOffset = 0;
1003   UsedFP = false;
1004   CantUnwind = false;
1005
1006   Opcodes.clear();
1007   UnwindOpAsm.Reset();
1008 }
1009
1010 void ARMELFStreamer::emitFnStart() {
1011   assert(FnStart == 0);
1012   FnStart = getContext().CreateTempSymbol();
1013   EmitLabel(FnStart);
1014 }
1015
1016 void ARMELFStreamer::emitFnEnd() {
1017   assert(FnStart && ".fnstart must preceeds .fnend");
1018
1019   // Emit unwind opcodes if there is no .handlerdata directive
1020   if (!ExTab && !CantUnwind)
1021     FlushUnwindOpcodes(true);
1022
1023   // Emit the exception index table entry
1024   SwitchToExIdxSection(*FnStart);
1025
1026   if (PersonalityIndex < ARM::EHABI::NUM_PERSONALITY_INDEX)
1027     EmitPersonalityFixup(GetAEABIUnwindPersonalityName(PersonalityIndex));
1028
1029   const MCSymbolRefExpr *FnStartRef =
1030     MCSymbolRefExpr::Create(FnStart,
1031                             MCSymbolRefExpr::VK_ARM_PREL31,
1032                             getContext());
1033
1034   EmitValue(FnStartRef, 4);
1035
1036   if (CantUnwind) {
1037     EmitIntValue(ARM::EHABI::EXIDX_CANTUNWIND, 4);
1038   } else if (ExTab) {
1039     // Emit a reference to the unwind opcodes in the ".ARM.extab" section.
1040     const MCSymbolRefExpr *ExTabEntryRef =
1041       MCSymbolRefExpr::Create(ExTab,
1042                               MCSymbolRefExpr::VK_ARM_PREL31,
1043                               getContext());
1044     EmitValue(ExTabEntryRef, 4);
1045   } else {
1046     // For the __aeabi_unwind_cpp_pr0, we have to emit the unwind opcodes in
1047     // the second word of exception index table entry.  The size of the unwind
1048     // opcodes should always be 4 bytes.
1049     assert(PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0 &&
1050            "Compact model must use __aeabi_cpp_unwind_pr0 as personality");
1051     assert(Opcodes.size() == 4u &&
1052            "Unwind opcode size for __aeabi_cpp_unwind_pr0 must be equal to 4");
1053     EmitBytes(StringRef(reinterpret_cast<const char*>(Opcodes.data()),
1054                         Opcodes.size()));
1055   }
1056
1057   // Switch to the section containing FnStart
1058   SwitchSection(&FnStart->getSection());
1059
1060   // Clean exception handling frame information
1061   Reset();
1062 }
1063
1064 void ARMELFStreamer::emitCantUnwind() { CantUnwind = true; }
1065
1066 // Add the R_ARM_NONE fixup at the same position
1067 void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
1068   const MCSymbol *PersonalitySym = getContext().GetOrCreateSymbol(Name);
1069
1070   const MCSymbolRefExpr *PersonalityRef = MCSymbolRefExpr::Create(
1071       PersonalitySym, MCSymbolRefExpr::VK_ARM_NONE, getContext());
1072
1073   AddValueSymbols(PersonalityRef);
1074   MCDataFragment *DF = getOrCreateDataFragment();
1075   DF->getFixups().push_back(MCFixup::Create(DF->getContents().size(),
1076                                             PersonalityRef,
1077                                             MCFixup::getKindForSize(4, false)));
1078 }
1079
1080 void ARMELFStreamer::FlushPendingOffset() {
1081   if (PendingOffset != 0) {
1082     UnwindOpAsm.EmitSPOffset(-PendingOffset);
1083     PendingOffset = 0;
1084   }
1085 }
1086
1087 void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
1088   // Emit the unwind opcode to restore $sp.
1089   if (UsedFP) {
1090     const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1091     int64_t LastRegSaveSPOffset = SPOffset - PendingOffset;
1092     UnwindOpAsm.EmitSPOffset(LastRegSaveSPOffset - FPOffset);
1093     UnwindOpAsm.EmitSetSP(MRI->getEncodingValue(FPReg));
1094   } else {
1095     FlushPendingOffset();
1096   }
1097
1098   // Finalize the unwind opcode sequence
1099   UnwindOpAsm.Finalize(PersonalityIndex, Opcodes);
1100
1101   // For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx
1102   // section.  Thus, we don't have to create an entry in the .ARM.extab
1103   // section.
1104   if (NoHandlerData && PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0)
1105     return;
1106
1107   // Switch to .ARM.extab section.
1108   SwitchToExTabSection(*FnStart);
1109
1110   // Create .ARM.extab label for offset in .ARM.exidx
1111   assert(!ExTab);
1112   ExTab = getContext().CreateTempSymbol();
1113   EmitLabel(ExTab);
1114
1115   // Emit personality
1116   if (Personality) {
1117     const MCSymbolRefExpr *PersonalityRef =
1118       MCSymbolRefExpr::Create(Personality,
1119                               MCSymbolRefExpr::VK_ARM_PREL31,
1120                               getContext());
1121
1122     EmitValue(PersonalityRef, 4);
1123   }
1124
1125   // Emit unwind opcodes
1126   EmitBytes(StringRef(reinterpret_cast<const char *>(Opcodes.data()),
1127                       Opcodes.size()));
1128
1129   // According to ARM EHABI section 9.2, if the __aeabi_unwind_cpp_pr1() or
1130   // __aeabi_unwind_cpp_pr2() is used, then the handler data must be emitted
1131   // after the unwind opcodes.  The handler data consists of several 32-bit
1132   // words, and should be terminated by zero.
1133   //
1134   // In case that the .handlerdata directive is not specified by the
1135   // programmer, we should emit zero to terminate the handler data.
1136   if (NoHandlerData && !Personality)
1137     EmitIntValue(0, 4);
1138 }
1139
1140 void ARMELFStreamer::emitHandlerData() { FlushUnwindOpcodes(false); }
1141
1142 void ARMELFStreamer::emitPersonality(const MCSymbol *Per) {
1143   Personality = Per;
1144   UnwindOpAsm.setPersonality(Per);
1145 }
1146
1147 void ARMELFStreamer::emitPersonalityIndex(unsigned Index) {
1148   assert(Index < ARM::EHABI::NUM_PERSONALITY_INDEX && "invalid index");
1149   PersonalityIndex = Index;
1150 }
1151
1152 void ARMELFStreamer::emitSetFP(unsigned NewFPReg, unsigned NewSPReg,
1153                                int64_t Offset) {
1154   assert((NewSPReg == ARM::SP || NewSPReg == FPReg) &&
1155          "the operand of .setfp directive should be either $sp or $fp");
1156
1157   UsedFP = true;
1158   FPReg = NewFPReg;
1159
1160   if (NewSPReg == ARM::SP)
1161     FPOffset = SPOffset + Offset;
1162   else
1163     FPOffset += Offset;
1164 }
1165
1166 void ARMELFStreamer::emitPad(int64_t Offset) {
1167   // Track the change of the $sp offset
1168   SPOffset -= Offset;
1169
1170   // To squash multiple .pad directives, we should delay the unwind opcode
1171   // until the .save, .vsave, .handlerdata, or .fnend directives.
1172   PendingOffset -= Offset;
1173 }
1174
1175 void ARMELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
1176                                  bool IsVector) {
1177   // Collect the registers in the register list
1178   unsigned Count = 0;
1179   uint32_t Mask = 0;
1180   const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1181   for (size_t i = 0; i < RegList.size(); ++i) {
1182     unsigned Reg = MRI->getEncodingValue(RegList[i]);
1183     assert(Reg < (IsVector ? 32U : 16U) && "Register out of range");
1184     unsigned Bit = (1u << Reg);
1185     if ((Mask & Bit) == 0) {
1186       Mask |= Bit;
1187       ++Count;
1188     }
1189   }
1190
1191   // Track the change the $sp offset: For the .save directive, the
1192   // corresponding push instruction will decrease the $sp by (4 * Count).
1193   // For the .vsave directive, the corresponding vpush instruction will
1194   // decrease $sp by (8 * Count).
1195   SPOffset -= Count * (IsVector ? 8 : 4);
1196
1197   // Emit the opcode
1198   FlushPendingOffset();
1199   if (IsVector)
1200     UnwindOpAsm.EmitVFPRegSave(Mask);
1201   else
1202     UnwindOpAsm.EmitRegSave(Mask);
1203 }
1204
1205 namespace llvm {
1206
1207 MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
1208                                 bool isVerboseAsm, bool useLoc, bool useCFI,
1209                                 bool useDwarfDirectory,
1210                                 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
1211                                 MCAsmBackend *TAB, bool ShowInst) {
1212   ARMTargetAsmStreamer *S = new ARMTargetAsmStreamer(OS, *InstPrint,
1213                                                      isVerboseAsm);
1214
1215   return llvm::createAsmStreamer(Ctx, S, OS, isVerboseAsm, useLoc, useCFI,
1216                                  useDwarfDirectory, InstPrint, CE, TAB,
1217                                  ShowInst);
1218 }
1219
1220   MCELFStreamer* createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
1221                                       raw_ostream &OS, MCCodeEmitter *Emitter,
1222                                       bool RelaxAll, bool NoExecStack,
1223                                       bool IsThumb) {
1224     ARMTargetELFStreamer *TS = new ARMTargetELFStreamer();
1225     ARMELFStreamer *S =
1226         new ARMELFStreamer(Context, TS, TAB, OS, Emitter, IsThumb);
1227     // FIXME: This should eventually end up somewhere else where more
1228     // intelligent flag decisions can be made. For now we are just maintaining
1229     // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default.
1230     S->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
1231
1232     if (RelaxAll)
1233       S->getAssembler().setRelaxAll(true);
1234     if (NoExecStack)
1235       S->getAssembler().setNoExecStack(true);
1236     return S;
1237   }
1238
1239 }
1240
1241