blob: 151d48df63e06d6ff37a224cc65d1830a25d3258 [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);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000139 virtual void emitFPU(unsigned FPU);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000140 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
Logan Chien8cbb80d2013-10-28 17:51:12 +0000141 virtual void finishAttributeSection();
142
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000143 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
144
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000145public:
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000146 ARMTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS,
147 MCInstPrinter &InstPrinter, bool VerboseAsm);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000148};
149
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000150ARMTargetAsmStreamer::ARMTargetAsmStreamer(MCStreamer &S,
151 formatted_raw_ostream &OS,
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000152 MCInstPrinter &InstPrinter,
153 bool VerboseAsm)
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000154 : ARMTargetStreamer(S), OS(OS), InstPrinter(InstPrinter),
155 IsVerboseAsm(VerboseAsm) {}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000156void ARMTargetAsmStreamer::emitFnStart() { OS << "\t.fnstart\n"; }
157void ARMTargetAsmStreamer::emitFnEnd() { OS << "\t.fnend\n"; }
158void ARMTargetAsmStreamer::emitCantUnwind() { OS << "\t.cantunwind\n"; }
159void ARMTargetAsmStreamer::emitPersonality(const MCSymbol *Personality) {
160 OS << "\t.personality " << Personality->getName() << '\n';
161}
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000162void ARMTargetAsmStreamer::emitPersonalityIndex(unsigned Index) {
163 OS << "\t.personalityindex " << Index << '\n';
164}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000165void ARMTargetAsmStreamer::emitHandlerData() { OS << "\t.handlerdata\n"; }
166void ARMTargetAsmStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
167 int64_t Offset) {
168 OS << "\t.setfp\t";
169 InstPrinter.printRegName(OS, FpReg);
170 OS << ", ";
171 InstPrinter.printRegName(OS, SpReg);
172 if (Offset)
173 OS << ", #" << Offset;
174 OS << '\n';
175}
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000176void ARMTargetAsmStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
177 assert((Reg != ARM::SP && Reg != ARM::PC) &&
178 "the operand of .movsp cannot be either sp or pc");
179
180 OS << "\t.movsp\t";
181 InstPrinter.printRegName(OS, Reg);
182 if (Offset)
183 OS << ", #" << Offset;
184 OS << '\n';
185}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000186void ARMTargetAsmStreamer::emitPad(int64_t Offset) {
187 OS << "\t.pad\t#" << Offset << '\n';
188}
189void ARMTargetAsmStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
190 bool isVector) {
191 assert(RegList.size() && "RegList should not be empty");
192 if (isVector)
193 OS << "\t.vsave\t{";
194 else
195 OS << "\t.save\t{";
196
197 InstPrinter.printRegName(OS, RegList[0]);
198
199 for (unsigned i = 1, e = RegList.size(); i != e; ++i) {
200 OS << ", ";
201 InstPrinter.printRegName(OS, RegList[i]);
202 }
203
204 OS << "}\n";
205}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000206void ARMTargetAsmStreamer::switchVendor(StringRef Vendor) {
207}
208void ARMTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000209 OS << "\t.eabi_attribute\t" << Attribute << ", " << Twine(Value);
210 if (IsVerboseAsm) {
211 StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute);
212 if (!Name.empty())
213 OS << "\t@ " << Name;
214 }
215 OS << "\n";
Logan Chien8cbb80d2013-10-28 17:51:12 +0000216}
217void ARMTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
218 StringRef String) {
219 switch (Attribute) {
Logan Chien8cbb80d2013-10-28 17:51:12 +0000220 case ARMBuildAttrs::CPU_name:
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000221 OS << "\t.cpu\t" << String.lower();
222 break;
223 default:
224 OS << "\t.eabi_attribute\t" << Attribute << ", \"" << String << "\"";
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000225 if (IsVerboseAsm) {
226 StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute);
227 if (!Name.empty())
228 OS << "\t@ " << Name;
229 }
Logan Chien8cbb80d2013-10-28 17:51:12 +0000230 break;
231 }
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000232 OS << "\n";
233}
234void ARMTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
235 unsigned IntValue,
236 StringRef StringValue) {
237 switch (Attribute) {
238 default: llvm_unreachable("unsupported multi-value attribute in asm mode");
239 case ARMBuildAttrs::compatibility:
240 OS << "\t.eabi_attribute\t" << Attribute << ", " << IntValue;
241 if (!StringValue.empty())
242 OS << ", \"" << StringValue << "\"";
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000243 if (IsVerboseAsm)
244 OS << "\t@ " << ARMBuildAttrs::AttrTypeAsString(Attribute);
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000245 break;
246 }
247 OS << "\n";
Logan Chien8cbb80d2013-10-28 17:51:12 +0000248}
Logan Chien439e8f92013-12-11 17:16:25 +0000249void ARMTargetAsmStreamer::emitArch(unsigned Arch) {
250 OS << "\t.arch\t" << GetArchName(Arch) << "\n";
251}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000252void ARMTargetAsmStreamer::emitFPU(unsigned FPU) {
253 OS << "\t.fpu\t" << GetFPUName(FPU) << "\n";
254}
255void ARMTargetAsmStreamer::finishAttributeSection() {
256}
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000257void
258ARMTargetAsmStreamer::AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *S) {
259 OS << "\t.tlsdescseq\t" << S->getSymbol().getName();
260}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000261
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000262void ARMTargetAsmStreamer::emitInst(uint32_t Inst, char Suffix) {
263 OS << "\t.inst";
264 if (Suffix)
265 OS << "." << Suffix;
266 OS << "\t0x" << utohexstr(Inst) << "\n";
267}
268
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000269void ARMTargetAsmStreamer::emitUnwindRaw(int64_t Offset,
270 const SmallVectorImpl<uint8_t> &Opcodes) {
271 OS << "\t.unwind_raw " << Offset;
272 for (SmallVectorImpl<uint8_t>::const_iterator OCI = Opcodes.begin(),
273 OCE = Opcodes.end();
274 OCI != OCE; ++OCI)
275 OS << ", 0x" << utohexstr(*OCI);
276 OS << '\n';
277}
278
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000279class ARMTargetELFStreamer : public ARMTargetStreamer {
Logan Chien8cbb80d2013-10-28 17:51:12 +0000280private:
281 // This structure holds all attributes, accounting for
282 // their string/numeric value, so we can later emmit them
283 // in declaration order, keeping all in the same vector
284 struct AttributeItem {
285 enum {
286 HiddenAttribute = 0,
287 NumericAttribute,
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000288 TextAttribute,
289 NumericAndTextAttributes
Logan Chien8cbb80d2013-10-28 17:51:12 +0000290 } Type;
291 unsigned Tag;
292 unsigned IntValue;
293 StringRef StringValue;
294
295 static bool LessTag(const AttributeItem &LHS, const AttributeItem &RHS) {
296 return (LHS.Tag < RHS.Tag);
297 }
298 };
299
300 StringRef CurrentVendor;
301 unsigned FPU;
Logan Chien439e8f92013-12-11 17:16:25 +0000302 unsigned Arch;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000303 SmallVector<AttributeItem, 64> Contents;
304
305 const MCSection *AttributeSection;
306
307 // FIXME: this should be in a more generic place, but
308 // getULEBSize() is in MCAsmInfo and will be moved to MCDwarf
309 static size_t getULEBSize(int Value) {
310 size_t Size = 0;
311 do {
312 Value >>= 7;
313 Size += sizeof(int8_t); // Is this really necessary?
314 } while (Value);
315 return Size;
316 }
317
318 AttributeItem *getAttributeItem(unsigned Attribute) {
319 for (size_t i = 0; i < Contents.size(); ++i)
320 if (Contents[i].Tag == Attribute)
321 return &Contents[i];
322 return 0;
323 }
324
325 void setAttributeItem(unsigned Attribute, unsigned Value,
326 bool OverwriteExisting) {
327 // Look for existing attribute item
328 if (AttributeItem *Item = getAttributeItem(Attribute)) {
329 if (!OverwriteExisting)
330 return;
Saleem Abdulrasool93900052014-01-19 08:25:41 +0000331 Item->Type = AttributeItem::NumericAttribute;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000332 Item->IntValue = Value;
333 return;
334 }
335
336 // Create new attribute item
337 AttributeItem Item = {
338 AttributeItem::NumericAttribute,
339 Attribute,
340 Value,
341 StringRef("")
342 };
343 Contents.push_back(Item);
344 }
345
346 void setAttributeItem(unsigned Attribute, StringRef Value,
347 bool OverwriteExisting) {
348 // Look for existing attribute item
349 if (AttributeItem *Item = getAttributeItem(Attribute)) {
350 if (!OverwriteExisting)
351 return;
Saleem Abdulrasool93900052014-01-19 08:25:41 +0000352 Item->Type = AttributeItem::TextAttribute;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000353 Item->StringValue = Value;
354 return;
355 }
356
357 // Create new attribute item
358 AttributeItem Item = {
359 AttributeItem::TextAttribute,
360 Attribute,
361 0,
362 Value
363 };
364 Contents.push_back(Item);
365 }
366
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000367 void setAttributeItems(unsigned Attribute, unsigned IntValue,
368 StringRef StringValue, bool OverwriteExisting) {
369 // Look for existing attribute item
370 if (AttributeItem *Item = getAttributeItem(Attribute)) {
371 if (!OverwriteExisting)
372 return;
Saleem Abdulrasool93900052014-01-19 08:25:41 +0000373 Item->Type = AttributeItem::NumericAndTextAttributes;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000374 Item->IntValue = IntValue;
375 Item->StringValue = StringValue;
376 return;
377 }
378
379 // Create new attribute item
380 AttributeItem Item = {
381 AttributeItem::NumericAndTextAttributes,
382 Attribute,
383 IntValue,
384 StringValue
385 };
386 Contents.push_back(Item);
387 }
388
Logan Chien439e8f92013-12-11 17:16:25 +0000389 void emitArchDefaultAttributes();
Logan Chien8cbb80d2013-10-28 17:51:12 +0000390 void emitFPUDefaultAttributes();
391
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000392 ARMELFStreamer &getStreamer();
Logan Chien8cbb80d2013-10-28 17:51:12 +0000393
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000394 virtual void emitFnStart();
395 virtual void emitFnEnd();
396 virtual void emitCantUnwind();
397 virtual void emitPersonality(const MCSymbol *Personality);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000398 virtual void emitPersonalityIndex(unsigned Index);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000399 virtual void emitHandlerData();
400 virtual void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000401 virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000402 virtual void emitPad(int64_t Offset);
403 virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
404 bool isVector);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000405 virtual void emitUnwindRaw(int64_t Offset,
406 const SmallVectorImpl<uint8_t> &Opcodes);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000407
408 virtual void switchVendor(StringRef Vendor);
409 virtual void emitAttribute(unsigned Attribute, unsigned Value);
410 virtual void emitTextAttribute(unsigned Attribute, StringRef String);
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000411 virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
412 StringRef StringValue);
Logan Chien439e8f92013-12-11 17:16:25 +0000413 virtual void emitArch(unsigned Arch);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000414 virtual void emitFPU(unsigned FPU);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000415 virtual void emitInst(uint32_t Inst, char Suffix = '\0');
Logan Chien8cbb80d2013-10-28 17:51:12 +0000416 virtual void finishAttributeSection();
417
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000418 virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
419
Logan Chien8cbb80d2013-10-28 17:51:12 +0000420 size_t calculateContentSize() const;
421
422public:
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000423 ARMTargetELFStreamer(MCStreamer &S)
424 : ARMTargetStreamer(S), CurrentVendor("aeabi"), FPU(ARM::INVALID_FPU),
425 Arch(ARM::INVALID_ARCH), AttributeSection(0) {}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000426};
427
Tim Northover5cc3dc82012-12-07 16:50:23 +0000428/// Extend the generic ELFStreamer class so that it can emit mapping symbols at
429/// the appropriate points in the object files. These symbols are defined in the
430/// ARM ELF ABI: infocenter.arm.com/help/topic/com.arm.../IHI0044D_aaelf.pdf.
431///
432/// In brief: $a, $t or $d should be emitted at the start of each contiguous
433/// region of ARM code, Thumb code or data in a section. In practice, this
434/// emission does not rely on explicit assembler directives but on inherent
435/// properties of the directives doing the emission (e.g. ".byte" is data, "add
436/// r0, r0, r0" an instruction).
437///
438/// As a result this system is orthogonal to the DataRegion infrastructure used
439/// by MachO. Beware!
440class ARMELFStreamer : public MCELFStreamer {
441public:
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000442 friend class ARMTargetELFStreamer;
443
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000444 ARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS,
445 MCCodeEmitter *Emitter, bool IsThumb)
446 : MCELFStreamer(Context, TAB, OS, Emitter), IsThumb(IsThumb),
447 MappingSymbolCounter(0), LastEMS(EMS_None) {
Logan Chiend8bb4b72013-04-16 12:02:21 +0000448 Reset();
449 }
Tim Northover5cc3dc82012-12-07 16:50:23 +0000450
451 ~ARMELFStreamer() {}
452
Logan Chien8cbb80d2013-10-28 17:51:12 +0000453 virtual void FinishImpl();
454
Logan Chien2bcc42c2013-01-30 15:39:04 +0000455 // ARM exception handling directives
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000456 void emitFnStart();
457 void emitFnEnd();
458 void emitCantUnwind();
459 void emitPersonality(const MCSymbol *Per);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000460 void emitPersonalityIndex(unsigned index);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000461 void emitHandlerData();
462 void emitSetFP(unsigned NewFpReg, unsigned NewSpReg, int64_t Offset = 0);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000463 void emitMovSP(unsigned Reg, int64_t Offset = 0);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000464 void emitPad(int64_t Offset);
465 void emitRegSave(const SmallVectorImpl<unsigned> &RegList, bool isVector);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000466 void emitUnwindRaw(int64_t Offset, const SmallVectorImpl<uint8_t> &Opcodes);
Logan Chien2bcc42c2013-01-30 15:39:04 +0000467
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000468 virtual void ChangeSection(const MCSection *Section,
469 const MCExpr *Subsection) {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000470 // We have to keep track of the mapping symbol state of any sections we
471 // use. Each one should start off as EMS_None, which is provided as the
472 // default constructor by DenseMap::lookup.
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000473 LastMappingSymbols[getPreviousSection().first] = LastEMS;
Tim Northover5cc3dc82012-12-07 16:50:23 +0000474 LastEMS = LastMappingSymbols.lookup(Section);
475
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000476 MCELFStreamer::ChangeSection(Section, Subsection);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000477 }
478
479 /// This function is the one used to emit instruction data into the ELF
480 /// streamer. We override it to add the appropriate mapping symbol if
481 /// necessary.
David Woodhousee6c13e42014-01-28 23:12:42 +0000482 virtual void EmitInstruction(const MCInst& Inst, const MCSubtargetInfo &STI) {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000483 if (IsThumb)
484 EmitThumbMappingSymbol();
485 else
486 EmitARMMappingSymbol();
487
David Woodhousee6c13e42014-01-28 23:12:42 +0000488 MCELFStreamer::EmitInstruction(Inst, STI);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000489 }
490
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000491 virtual void emitInst(uint32_t Inst, char Suffix) {
492 unsigned Size;
493 char Buffer[4];
494 const bool LittleEndian = getContext().getAsmInfo()->isLittleEndian();
495
496 switch (Suffix) {
497 case '\0':
498 Size = 4;
499
500 assert(!IsThumb);
501 EmitARMMappingSymbol();
502 for (unsigned II = 0, IE = Size; II != IE; II++) {
503 const unsigned I = LittleEndian ? (Size - II - 1) : II;
504 Buffer[Size - II - 1] = uint8_t(Inst >> I * CHAR_BIT);
505 }
506
507 break;
508 case 'n':
509 case 'w':
510 Size = (Suffix == 'n' ? 2 : 4);
511
512 assert(IsThumb);
513 EmitThumbMappingSymbol();
514 for (unsigned II = 0, IE = Size; II != IE; II = II + 2) {
515 const unsigned I0 = LittleEndian ? II + 0 : (Size - II - 1);
516 const unsigned I1 = LittleEndian ? II + 1 : (Size - II - 2);
517 Buffer[Size - II - 2] = uint8_t(Inst >> I0 * CHAR_BIT);
518 Buffer[Size - II - 1] = uint8_t(Inst >> I1 * CHAR_BIT);
519 }
520
521 break;
522 default:
523 llvm_unreachable("Invalid Suffix");
524 }
525
526 MCELFStreamer::EmitBytes(StringRef(Buffer, Size));
527 }
528
Tim Northover5cc3dc82012-12-07 16:50:23 +0000529 /// This is one of the functions used to emit data into an ELF section, so the
530 /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
531 /// necessary.
Rafael Espindola64e1af82013-07-02 15:49:13 +0000532 virtual void EmitBytes(StringRef Data) {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000533 EmitDataMappingSymbol();
Rafael Espindola64e1af82013-07-02 15:49:13 +0000534 MCELFStreamer::EmitBytes(Data);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000535 }
536
537 /// This is one of the functions used to emit data into an ELF section, so the
538 /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
539 /// necessary.
Rafael Espindola64e1af82013-07-02 15:49:13 +0000540 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size) {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000541 EmitDataMappingSymbol();
Rafael Espindola64e1af82013-07-02 15:49:13 +0000542 MCELFStreamer::EmitValueImpl(Value, Size);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000543 }
544
545 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag) {
546 MCELFStreamer::EmitAssemblerFlag(Flag);
547
548 switch (Flag) {
549 case MCAF_SyntaxUnified:
550 return; // no-op here.
551 case MCAF_Code16:
552 IsThumb = true;
553 return; // Change to Thumb mode
554 case MCAF_Code32:
555 IsThumb = false;
556 return; // Change to ARM mode
557 case MCAF_Code64:
558 return;
559 case MCAF_SubsectionsViaSymbols:
560 return;
561 }
562 }
563
564private:
565 enum ElfMappingSymbol {
566 EMS_None,
567 EMS_ARM,
568 EMS_Thumb,
569 EMS_Data
570 };
571
572 void EmitDataMappingSymbol() {
573 if (LastEMS == EMS_Data) return;
574 EmitMappingSymbol("$d");
575 LastEMS = EMS_Data;
576 }
577
578 void EmitThumbMappingSymbol() {
579 if (LastEMS == EMS_Thumb) return;
580 EmitMappingSymbol("$t");
581 LastEMS = EMS_Thumb;
582 }
583
584 void EmitARMMappingSymbol() {
585 if (LastEMS == EMS_ARM) return;
586 EmitMappingSymbol("$a");
587 LastEMS = EMS_ARM;
588 }
589
590 void EmitMappingSymbol(StringRef Name) {
591 MCSymbol *Start = getContext().CreateTempSymbol();
592 EmitLabel(Start);
593
Chandler Carruth1d94e932012-12-08 03:10:14 +0000594 MCSymbol *Symbol =
Benjamin Kramerf242d8c2012-12-08 10:45:24 +0000595 getContext().GetOrCreateSymbol(Name + "." +
596 Twine(MappingSymbolCounter++));
Tim Northover5cc3dc82012-12-07 16:50:23 +0000597
598 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
599 MCELF::SetType(SD, ELF::STT_NOTYPE);
600 MCELF::SetBinding(SD, ELF::STB_LOCAL);
601 SD.setExternal(false);
Richard Mitton21101b32013-09-19 23:21:01 +0000602 AssignSection(Symbol, getCurrentSection().first);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000603
604 const MCExpr *Value = MCSymbolRefExpr::Create(Start, getContext());
605 Symbol->setVariableValue(Value);
606 }
607
608 void EmitThumbFunc(MCSymbol *Func) {
609 // FIXME: Anything needed here to flag the function as thumb?
610
611 getAssembler().setIsThumbFunc(Func);
612
613 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Func);
614 SD.setFlags(SD.getFlags() | ELF_Other_ThumbFunc);
615 }
616
Logan Chien2bcc42c2013-01-30 15:39:04 +0000617 // Helper functions for ARM exception handling directives
618 void Reset();
619
620 void EmitPersonalityFixup(StringRef Name);
Logan Chien325823a2013-06-09 12:22:30 +0000621 void FlushPendingOffset();
Logan Chienc931fce2013-07-02 12:43:27 +0000622 void FlushUnwindOpcodes(bool NoHandlerData);
Logan Chien2bcc42c2013-01-30 15:39:04 +0000623
624 void SwitchToEHSection(const char *Prefix, unsigned Type, unsigned Flags,
625 SectionKind Kind, const MCSymbol &Fn);
626 void SwitchToExTabSection(const MCSymbol &FnStart);
627 void SwitchToExIdxSection(const MCSymbol &FnStart);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000628
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000629 void EmitFixup(const MCExpr *Expr, MCFixupKind Kind);
630
Tim Northover5cc3dc82012-12-07 16:50:23 +0000631 bool IsThumb;
632 int64_t MappingSymbolCounter;
633
634 DenseMap<const MCSection *, ElfMappingSymbol> LastMappingSymbols;
635 ElfMappingSymbol LastEMS;
636
Logan Chien2bcc42c2013-01-30 15:39:04 +0000637 // ARM Exception Handling Frame Information
638 MCSymbol *ExTab;
639 MCSymbol *FnStart;
640 const MCSymbol *Personality;
Logan Chien325823a2013-06-09 12:22:30 +0000641 unsigned PersonalityIndex;
642 unsigned FPReg; // Frame pointer register
643 int64_t FPOffset; // Offset: (final frame pointer) - (initial $sp)
644 int64_t SPOffset; // Offset: (final $sp) - (initial $sp)
645 int64_t PendingOffset; // Offset: (final $sp) - (emitted $sp)
Logan Chiend8bb4b72013-04-16 12:02:21 +0000646 bool UsedFP;
Logan Chien2bcc42c2013-01-30 15:39:04 +0000647 bool CantUnwind;
Logan Chien325823a2013-06-09 12:22:30 +0000648 SmallVector<uint8_t, 64> Opcodes;
Logan Chiend8bb4b72013-04-16 12:02:21 +0000649 UnwindOpcodeAssembler UnwindOpAsm;
Tim Northover5cc3dc82012-12-07 16:50:23 +0000650};
Logan Chiend8bb4b72013-04-16 12:02:21 +0000651} // end anonymous namespace
Tim Northover5cc3dc82012-12-07 16:50:23 +0000652
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000653ARMELFStreamer &ARMTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000654 return static_cast<ARMELFStreamer &>(Streamer);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000655}
656
657void ARMTargetELFStreamer::emitFnStart() { getStreamer().emitFnStart(); }
658void ARMTargetELFStreamer::emitFnEnd() { getStreamer().emitFnEnd(); }
659void ARMTargetELFStreamer::emitCantUnwind() { getStreamer().emitCantUnwind(); }
660void ARMTargetELFStreamer::emitPersonality(const MCSymbol *Personality) {
661 getStreamer().emitPersonality(Personality);
662}
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000663void ARMTargetELFStreamer::emitPersonalityIndex(unsigned Index) {
664 getStreamer().emitPersonalityIndex(Index);
665}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000666void ARMTargetELFStreamer::emitHandlerData() {
667 getStreamer().emitHandlerData();
668}
669void ARMTargetELFStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
670 int64_t Offset) {
671 getStreamer().emitSetFP(FpReg, SpReg, Offset);
672}
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000673void ARMTargetELFStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
674 getStreamer().emitMovSP(Reg, Offset);
675}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000676void ARMTargetELFStreamer::emitPad(int64_t Offset) {
677 getStreamer().emitPad(Offset);
678}
679void ARMTargetELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
680 bool isVector) {
681 getStreamer().emitRegSave(RegList, isVector);
682}
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000683void ARMTargetELFStreamer::emitUnwindRaw(int64_t Offset,
684 const SmallVectorImpl<uint8_t> &Opcodes) {
685 getStreamer().emitUnwindRaw(Offset, Opcodes);
686}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000687void ARMTargetELFStreamer::switchVendor(StringRef Vendor) {
688 assert(!Vendor.empty() && "Vendor cannot be empty.");
689
690 if (CurrentVendor == Vendor)
691 return;
692
693 if (!CurrentVendor.empty())
694 finishAttributeSection();
695
696 assert(Contents.empty() &&
697 ".ARM.attributes should be flushed before changing vendor");
698 CurrentVendor = Vendor;
699
700}
701void ARMTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
702 setAttributeItem(Attribute, Value, /* OverwriteExisting= */ true);
703}
704void ARMTargetELFStreamer::emitTextAttribute(unsigned Attribute,
705 StringRef Value) {
706 setAttributeItem(Attribute, Value, /* OverwriteExisting= */ true);
707}
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000708void ARMTargetELFStreamer::emitIntTextAttribute(unsigned Attribute,
709 unsigned IntValue,
710 StringRef StringValue) {
711 setAttributeItems(Attribute, IntValue, StringValue,
712 /* OverwriteExisting= */ true);
713}
Logan Chien439e8f92013-12-11 17:16:25 +0000714void ARMTargetELFStreamer::emitArch(unsigned Value) {
715 Arch = Value;
716}
717void ARMTargetELFStreamer::emitArchDefaultAttributes() {
718 using namespace ARMBuildAttrs;
719 setAttributeItem(CPU_name, GetArchDefaultCPUName(Arch), false);
720 setAttributeItem(CPU_arch, GetArchDefaultCPUArch(Arch), false);
721
722 switch (Arch) {
723 case ARM::ARMV2:
724 case ARM::ARMV2A:
725 case ARM::ARMV3:
726 case ARM::ARMV3M:
727 case ARM::ARMV4:
728 case ARM::ARMV5:
729 setAttributeItem(ARM_ISA_use, Allowed, false);
730 break;
731
732 case ARM::ARMV4T:
733 case ARM::ARMV5T:
734 case ARM::ARMV5TE:
735 case ARM::ARMV6:
736 case ARM::ARMV6J:
737 setAttributeItem(ARM_ISA_use, Allowed, false);
738 setAttributeItem(THUMB_ISA_use, Allowed, false);
739 break;
740
741 case ARM::ARMV6T2:
742 setAttributeItem(ARM_ISA_use, Allowed, false);
743 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
744 break;
745
746 case ARM::ARMV6Z:
747 case ARM::ARMV6ZK:
748 setAttributeItem(ARM_ISA_use, Allowed, false);
749 setAttributeItem(THUMB_ISA_use, Allowed, false);
750 setAttributeItem(Virtualization_use, AllowTZ, false);
751 break;
752
753 case ARM::ARMV6M:
Logan Chien439e8f92013-12-11 17:16:25 +0000754 setAttributeItem(THUMB_ISA_use, Allowed, false);
755 break;
756
757 case ARM::ARMV7:
758 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
759 break;
760
761 case ARM::ARMV7A:
762 setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
763 setAttributeItem(ARM_ISA_use, Allowed, false);
764 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
765 break;
766
767 case ARM::ARMV7R:
768 setAttributeItem(CPU_arch_profile, RealTimeProfile, false);
769 setAttributeItem(ARM_ISA_use, Allowed, false);
770 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
771 break;
772
773 case ARM::ARMV7M:
774 setAttributeItem(CPU_arch_profile, MicroControllerProfile, false);
775 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
776 break;
777
778 case ARM::ARMV8A:
779 setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
780 setAttributeItem(ARM_ISA_use, Allowed, false);
781 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
782 setAttributeItem(MPextension_use, Allowed, false);
783 setAttributeItem(Virtualization_use, AllowTZVirtualization, false);
784 break;
785
786 case ARM::IWMMXT:
787 setAttributeItem(ARM_ISA_use, Allowed, false);
788 setAttributeItem(THUMB_ISA_use, Allowed, false);
789 setAttributeItem(WMMX_arch, AllowWMMXv1, false);
790 break;
791
792 case ARM::IWMMXT2:
793 setAttributeItem(ARM_ISA_use, Allowed, false);
794 setAttributeItem(THUMB_ISA_use, Allowed, false);
795 setAttributeItem(WMMX_arch, AllowWMMXv2, false);
796 break;
797
798 default:
799 report_fatal_error("Unknown Arch: " + Twine(Arch));
800 break;
801 }
802}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000803void ARMTargetELFStreamer::emitFPU(unsigned Value) {
804 FPU = Value;
805}
806void ARMTargetELFStreamer::emitFPUDefaultAttributes() {
807 switch (FPU) {
808 case ARM::VFP:
809 case ARM::VFPV2:
Logan Chiena39510a2013-12-18 17:23:15 +0000810 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000811 ARMBuildAttrs::AllowFPv2,
812 /* OverwriteExisting= */ false);
813 break;
814
815 case ARM::VFPV3:
Logan Chiena39510a2013-12-18 17:23:15 +0000816 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000817 ARMBuildAttrs::AllowFPv3A,
818 /* OverwriteExisting= */ false);
819 break;
820
821 case ARM::VFPV3_D16:
Logan Chiena39510a2013-12-18 17:23:15 +0000822 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000823 ARMBuildAttrs::AllowFPv3B,
824 /* OverwriteExisting= */ false);
825 break;
826
827 case ARM::VFPV4:
Logan Chiena39510a2013-12-18 17:23:15 +0000828 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000829 ARMBuildAttrs::AllowFPv4A,
830 /* OverwriteExisting= */ false);
831 break;
832
833 case ARM::VFPV4_D16:
Logan Chiena39510a2013-12-18 17:23:15 +0000834 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000835 ARMBuildAttrs::AllowFPv4B,
836 /* OverwriteExisting= */ false);
837 break;
838
839 case ARM::FP_ARMV8:
Logan Chiena39510a2013-12-18 17:23:15 +0000840 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000841 ARMBuildAttrs::AllowFPARMv8A,
842 /* OverwriteExisting= */ false);
843 break;
844
845 case ARM::NEON:
Logan Chiena39510a2013-12-18 17:23:15 +0000846 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000847 ARMBuildAttrs::AllowFPv3A,
848 /* OverwriteExisting= */ false);
849 setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
850 ARMBuildAttrs::AllowNeon,
851 /* OverwriteExisting= */ false);
852 break;
853
854 case ARM::NEON_VFPV4:
Logan Chiena39510a2013-12-18 17:23:15 +0000855 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000856 ARMBuildAttrs::AllowFPv4A,
857 /* OverwriteExisting= */ false);
858 setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
859 ARMBuildAttrs::AllowNeon2,
860 /* OverwriteExisting= */ false);
861 break;
862
863 case ARM::NEON_FP_ARMV8:
864 case ARM::CRYPTO_NEON_FP_ARMV8:
Logan Chiena39510a2013-12-18 17:23:15 +0000865 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000866 ARMBuildAttrs::AllowFPARMv8A,
867 /* OverwriteExisting= */ false);
868 setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
869 ARMBuildAttrs::AllowNeonARMv8,
870 /* OverwriteExisting= */ false);
871 break;
872
Logan Chien05ae7442014-01-02 15:50:02 +0000873 case ARM::SOFTVFP:
874 break;
875
Logan Chien8cbb80d2013-10-28 17:51:12 +0000876 default:
877 report_fatal_error("Unknown FPU: " + Twine(FPU));
878 break;
879 }
880}
881size_t ARMTargetELFStreamer::calculateContentSize() const {
882 size_t Result = 0;
883 for (size_t i = 0; i < Contents.size(); ++i) {
884 AttributeItem item = Contents[i];
885 switch (item.Type) {
886 case AttributeItem::HiddenAttribute:
887 break;
888 case AttributeItem::NumericAttribute:
889 Result += getULEBSize(item.Tag);
890 Result += getULEBSize(item.IntValue);
891 break;
892 case AttributeItem::TextAttribute:
893 Result += getULEBSize(item.Tag);
894 Result += item.StringValue.size() + 1; // string + '\0'
895 break;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000896 case AttributeItem::NumericAndTextAttributes:
897 Result += getULEBSize(item.Tag);
898 Result += getULEBSize(item.IntValue);
899 Result += item.StringValue.size() + 1; // string + '\0';
900 break;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000901 }
902 }
903 return Result;
904}
905void ARMTargetELFStreamer::finishAttributeSection() {
906 // <format-version>
907 // [ <section-length> "vendor-name"
908 // [ <file-tag> <size> <attribute>*
909 // | <section-tag> <size> <section-number>* 0 <attribute>*
910 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
911 // ]+
912 // ]*
913
914 if (FPU != ARM::INVALID_FPU)
915 emitFPUDefaultAttributes();
916
Logan Chien439e8f92013-12-11 17:16:25 +0000917 if (Arch != ARM::INVALID_ARCH)
918 emitArchDefaultAttributes();
919
Logan Chien8cbb80d2013-10-28 17:51:12 +0000920 if (Contents.empty())
921 return;
922
923 std::sort(Contents.begin(), Contents.end(), AttributeItem::LessTag);
924
925 ARMELFStreamer &Streamer = getStreamer();
926
927 // Switch to .ARM.attributes section
928 if (AttributeSection) {
929 Streamer.SwitchSection(AttributeSection);
930 } else {
931 AttributeSection =
932 Streamer.getContext().getELFSection(".ARM.attributes",
933 ELF::SHT_ARM_ATTRIBUTES,
934 0,
935 SectionKind::getMetadata());
936 Streamer.SwitchSection(AttributeSection);
937
938 // Format version
939 Streamer.EmitIntValue(0x41, 1);
940 }
941
942 // Vendor size + Vendor name + '\0'
943 const size_t VendorHeaderSize = 4 + CurrentVendor.size() + 1;
944
945 // Tag + Tag Size
946 const size_t TagHeaderSize = 1 + 4;
947
948 const size_t ContentsSize = calculateContentSize();
949
950 Streamer.EmitIntValue(VendorHeaderSize + TagHeaderSize + ContentsSize, 4);
951 Streamer.EmitBytes(CurrentVendor);
952 Streamer.EmitIntValue(0, 1); // '\0'
953
954 Streamer.EmitIntValue(ARMBuildAttrs::File, 1);
955 Streamer.EmitIntValue(TagHeaderSize + ContentsSize, 4);
956
957 // Size should have been accounted for already, now
958 // emit each field as its type (ULEB or String)
959 for (size_t i = 0; i < Contents.size(); ++i) {
960 AttributeItem item = Contents[i];
961 Streamer.EmitULEB128IntValue(item.Tag);
962 switch (item.Type) {
963 default: llvm_unreachable("Invalid attribute type");
964 case AttributeItem::NumericAttribute:
965 Streamer.EmitULEB128IntValue(item.IntValue);
966 break;
967 case AttributeItem::TextAttribute:
968 Streamer.EmitBytes(item.StringValue.upper());
969 Streamer.EmitIntValue(0, 1); // '\0'
970 break;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000971 case AttributeItem::NumericAndTextAttributes:
972 Streamer.EmitULEB128IntValue(item.IntValue);
973 Streamer.EmitBytes(item.StringValue.upper());
974 Streamer.EmitIntValue(0, 1); // '\0'
975 break;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000976 }
977 }
978
979 Contents.clear();
980 FPU = ARM::INVALID_FPU;
981}
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000982void
983ARMTargetELFStreamer::AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *S) {
984 getStreamer().EmitFixup(S, FK_Data_4);
985}
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000986void ARMTargetELFStreamer::emitInst(uint32_t Inst, char Suffix) {
987 getStreamer().emitInst(Inst, Suffix);
988}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000989
990void ARMELFStreamer::FinishImpl() {
Rafael Espindola4a1a3602014-01-14 01:21:46 +0000991 MCTargetStreamer &TS = *getTargetStreamer();
Logan Chien8cbb80d2013-10-28 17:51:12 +0000992 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
993 ATS.finishAttributeSection();
994
995 MCELFStreamer::FinishImpl();
996}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000997
Logan Chien2bcc42c2013-01-30 15:39:04 +0000998inline void ARMELFStreamer::SwitchToEHSection(const char *Prefix,
999 unsigned Type,
1000 unsigned Flags,
1001 SectionKind Kind,
1002 const MCSymbol &Fn) {
1003 const MCSectionELF &FnSection =
1004 static_cast<const MCSectionELF &>(Fn.getSection());
1005
1006 // Create the name for new section
1007 StringRef FnSecName(FnSection.getSectionName());
1008 SmallString<128> EHSecName(Prefix);
1009 if (FnSecName != ".text") {
1010 EHSecName += FnSecName;
1011 }
1012
1013 // Get .ARM.extab or .ARM.exidx section
1014 const MCSectionELF *EHSection = NULL;
1015 if (const MCSymbol *Group = FnSection.getGroup()) {
1016 EHSection = getContext().getELFSection(
1017 EHSecName, Type, Flags | ELF::SHF_GROUP, Kind,
1018 FnSection.getEntrySize(), Group->getName());
1019 } else {
1020 EHSection = getContext().getELFSection(EHSecName, Type, Flags, Kind);
1021 }
Logan Chiend8bb4b72013-04-16 12:02:21 +00001022 assert(EHSection && "Failed to get the required EH section");
Logan Chien2bcc42c2013-01-30 15:39:04 +00001023
1024 // Switch to .ARM.extab or .ARM.exidx section
1025 SwitchSection(EHSection);
1026 EmitCodeAlignment(4, 0);
1027}
1028
1029inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) {
1030 SwitchToEHSection(".ARM.extab",
1031 ELF::SHT_PROGBITS,
1032 ELF::SHF_ALLOC,
1033 SectionKind::getDataRel(),
1034 FnStart);
1035}
1036
1037inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {
1038 SwitchToEHSection(".ARM.exidx",
1039 ELF::SHT_ARM_EXIDX,
1040 ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER,
1041 SectionKind::getDataRel(),
1042 FnStart);
1043}
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00001044void ARMELFStreamer::EmitFixup(const MCExpr *Expr, MCFixupKind Kind) {
1045 MCDataFragment *Frag = getOrCreateDataFragment();
1046 Frag->getFixups().push_back(MCFixup::Create(Frag->getContents().size(), Expr,
1047 Kind));
1048}
Logan Chien2bcc42c2013-01-30 15:39:04 +00001049
1050void ARMELFStreamer::Reset() {
1051 ExTab = NULL;
1052 FnStart = NULL;
1053 Personality = NULL;
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001054 PersonalityIndex = ARM::EHABI::NUM_PERSONALITY_INDEX;
Logan Chien325823a2013-06-09 12:22:30 +00001055 FPReg = ARM::SP;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001056 FPOffset = 0;
1057 SPOffset = 0;
Logan Chien325823a2013-06-09 12:22:30 +00001058 PendingOffset = 0;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001059 UsedFP = false;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001060 CantUnwind = false;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001061
Logan Chien325823a2013-06-09 12:22:30 +00001062 Opcodes.clear();
Logan Chiend8bb4b72013-04-16 12:02:21 +00001063 UnwindOpAsm.Reset();
Logan Chien2bcc42c2013-01-30 15:39:04 +00001064}
1065
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001066void ARMELFStreamer::emitFnStart() {
Logan Chien2bcc42c2013-01-30 15:39:04 +00001067 assert(FnStart == 0);
1068 FnStart = getContext().CreateTempSymbol();
1069 EmitLabel(FnStart);
1070}
1071
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001072void ARMELFStreamer::emitFnEnd() {
Alp Tokercb402912014-01-24 17:20:08 +00001073 assert(FnStart && ".fnstart must precedes .fnend");
Logan Chien2bcc42c2013-01-30 15:39:04 +00001074
1075 // Emit unwind opcodes if there is no .handlerdata directive
Logan Chien4ea23b52013-05-10 16:17:24 +00001076 if (!ExTab && !CantUnwind)
1077 FlushUnwindOpcodes(true);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001078
1079 // Emit the exception index table entry
1080 SwitchToExIdxSection(*FnStart);
1081
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001082 if (PersonalityIndex < ARM::EHABI::NUM_PERSONALITY_INDEX)
Logan Chiend8bb4b72013-04-16 12:02:21 +00001083 EmitPersonalityFixup(GetAEABIUnwindPersonalityName(PersonalityIndex));
Logan Chien2bcc42c2013-01-30 15:39:04 +00001084
1085 const MCSymbolRefExpr *FnStartRef =
1086 MCSymbolRefExpr::Create(FnStart,
1087 MCSymbolRefExpr::VK_ARM_PREL31,
1088 getContext());
1089
Rafael Espindola64e1af82013-07-02 15:49:13 +00001090 EmitValue(FnStartRef, 4);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001091
1092 if (CantUnwind) {
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001093 EmitIntValue(ARM::EHABI::EXIDX_CANTUNWIND, 4);
Logan Chiend8bb4b72013-04-16 12:02:21 +00001094 } else if (ExTab) {
1095 // Emit a reference to the unwind opcodes in the ".ARM.extab" section.
Logan Chien2bcc42c2013-01-30 15:39:04 +00001096 const MCSymbolRefExpr *ExTabEntryRef =
1097 MCSymbolRefExpr::Create(ExTab,
1098 MCSymbolRefExpr::VK_ARM_PREL31,
1099 getContext());
Rafael Espindola64e1af82013-07-02 15:49:13 +00001100 EmitValue(ExTabEntryRef, 4);
Logan Chiend8bb4b72013-04-16 12:02:21 +00001101 } else {
1102 // For the __aeabi_unwind_cpp_pr0, we have to emit the unwind opcodes in
1103 // the second word of exception index table entry. The size of the unwind
1104 // opcodes should always be 4 bytes.
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001105 assert(PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0 &&
Logan Chiend8bb4b72013-04-16 12:02:21 +00001106 "Compact model must use __aeabi_cpp_unwind_pr0 as personality");
Logan Chien325823a2013-06-09 12:22:30 +00001107 assert(Opcodes.size() == 4u &&
Logan Chiend8bb4b72013-04-16 12:02:21 +00001108 "Unwind opcode size for __aeabi_cpp_unwind_pr0 must be equal to 4");
Logan Chien325823a2013-06-09 12:22:30 +00001109 EmitBytes(StringRef(reinterpret_cast<const char*>(Opcodes.data()),
Rafael Espindola64e1af82013-07-02 15:49:13 +00001110 Opcodes.size()));
Logan Chien2bcc42c2013-01-30 15:39:04 +00001111 }
1112
Logan Chien4ea23b52013-05-10 16:17:24 +00001113 // Switch to the section containing FnStart
1114 SwitchSection(&FnStart->getSection());
1115
Logan Chien2bcc42c2013-01-30 15:39:04 +00001116 // Clean exception handling frame information
1117 Reset();
1118}
1119
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001120void ARMELFStreamer::emitCantUnwind() { CantUnwind = true; }
1121
1122// Add the R_ARM_NONE fixup at the same position
1123void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
1124 const MCSymbol *PersonalitySym = getContext().GetOrCreateSymbol(Name);
1125
1126 const MCSymbolRefExpr *PersonalityRef = MCSymbolRefExpr::Create(
1127 PersonalitySym, MCSymbolRefExpr::VK_ARM_NONE, getContext());
1128
1129 AddValueSymbols(PersonalityRef);
1130 MCDataFragment *DF = getOrCreateDataFragment();
1131 DF->getFixups().push_back(MCFixup::Create(DF->getContents().size(),
1132 PersonalityRef,
1133 MCFixup::getKindForSize(4, false)));
Logan Chien2bcc42c2013-01-30 15:39:04 +00001134}
1135
Logan Chien325823a2013-06-09 12:22:30 +00001136void ARMELFStreamer::FlushPendingOffset() {
1137 if (PendingOffset != 0) {
1138 UnwindOpAsm.EmitSPOffset(-PendingOffset);
1139 PendingOffset = 0;
1140 }
1141}
1142
Logan Chienc931fce2013-07-02 12:43:27 +00001143void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
Logan Chien325823a2013-06-09 12:22:30 +00001144 // Emit the unwind opcode to restore $sp.
1145 if (UsedFP) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00001146 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
Logan Chien325823a2013-06-09 12:22:30 +00001147 int64_t LastRegSaveSPOffset = SPOffset - PendingOffset;
1148 UnwindOpAsm.EmitSPOffset(LastRegSaveSPOffset - FPOffset);
Bill Wendlingbc07a892013-06-18 07:20:20 +00001149 UnwindOpAsm.EmitSetSP(MRI->getEncodingValue(FPReg));
Logan Chien325823a2013-06-09 12:22:30 +00001150 } else {
1151 FlushPendingOffset();
1152 }
1153
1154 // Finalize the unwind opcode sequence
1155 UnwindOpAsm.Finalize(PersonalityIndex, Opcodes);
Logan Chien4ea23b52013-05-10 16:17:24 +00001156
1157 // For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx
1158 // section. Thus, we don't have to create an entry in the .ARM.extab
1159 // section.
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001160 if (NoHandlerData && PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0)
Logan Chien4ea23b52013-05-10 16:17:24 +00001161 return;
1162
1163 // Switch to .ARM.extab section.
Logan Chien2bcc42c2013-01-30 15:39:04 +00001164 SwitchToExTabSection(*FnStart);
1165
1166 // Create .ARM.extab label for offset in .ARM.exidx
1167 assert(!ExTab);
1168 ExTab = getContext().CreateTempSymbol();
1169 EmitLabel(ExTab);
1170
Logan Chien4ea23b52013-05-10 16:17:24 +00001171 // Emit personality
1172 if (Personality) {
1173 const MCSymbolRefExpr *PersonalityRef =
1174 MCSymbolRefExpr::Create(Personality,
1175 MCSymbolRefExpr::VK_ARM_PREL31,
1176 getContext());
Logan Chien2bcc42c2013-01-30 15:39:04 +00001177
Rafael Espindola64e1af82013-07-02 15:49:13 +00001178 EmitValue(PersonalityRef, 4);
Logan Chien4ea23b52013-05-10 16:17:24 +00001179 }
Logan Chien2bcc42c2013-01-30 15:39:04 +00001180
1181 // Emit unwind opcodes
Logan Chien325823a2013-06-09 12:22:30 +00001182 EmitBytes(StringRef(reinterpret_cast<const char *>(Opcodes.data()),
Rafael Espindola64e1af82013-07-02 15:49:13 +00001183 Opcodes.size()));
Logan Chienc931fce2013-07-02 12:43:27 +00001184
1185 // According to ARM EHABI section 9.2, if the __aeabi_unwind_cpp_pr1() or
1186 // __aeabi_unwind_cpp_pr2() is used, then the handler data must be emitted
1187 // after the unwind opcodes. The handler data consists of several 32-bit
1188 // words, and should be terminated by zero.
1189 //
1190 // In case that the .handlerdata directive is not specified by the
1191 // programmer, we should emit zero to terminate the handler data.
1192 if (NoHandlerData && !Personality)
1193 EmitIntValue(0, 4);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001194}
1195
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001196void ARMELFStreamer::emitHandlerData() { FlushUnwindOpcodes(false); }
Logan Chien4ea23b52013-05-10 16:17:24 +00001197
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001198void ARMELFStreamer::emitPersonality(const MCSymbol *Per) {
Logan Chien2bcc42c2013-01-30 15:39:04 +00001199 Personality = Per;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001200 UnwindOpAsm.setPersonality(Per);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001201}
1202
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00001203void ARMELFStreamer::emitPersonalityIndex(unsigned Index) {
1204 assert(Index < ARM::EHABI::NUM_PERSONALITY_INDEX && "invalid index");
1205 PersonalityIndex = Index;
1206}
1207
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001208void ARMELFStreamer::emitSetFP(unsigned NewFPReg, unsigned NewSPReg,
Logan Chien2bcc42c2013-01-30 15:39:04 +00001209 int64_t Offset) {
Logan Chien325823a2013-06-09 12:22:30 +00001210 assert((NewSPReg == ARM::SP || NewSPReg == FPReg) &&
Logan Chiend8bb4b72013-04-16 12:02:21 +00001211 "the operand of .setfp directive should be either $sp or $fp");
1212
1213 UsedFP = true;
Logan Chien325823a2013-06-09 12:22:30 +00001214 FPReg = NewFPReg;
1215
1216 if (NewSPReg == ARM::SP)
1217 FPOffset = SPOffset + Offset;
1218 else
1219 FPOffset += Offset;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001220}
1221
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00001222void ARMELFStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
1223 assert((Reg != ARM::SP && Reg != ARM::PC) &&
1224 "the operand of .movsp cannot be either sp or pc");
1225 assert(FPReg == ARM::SP && "current FP must be SP");
1226
1227 FlushPendingOffset();
1228
1229 FPReg = Reg;
1230 FPOffset = SPOffset + Offset;
1231
1232 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1233 UnwindOpAsm.EmitSetSP(MRI->getEncodingValue(FPReg));
1234}
1235
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001236void ARMELFStreamer::emitPad(int64_t Offset) {
Logan Chien325823a2013-06-09 12:22:30 +00001237 // Track the change of the $sp offset
1238 SPOffset -= Offset;
1239
1240 // To squash multiple .pad directives, we should delay the unwind opcode
1241 // until the .save, .vsave, .handlerdata, or .fnend directives.
1242 PendingOffset -= Offset;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001243}
1244
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001245void ARMELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
Logan Chien2bcc42c2013-01-30 15:39:04 +00001246 bool IsVector) {
Logan Chien325823a2013-06-09 12:22:30 +00001247 // Collect the registers in the register list
1248 unsigned Count = 0;
1249 uint32_t Mask = 0;
Bill Wendlingbc07a892013-06-18 07:20:20 +00001250 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
Logan Chiend8bb4b72013-04-16 12:02:21 +00001251 for (size_t i = 0; i < RegList.size(); ++i) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00001252 unsigned Reg = MRI->getEncodingValue(RegList[i]);
Aaron Ballmanab1d27e2013-06-10 16:45:40 +00001253 assert(Reg < (IsVector ? 32U : 16U) && "Register out of range");
Logan Chien325823a2013-06-09 12:22:30 +00001254 unsigned Bit = (1u << Reg);
1255 if ((Mask & Bit) == 0) {
1256 Mask |= Bit;
1257 ++Count;
1258 }
Logan Chiend8bb4b72013-04-16 12:02:21 +00001259 }
Logan Chien325823a2013-06-09 12:22:30 +00001260
1261 // Track the change the $sp offset: For the .save directive, the
1262 // corresponding push instruction will decrease the $sp by (4 * Count).
1263 // For the .vsave directive, the corresponding vpush instruction will
1264 // decrease $sp by (8 * Count).
1265 SPOffset -= Count * (IsVector ? 8 : 4);
1266
1267 // Emit the opcode
1268 FlushPendingOffset();
1269 if (IsVector)
1270 UnwindOpAsm.EmitVFPRegSave(Mask);
1271 else
1272 UnwindOpAsm.EmitRegSave(Mask);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001273}
1274
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00001275void ARMELFStreamer::emitUnwindRaw(int64_t Offset,
1276 const SmallVectorImpl<uint8_t> &Opcodes) {
1277 FlushPendingOffset();
1278 SPOffset = SPOffset - Offset;
1279 UnwindOpAsm.EmitRaw(Opcodes);
1280}
1281
Tim Northover5cc3dc82012-12-07 16:50:23 +00001282namespace llvm {
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001283
1284MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
1285 bool isVerboseAsm, bool useLoc, bool useCFI,
1286 bool useDwarfDirectory,
1287 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
1288 MCAsmBackend *TAB, bool ShowInst) {
Rafael Espindola24ea09e2014-01-26 06:06:37 +00001289 MCStreamer *S =
1290 llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useLoc, useCFI,
1291 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
1292 new ARMTargetAsmStreamer(*S, OS, *InstPrint, isVerboseAsm);
1293 return S;
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001294}
1295
Tim Northover5cc3dc82012-12-07 16:50:23 +00001296 MCELFStreamer* createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
1297 raw_ostream &OS, MCCodeEmitter *Emitter,
1298 bool RelaxAll, bool NoExecStack,
1299 bool IsThumb) {
Rafael Espindola24ea09e2014-01-26 06:06:37 +00001300 ARMELFStreamer *S = new ARMELFStreamer(Context, TAB, OS, Emitter, IsThumb);
1301 new ARMTargetELFStreamer(*S);
Rafael Espindolaac4ad252013-10-05 16:42:21 +00001302 // FIXME: This should eventually end up somewhere else where more
1303 // intelligent flag decisions can be made. For now we are just maintaining
1304 // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default.
1305 S->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
1306
Tim Northover5cc3dc82012-12-07 16:50:23 +00001307 if (RelaxAll)
1308 S->getAssembler().setRelaxAll(true);
1309 if (NoExecStack)
1310 S->getAssembler().setNoExecStack(true);
1311 return S;
1312 }
1313
1314}
1315
1316