blob: 44b56fbe199f56ada28ae01e8051c09ce6d4d140 [file] [log] [blame]
Tim Northover5cc3dc82012-12-07 16:50:23 +00001//===- 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
Logan Chien439e8f92013-12-11 17:16:25 +000016#include "ARMArchName.h"
Logan Chien8cbb80d2013-10-28 17:51:12 +000017#include "ARMFPUName.h"
Logan Chiend8bb4b72013-04-16 12:02:21 +000018#include "ARMRegisterInfo.h"
Logan Chiend8bb4b72013-04-16 12:02:21 +000019#include "ARMUnwindOpAsm.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000020#include "llvm/ADT/SmallPtrSet.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000021#include "llvm/ADT/StringExtras.h"
Benjamin Kramerf242d8c2012-12-08 10:45:24 +000022#include "llvm/ADT/Twine.h"
23#include "llvm/MC/MCAsmBackend.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000024#include "llvm/MC/MCAsmInfo.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000025#include "llvm/MC/MCAssembler.h"
26#include "llvm/MC/MCCodeEmitter.h"
27#include "llvm/MC/MCContext.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000028#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"
Rafael Espindolaa17151a2013-10-08 13:08:17 +000033#include "llvm/MC/MCInstPrinter.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000034#include "llvm/MC/MCObjectStreamer.h"
Logan Chiend8bb4b72013-04-16 12:02:21 +000035#include "llvm/MC/MCRegisterInfo.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000036#include "llvm/MC/MCSection.h"
Benjamin Kramerf242d8c2012-12-08 10:45:24 +000037#include "llvm/MC/MCSectionELF.h"
38#include "llvm/MC/MCStreamer.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000039#include "llvm/MC/MCSymbol.h"
40#include "llvm/MC/MCValue.h"
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +000041#include "llvm/Support/ARMBuildAttributes.h"
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +000042#include "llvm/Support/ARMEHABI.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000043#include "llvm/Support/Debug.h"
44#include "llvm/Support/ELF.h"
Rafael Espindolaa17151a2013-10-08 13:08:17 +000045#include "llvm/Support/FormattedStream.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000046#include "llvm/Support/raw_ostream.h"
Logan Chien8cbb80d2013-10-28 17:51:12 +000047#include <algorithm>
Tim Northover5cc3dc82012-12-07 16:50:23 +000048
49using namespace llvm;
50
Logan Chiend8bb4b72013-04-16 12:02:21 +000051static std::string GetAEABIUnwindPersonalityName(unsigned Index) {
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +000052 assert(Index < ARM::EHABI::NUM_PERSONALITY_INDEX &&
53 "Invalid personality index");
Logan Chiend8bb4b72013-04-16 12:02:21 +000054 return (Twine("__aeabi_unwind_cpp_pr") + Twine(Index)).str();
55}
56
Logan Chien8cbb80d2013-10-28 17:51:12 +000057static 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
Logan Chien439e8f92013-12-11 17:16:25 +000068static 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;
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +000075#define ARM_ARCH_ALIAS(NAME, ID) /* empty */
Logan Chien439e8f92013-12-11 17:16:25 +000076#include "ARMArchName.def"
77 }
78 return NULL;
79}
80
81static 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;
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +000088#define ARM_ARCH_ALIAS(NAME, ID) /* empty */
Logan Chien439e8f92013-12-11 17:16:25 +000089#include "ARMArchName.def"
90 }
91 return NULL;
92}
93
94static 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;
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +0000101#define ARM_ARCH_ALIAS(NAME, ID) /* empty */
Logan Chien439e8f92013-12-11 17:16:25 +0000102#include "ARMArchName.def"
103 }
104 return 0;
105}
106
Greg Fitzgerald1f6a6082014-01-22 18:32:35 +0000107void ARMTargetStreamer::anchor() {}
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000108ARMTargetStreamer::ARMTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
Greg Fitzgerald1f6a6082014-01-22 18:32:35 +0000109
Tim Northover5cc3dc82012-12-07 16:50:23 +0000110namespace {
111
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000112class ARMELFStreamer;
113
114class ARMTargetAsmStreamer : public ARMTargetStreamer {
115 formatted_raw_ostream &OS;
116 MCInstPrinter &InstPrinter;
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000117 bool IsVerboseAsm;
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000118
119 virtual void emitFnStart();
120 virtual void emitFnEnd();
121 virtual void emitCantUnwind();
122 virtual void emitPersonality(const MCSymbol *Personality);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000123 virtual void emitPersonalityIndex(unsigned Index);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000124 virtual void emitHandlerData();
125 virtual void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000126 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000127 virtual void emitPad(int64_t Offset);
128 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
129 bool isVector);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000130 virtual void emitUnwindRaw(int64_t Offset,
131 const SmallVectorImpl<uint8_t> &Opcodes);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000132
Logan Chien8cbb80d2013-10-28 17:51:12 +0000133 virtual void switchVendor(StringRef Vendor);
134 virtual void emitAttribute(unsigned Attribute, unsigned Value);
135 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000136 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
137 StringRef StrinValue);
Logan Chien439e8f92013-12-11 17:16:25 +0000138 virtual void emitArch(unsigned Arch);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000139 virtual void emitObjectArch(unsigned Arch);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000140 virtual void emitFPU(unsigned FPU);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000141 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
Logan Chien8cbb80d2013-10-28 17:51:12 +0000142 virtual void finishAttributeSection();
143
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000144 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
145
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000146public:
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000147 ARMTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS,
148 MCInstPrinter &InstPrinter, bool VerboseAsm);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000149};
150
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000151ARMTargetAsmStreamer::ARMTargetAsmStreamer(MCStreamer &S,
152 formatted_raw_ostream &OS,
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000153 MCInstPrinter &InstPrinter,
154 bool VerboseAsm)
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000155 : ARMTargetStreamer(S), OS(OS), InstPrinter(InstPrinter),
156 IsVerboseAsm(VerboseAsm) {}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000157void ARMTargetAsmStreamer::emitFnStart() { OS << "\t.fnstart\n"; }
158void ARMTargetAsmStreamer::emitFnEnd() { OS << "\t.fnend\n"; }
159void ARMTargetAsmStreamer::emitCantUnwind() { OS << "\t.cantunwind\n"; }
160void ARMTargetAsmStreamer::emitPersonality(const MCSymbol *Personality) {
161 OS << "\t.personality " << Personality->getName() << '\n';
162}
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000163void ARMTargetAsmStreamer::emitPersonalityIndex(unsigned Index) {
164 OS << "\t.personalityindex " << Index << '\n';
165}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000166void ARMTargetAsmStreamer::emitHandlerData() { OS << "\t.handlerdata\n"; }
167void ARMTargetAsmStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
168 int64_t Offset) {
169 OS << "\t.setfp\t";
170 InstPrinter.printRegName(OS, FpReg);
171 OS << ", ";
172 InstPrinter.printRegName(OS, SpReg);
173 if (Offset)
174 OS << ", #" << Offset;
175 OS << '\n';
176}
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000177void ARMTargetAsmStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
178 assert((Reg != ARM::SP && Reg != ARM::PC) &&
179 "the operand of .movsp cannot be either sp or pc");
180
181 OS << "\t.movsp\t";
182 InstPrinter.printRegName(OS, Reg);
183 if (Offset)
184 OS << ", #" << Offset;
185 OS << '\n';
186}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000187void ARMTargetAsmStreamer::emitPad(int64_t Offset) {
188 OS << "\t.pad\t#" << Offset << '\n';
189}
190void ARMTargetAsmStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
191 bool isVector) {
192 assert(RegList.size() && "RegList should not be empty");
193 if (isVector)
194 OS << "\t.vsave\t{";
195 else
196 OS << "\t.save\t{";
197
198 InstPrinter.printRegName(OS, RegList[0]);
199
200 for (unsigned i = 1, e = RegList.size(); i != e; ++i) {
201 OS << ", ";
202 InstPrinter.printRegName(OS, RegList[i]);
203 }
204
205 OS << "}\n";
206}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000207void ARMTargetAsmStreamer::switchVendor(StringRef Vendor) {
208}
209void ARMTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000210 OS << "\t.eabi_attribute\t" << Attribute << ", " << Twine(Value);
211 if (IsVerboseAsm) {
212 StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute);
213 if (!Name.empty())
214 OS << "\t@ " << Name;
215 }
216 OS << "\n";
Logan Chien8cbb80d2013-10-28 17:51:12 +0000217}
218void ARMTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
219 StringRef String) {
220 switch (Attribute) {
Logan Chien8cbb80d2013-10-28 17:51:12 +0000221 case ARMBuildAttrs::CPU_name:
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000222 OS << "\t.cpu\t" << String.lower();
223 break;
224 default:
225 OS << "\t.eabi_attribute\t" << Attribute << ", \"" << String << "\"";
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000226 if (IsVerboseAsm) {
227 StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute);
228 if (!Name.empty())
229 OS << "\t@ " << Name;
230 }
Logan Chien8cbb80d2013-10-28 17:51:12 +0000231 break;
232 }
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000233 OS << "\n";
234}
235void ARMTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
236 unsigned IntValue,
237 StringRef StringValue) {
238 switch (Attribute) {
239 default: llvm_unreachable("unsupported multi-value attribute in asm mode");
240 case ARMBuildAttrs::compatibility:
241 OS << "\t.eabi_attribute\t" << Attribute << ", " << IntValue;
242 if (!StringValue.empty())
243 OS << ", \"" << StringValue << "\"";
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000244 if (IsVerboseAsm)
245 OS << "\t@ " << ARMBuildAttrs::AttrTypeAsString(Attribute);
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000246 break;
247 }
248 OS << "\n";
Logan Chien8cbb80d2013-10-28 17:51:12 +0000249}
Logan Chien439e8f92013-12-11 17:16:25 +0000250void ARMTargetAsmStreamer::emitArch(unsigned Arch) {
251 OS << "\t.arch\t" << GetArchName(Arch) << "\n";
252}
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000253void ARMTargetAsmStreamer::emitObjectArch(unsigned Arch) {
254 OS << "\t.object_arch\t" << GetArchName(Arch) << '\n';
255}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000256void ARMTargetAsmStreamer::emitFPU(unsigned FPU) {
257 OS << "\t.fpu\t" << GetFPUName(FPU) << "\n";
258}
259void ARMTargetAsmStreamer::finishAttributeSection() {
260}
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000261void
262ARMTargetAsmStreamer::AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *S) {
263 OS << "\t.tlsdescseq\t" << S->getSymbol().getName();
264}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000265
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000266void ARMTargetAsmStreamer::emitInst(uint32_t Inst, char Suffix) {
267 OS << "\t.inst";
268 if (Suffix)
269 OS << "." << Suffix;
270 OS << "\t0x" << utohexstr(Inst) << "\n";
271}
272
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000273void ARMTargetAsmStreamer::emitUnwindRaw(int64_t Offset,
274 const SmallVectorImpl<uint8_t> &Opcodes) {
275 OS << "\t.unwind_raw " << Offset;
276 for (SmallVectorImpl<uint8_t>::const_iterator OCI = Opcodes.begin(),
277 OCE = Opcodes.end();
278 OCI != OCE; ++OCI)
279 OS << ", 0x" << utohexstr(*OCI);
280 OS << '\n';
281}
282
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000283class ARMTargetELFStreamer : public ARMTargetStreamer {
Logan Chien8cbb80d2013-10-28 17:51:12 +0000284private:
285 // This structure holds all attributes, accounting for
286 // their string/numeric value, so we can later emmit them
287 // in declaration order, keeping all in the same vector
288 struct AttributeItem {
289 enum {
290 HiddenAttribute = 0,
291 NumericAttribute,
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000292 TextAttribute,
293 NumericAndTextAttributes
Logan Chien8cbb80d2013-10-28 17:51:12 +0000294 } Type;
295 unsigned Tag;
296 unsigned IntValue;
297 StringRef StringValue;
298
299 static bool LessTag(const AttributeItem &LHS, const AttributeItem &RHS) {
300 return (LHS.Tag < RHS.Tag);
301 }
302 };
303
304 StringRef CurrentVendor;
305 unsigned FPU;
Logan Chien439e8f92013-12-11 17:16:25 +0000306 unsigned Arch;
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000307 unsigned EmittedArch;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000308 SmallVector<AttributeItem, 64> Contents;
309
310 const MCSection *AttributeSection;
311
312 // FIXME: this should be in a more generic place, but
313 // getULEBSize() is in MCAsmInfo and will be moved to MCDwarf
314 static size_t getULEBSize(int Value) {
315 size_t Size = 0;
316 do {
317 Value >>= 7;
318 Size += sizeof(int8_t); // Is this really necessary?
319 } while (Value);
320 return Size;
321 }
322
323 AttributeItem *getAttributeItem(unsigned Attribute) {
324 for (size_t i = 0; i < Contents.size(); ++i)
325 if (Contents[i].Tag == Attribute)
326 return &Contents[i];
327 return 0;
328 }
329
330 void setAttributeItem(unsigned Attribute, unsigned Value,
331 bool OverwriteExisting) {
332 // Look for existing attribute item
333 if (AttributeItem *Item = getAttributeItem(Attribute)) {
334 if (!OverwriteExisting)
335 return;
Saleem Abdulrasool93900052014-01-19 08:25:41 +0000336 Item->Type = AttributeItem::NumericAttribute;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000337 Item->IntValue = Value;
338 return;
339 }
340
341 // Create new attribute item
342 AttributeItem Item = {
343 AttributeItem::NumericAttribute,
344 Attribute,
345 Value,
346 StringRef("")
347 };
348 Contents.push_back(Item);
349 }
350
351 void setAttributeItem(unsigned Attribute, StringRef Value,
352 bool OverwriteExisting) {
353 // Look for existing attribute item
354 if (AttributeItem *Item = getAttributeItem(Attribute)) {
355 if (!OverwriteExisting)
356 return;
Saleem Abdulrasool93900052014-01-19 08:25:41 +0000357 Item->Type = AttributeItem::TextAttribute;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000358 Item->StringValue = Value;
359 return;
360 }
361
362 // Create new attribute item
363 AttributeItem Item = {
364 AttributeItem::TextAttribute,
365 Attribute,
366 0,
367 Value
368 };
369 Contents.push_back(Item);
370 }
371
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000372 void setAttributeItems(unsigned Attribute, unsigned IntValue,
373 StringRef StringValue, bool OverwriteExisting) {
374 // Look for existing attribute item
375 if (AttributeItem *Item = getAttributeItem(Attribute)) {
376 if (!OverwriteExisting)
377 return;
Saleem Abdulrasool93900052014-01-19 08:25:41 +0000378 Item->Type = AttributeItem::NumericAndTextAttributes;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000379 Item->IntValue = IntValue;
380 Item->StringValue = StringValue;
381 return;
382 }
383
384 // Create new attribute item
385 AttributeItem Item = {
386 AttributeItem::NumericAndTextAttributes,
387 Attribute,
388 IntValue,
389 StringValue
390 };
391 Contents.push_back(Item);
392 }
393
Logan Chien439e8f92013-12-11 17:16:25 +0000394 void emitArchDefaultAttributes();
Logan Chien8cbb80d2013-10-28 17:51:12 +0000395 void emitFPUDefaultAttributes();
396
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000397 ARMELFStreamer &getStreamer();
Logan Chien8cbb80d2013-10-28 17:51:12 +0000398
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000399 virtual void emitFnStart();
400 virtual void emitFnEnd();
401 virtual void emitCantUnwind();
402 virtual void emitPersonality(const MCSymbol *Personality);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000403 virtual void emitPersonalityIndex(unsigned Index);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000404 virtual void emitHandlerData();
405 virtual void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000406 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000407 virtual void emitPad(int64_t Offset);
408 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
409 bool isVector);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000410 virtual void emitUnwindRaw(int64_t Offset,
411 const SmallVectorImpl<uint8_t> &Opcodes);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000412
413 virtual void switchVendor(StringRef Vendor);
414 virtual void emitAttribute(unsigned Attribute, unsigned Value);
415 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000416 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
417 StringRef StringValue);
Logan Chien439e8f92013-12-11 17:16:25 +0000418 virtual void emitArch(unsigned Arch);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000419 virtual void emitObjectArch(unsigned Arch);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000420 virtual void emitFPU(unsigned FPU);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000421 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
Logan Chien8cbb80d2013-10-28 17:51:12 +0000422 virtual void finishAttributeSection();
423
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000424 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
425
Logan Chien8cbb80d2013-10-28 17:51:12 +0000426 size_t calculateContentSize() const;
427
428public:
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000429 ARMTargetELFStreamer(MCStreamer &S)
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000430 : ARMTargetStreamer(S), CurrentVendor("aeabi"), FPU(ARM::INVALID_FPU),
431 Arch(ARM::INVALID_ARCH), EmittedArch(ARM::INVALID_ARCH),
432 AttributeSection(0) {}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000433};
434
Tim Northover5cc3dc82012-12-07 16:50:23 +0000435/// Extend the generic ELFStreamer class so that it can emit mapping symbols at
436/// the appropriate points in the object files. These symbols are defined in the
437/// ARM ELF ABI: infocenter.arm.com/help/topic/com.arm.../IHI0044D_aaelf.pdf.
438///
439/// In brief: $a, $t or $d should be emitted at the start of each contiguous
440/// region of ARM code, Thumb code or data in a section. In practice, this
441/// emission does not rely on explicit assembler directives but on inherent
442/// properties of the directives doing the emission (e.g. ".byte" is data, "add
443/// r0, r0, r0" an instruction).
444///
445/// As a result this system is orthogonal to the DataRegion infrastructure used
446/// by MachO. Beware!
447class ARMELFStreamer : public MCELFStreamer {
448public:
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000449 friend class ARMTargetELFStreamer;
450
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000451 ARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS,
452 MCCodeEmitter *Emitter, bool IsThumb)
453 : MCELFStreamer(Context, TAB, OS, Emitter), IsThumb(IsThumb),
454 MappingSymbolCounter(0), LastEMS(EMS_None) {
Logan Chiend8bb4b72013-04-16 12:02:21 +0000455 Reset();
456 }
Tim Northover5cc3dc82012-12-07 16:50:23 +0000457
458 ~ARMELFStreamer() {}
459
Logan Chien8cbb80d2013-10-28 17:51:12 +0000460 virtual void FinishImpl();
461
Logan Chien2bcc42c2013-01-30 15:39:04 +0000462 // ARM exception handling directives
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000463 void emitFnStart();
464 void emitFnEnd();
465 void emitCantUnwind();
466 void emitPersonality(const MCSymbol *Per);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000467 void emitPersonalityIndex(unsigned index);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000468 void emitHandlerData();
469 void emitSetFP(unsigned NewFpReg, unsigned NewSpReg, int64_t Offset = 0);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000470 void emitMovSP(unsigned Reg, int64_t Offset = 0);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000471 void emitPad(int64_t Offset);
472 void emitRegSave(const SmallVectorImpl<unsigned> &RegList, bool isVector);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000473 void emitUnwindRaw(int64_t Offset, const SmallVectorImpl<uint8_t> &Opcodes);
Logan Chien2bcc42c2013-01-30 15:39:04 +0000474
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000475 virtual void ChangeSection(const MCSection *Section,
476 const MCExpr *Subsection) {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000477 // We have to keep track of the mapping symbol state of any sections we
478 // use. Each one should start off as EMS_None, which is provided as the
479 // default constructor by DenseMap::lookup.
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000480 LastMappingSymbols[getPreviousSection().first] = LastEMS;
Tim Northover5cc3dc82012-12-07 16:50:23 +0000481 LastEMS = LastMappingSymbols.lookup(Section);
482
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000483 MCELFStreamer::ChangeSection(Section, Subsection);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000484 }
485
486 /// This function is the one used to emit instruction data into the ELF
487 /// streamer. We override it to add the appropriate mapping symbol if
488 /// necessary.
David Woodhousee6c13e42014-01-28 23:12:42 +0000489 virtual void EmitInstruction(const MCInst& Inst, const MCSubtargetInfo &STI) {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000490 if (IsThumb)
491 EmitThumbMappingSymbol();
492 else
493 EmitARMMappingSymbol();
494
David Woodhousee6c13e42014-01-28 23:12:42 +0000495 MCELFStreamer::EmitInstruction(Inst, STI);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000496 }
497
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000498 virtual void emitInst(uint32_t Inst, char Suffix) {
499 unsigned Size;
500 char Buffer[4];
501 const bool LittleEndian = getContext().getAsmInfo()->isLittleEndian();
502
503 switch (Suffix) {
504 case '\0':
505 Size = 4;
506
507 assert(!IsThumb);
508 EmitARMMappingSymbol();
509 for (unsigned II = 0, IE = Size; II != IE; II++) {
510 const unsigned I = LittleEndian ? (Size - II - 1) : II;
511 Buffer[Size - II - 1] = uint8_t(Inst >> I * CHAR_BIT);
512 }
513
514 break;
515 case 'n':
516 case 'w':
517 Size = (Suffix == 'n' ? 2 : 4);
518
519 assert(IsThumb);
520 EmitThumbMappingSymbol();
521 for (unsigned II = 0, IE = Size; II != IE; II = II + 2) {
522 const unsigned I0 = LittleEndian ? II + 0 : (Size - II - 1);
523 const unsigned I1 = LittleEndian ? II + 1 : (Size - II - 2);
524 Buffer[Size - II - 2] = uint8_t(Inst >> I0 * CHAR_BIT);
525 Buffer[Size - II - 1] = uint8_t(Inst >> I1 * CHAR_BIT);
526 }
527
528 break;
529 default:
530 llvm_unreachable("Invalid Suffix");
531 }
532
533 MCELFStreamer::EmitBytes(StringRef(Buffer, Size));
534 }
535
Tim Northover5cc3dc82012-12-07 16:50:23 +0000536 /// This is one of the functions used to emit data into an ELF section, so the
537 /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
538 /// necessary.
Rafael Espindola64e1af82013-07-02 15:49:13 +0000539 virtual void EmitBytes(StringRef Data) {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000540 EmitDataMappingSymbol();
Rafael Espindola64e1af82013-07-02 15:49:13 +0000541 MCELFStreamer::EmitBytes(Data);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000542 }
543
544 /// This is one of the functions used to emit data into an ELF section, so the
545 /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
546 /// necessary.
Rafael Espindola64e1af82013-07-02 15:49:13 +0000547 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000548 EmitDataMappingSymbol();
Rafael Espindola64e1af82013-07-02 15:49:13 +0000549 MCELFStreamer::EmitValueImpl(Value, Size);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000550 }
551
552 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {
553 MCELFStreamer::EmitAssemblerFlag(Flag);
554
555 switch (Flag) {
556 case MCAF_SyntaxUnified:
557 return; // no-op here.
558 case MCAF_Code16:
559 IsThumb = true;
560 return; // Change to Thumb mode
561 case MCAF_Code32:
562 IsThumb = false;
563 return; // Change to ARM mode
564 case MCAF_Code64:
565 return;
566 case MCAF_SubsectionsViaSymbols:
567 return;
568 }
569 }
570
571private:
572 enum ElfMappingSymbol {
573 EMS_None,
574 EMS_ARM,
575 EMS_Thumb,
576 EMS_Data
577 };
578
579 void EmitDataMappingSymbol() {
580 if (LastEMS == EMS_Data) return;
581 EmitMappingSymbol("$d");
582 LastEMS = EMS_Data;
583 }
584
585 void EmitThumbMappingSymbol() {
586 if (LastEMS == EMS_Thumb) return;
587 EmitMappingSymbol("$t");
588 LastEMS = EMS_Thumb;
589 }
590
591 void EmitARMMappingSymbol() {
592 if (LastEMS == EMS_ARM) return;
593 EmitMappingSymbol("$a");
594 LastEMS = EMS_ARM;
595 }
596
597 void EmitMappingSymbol(StringRef Name) {
598 MCSymbol *Start = getContext().CreateTempSymbol();
599 EmitLabel(Start);
600
Chandler Carruth1d94e932012-12-08 03:10:14 +0000601 MCSymbol *Symbol =
Benjamin Kramerf242d8c2012-12-08 10:45:24 +0000602 getContext().GetOrCreateSymbol(Name + "." +
603 Twine(MappingSymbolCounter++));
Tim Northover5cc3dc82012-12-07 16:50:23 +0000604
605 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
606 MCELF::SetType(SD, ELF::STT_NOTYPE);
607 MCELF::SetBinding(SD, ELF::STB_LOCAL);
608 SD.setExternal(false);
Richard Mitton21101b32013-09-19 23:21:01 +0000609 AssignSection(Symbol, getCurrentSection().first);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000610
611 const MCExpr *Value = MCSymbolRefExpr::Create(Start, getContext());
612 Symbol->setVariableValue(Value);
613 }
614
615 void EmitThumbFunc(MCSymbol *Func) {
616 // FIXME: Anything needed here to flag the function as thumb?
617
618 getAssembler().setIsThumbFunc(Func);
619
620 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Func);
621 SD.setFlags(SD.getFlags() | ELF_Other_ThumbFunc);
622 }
623
Logan Chien2bcc42c2013-01-30 15:39:04 +0000624 // Helper functions for ARM exception handling directives
625 void Reset();
626
627 void EmitPersonalityFixup(StringRef Name);
Logan Chien325823a2013-06-09 12:22:30 +0000628 void FlushPendingOffset();
Logan Chienc931fce2013-07-02 12:43:27 +0000629 void FlushUnwindOpcodes(bool NoHandlerData);
Logan Chien2bcc42c2013-01-30 15:39:04 +0000630
631 void SwitchToEHSection(const char *Prefix, unsigned Type, unsigned Flags,
632 SectionKind Kind, const MCSymbol &Fn);
633 void SwitchToExTabSection(const MCSymbol &FnStart);
634 void SwitchToExIdxSection(const MCSymbol &FnStart);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000635
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000636 void EmitFixup(const MCExpr *Expr, MCFixupKind Kind);
637
Tim Northover5cc3dc82012-12-07 16:50:23 +0000638 bool IsThumb;
639 int64_t MappingSymbolCounter;
640
641 DenseMap<const MCSection *, ElfMappingSymbol> LastMappingSymbols;
642 ElfMappingSymbol LastEMS;
643
Logan Chien2bcc42c2013-01-30 15:39:04 +0000644 // ARM Exception Handling Frame Information
645 MCSymbol *ExTab;
646 MCSymbol *FnStart;
647 const MCSymbol *Personality;
Logan Chien325823a2013-06-09 12:22:30 +0000648 unsigned PersonalityIndex;
649 unsigned FPReg; // Frame pointer register
650 int64_t FPOffset; // Offset: (final frame pointer) - (initial $sp)
651 int64_t SPOffset; // Offset: (final $sp) - (initial $sp)
652 int64_t PendingOffset; // Offset: (final $sp) - (emitted $sp)
Logan Chiend8bb4b72013-04-16 12:02:21 +0000653 bool UsedFP;
Logan Chien2bcc42c2013-01-30 15:39:04 +0000654 bool CantUnwind;
Logan Chien325823a2013-06-09 12:22:30 +0000655 SmallVector<uint8_t, 64> Opcodes;
Logan Chiend8bb4b72013-04-16 12:02:21 +0000656 UnwindOpcodeAssembler UnwindOpAsm;
Tim Northover5cc3dc82012-12-07 16:50:23 +0000657};
Logan Chiend8bb4b72013-04-16 12:02:21 +0000658} // end anonymous namespace
Tim Northover5cc3dc82012-12-07 16:50:23 +0000659
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000660ARMELFStreamer &ARMTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000661 return static_cast<ARMELFStreamer &>(Streamer);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000662}
663
664void ARMTargetELFStreamer::emitFnStart() { getStreamer().emitFnStart(); }
665void ARMTargetELFStreamer::emitFnEnd() { getStreamer().emitFnEnd(); }
666void ARMTargetELFStreamer::emitCantUnwind() { getStreamer().emitCantUnwind(); }
667void ARMTargetELFStreamer::emitPersonality(const MCSymbol *Personality) {
668 getStreamer().emitPersonality(Personality);
669}
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000670void ARMTargetELFStreamer::emitPersonalityIndex(unsigned Index) {
671 getStreamer().emitPersonalityIndex(Index);
672}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000673void ARMTargetELFStreamer::emitHandlerData() {
674 getStreamer().emitHandlerData();
675}
676void ARMTargetELFStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
677 int64_t Offset) {
678 getStreamer().emitSetFP(FpReg, SpReg, Offset);
679}
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000680void ARMTargetELFStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
681 getStreamer().emitMovSP(Reg, Offset);
682}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000683void ARMTargetELFStreamer::emitPad(int64_t Offset) {
684 getStreamer().emitPad(Offset);
685}
686void ARMTargetELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
687 bool isVector) {
688 getStreamer().emitRegSave(RegList, isVector);
689}
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000690void ARMTargetELFStreamer::emitUnwindRaw(int64_t Offset,
691 const SmallVectorImpl<uint8_t> &Opcodes) {
692 getStreamer().emitUnwindRaw(Offset, Opcodes);
693}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000694void ARMTargetELFStreamer::switchVendor(StringRef Vendor) {
695 assert(!Vendor.empty() && "Vendor cannot be empty.");
696
697 if (CurrentVendor == Vendor)
698 return;
699
700 if (!CurrentVendor.empty())
701 finishAttributeSection();
702
703 assert(Contents.empty() &&
704 ".ARM.attributes should be flushed before changing vendor");
705 CurrentVendor = Vendor;
706
707}
708void ARMTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
709 setAttributeItem(Attribute, Value, /* OverwriteExisting= */ true);
710}
711void ARMTargetELFStreamer::emitTextAttribute(unsigned Attribute,
712 StringRef Value) {
713 setAttributeItem(Attribute, Value, /* OverwriteExisting= */ true);
714}
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000715void ARMTargetELFStreamer::emitIntTextAttribute(unsigned Attribute,
716 unsigned IntValue,
717 StringRef StringValue) {
718 setAttributeItems(Attribute, IntValue, StringValue,
719 /* OverwriteExisting= */ true);
720}
Logan Chien439e8f92013-12-11 17:16:25 +0000721void ARMTargetELFStreamer::emitArch(unsigned Value) {
722 Arch = Value;
723}
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000724void ARMTargetELFStreamer::emitObjectArch(unsigned Value) {
725 EmittedArch = Value;
726}
Logan Chien439e8f92013-12-11 17:16:25 +0000727void ARMTargetELFStreamer::emitArchDefaultAttributes() {
728 using namespace ARMBuildAttrs;
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000729
Logan Chien439e8f92013-12-11 17:16:25 +0000730 setAttributeItem(CPU_name, GetArchDefaultCPUName(Arch), false);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000731 if (EmittedArch == ARM::INVALID_ARCH)
732 setAttributeItem(CPU_arch, GetArchDefaultCPUArch(Arch), false);
733 else
734 setAttributeItem(CPU_arch, GetArchDefaultCPUArch(EmittedArch), false);
Logan Chien439e8f92013-12-11 17:16:25 +0000735
736 switch (Arch) {
737 case ARM::ARMV2:
738 case ARM::ARMV2A:
739 case ARM::ARMV3:
740 case ARM::ARMV3M:
741 case ARM::ARMV4:
742 case ARM::ARMV5:
743 setAttributeItem(ARM_ISA_use, Allowed, false);
744 break;
745
746 case ARM::ARMV4T:
747 case ARM::ARMV5T:
748 case ARM::ARMV5TE:
749 case ARM::ARMV6:
750 case ARM::ARMV6J:
751 setAttributeItem(ARM_ISA_use, Allowed, false);
752 setAttributeItem(THUMB_ISA_use, Allowed, false);
753 break;
754
755 case ARM::ARMV6T2:
756 setAttributeItem(ARM_ISA_use, Allowed, false);
757 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
758 break;
759
760 case ARM::ARMV6Z:
761 case ARM::ARMV6ZK:
762 setAttributeItem(ARM_ISA_use, Allowed, false);
763 setAttributeItem(THUMB_ISA_use, Allowed, false);
764 setAttributeItem(Virtualization_use, AllowTZ, false);
765 break;
766
767 case ARM::ARMV6M:
Logan Chien439e8f92013-12-11 17:16:25 +0000768 setAttributeItem(THUMB_ISA_use, Allowed, false);
769 break;
770
771 case ARM::ARMV7:
772 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
773 break;
774
775 case ARM::ARMV7A:
776 setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
777 setAttributeItem(ARM_ISA_use, Allowed, false);
778 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
779 break;
780
781 case ARM::ARMV7R:
782 setAttributeItem(CPU_arch_profile, RealTimeProfile, false);
783 setAttributeItem(ARM_ISA_use, Allowed, false);
784 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
785 break;
786
787 case ARM::ARMV7M:
788 setAttributeItem(CPU_arch_profile, MicroControllerProfile, false);
789 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
790 break;
791
792 case ARM::ARMV8A:
793 setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
794 setAttributeItem(ARM_ISA_use, Allowed, false);
795 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
796 setAttributeItem(MPextension_use, Allowed, false);
797 setAttributeItem(Virtualization_use, AllowTZVirtualization, false);
798 break;
799
800 case ARM::IWMMXT:
801 setAttributeItem(ARM_ISA_use, Allowed, false);
802 setAttributeItem(THUMB_ISA_use, Allowed, false);
803 setAttributeItem(WMMX_arch, AllowWMMXv1, false);
804 break;
805
806 case ARM::IWMMXT2:
807 setAttributeItem(ARM_ISA_use, Allowed, false);
808 setAttributeItem(THUMB_ISA_use, Allowed, false);
809 setAttributeItem(WMMX_arch, AllowWMMXv2, false);
810 break;
811
812 default:
813 report_fatal_error("Unknown Arch: " + Twine(Arch));
814 break;
815 }
816}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000817void ARMTargetELFStreamer::emitFPU(unsigned Value) {
818 FPU = Value;
819}
820void ARMTargetELFStreamer::emitFPUDefaultAttributes() {
821 switch (FPU) {
822 case ARM::VFP:
823 case ARM::VFPV2:
Logan Chiena39510a2013-12-18 17:23:15 +0000824 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000825 ARMBuildAttrs::AllowFPv2,
826 /* OverwriteExisting= */ false);
827 break;
828
829 case ARM::VFPV3:
Logan Chiena39510a2013-12-18 17:23:15 +0000830 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000831 ARMBuildAttrs::AllowFPv3A,
832 /* OverwriteExisting= */ false);
833 break;
834
835 case ARM::VFPV3_D16:
Logan Chiena39510a2013-12-18 17:23:15 +0000836 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000837 ARMBuildAttrs::AllowFPv3B,
838 /* OverwriteExisting= */ false);
839 break;
840
841 case ARM::VFPV4:
Logan Chiena39510a2013-12-18 17:23:15 +0000842 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000843 ARMBuildAttrs::AllowFPv4A,
844 /* OverwriteExisting= */ false);
845 break;
846
847 case ARM::VFPV4_D16:
Logan Chiena39510a2013-12-18 17:23:15 +0000848 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000849 ARMBuildAttrs::AllowFPv4B,
850 /* OverwriteExisting= */ false);
851 break;
852
853 case ARM::FP_ARMV8:
Logan Chiena39510a2013-12-18 17:23:15 +0000854 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000855 ARMBuildAttrs::AllowFPARMv8A,
856 /* OverwriteExisting= */ false);
857 break;
858
859 case ARM::NEON:
Logan Chiena39510a2013-12-18 17:23:15 +0000860 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000861 ARMBuildAttrs::AllowFPv3A,
862 /* OverwriteExisting= */ false);
863 setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
864 ARMBuildAttrs::AllowNeon,
865 /* OverwriteExisting= */ false);
866 break;
867
868 case ARM::NEON_VFPV4:
Logan Chiena39510a2013-12-18 17:23:15 +0000869 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000870 ARMBuildAttrs::AllowFPv4A,
871 /* OverwriteExisting= */ false);
872 setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
873 ARMBuildAttrs::AllowNeon2,
874 /* OverwriteExisting= */ false);
875 break;
876
877 case ARM::NEON_FP_ARMV8:
878 case ARM::CRYPTO_NEON_FP_ARMV8:
Logan Chiena39510a2013-12-18 17:23:15 +0000879 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000880 ARMBuildAttrs::AllowFPARMv8A,
881 /* OverwriteExisting= */ false);
882 setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
883 ARMBuildAttrs::AllowNeonARMv8,
884 /* OverwriteExisting= */ false);
885 break;
886
Logan Chien05ae7442014-01-02 15:50:02 +0000887 case ARM::SOFTVFP:
888 break;
889
Logan Chien8cbb80d2013-10-28 17:51:12 +0000890 default:
891 report_fatal_error("Unknown FPU: " + Twine(FPU));
892 break;
893 }
894}
895size_t ARMTargetELFStreamer::calculateContentSize() const {
896 size_t Result = 0;
897 for (size_t i = 0; i < Contents.size(); ++i) {
898 AttributeItem item = Contents[i];
899 switch (item.Type) {
900 case AttributeItem::HiddenAttribute:
901 break;
902 case AttributeItem::NumericAttribute:
903 Result += getULEBSize(item.Tag);
904 Result += getULEBSize(item.IntValue);
905 break;
906 case AttributeItem::TextAttribute:
907 Result += getULEBSize(item.Tag);
908 Result += item.StringValue.size() + 1; // string + '\0'
909 break;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000910 case AttributeItem::NumericAndTextAttributes:
911 Result += getULEBSize(item.Tag);
912 Result += getULEBSize(item.IntValue);
913 Result += item.StringValue.size() + 1; // string + '\0';
914 break;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000915 }
916 }
917 return Result;
918}
919void ARMTargetELFStreamer::finishAttributeSection() {
920 // <format-version>
921 // [ <section-length> "vendor-name"
922 // [ <file-tag> <size> <attribute>*
923 // | <section-tag> <size> <section-number>* 0 <attribute>*
924 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
925 // ]+
926 // ]*
927
928 if (FPU != ARM::INVALID_FPU)
929 emitFPUDefaultAttributes();
930
Logan Chien439e8f92013-12-11 17:16:25 +0000931 if (Arch != ARM::INVALID_ARCH)
932 emitArchDefaultAttributes();
933
Logan Chien8cbb80d2013-10-28 17:51:12 +0000934 if (Contents.empty())
935 return;
936
937 std::sort(Contents.begin(), Contents.end(), AttributeItem::LessTag);
938
939 ARMELFStreamer &Streamer = getStreamer();
940
941 // Switch to .ARM.attributes section
942 if (AttributeSection) {
943 Streamer.SwitchSection(AttributeSection);
944 } else {
945 AttributeSection =
946 Streamer.getContext().getELFSection(".ARM.attributes",
947 ELF::SHT_ARM_ATTRIBUTES,
948 0,
949 SectionKind::getMetadata());
950 Streamer.SwitchSection(AttributeSection);
951
952 // Format version
953 Streamer.EmitIntValue(0x41, 1);
954 }
955
956 // Vendor size + Vendor name + '\0'
957 const size_t VendorHeaderSize = 4 + CurrentVendor.size() + 1;
958
959 // Tag + Tag Size
960 const size_t TagHeaderSize = 1 + 4;
961
962 const size_t ContentsSize = calculateContentSize();
963
964 Streamer.EmitIntValue(VendorHeaderSize + TagHeaderSize + ContentsSize, 4);
965 Streamer.EmitBytes(CurrentVendor);
966 Streamer.EmitIntValue(0, 1); // '\0'
967
968 Streamer.EmitIntValue(ARMBuildAttrs::File, 1);
969 Streamer.EmitIntValue(TagHeaderSize + ContentsSize, 4);
970
971 // Size should have been accounted for already, now
972 // emit each field as its type (ULEB or String)
973 for (size_t i = 0; i < Contents.size(); ++i) {
974 AttributeItem item = Contents[i];
975 Streamer.EmitULEB128IntValue(item.Tag);
976 switch (item.Type) {
977 default: llvm_unreachable("Invalid attribute type");
978 case AttributeItem::NumericAttribute:
979 Streamer.EmitULEB128IntValue(item.IntValue);
980 break;
981 case AttributeItem::TextAttribute:
982 Streamer.EmitBytes(item.StringValue.upper());
983 Streamer.EmitIntValue(0, 1); // '\0'
984 break;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000985 case AttributeItem::NumericAndTextAttributes:
986 Streamer.EmitULEB128IntValue(item.IntValue);
987 Streamer.EmitBytes(item.StringValue.upper());
988 Streamer.EmitIntValue(0, 1); // '\0'
989 break;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000990 }
991 }
992
993 Contents.clear();
994 FPU = ARM::INVALID_FPU;
995}
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000996void
997ARMTargetELFStreamer::AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *S) {
998 getStreamer().EmitFixup(S, FK_Data_4);
999}
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00001000void ARMTargetELFStreamer::emitInst(uint32_t Inst, char Suffix) {
1001 getStreamer().emitInst(Inst, Suffix);
1002}
Logan Chien8cbb80d2013-10-28 17:51:12 +00001003
1004void ARMELFStreamer::FinishImpl() {
Rafael Espindola4a1a3602014-01-14 01:21:46 +00001005 MCTargetStreamer &TS = *getTargetStreamer();
Logan Chien8cbb80d2013-10-28 17:51:12 +00001006 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1007 ATS.finishAttributeSection();
1008
1009 MCELFStreamer::FinishImpl();
1010}
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001011
Logan Chien2bcc42c2013-01-30 15:39:04 +00001012inline void ARMELFStreamer::SwitchToEHSection(const char *Prefix,
1013 unsigned Type,
1014 unsigned Flags,
1015 SectionKind Kind,
1016 const MCSymbol &Fn) {
1017 const MCSectionELF &FnSection =
1018 static_cast<const MCSectionELF &>(Fn.getSection());
1019
1020 // Create the name for new section
1021 StringRef FnSecName(FnSection.getSectionName());
1022 SmallString<128> EHSecName(Prefix);
1023 if (FnSecName != ".text") {
1024 EHSecName += FnSecName;
1025 }
1026
1027 // Get .ARM.extab or .ARM.exidx section
1028 const MCSectionELF *EHSection = NULL;
1029 if (const MCSymbol *Group = FnSection.getGroup()) {
1030 EHSection = getContext().getELFSection(
1031 EHSecName, Type, Flags | ELF::SHF_GROUP, Kind,
1032 FnSection.getEntrySize(), Group->getName());
1033 } else {
1034 EHSection = getContext().getELFSection(EHSecName, Type, Flags, Kind);
1035 }
Logan Chiend8bb4b72013-04-16 12:02:21 +00001036 assert(EHSection && "Failed to get the required EH section");
Logan Chien2bcc42c2013-01-30 15:39:04 +00001037
1038 // Switch to .ARM.extab or .ARM.exidx section
1039 SwitchSection(EHSection);
1040 EmitCodeAlignment(4, 0);
1041}
1042
1043inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) {
1044 SwitchToEHSection(".ARM.extab",
1045 ELF::SHT_PROGBITS,
1046 ELF::SHF_ALLOC,
1047 SectionKind::getDataRel(),
1048 FnStart);
1049}
1050
1051inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {
1052 SwitchToEHSection(".ARM.exidx",
1053 ELF::SHT_ARM_EXIDX,
1054 ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER,
1055 SectionKind::getDataRel(),
1056 FnStart);
1057}
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00001058void ARMELFStreamer::EmitFixup(const MCExpr *Expr, MCFixupKind Kind) {
1059 MCDataFragment *Frag = getOrCreateDataFragment();
1060 Frag->getFixups().push_back(MCFixup::Create(Frag->getContents().size(), Expr,
1061 Kind));
1062}
Logan Chien2bcc42c2013-01-30 15:39:04 +00001063
1064void ARMELFStreamer::Reset() {
1065 ExTab = NULL;
1066 FnStart = NULL;
1067 Personality = NULL;
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001068 PersonalityIndex = ARM::EHABI::NUM_PERSONALITY_INDEX;
Logan Chien325823a2013-06-09 12:22:30 +00001069 FPReg = ARM::SP;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001070 FPOffset = 0;
1071 SPOffset = 0;
Logan Chien325823a2013-06-09 12:22:30 +00001072 PendingOffset = 0;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001073 UsedFP = false;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001074 CantUnwind = false;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001075
Logan Chien325823a2013-06-09 12:22:30 +00001076 Opcodes.clear();
Logan Chiend8bb4b72013-04-16 12:02:21 +00001077 UnwindOpAsm.Reset();
Logan Chien2bcc42c2013-01-30 15:39:04 +00001078}
1079
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001080void ARMELFStreamer::emitFnStart() {
Logan Chien2bcc42c2013-01-30 15:39:04 +00001081 assert(FnStart == 0);
1082 FnStart = getContext().CreateTempSymbol();
1083 EmitLabel(FnStart);
1084}
1085
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001086void ARMELFStreamer::emitFnEnd() {
Alp Tokercb402912014-01-24 17:20:08 +00001087 assert(FnStart && ".fnstart must precedes .fnend");
Logan Chien2bcc42c2013-01-30 15:39:04 +00001088
1089 // Emit unwind opcodes if there is no .handlerdata directive
Logan Chien4ea23b52013-05-10 16:17:24 +00001090 if (!ExTab && !CantUnwind)
1091 FlushUnwindOpcodes(true);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001092
1093 // Emit the exception index table entry
1094 SwitchToExIdxSection(*FnStart);
1095
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001096 if (PersonalityIndex < ARM::EHABI::NUM_PERSONALITY_INDEX)
Logan Chiend8bb4b72013-04-16 12:02:21 +00001097 EmitPersonalityFixup(GetAEABIUnwindPersonalityName(PersonalityIndex));
Logan Chien2bcc42c2013-01-30 15:39:04 +00001098
1099 const MCSymbolRefExpr *FnStartRef =
1100 MCSymbolRefExpr::Create(FnStart,
1101 MCSymbolRefExpr::VK_ARM_PREL31,
1102 getContext());
1103
Rafael Espindola64e1af82013-07-02 15:49:13 +00001104 EmitValue(FnStartRef, 4);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001105
1106 if (CantUnwind) {
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001107 EmitIntValue(ARM::EHABI::EXIDX_CANTUNWIND, 4);
Logan Chiend8bb4b72013-04-16 12:02:21 +00001108 } else if (ExTab) {
1109 // Emit a reference to the unwind opcodes in the ".ARM.extab" section.
Logan Chien2bcc42c2013-01-30 15:39:04 +00001110 const MCSymbolRefExpr *ExTabEntryRef =
1111 MCSymbolRefExpr::Create(ExTab,
1112 MCSymbolRefExpr::VK_ARM_PREL31,
1113 getContext());
Rafael Espindola64e1af82013-07-02 15:49:13 +00001114 EmitValue(ExTabEntryRef, 4);
Logan Chiend8bb4b72013-04-16 12:02:21 +00001115 } else {
1116 // For the __aeabi_unwind_cpp_pr0, we have to emit the unwind opcodes in
1117 // the second word of exception index table entry. The size of the unwind
1118 // opcodes should always be 4 bytes.
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001119 assert(PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0 &&
Logan Chiend8bb4b72013-04-16 12:02:21 +00001120 "Compact model must use __aeabi_cpp_unwind_pr0 as personality");
Logan Chien325823a2013-06-09 12:22:30 +00001121 assert(Opcodes.size() == 4u &&
Logan Chiend8bb4b72013-04-16 12:02:21 +00001122 "Unwind opcode size for __aeabi_cpp_unwind_pr0 must be equal to 4");
Logan Chien325823a2013-06-09 12:22:30 +00001123 EmitBytes(StringRef(reinterpret_cast<const char*>(Opcodes.data()),
Rafael Espindola64e1af82013-07-02 15:49:13 +00001124 Opcodes.size()));
Logan Chien2bcc42c2013-01-30 15:39:04 +00001125 }
1126
Logan Chien4ea23b52013-05-10 16:17:24 +00001127 // Switch to the section containing FnStart
1128 SwitchSection(&FnStart->getSection());
1129
Logan Chien2bcc42c2013-01-30 15:39:04 +00001130 // Clean exception handling frame information
1131 Reset();
1132}
1133
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001134void ARMELFStreamer::emitCantUnwind() { CantUnwind = true; }
1135
1136// Add the R_ARM_NONE fixup at the same position
1137void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
1138 const MCSymbol *PersonalitySym = getContext().GetOrCreateSymbol(Name);
1139
1140 const MCSymbolRefExpr *PersonalityRef = MCSymbolRefExpr::Create(
1141 PersonalitySym, MCSymbolRefExpr::VK_ARM_NONE, getContext());
1142
1143 AddValueSymbols(PersonalityRef);
1144 MCDataFragment *DF = getOrCreateDataFragment();
1145 DF->getFixups().push_back(MCFixup::Create(DF->getContents().size(),
1146 PersonalityRef,
1147 MCFixup::getKindForSize(4, false)));
Logan Chien2bcc42c2013-01-30 15:39:04 +00001148}
1149
Logan Chien325823a2013-06-09 12:22:30 +00001150void ARMELFStreamer::FlushPendingOffset() {
1151 if (PendingOffset != 0) {
1152 UnwindOpAsm.EmitSPOffset(-PendingOffset);
1153 PendingOffset = 0;
1154 }
1155}
1156
Logan Chienc931fce2013-07-02 12:43:27 +00001157void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
Logan Chien325823a2013-06-09 12:22:30 +00001158 // Emit the unwind opcode to restore $sp.
1159 if (UsedFP) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00001160 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
Logan Chien325823a2013-06-09 12:22:30 +00001161 int64_t LastRegSaveSPOffset = SPOffset - PendingOffset;
1162 UnwindOpAsm.EmitSPOffset(LastRegSaveSPOffset - FPOffset);
Bill Wendlingbc07a892013-06-18 07:20:20 +00001163 UnwindOpAsm.EmitSetSP(MRI->getEncodingValue(FPReg));
Logan Chien325823a2013-06-09 12:22:30 +00001164 } else {
1165 FlushPendingOffset();
1166 }
1167
1168 // Finalize the unwind opcode sequence
1169 UnwindOpAsm.Finalize(PersonalityIndex, Opcodes);
Logan Chien4ea23b52013-05-10 16:17:24 +00001170
1171 // For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx
1172 // section. Thus, we don't have to create an entry in the .ARM.extab
1173 // section.
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001174 if (NoHandlerData && PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0)
Logan Chien4ea23b52013-05-10 16:17:24 +00001175 return;
1176
1177 // Switch to .ARM.extab section.
Logan Chien2bcc42c2013-01-30 15:39:04 +00001178 SwitchToExTabSection(*FnStart);
1179
1180 // Create .ARM.extab label for offset in .ARM.exidx
1181 assert(!ExTab);
1182 ExTab = getContext().CreateTempSymbol();
1183 EmitLabel(ExTab);
1184
Logan Chien4ea23b52013-05-10 16:17:24 +00001185 // Emit personality
1186 if (Personality) {
1187 const MCSymbolRefExpr *PersonalityRef =
1188 MCSymbolRefExpr::Create(Personality,
1189 MCSymbolRefExpr::VK_ARM_PREL31,
1190 getContext());
Logan Chien2bcc42c2013-01-30 15:39:04 +00001191
Rafael Espindola64e1af82013-07-02 15:49:13 +00001192 EmitValue(PersonalityRef, 4);
Logan Chien4ea23b52013-05-10 16:17:24 +00001193 }
Logan Chien2bcc42c2013-01-30 15:39:04 +00001194
1195 // Emit unwind opcodes
Logan Chien325823a2013-06-09 12:22:30 +00001196 EmitBytes(StringRef(reinterpret_cast<const char *>(Opcodes.data()),
Rafael Espindola64e1af82013-07-02 15:49:13 +00001197 Opcodes.size()));
Logan Chienc931fce2013-07-02 12:43:27 +00001198
1199 // According to ARM EHABI section 9.2, if the __aeabi_unwind_cpp_pr1() or
1200 // __aeabi_unwind_cpp_pr2() is used, then the handler data must be emitted
1201 // after the unwind opcodes. The handler data consists of several 32-bit
1202 // words, and should be terminated by zero.
1203 //
1204 // In case that the .handlerdata directive is not specified by the
1205 // programmer, we should emit zero to terminate the handler data.
1206 if (NoHandlerData && !Personality)
1207 EmitIntValue(0, 4);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001208}
1209
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001210void ARMELFStreamer::emitHandlerData() { FlushUnwindOpcodes(false); }
Logan Chien4ea23b52013-05-10 16:17:24 +00001211
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001212void ARMELFStreamer::emitPersonality(const MCSymbol *Per) {
Logan Chien2bcc42c2013-01-30 15:39:04 +00001213 Personality = Per;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001214 UnwindOpAsm.setPersonality(Per);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001215}
1216
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00001217void ARMELFStreamer::emitPersonalityIndex(unsigned Index) {
1218 assert(Index < ARM::EHABI::NUM_PERSONALITY_INDEX && "invalid index");
1219 PersonalityIndex = Index;
1220}
1221
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001222void ARMELFStreamer::emitSetFP(unsigned NewFPReg, unsigned NewSPReg,
Logan Chien2bcc42c2013-01-30 15:39:04 +00001223 int64_t Offset) {
Logan Chien325823a2013-06-09 12:22:30 +00001224 assert((NewSPReg == ARM::SP || NewSPReg == FPReg) &&
Logan Chiend8bb4b72013-04-16 12:02:21 +00001225 "the operand of .setfp directive should be either $sp or $fp");
1226
1227 UsedFP = true;
Logan Chien325823a2013-06-09 12:22:30 +00001228 FPReg = NewFPReg;
1229
1230 if (NewSPReg == ARM::SP)
1231 FPOffset = SPOffset + Offset;
1232 else
1233 FPOffset += Offset;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001234}
1235
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00001236void ARMELFStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
1237 assert((Reg != ARM::SP && Reg != ARM::PC) &&
1238 "the operand of .movsp cannot be either sp or pc");
1239 assert(FPReg == ARM::SP && "current FP must be SP");
1240
1241 FlushPendingOffset();
1242
1243 FPReg = Reg;
1244 FPOffset = SPOffset + Offset;
1245
1246 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1247 UnwindOpAsm.EmitSetSP(MRI->getEncodingValue(FPReg));
1248}
1249
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001250void ARMELFStreamer::emitPad(int64_t Offset) {
Logan Chien325823a2013-06-09 12:22:30 +00001251 // Track the change of the $sp offset
1252 SPOffset -= Offset;
1253
1254 // To squash multiple .pad directives, we should delay the unwind opcode
1255 // until the .save, .vsave, .handlerdata, or .fnend directives.
1256 PendingOffset -= Offset;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001257}
1258
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001259void ARMELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
Logan Chien2bcc42c2013-01-30 15:39:04 +00001260 bool IsVector) {
Logan Chien325823a2013-06-09 12:22:30 +00001261 // Collect the registers in the register list
1262 unsigned Count = 0;
1263 uint32_t Mask = 0;
Bill Wendlingbc07a892013-06-18 07:20:20 +00001264 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
Logan Chiend8bb4b72013-04-16 12:02:21 +00001265 for (size_t i = 0; i < RegList.size(); ++i) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00001266 unsigned Reg = MRI->getEncodingValue(RegList[i]);
Aaron Ballmanab1d27e2013-06-10 16:45:40 +00001267 assert(Reg < (IsVector ? 32U : 16U) && "Register out of range");
Logan Chien325823a2013-06-09 12:22:30 +00001268 unsigned Bit = (1u << Reg);
1269 if ((Mask & Bit) == 0) {
1270 Mask |= Bit;
1271 ++Count;
1272 }
Logan Chiend8bb4b72013-04-16 12:02:21 +00001273 }
Logan Chien325823a2013-06-09 12:22:30 +00001274
1275 // Track the change the $sp offset: For the .save directive, the
1276 // corresponding push instruction will decrease the $sp by (4 * Count).
1277 // For the .vsave directive, the corresponding vpush instruction will
1278 // decrease $sp by (8 * Count).
1279 SPOffset -= Count * (IsVector ? 8 : 4);
1280
1281 // Emit the opcode
1282 FlushPendingOffset();
1283 if (IsVector)
1284 UnwindOpAsm.EmitVFPRegSave(Mask);
1285 else
1286 UnwindOpAsm.EmitRegSave(Mask);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001287}
1288
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00001289void ARMELFStreamer::emitUnwindRaw(int64_t Offset,
1290 const SmallVectorImpl<uint8_t> &Opcodes) {
1291 FlushPendingOffset();
1292 SPOffset = SPOffset - Offset;
1293 UnwindOpAsm.EmitRaw(Opcodes);
1294}
1295
Tim Northover5cc3dc82012-12-07 16:50:23 +00001296namespace llvm {
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001297
1298MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
1299 bool isVerboseAsm, bool useLoc, bool useCFI,
1300 bool useDwarfDirectory,
1301 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
1302 MCAsmBackend *TAB, bool ShowInst) {
Rafael Espindola24ea09e2014-01-26 06:06:37 +00001303 MCStreamer *S =
1304 llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useLoc, useCFI,
1305 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
1306 new ARMTargetAsmStreamer(*S, OS, *InstPrint, isVerboseAsm);
1307 return S;
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001308}
1309
Tim Northover5cc3dc82012-12-07 16:50:23 +00001310 MCELFStreamer* createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
1311 raw_ostream &OS, MCCodeEmitter *Emitter,
1312 bool RelaxAll, bool NoExecStack,
1313 bool IsThumb) {
Rafael Espindola24ea09e2014-01-26 06:06:37 +00001314 ARMELFStreamer *S = new ARMELFStreamer(Context, TAB, OS, Emitter, IsThumb);
1315 new ARMTargetELFStreamer(*S);
Rafael Espindolaac4ad252013-10-05 16:42:21 +00001316 // FIXME: This should eventually end up somewhere else where more
1317 // intelligent flag decisions can be made. For now we are just maintaining
1318 // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default.
1319 S->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
1320
Tim Northover5cc3dc82012-12-07 16:50:23 +00001321 if (RelaxAll)
1322 S->getAssembler().setRelaxAll(true);
1323 if (NoExecStack)
1324 S->getAssembler().setNoExecStack(true);
1325 return S;
1326 }
1327
1328}
1329
1330