blob: 3e87c6a7a80b491e21887b819322f85428309c3d [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"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000020#include "llvm/ADT/StringExtras.h"
Benjamin Kramerf242d8c2012-12-08 10:45:24 +000021#include "llvm/ADT/Twine.h"
22#include "llvm/MC/MCAsmBackend.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000023#include "llvm/MC/MCAsmInfo.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000024#include "llvm/MC/MCAssembler.h"
25#include "llvm/MC/MCCodeEmitter.h"
26#include "llvm/MC/MCContext.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000027#include "llvm/MC/MCELF.h"
28#include "llvm/MC/MCELFStreamer.h"
29#include "llvm/MC/MCELFSymbolFlags.h"
30#include "llvm/MC/MCExpr.h"
31#include "llvm/MC/MCInst.h"
Rafael Espindolaa17151a2013-10-08 13:08:17 +000032#include "llvm/MC/MCInstPrinter.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000033#include "llvm/MC/MCObjectStreamer.h"
Logan Chiend8bb4b72013-04-16 12:02:21 +000034#include "llvm/MC/MCRegisterInfo.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000035#include "llvm/MC/MCSection.h"
Benjamin Kramerf242d8c2012-12-08 10:45:24 +000036#include "llvm/MC/MCSectionELF.h"
37#include "llvm/MC/MCStreamer.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000038#include "llvm/MC/MCSymbol.h"
39#include "llvm/MC/MCValue.h"
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +000040#include "llvm/Support/ARMBuildAttributes.h"
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +000041#include "llvm/Support/ARMEHABI.h"
Tim Northover5cc3dc82012-12-07 16:50:23 +000042#include "llvm/Support/Debug.h"
43#include "llvm/Support/ELF.h"
Rafael Espindolaa17151a2013-10-08 13:08:17 +000044#include "llvm/Support/FormattedStream.h"
Logan Chien5b776b72014-02-22 14:00:39 +000045#include "llvm/Support/LEB128.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 }
Craig Topper062a2ba2014-04-25 05:30:21 +000065 return nullptr;
Logan Chien8cbb80d2013-10-28 17:51:12 +000066}
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 }
Craig Topper062a2ba2014-04-25 05:30:21 +000078 return nullptr;
Logan Chien439e8f92013-12-11 17:16:25 +000079}
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 }
Craig Topper062a2ba2014-04-25 05:30:21 +000091 return nullptr;
Logan Chien439e8f92013-12-11 17:16:25 +000092}
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
Tim Northover5cc3dc82012-12-07 16:50:23 +0000107namespace {
108
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000109class ARMELFStreamer;
110
111class ARMTargetAsmStreamer : public ARMTargetStreamer {
112 formatted_raw_ostream &OS;
113 MCInstPrinter &InstPrinter;
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000114 bool IsVerboseAsm;
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000115
Craig Topperca7e3e52014-03-10 03:19:03 +0000116 void emitFnStart() override;
117 void emitFnEnd() override;
118 void emitCantUnwind() override;
119 void emitPersonality(const MCSymbol *Personality) override;
120 void emitPersonalityIndex(unsigned Index) override;
121 void emitHandlerData() override;
122 void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0) override;
123 void emitMovSP(unsigned Reg, int64_t Offset = 0) override;
124 void emitPad(int64_t Offset) override;
125 void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
126 bool isVector) override;
127 void emitUnwindRaw(int64_t Offset,
128 const SmallVectorImpl<uint8_t> &Opcodes) override;
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000129
Craig Topperca7e3e52014-03-10 03:19:03 +0000130 void switchVendor(StringRef Vendor) override;
131 void emitAttribute(unsigned Attribute, unsigned Value) override;
132 void emitTextAttribute(unsigned Attribute, StringRef String) override;
133 void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
134 StringRef StrinValue) override;
135 void emitArch(unsigned Arch) override;
136 void emitObjectArch(unsigned Arch) override;
137 void emitFPU(unsigned FPU) override;
138 void emitInst(uint32_t Inst, char Suffix = '\0') override;
139 void finishAttributeSection() override;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000140
Craig Topperca7e3e52014-03-10 03:19:03 +0000141 void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE) override;
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000142
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000143public:
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000144 ARMTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS,
145 MCInstPrinter &InstPrinter, bool VerboseAsm);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000146};
147
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000148ARMTargetAsmStreamer::ARMTargetAsmStreamer(MCStreamer &S,
149 formatted_raw_ostream &OS,
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000150 MCInstPrinter &InstPrinter,
151 bool VerboseAsm)
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000152 : ARMTargetStreamer(S), OS(OS), InstPrinter(InstPrinter),
153 IsVerboseAsm(VerboseAsm) {}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000154void ARMTargetAsmStreamer::emitFnStart() { OS << "\t.fnstart\n"; }
155void ARMTargetAsmStreamer::emitFnEnd() { OS << "\t.fnend\n"; }
156void ARMTargetAsmStreamer::emitCantUnwind() { OS << "\t.cantunwind\n"; }
157void ARMTargetAsmStreamer::emitPersonality(const MCSymbol *Personality) {
158 OS << "\t.personality " << Personality->getName() << '\n';
159}
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000160void ARMTargetAsmStreamer::emitPersonalityIndex(unsigned Index) {
161 OS << "\t.personalityindex " << Index << '\n';
162}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000163void ARMTargetAsmStreamer::emitHandlerData() { OS << "\t.handlerdata\n"; }
164void ARMTargetAsmStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
165 int64_t Offset) {
166 OS << "\t.setfp\t";
167 InstPrinter.printRegName(OS, FpReg);
168 OS << ", ";
169 InstPrinter.printRegName(OS, SpReg);
170 if (Offset)
171 OS << ", #" << Offset;
172 OS << '\n';
173}
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000174void ARMTargetAsmStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
175 assert((Reg != ARM::SP && Reg != ARM::PC) &&
176 "the operand of .movsp cannot be either sp or pc");
177
178 OS << "\t.movsp\t";
179 InstPrinter.printRegName(OS, Reg);
180 if (Offset)
181 OS << ", #" << Offset;
182 OS << '\n';
183}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000184void ARMTargetAsmStreamer::emitPad(int64_t Offset) {
185 OS << "\t.pad\t#" << Offset << '\n';
186}
187void ARMTargetAsmStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
188 bool isVector) {
189 assert(RegList.size() && "RegList should not be empty");
190 if (isVector)
191 OS << "\t.vsave\t{";
192 else
193 OS << "\t.save\t{";
194
195 InstPrinter.printRegName(OS, RegList[0]);
196
197 for (unsigned i = 1, e = RegList.size(); i != e; ++i) {
198 OS << ", ";
199 InstPrinter.printRegName(OS, RegList[i]);
200 }
201
202 OS << "}\n";
203}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000204void ARMTargetAsmStreamer::switchVendor(StringRef Vendor) {
205}
206void ARMTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000207 OS << "\t.eabi_attribute\t" << Attribute << ", " << Twine(Value);
208 if (IsVerboseAsm) {
209 StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute);
210 if (!Name.empty())
211 OS << "\t@ " << Name;
212 }
213 OS << "\n";
Logan Chien8cbb80d2013-10-28 17:51:12 +0000214}
215void ARMTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
216 StringRef String) {
217 switch (Attribute) {
Logan Chien8cbb80d2013-10-28 17:51:12 +0000218 case ARMBuildAttrs::CPU_name:
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000219 OS << "\t.cpu\t" << String.lower();
220 break;
221 default:
222 OS << "\t.eabi_attribute\t" << Attribute << ", \"" << String << "\"";
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000223 if (IsVerboseAsm) {
224 StringRef Name = ARMBuildAttrs::AttrTypeAsString(Attribute);
225 if (!Name.empty())
226 OS << "\t@ " << Name;
227 }
Logan Chien8cbb80d2013-10-28 17:51:12 +0000228 break;
229 }
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000230 OS << "\n";
231}
232void ARMTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
233 unsigned IntValue,
234 StringRef StringValue) {
235 switch (Attribute) {
236 default: llvm_unreachable("unsupported multi-value attribute in asm mode");
237 case ARMBuildAttrs::compatibility:
238 OS << "\t.eabi_attribute\t" << Attribute << ", " << IntValue;
239 if (!StringValue.empty())
240 OS << ", \"" << StringValue << "\"";
Saleem Abdulrasoolf16e68a2014-01-07 02:28:50 +0000241 if (IsVerboseAsm)
242 OS << "\t@ " << ARMBuildAttrs::AttrTypeAsString(Attribute);
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000243 break;
244 }
245 OS << "\n";
Logan Chien8cbb80d2013-10-28 17:51:12 +0000246}
Logan Chien439e8f92013-12-11 17:16:25 +0000247void ARMTargetAsmStreamer::emitArch(unsigned Arch) {
248 OS << "\t.arch\t" << GetArchName(Arch) << "\n";
249}
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000250void ARMTargetAsmStreamer::emitObjectArch(unsigned Arch) {
251 OS << "\t.object_arch\t" << GetArchName(Arch) << '\n';
252}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000253void ARMTargetAsmStreamer::emitFPU(unsigned FPU) {
254 OS << "\t.fpu\t" << GetFPUName(FPU) << "\n";
255}
256void ARMTargetAsmStreamer::finishAttributeSection() {
257}
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000258void
259ARMTargetAsmStreamer::AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *S) {
260 OS << "\t.tlsdescseq\t" << S->getSymbol().getName();
261}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000262
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000263void ARMTargetAsmStreamer::emitInst(uint32_t Inst, char Suffix) {
264 OS << "\t.inst";
265 if (Suffix)
266 OS << "." << Suffix;
267 OS << "\t0x" << utohexstr(Inst) << "\n";
268}
269
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000270void ARMTargetAsmStreamer::emitUnwindRaw(int64_t Offset,
271 const SmallVectorImpl<uint8_t> &Opcodes) {
272 OS << "\t.unwind_raw " << Offset;
273 for (SmallVectorImpl<uint8_t>::const_iterator OCI = Opcodes.begin(),
274 OCE = Opcodes.end();
275 OCI != OCE; ++OCI)
276 OS << ", 0x" << utohexstr(*OCI);
277 OS << '\n';
278}
279
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000280class ARMTargetELFStreamer : public ARMTargetStreamer {
Logan Chien8cbb80d2013-10-28 17:51:12 +0000281private:
282 // This structure holds all attributes, accounting for
283 // their string/numeric value, so we can later emmit them
284 // in declaration order, keeping all in the same vector
285 struct AttributeItem {
286 enum {
287 HiddenAttribute = 0,
288 NumericAttribute,
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000289 TextAttribute,
290 NumericAndTextAttributes
Logan Chien8cbb80d2013-10-28 17:51:12 +0000291 } Type;
292 unsigned Tag;
293 unsigned IntValue;
294 StringRef StringValue;
295
296 static bool LessTag(const AttributeItem &LHS, const AttributeItem &RHS) {
297 return (LHS.Tag < RHS.Tag);
298 }
299 };
300
301 StringRef CurrentVendor;
302 unsigned FPU;
Logan Chien439e8f92013-12-11 17:16:25 +0000303 unsigned Arch;
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000304 unsigned EmittedArch;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000305 SmallVector<AttributeItem, 64> Contents;
306
307 const MCSection *AttributeSection;
308
Logan Chien8cbb80d2013-10-28 17:51:12 +0000309 AttributeItem *getAttributeItem(unsigned Attribute) {
310 for (size_t i = 0; i < Contents.size(); ++i)
311 if (Contents[i].Tag == Attribute)
312 return &Contents[i];
Craig Topper062a2ba2014-04-25 05:30:21 +0000313 return nullptr;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000314 }
315
316 void setAttributeItem(unsigned Attribute, unsigned Value,
317 bool OverwriteExisting) {
318 // Look for existing attribute item
319 if (AttributeItem *Item = getAttributeItem(Attribute)) {
320 if (!OverwriteExisting)
321 return;
Saleem Abdulrasool93900052014-01-19 08:25:41 +0000322 Item->Type = AttributeItem::NumericAttribute;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000323 Item->IntValue = Value;
324 return;
325 }
326
327 // Create new attribute item
328 AttributeItem Item = {
329 AttributeItem::NumericAttribute,
330 Attribute,
331 Value,
332 StringRef("")
333 };
334 Contents.push_back(Item);
335 }
336
337 void setAttributeItem(unsigned Attribute, StringRef Value,
338 bool OverwriteExisting) {
339 // Look for existing attribute item
340 if (AttributeItem *Item = getAttributeItem(Attribute)) {
341 if (!OverwriteExisting)
342 return;
Saleem Abdulrasool93900052014-01-19 08:25:41 +0000343 Item->Type = AttributeItem::TextAttribute;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000344 Item->StringValue = Value;
345 return;
346 }
347
348 // Create new attribute item
349 AttributeItem Item = {
350 AttributeItem::TextAttribute,
351 Attribute,
352 0,
353 Value
354 };
355 Contents.push_back(Item);
356 }
357
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000358 void setAttributeItems(unsigned Attribute, unsigned IntValue,
359 StringRef StringValue, bool OverwriteExisting) {
360 // Look for existing attribute item
361 if (AttributeItem *Item = getAttributeItem(Attribute)) {
362 if (!OverwriteExisting)
363 return;
Saleem Abdulrasool93900052014-01-19 08:25:41 +0000364 Item->Type = AttributeItem::NumericAndTextAttributes;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000365 Item->IntValue = IntValue;
366 Item->StringValue = StringValue;
367 return;
368 }
369
370 // Create new attribute item
371 AttributeItem Item = {
372 AttributeItem::NumericAndTextAttributes,
373 Attribute,
374 IntValue,
375 StringValue
376 };
377 Contents.push_back(Item);
378 }
379
Logan Chien439e8f92013-12-11 17:16:25 +0000380 void emitArchDefaultAttributes();
Logan Chien8cbb80d2013-10-28 17:51:12 +0000381 void emitFPUDefaultAttributes();
382
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000383 ARMELFStreamer &getStreamer();
Logan Chien8cbb80d2013-10-28 17:51:12 +0000384
Craig Topperca7e3e52014-03-10 03:19:03 +0000385 void emitFnStart() override;
386 void emitFnEnd() override;
387 void emitCantUnwind() override;
388 void emitPersonality(const MCSymbol *Personality) override;
389 void emitPersonalityIndex(unsigned Index) override;
390 void emitHandlerData() override;
391 void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0) override;
392 void emitMovSP(unsigned Reg, int64_t Offset = 0) override;
393 void emitPad(int64_t Offset) override;
394 void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
395 bool isVector) override;
396 void emitUnwindRaw(int64_t Offset,
397 const SmallVectorImpl<uint8_t> &Opcodes) override;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000398
Craig Topperca7e3e52014-03-10 03:19:03 +0000399 void switchVendor(StringRef Vendor) override;
400 void emitAttribute(unsigned Attribute, unsigned Value) override;
401 void emitTextAttribute(unsigned Attribute, StringRef String) override;
402 void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
403 StringRef StringValue) override;
404 void emitArch(unsigned Arch) override;
405 void emitObjectArch(unsigned Arch) override;
406 void emitFPU(unsigned FPU) override;
407 void emitInst(uint32_t Inst, char Suffix = '\0') override;
408 void finishAttributeSection() override;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000409
Craig Topperca7e3e52014-03-10 03:19:03 +0000410 void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE) override;
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000411
Logan Chien8cbb80d2013-10-28 17:51:12 +0000412 size_t calculateContentSize() const;
413
414public:
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000415 ARMTargetELFStreamer(MCStreamer &S)
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000416 : ARMTargetStreamer(S), CurrentVendor("aeabi"), FPU(ARM::INVALID_FPU),
417 Arch(ARM::INVALID_ARCH), EmittedArch(ARM::INVALID_ARCH),
Craig Topper062a2ba2014-04-25 05:30:21 +0000418 AttributeSection(nullptr) {}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000419};
420
Tim Northover5cc3dc82012-12-07 16:50:23 +0000421/// Extend the generic ELFStreamer class so that it can emit mapping symbols at
422/// the appropriate points in the object files. These symbols are defined in the
423/// ARM ELF ABI: infocenter.arm.com/help/topic/com.arm.../IHI0044D_aaelf.pdf.
424///
425/// In brief: $a, $t or $d should be emitted at the start of each contiguous
426/// region of ARM code, Thumb code or data in a section. In practice, this
427/// emission does not rely on explicit assembler directives but on inherent
428/// properties of the directives doing the emission (e.g. ".byte" is data, "add
429/// r0, r0, r0" an instruction).
430///
431/// As a result this system is orthogonal to the DataRegion infrastructure used
432/// by MachO. Beware!
433class ARMELFStreamer : public MCELFStreamer {
434public:
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000435 friend class ARMTargetELFStreamer;
436
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000437 ARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS,
438 MCCodeEmitter *Emitter, bool IsThumb)
439 : MCELFStreamer(Context, TAB, OS, Emitter), IsThumb(IsThumb),
440 MappingSymbolCounter(0), LastEMS(EMS_None) {
Logan Chiend8bb4b72013-04-16 12:02:21 +0000441 Reset();
442 }
Tim Northover5cc3dc82012-12-07 16:50:23 +0000443
444 ~ARMELFStreamer() {}
445
Craig Topperca7e3e52014-03-10 03:19:03 +0000446 void FinishImpl() override;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000447
Logan Chien2bcc42c2013-01-30 15:39:04 +0000448 // ARM exception handling directives
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000449 void emitFnStart();
450 void emitFnEnd();
451 void emitCantUnwind();
452 void emitPersonality(const MCSymbol *Per);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000453 void emitPersonalityIndex(unsigned index);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000454 void emitHandlerData();
455 void emitSetFP(unsigned NewFpReg, unsigned NewSpReg, int64_t Offset = 0);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000456 void emitMovSP(unsigned Reg, int64_t Offset = 0);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000457 void emitPad(int64_t Offset);
458 void emitRegSave(const SmallVectorImpl<unsigned> &RegList, bool isVector);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000459 void emitUnwindRaw(int64_t Offset, const SmallVectorImpl<uint8_t> &Opcodes);
Logan Chien2bcc42c2013-01-30 15:39:04 +0000460
Craig Topperca7e3e52014-03-10 03:19:03 +0000461 void ChangeSection(const MCSection *Section,
462 const MCExpr *Subsection) override {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000463 // We have to keep track of the mapping symbol state of any sections we
464 // use. Each one should start off as EMS_None, which is provided as the
465 // default constructor by DenseMap::lookup.
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000466 LastMappingSymbols[getPreviousSection().first] = LastEMS;
Tim Northover5cc3dc82012-12-07 16:50:23 +0000467 LastEMS = LastMappingSymbols.lookup(Section);
468
Peter Collingbourne2f495b92013-04-17 21:18:16 +0000469 MCELFStreamer::ChangeSection(Section, Subsection);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000470 }
471
472 /// This function is the one used to emit instruction data into the ELF
473 /// streamer. We override it to add the appropriate mapping symbol if
474 /// necessary.
Craig Topperca7e3e52014-03-10 03:19:03 +0000475 void EmitInstruction(const MCInst& Inst,
476 const MCSubtargetInfo &STI) override {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000477 if (IsThumb)
478 EmitThumbMappingSymbol();
479 else
480 EmitARMMappingSymbol();
481
David Woodhousee6c13e42014-01-28 23:12:42 +0000482 MCELFStreamer::EmitInstruction(Inst, STI);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000483 }
484
Craig Topperd25ff6f2014-03-10 03:22:59 +0000485 void emitInst(uint32_t Inst, char Suffix) {
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000486 unsigned Size;
487 char Buffer[4];
488 const bool LittleEndian = getContext().getAsmInfo()->isLittleEndian();
489
490 switch (Suffix) {
491 case '\0':
492 Size = 4;
493
494 assert(!IsThumb);
495 EmitARMMappingSymbol();
496 for (unsigned II = 0, IE = Size; II != IE; II++) {
497 const unsigned I = LittleEndian ? (Size - II - 1) : II;
498 Buffer[Size - II - 1] = uint8_t(Inst >> I * CHAR_BIT);
499 }
500
501 break;
502 case 'n':
503 case 'w':
504 Size = (Suffix == 'n' ? 2 : 4);
505
506 assert(IsThumb);
507 EmitThumbMappingSymbol();
508 for (unsigned II = 0, IE = Size; II != IE; II = II + 2) {
509 const unsigned I0 = LittleEndian ? II + 0 : (Size - II - 1);
510 const unsigned I1 = LittleEndian ? II + 1 : (Size - II - 2);
511 Buffer[Size - II - 2] = uint8_t(Inst >> I0 * CHAR_BIT);
512 Buffer[Size - II - 1] = uint8_t(Inst >> I1 * CHAR_BIT);
513 }
514
515 break;
516 default:
517 llvm_unreachable("Invalid Suffix");
518 }
519
520 MCELFStreamer::EmitBytes(StringRef(Buffer, Size));
521 }
522
Tim Northover5cc3dc82012-12-07 16:50:23 +0000523 /// This is one of the functions used to emit data into an ELF section, so the
524 /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
525 /// necessary.
Craig Topperca7e3e52014-03-10 03:19:03 +0000526 void EmitBytes(StringRef Data) override {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000527 EmitDataMappingSymbol();
Rafael Espindola64e1af82013-07-02 15:49:13 +0000528 MCELFStreamer::EmitBytes(Data);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000529 }
530
531 /// This is one of the functions used to emit data into an ELF section, so the
532 /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
533 /// necessary.
Kevin Enderby96918bc2014-04-22 17:27:29 +0000534 void EmitValueImpl(const MCExpr *Value, unsigned Size,
535 const SMLoc &Loc) override {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000536 EmitDataMappingSymbol();
Rafael Espindola64e1af82013-07-02 15:49:13 +0000537 MCELFStreamer::EmitValueImpl(Value, Size);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000538 }
539
Craig Topperca7e3e52014-03-10 03:19:03 +0000540 void EmitAssemblerFlag(MCAssemblerFlag Flag) override {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000541 MCELFStreamer::EmitAssemblerFlag(Flag);
542
543 switch (Flag) {
544 case MCAF_SyntaxUnified:
545 return; // no-op here.
546 case MCAF_Code16:
547 IsThumb = true;
548 return; // Change to Thumb mode
549 case MCAF_Code32:
550 IsThumb = false;
551 return; // Change to ARM mode
552 case MCAF_Code64:
553 return;
554 case MCAF_SubsectionsViaSymbols:
555 return;
556 }
557 }
558
559private:
560 enum ElfMappingSymbol {
561 EMS_None,
562 EMS_ARM,
563 EMS_Thumb,
564 EMS_Data
565 };
566
567 void EmitDataMappingSymbol() {
568 if (LastEMS == EMS_Data) return;
569 EmitMappingSymbol("$d");
570 LastEMS = EMS_Data;
571 }
572
573 void EmitThumbMappingSymbol() {
574 if (LastEMS == EMS_Thumb) return;
575 EmitMappingSymbol("$t");
576 LastEMS = EMS_Thumb;
577 }
578
579 void EmitARMMappingSymbol() {
580 if (LastEMS == EMS_ARM) return;
581 EmitMappingSymbol("$a");
582 LastEMS = EMS_ARM;
583 }
584
585 void EmitMappingSymbol(StringRef Name) {
586 MCSymbol *Start = getContext().CreateTempSymbol();
587 EmitLabel(Start);
588
Chandler Carruth1d94e932012-12-08 03:10:14 +0000589 MCSymbol *Symbol =
Benjamin Kramerf242d8c2012-12-08 10:45:24 +0000590 getContext().GetOrCreateSymbol(Name + "." +
591 Twine(MappingSymbolCounter++));
Tim Northover5cc3dc82012-12-07 16:50:23 +0000592
593 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
594 MCELF::SetType(SD, ELF::STT_NOTYPE);
595 MCELF::SetBinding(SD, ELF::STB_LOCAL);
596 SD.setExternal(false);
Richard Mitton21101b32013-09-19 23:21:01 +0000597 AssignSection(Symbol, getCurrentSection().first);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000598
599 const MCExpr *Value = MCSymbolRefExpr::Create(Start, getContext());
600 Symbol->setVariableValue(Value);
601 }
602
Craig Topperca7e3e52014-03-10 03:19:03 +0000603 void EmitThumbFunc(MCSymbol *Func) override {
Tim Northover5cc3dc82012-12-07 16:50:23 +0000604 // FIXME: Anything needed here to flag the function as thumb?
605
606 getAssembler().setIsThumbFunc(Func);
607
608 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Func);
609 SD.setFlags(SD.getFlags() | ELF_Other_ThumbFunc);
610 }
611
Logan Chien2bcc42c2013-01-30 15:39:04 +0000612 // Helper functions for ARM exception handling directives
613 void Reset();
614
615 void EmitPersonalityFixup(StringRef Name);
Logan Chien325823a2013-06-09 12:22:30 +0000616 void FlushPendingOffset();
Logan Chienc931fce2013-07-02 12:43:27 +0000617 void FlushUnwindOpcodes(bool NoHandlerData);
Logan Chien2bcc42c2013-01-30 15:39:04 +0000618
619 void SwitchToEHSection(const char *Prefix, unsigned Type, unsigned Flags,
620 SectionKind Kind, const MCSymbol &Fn);
621 void SwitchToExTabSection(const MCSymbol &FnStart);
622 void SwitchToExIdxSection(const MCSymbol &FnStart);
Tim Northover5cc3dc82012-12-07 16:50:23 +0000623
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000624 void EmitFixup(const MCExpr *Expr, MCFixupKind Kind);
625
Tim Northover5cc3dc82012-12-07 16:50:23 +0000626 bool IsThumb;
627 int64_t MappingSymbolCounter;
628
629 DenseMap<const MCSection *, ElfMappingSymbol> LastMappingSymbols;
630 ElfMappingSymbol LastEMS;
631
Logan Chien2bcc42c2013-01-30 15:39:04 +0000632 // ARM Exception Handling Frame Information
633 MCSymbol *ExTab;
634 MCSymbol *FnStart;
635 const MCSymbol *Personality;
Logan Chien325823a2013-06-09 12:22:30 +0000636 unsigned PersonalityIndex;
637 unsigned FPReg; // Frame pointer register
638 int64_t FPOffset; // Offset: (final frame pointer) - (initial $sp)
639 int64_t SPOffset; // Offset: (final $sp) - (initial $sp)
640 int64_t PendingOffset; // Offset: (final $sp) - (emitted $sp)
Logan Chiend8bb4b72013-04-16 12:02:21 +0000641 bool UsedFP;
Logan Chien2bcc42c2013-01-30 15:39:04 +0000642 bool CantUnwind;
Logan Chien325823a2013-06-09 12:22:30 +0000643 SmallVector<uint8_t, 64> Opcodes;
Logan Chiend8bb4b72013-04-16 12:02:21 +0000644 UnwindOpcodeAssembler UnwindOpAsm;
Tim Northover5cc3dc82012-12-07 16:50:23 +0000645};
Logan Chiend8bb4b72013-04-16 12:02:21 +0000646} // end anonymous namespace
Tim Northover5cc3dc82012-12-07 16:50:23 +0000647
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000648ARMELFStreamer &ARMTargetELFStreamer::getStreamer() {
Rafael Espindola24ea09e2014-01-26 06:06:37 +0000649 return static_cast<ARMELFStreamer &>(Streamer);
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000650}
651
652void ARMTargetELFStreamer::emitFnStart() { getStreamer().emitFnStart(); }
653void ARMTargetELFStreamer::emitFnEnd() { getStreamer().emitFnEnd(); }
654void ARMTargetELFStreamer::emitCantUnwind() { getStreamer().emitCantUnwind(); }
655void ARMTargetELFStreamer::emitPersonality(const MCSymbol *Personality) {
656 getStreamer().emitPersonality(Personality);
657}
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000658void ARMTargetELFStreamer::emitPersonalityIndex(unsigned Index) {
659 getStreamer().emitPersonalityIndex(Index);
660}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000661void ARMTargetELFStreamer::emitHandlerData() {
662 getStreamer().emitHandlerData();
663}
664void ARMTargetELFStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
665 int64_t Offset) {
666 getStreamer().emitSetFP(FpReg, SpReg, Offset);
667}
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000668void ARMTargetELFStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
669 getStreamer().emitMovSP(Reg, Offset);
670}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000671void ARMTargetELFStreamer::emitPad(int64_t Offset) {
672 getStreamer().emitPad(Offset);
673}
674void ARMTargetELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
675 bool isVector) {
676 getStreamer().emitRegSave(RegList, isVector);
677}
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000678void ARMTargetELFStreamer::emitUnwindRaw(int64_t Offset,
679 const SmallVectorImpl<uint8_t> &Opcodes) {
680 getStreamer().emitUnwindRaw(Offset, Opcodes);
681}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000682void ARMTargetELFStreamer::switchVendor(StringRef Vendor) {
683 assert(!Vendor.empty() && "Vendor cannot be empty.");
684
685 if (CurrentVendor == Vendor)
686 return;
687
688 if (!CurrentVendor.empty())
689 finishAttributeSection();
690
691 assert(Contents.empty() &&
692 ".ARM.attributes should be flushed before changing vendor");
693 CurrentVendor = Vendor;
694
695}
696void ARMTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
697 setAttributeItem(Attribute, Value, /* OverwriteExisting= */ true);
698}
699void ARMTargetELFStreamer::emitTextAttribute(unsigned Attribute,
700 StringRef Value) {
701 setAttributeItem(Attribute, Value, /* OverwriteExisting= */ true);
702}
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000703void ARMTargetELFStreamer::emitIntTextAttribute(unsigned Attribute,
704 unsigned IntValue,
705 StringRef StringValue) {
706 setAttributeItems(Attribute, IntValue, StringValue,
707 /* OverwriteExisting= */ true);
708}
Logan Chien439e8f92013-12-11 17:16:25 +0000709void ARMTargetELFStreamer::emitArch(unsigned Value) {
710 Arch = Value;
711}
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000712void ARMTargetELFStreamer::emitObjectArch(unsigned Value) {
713 EmittedArch = Value;
714}
Logan Chien439e8f92013-12-11 17:16:25 +0000715void ARMTargetELFStreamer::emitArchDefaultAttributes() {
716 using namespace ARMBuildAttrs;
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000717
Logan Chien439e8f92013-12-11 17:16:25 +0000718 setAttributeItem(CPU_name, GetArchDefaultCPUName(Arch), false);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000719 if (EmittedArch == ARM::INVALID_ARCH)
720 setAttributeItem(CPU_arch, GetArchDefaultCPUArch(Arch), false);
721 else
722 setAttributeItem(CPU_arch, GetArchDefaultCPUArch(EmittedArch), false);
Logan Chien439e8f92013-12-11 17:16:25 +0000723
724 switch (Arch) {
725 case ARM::ARMV2:
726 case ARM::ARMV2A:
727 case ARM::ARMV3:
728 case ARM::ARMV3M:
729 case ARM::ARMV4:
730 case ARM::ARMV5:
731 setAttributeItem(ARM_ISA_use, Allowed, false);
732 break;
733
734 case ARM::ARMV4T:
735 case ARM::ARMV5T:
736 case ARM::ARMV5TE:
737 case ARM::ARMV6:
738 case ARM::ARMV6J:
739 setAttributeItem(ARM_ISA_use, Allowed, false);
740 setAttributeItem(THUMB_ISA_use, Allowed, false);
741 break;
742
743 case ARM::ARMV6T2:
744 setAttributeItem(ARM_ISA_use, Allowed, false);
745 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
746 break;
747
748 case ARM::ARMV6Z:
749 case ARM::ARMV6ZK:
750 setAttributeItem(ARM_ISA_use, Allowed, false);
751 setAttributeItem(THUMB_ISA_use, Allowed, false);
752 setAttributeItem(Virtualization_use, AllowTZ, false);
753 break;
754
755 case ARM::ARMV6M:
Logan Chien439e8f92013-12-11 17:16:25 +0000756 setAttributeItem(THUMB_ISA_use, Allowed, false);
757 break;
758
759 case ARM::ARMV7:
760 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
761 break;
762
763 case ARM::ARMV7A:
764 setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
765 setAttributeItem(ARM_ISA_use, Allowed, false);
766 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
767 break;
768
769 case ARM::ARMV7R:
770 setAttributeItem(CPU_arch_profile, RealTimeProfile, false);
771 setAttributeItem(ARM_ISA_use, Allowed, false);
772 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
773 break;
774
775 case ARM::ARMV7M:
776 setAttributeItem(CPU_arch_profile, MicroControllerProfile, false);
777 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
778 break;
779
780 case ARM::ARMV8A:
781 setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
782 setAttributeItem(ARM_ISA_use, Allowed, false);
783 setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
784 setAttributeItem(MPextension_use, Allowed, false);
785 setAttributeItem(Virtualization_use, AllowTZVirtualization, false);
786 break;
787
788 case ARM::IWMMXT:
789 setAttributeItem(ARM_ISA_use, Allowed, false);
790 setAttributeItem(THUMB_ISA_use, Allowed, false);
791 setAttributeItem(WMMX_arch, AllowWMMXv1, false);
792 break;
793
794 case ARM::IWMMXT2:
795 setAttributeItem(ARM_ISA_use, Allowed, false);
796 setAttributeItem(THUMB_ISA_use, Allowed, false);
797 setAttributeItem(WMMX_arch, AllowWMMXv2, false);
798 break;
799
800 default:
801 report_fatal_error("Unknown Arch: " + Twine(Arch));
802 break;
803 }
804}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000805void ARMTargetELFStreamer::emitFPU(unsigned Value) {
806 FPU = Value;
807}
808void ARMTargetELFStreamer::emitFPUDefaultAttributes() {
809 switch (FPU) {
810 case ARM::VFP:
811 case ARM::VFPV2:
Logan Chiena39510a2013-12-18 17:23:15 +0000812 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000813 ARMBuildAttrs::AllowFPv2,
814 /* OverwriteExisting= */ false);
815 break;
816
817 case ARM::VFPV3:
Logan Chiena39510a2013-12-18 17:23:15 +0000818 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000819 ARMBuildAttrs::AllowFPv3A,
820 /* OverwriteExisting= */ false);
821 break;
822
823 case ARM::VFPV3_D16:
Logan Chiena39510a2013-12-18 17:23:15 +0000824 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000825 ARMBuildAttrs::AllowFPv3B,
826 /* OverwriteExisting= */ false);
827 break;
828
829 case ARM::VFPV4:
Logan Chiena39510a2013-12-18 17:23:15 +0000830 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000831 ARMBuildAttrs::AllowFPv4A,
832 /* OverwriteExisting= */ false);
833 break;
834
835 case ARM::VFPV4_D16:
Logan Chiena39510a2013-12-18 17:23:15 +0000836 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000837 ARMBuildAttrs::AllowFPv4B,
838 /* OverwriteExisting= */ false);
839 break;
840
841 case ARM::FP_ARMV8:
Logan Chiena39510a2013-12-18 17:23:15 +0000842 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000843 ARMBuildAttrs::AllowFPARMv8A,
844 /* OverwriteExisting= */ false);
845 break;
846
847 case ARM::NEON:
Logan Chiena39510a2013-12-18 17:23:15 +0000848 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000849 ARMBuildAttrs::AllowFPv3A,
850 /* OverwriteExisting= */ false);
851 setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
852 ARMBuildAttrs::AllowNeon,
853 /* OverwriteExisting= */ false);
854 break;
855
856 case ARM::NEON_VFPV4:
Logan Chiena39510a2013-12-18 17:23:15 +0000857 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000858 ARMBuildAttrs::AllowFPv4A,
859 /* OverwriteExisting= */ false);
860 setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
861 ARMBuildAttrs::AllowNeon2,
862 /* OverwriteExisting= */ false);
863 break;
864
865 case ARM::NEON_FP_ARMV8:
866 case ARM::CRYPTO_NEON_FP_ARMV8:
Logan Chiena39510a2013-12-18 17:23:15 +0000867 setAttributeItem(ARMBuildAttrs::FP_arch,
Logan Chien8cbb80d2013-10-28 17:51:12 +0000868 ARMBuildAttrs::AllowFPARMv8A,
869 /* OverwriteExisting= */ false);
870 setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
871 ARMBuildAttrs::AllowNeonARMv8,
872 /* OverwriteExisting= */ false);
873 break;
874
Logan Chien05ae7442014-01-02 15:50:02 +0000875 case ARM::SOFTVFP:
876 break;
877
Logan Chien8cbb80d2013-10-28 17:51:12 +0000878 default:
879 report_fatal_error("Unknown FPU: " + Twine(FPU));
880 break;
881 }
882}
883size_t ARMTargetELFStreamer::calculateContentSize() const {
884 size_t Result = 0;
885 for (size_t i = 0; i < Contents.size(); ++i) {
886 AttributeItem item = Contents[i];
887 switch (item.Type) {
888 case AttributeItem::HiddenAttribute:
889 break;
890 case AttributeItem::NumericAttribute:
Logan Chien5b776b72014-02-22 14:00:39 +0000891 Result += getULEB128Size(item.Tag);
892 Result += getULEB128Size(item.IntValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000893 break;
894 case AttributeItem::TextAttribute:
Logan Chien5b776b72014-02-22 14:00:39 +0000895 Result += getULEB128Size(item.Tag);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000896 Result += item.StringValue.size() + 1; // string + '\0'
897 break;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000898 case AttributeItem::NumericAndTextAttributes:
Logan Chien5b776b72014-02-22 14:00:39 +0000899 Result += getULEB128Size(item.Tag);
900 Result += getULEB128Size(item.IntValue);
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000901 Result += item.StringValue.size() + 1; // string + '\0';
902 break;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000903 }
904 }
905 return Result;
906}
907void ARMTargetELFStreamer::finishAttributeSection() {
908 // <format-version>
909 // [ <section-length> "vendor-name"
910 // [ <file-tag> <size> <attribute>*
911 // | <section-tag> <size> <section-number>* 0 <attribute>*
912 // | <symbol-tag> <size> <symbol-number>* 0 <attribute>*
913 // ]+
914 // ]*
915
916 if (FPU != ARM::INVALID_FPU)
917 emitFPUDefaultAttributes();
918
Logan Chien439e8f92013-12-11 17:16:25 +0000919 if (Arch != ARM::INVALID_ARCH)
920 emitArchDefaultAttributes();
921
Logan Chien8cbb80d2013-10-28 17:51:12 +0000922 if (Contents.empty())
923 return;
924
925 std::sort(Contents.begin(), Contents.end(), AttributeItem::LessTag);
926
927 ARMELFStreamer &Streamer = getStreamer();
928
929 // Switch to .ARM.attributes section
930 if (AttributeSection) {
931 Streamer.SwitchSection(AttributeSection);
932 } else {
933 AttributeSection =
934 Streamer.getContext().getELFSection(".ARM.attributes",
935 ELF::SHT_ARM_ATTRIBUTES,
936 0,
937 SectionKind::getMetadata());
938 Streamer.SwitchSection(AttributeSection);
939
940 // Format version
941 Streamer.EmitIntValue(0x41, 1);
942 }
943
944 // Vendor size + Vendor name + '\0'
945 const size_t VendorHeaderSize = 4 + CurrentVendor.size() + 1;
946
947 // Tag + Tag Size
948 const size_t TagHeaderSize = 1 + 4;
949
950 const size_t ContentsSize = calculateContentSize();
951
952 Streamer.EmitIntValue(VendorHeaderSize + TagHeaderSize + ContentsSize, 4);
953 Streamer.EmitBytes(CurrentVendor);
954 Streamer.EmitIntValue(0, 1); // '\0'
955
956 Streamer.EmitIntValue(ARMBuildAttrs::File, 1);
957 Streamer.EmitIntValue(TagHeaderSize + ContentsSize, 4);
958
959 // Size should have been accounted for already, now
960 // emit each field as its type (ULEB or String)
961 for (size_t i = 0; i < Contents.size(); ++i) {
962 AttributeItem item = Contents[i];
963 Streamer.EmitULEB128IntValue(item.Tag);
964 switch (item.Type) {
965 default: llvm_unreachable("Invalid attribute type");
966 case AttributeItem::NumericAttribute:
967 Streamer.EmitULEB128IntValue(item.IntValue);
968 break;
969 case AttributeItem::TextAttribute:
970 Streamer.EmitBytes(item.StringValue.upper());
971 Streamer.EmitIntValue(0, 1); // '\0'
972 break;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +0000973 case AttributeItem::NumericAndTextAttributes:
974 Streamer.EmitULEB128IntValue(item.IntValue);
975 Streamer.EmitBytes(item.StringValue.upper());
976 Streamer.EmitIntValue(0, 1); // '\0'
977 break;
Logan Chien8cbb80d2013-10-28 17:51:12 +0000978 }
979 }
980
981 Contents.clear();
982 FPU = ARM::INVALID_FPU;
983}
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000984void
985ARMTargetELFStreamer::AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *S) {
986 getStreamer().EmitFixup(S, FK_Data_4);
987}
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000988void ARMTargetELFStreamer::emitInst(uint32_t Inst, char Suffix) {
989 getStreamer().emitInst(Inst, Suffix);
990}
Logan Chien8cbb80d2013-10-28 17:51:12 +0000991
992void ARMELFStreamer::FinishImpl() {
Rafael Espindola4a1a3602014-01-14 01:21:46 +0000993 MCTargetStreamer &TS = *getTargetStreamer();
Logan Chien8cbb80d2013-10-28 17:51:12 +0000994 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
995 ATS.finishAttributeSection();
996
997 MCELFStreamer::FinishImpl();
998}
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000999
Logan Chien2bcc42c2013-01-30 15:39:04 +00001000inline void ARMELFStreamer::SwitchToEHSection(const char *Prefix,
1001 unsigned Type,
1002 unsigned Flags,
1003 SectionKind Kind,
1004 const MCSymbol &Fn) {
1005 const MCSectionELF &FnSection =
1006 static_cast<const MCSectionELF &>(Fn.getSection());
1007
1008 // Create the name for new section
1009 StringRef FnSecName(FnSection.getSectionName());
1010 SmallString<128> EHSecName(Prefix);
1011 if (FnSecName != ".text") {
1012 EHSecName += FnSecName;
1013 }
1014
1015 // Get .ARM.extab or .ARM.exidx section
Craig Topper062a2ba2014-04-25 05:30:21 +00001016 const MCSectionELF *EHSection = nullptr;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001017 if (const MCSymbol *Group = FnSection.getGroup()) {
1018 EHSection = getContext().getELFSection(
1019 EHSecName, Type, Flags | ELF::SHF_GROUP, Kind,
1020 FnSection.getEntrySize(), Group->getName());
1021 } else {
1022 EHSection = getContext().getELFSection(EHSecName, Type, Flags, Kind);
1023 }
Logan Chiend8bb4b72013-04-16 12:02:21 +00001024 assert(EHSection && "Failed to get the required EH section");
Logan Chien2bcc42c2013-01-30 15:39:04 +00001025
1026 // Switch to .ARM.extab or .ARM.exidx section
1027 SwitchSection(EHSection);
Rafael Espindola7b514962014-02-04 18:34:04 +00001028 EmitCodeAlignment(4);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001029}
1030
1031inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) {
1032 SwitchToEHSection(".ARM.extab",
1033 ELF::SHT_PROGBITS,
1034 ELF::SHF_ALLOC,
1035 SectionKind::getDataRel(),
1036 FnStart);
1037}
1038
1039inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {
1040 SwitchToEHSection(".ARM.exidx",
1041 ELF::SHT_ARM_EXIDX,
1042 ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER,
1043 SectionKind::getDataRel(),
1044 FnStart);
1045}
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00001046void ARMELFStreamer::EmitFixup(const MCExpr *Expr, MCFixupKind Kind) {
1047 MCDataFragment *Frag = getOrCreateDataFragment();
1048 Frag->getFixups().push_back(MCFixup::Create(Frag->getContents().size(), Expr,
1049 Kind));
1050}
Logan Chien2bcc42c2013-01-30 15:39:04 +00001051
1052void ARMELFStreamer::Reset() {
Craig Topper062a2ba2014-04-25 05:30:21 +00001053 ExTab = nullptr;
1054 FnStart = nullptr;
1055 Personality = nullptr;
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001056 PersonalityIndex = ARM::EHABI::NUM_PERSONALITY_INDEX;
Logan Chien325823a2013-06-09 12:22:30 +00001057 FPReg = ARM::SP;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001058 FPOffset = 0;
1059 SPOffset = 0;
Logan Chien325823a2013-06-09 12:22:30 +00001060 PendingOffset = 0;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001061 UsedFP = false;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001062 CantUnwind = false;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001063
Logan Chien325823a2013-06-09 12:22:30 +00001064 Opcodes.clear();
Logan Chiend8bb4b72013-04-16 12:02:21 +00001065 UnwindOpAsm.Reset();
Logan Chien2bcc42c2013-01-30 15:39:04 +00001066}
1067
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001068void ARMELFStreamer::emitFnStart() {
Logan Chien2bcc42c2013-01-30 15:39:04 +00001069 assert(FnStart == 0);
1070 FnStart = getContext().CreateTempSymbol();
1071 EmitLabel(FnStart);
1072}
1073
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001074void ARMELFStreamer::emitFnEnd() {
Alp Tokercb402912014-01-24 17:20:08 +00001075 assert(FnStart && ".fnstart must precedes .fnend");
Logan Chien2bcc42c2013-01-30 15:39:04 +00001076
1077 // Emit unwind opcodes if there is no .handlerdata directive
Logan Chien4ea23b52013-05-10 16:17:24 +00001078 if (!ExTab && !CantUnwind)
1079 FlushUnwindOpcodes(true);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001080
1081 // Emit the exception index table entry
1082 SwitchToExIdxSection(*FnStart);
1083
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001084 if (PersonalityIndex < ARM::EHABI::NUM_PERSONALITY_INDEX)
Logan Chiend8bb4b72013-04-16 12:02:21 +00001085 EmitPersonalityFixup(GetAEABIUnwindPersonalityName(PersonalityIndex));
Logan Chien2bcc42c2013-01-30 15:39:04 +00001086
1087 const MCSymbolRefExpr *FnStartRef =
1088 MCSymbolRefExpr::Create(FnStart,
1089 MCSymbolRefExpr::VK_ARM_PREL31,
1090 getContext());
1091
Rafael Espindola64e1af82013-07-02 15:49:13 +00001092 EmitValue(FnStartRef, 4);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001093
1094 if (CantUnwind) {
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001095 EmitIntValue(ARM::EHABI::EXIDX_CANTUNWIND, 4);
Logan Chiend8bb4b72013-04-16 12:02:21 +00001096 } else if (ExTab) {
1097 // Emit a reference to the unwind opcodes in the ".ARM.extab" section.
Logan Chien2bcc42c2013-01-30 15:39:04 +00001098 const MCSymbolRefExpr *ExTabEntryRef =
1099 MCSymbolRefExpr::Create(ExTab,
1100 MCSymbolRefExpr::VK_ARM_PREL31,
1101 getContext());
Rafael Espindola64e1af82013-07-02 15:49:13 +00001102 EmitValue(ExTabEntryRef, 4);
Logan Chiend8bb4b72013-04-16 12:02:21 +00001103 } else {
1104 // For the __aeabi_unwind_cpp_pr0, we have to emit the unwind opcodes in
1105 // the second word of exception index table entry. The size of the unwind
1106 // opcodes should always be 4 bytes.
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001107 assert(PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0 &&
Logan Chiend8bb4b72013-04-16 12:02:21 +00001108 "Compact model must use __aeabi_cpp_unwind_pr0 as personality");
Logan Chien325823a2013-06-09 12:22:30 +00001109 assert(Opcodes.size() == 4u &&
Logan Chiend8bb4b72013-04-16 12:02:21 +00001110 "Unwind opcode size for __aeabi_cpp_unwind_pr0 must be equal to 4");
Logan Chien325823a2013-06-09 12:22:30 +00001111 EmitBytes(StringRef(reinterpret_cast<const char*>(Opcodes.data()),
Rafael Espindola64e1af82013-07-02 15:49:13 +00001112 Opcodes.size()));
Logan Chien2bcc42c2013-01-30 15:39:04 +00001113 }
1114
Logan Chien4ea23b52013-05-10 16:17:24 +00001115 // Switch to the section containing FnStart
1116 SwitchSection(&FnStart->getSection());
1117
Logan Chien2bcc42c2013-01-30 15:39:04 +00001118 // Clean exception handling frame information
1119 Reset();
1120}
1121
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001122void ARMELFStreamer::emitCantUnwind() { CantUnwind = true; }
1123
1124// Add the R_ARM_NONE fixup at the same position
1125void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
1126 const MCSymbol *PersonalitySym = getContext().GetOrCreateSymbol(Name);
1127
1128 const MCSymbolRefExpr *PersonalityRef = MCSymbolRefExpr::Create(
1129 PersonalitySym, MCSymbolRefExpr::VK_ARM_NONE, getContext());
1130
1131 AddValueSymbols(PersonalityRef);
1132 MCDataFragment *DF = getOrCreateDataFragment();
1133 DF->getFixups().push_back(MCFixup::Create(DF->getContents().size(),
1134 PersonalityRef,
1135 MCFixup::getKindForSize(4, false)));
Logan Chien2bcc42c2013-01-30 15:39:04 +00001136}
1137
Logan Chien325823a2013-06-09 12:22:30 +00001138void ARMELFStreamer::FlushPendingOffset() {
1139 if (PendingOffset != 0) {
1140 UnwindOpAsm.EmitSPOffset(-PendingOffset);
1141 PendingOffset = 0;
1142 }
1143}
1144
Logan Chienc931fce2013-07-02 12:43:27 +00001145void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
Logan Chien325823a2013-06-09 12:22:30 +00001146 // Emit the unwind opcode to restore $sp.
1147 if (UsedFP) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00001148 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
Logan Chien325823a2013-06-09 12:22:30 +00001149 int64_t LastRegSaveSPOffset = SPOffset - PendingOffset;
1150 UnwindOpAsm.EmitSPOffset(LastRegSaveSPOffset - FPOffset);
Bill Wendlingbc07a892013-06-18 07:20:20 +00001151 UnwindOpAsm.EmitSetSP(MRI->getEncodingValue(FPReg));
Logan Chien325823a2013-06-09 12:22:30 +00001152 } else {
1153 FlushPendingOffset();
1154 }
1155
1156 // Finalize the unwind opcode sequence
1157 UnwindOpAsm.Finalize(PersonalityIndex, Opcodes);
Logan Chien4ea23b52013-05-10 16:17:24 +00001158
1159 // For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx
1160 // section. Thus, we don't have to create an entry in the .ARM.extab
1161 // section.
Saleem Abdulrasoolb961c992014-01-06 00:15:00 +00001162 if (NoHandlerData && PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0)
Logan Chien4ea23b52013-05-10 16:17:24 +00001163 return;
1164
1165 // Switch to .ARM.extab section.
Logan Chien2bcc42c2013-01-30 15:39:04 +00001166 SwitchToExTabSection(*FnStart);
1167
1168 // Create .ARM.extab label for offset in .ARM.exidx
1169 assert(!ExTab);
1170 ExTab = getContext().CreateTempSymbol();
1171 EmitLabel(ExTab);
1172
Logan Chien4ea23b52013-05-10 16:17:24 +00001173 // Emit personality
1174 if (Personality) {
1175 const MCSymbolRefExpr *PersonalityRef =
1176 MCSymbolRefExpr::Create(Personality,
1177 MCSymbolRefExpr::VK_ARM_PREL31,
1178 getContext());
Logan Chien2bcc42c2013-01-30 15:39:04 +00001179
Rafael Espindola64e1af82013-07-02 15:49:13 +00001180 EmitValue(PersonalityRef, 4);
Logan Chien4ea23b52013-05-10 16:17:24 +00001181 }
Logan Chien2bcc42c2013-01-30 15:39:04 +00001182
1183 // Emit unwind opcodes
Logan Chien325823a2013-06-09 12:22:30 +00001184 EmitBytes(StringRef(reinterpret_cast<const char *>(Opcodes.data()),
Rafael Espindola64e1af82013-07-02 15:49:13 +00001185 Opcodes.size()));
Logan Chienc931fce2013-07-02 12:43:27 +00001186
1187 // According to ARM EHABI section 9.2, if the __aeabi_unwind_cpp_pr1() or
1188 // __aeabi_unwind_cpp_pr2() is used, then the handler data must be emitted
1189 // after the unwind opcodes. The handler data consists of several 32-bit
1190 // words, and should be terminated by zero.
1191 //
1192 // In case that the .handlerdata directive is not specified by the
1193 // programmer, we should emit zero to terminate the handler data.
1194 if (NoHandlerData && !Personality)
1195 EmitIntValue(0, 4);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001196}
1197
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001198void ARMELFStreamer::emitHandlerData() { FlushUnwindOpcodes(false); }
Logan Chien4ea23b52013-05-10 16:17:24 +00001199
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001200void ARMELFStreamer::emitPersonality(const MCSymbol *Per) {
Logan Chien2bcc42c2013-01-30 15:39:04 +00001201 Personality = Per;
Logan Chiend8bb4b72013-04-16 12:02:21 +00001202 UnwindOpAsm.setPersonality(Per);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001203}
1204
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00001205void ARMELFStreamer::emitPersonalityIndex(unsigned Index) {
1206 assert(Index < ARM::EHABI::NUM_PERSONALITY_INDEX && "invalid index");
1207 PersonalityIndex = Index;
1208}
1209
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001210void ARMELFStreamer::emitSetFP(unsigned NewFPReg, unsigned NewSPReg,
Logan Chien2bcc42c2013-01-30 15:39:04 +00001211 int64_t Offset) {
Logan Chien325823a2013-06-09 12:22:30 +00001212 assert((NewSPReg == ARM::SP || NewSPReg == FPReg) &&
Logan Chiend8bb4b72013-04-16 12:02:21 +00001213 "the operand of .setfp directive should be either $sp or $fp");
1214
1215 UsedFP = true;
Logan Chien325823a2013-06-09 12:22:30 +00001216 FPReg = NewFPReg;
1217
1218 if (NewSPReg == ARM::SP)
1219 FPOffset = SPOffset + Offset;
1220 else
1221 FPOffset += Offset;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001222}
1223
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00001224void ARMELFStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
1225 assert((Reg != ARM::SP && Reg != ARM::PC) &&
1226 "the operand of .movsp cannot be either sp or pc");
1227 assert(FPReg == ARM::SP && "current FP must be SP");
1228
1229 FlushPendingOffset();
1230
1231 FPReg = Reg;
1232 FPOffset = SPOffset + Offset;
1233
1234 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1235 UnwindOpAsm.EmitSetSP(MRI->getEncodingValue(FPReg));
1236}
1237
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001238void ARMELFStreamer::emitPad(int64_t Offset) {
Logan Chien325823a2013-06-09 12:22:30 +00001239 // Track the change of the $sp offset
1240 SPOffset -= Offset;
1241
1242 // To squash multiple .pad directives, we should delay the unwind opcode
1243 // until the .save, .vsave, .handlerdata, or .fnend directives.
1244 PendingOffset -= Offset;
Logan Chien2bcc42c2013-01-30 15:39:04 +00001245}
1246
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001247void ARMELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
Logan Chien2bcc42c2013-01-30 15:39:04 +00001248 bool IsVector) {
Logan Chien325823a2013-06-09 12:22:30 +00001249 // Collect the registers in the register list
1250 unsigned Count = 0;
1251 uint32_t Mask = 0;
Bill Wendlingbc07a892013-06-18 07:20:20 +00001252 const MCRegisterInfo *MRI = getContext().getRegisterInfo();
Logan Chiend8bb4b72013-04-16 12:02:21 +00001253 for (size_t i = 0; i < RegList.size(); ++i) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00001254 unsigned Reg = MRI->getEncodingValue(RegList[i]);
Aaron Ballmanab1d27e2013-06-10 16:45:40 +00001255 assert(Reg < (IsVector ? 32U : 16U) && "Register out of range");
Logan Chien325823a2013-06-09 12:22:30 +00001256 unsigned Bit = (1u << Reg);
1257 if ((Mask & Bit) == 0) {
1258 Mask |= Bit;
1259 ++Count;
1260 }
Logan Chiend8bb4b72013-04-16 12:02:21 +00001261 }
Logan Chien325823a2013-06-09 12:22:30 +00001262
1263 // Track the change the $sp offset: For the .save directive, the
1264 // corresponding push instruction will decrease the $sp by (4 * Count).
1265 // For the .vsave directive, the corresponding vpush instruction will
1266 // decrease $sp by (8 * Count).
1267 SPOffset -= Count * (IsVector ? 8 : 4);
1268
1269 // Emit the opcode
1270 FlushPendingOffset();
1271 if (IsVector)
1272 UnwindOpAsm.EmitVFPRegSave(Mask);
1273 else
1274 UnwindOpAsm.EmitRegSave(Mask);
Logan Chien2bcc42c2013-01-30 15:39:04 +00001275}
1276
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00001277void ARMELFStreamer::emitUnwindRaw(int64_t Offset,
1278 const SmallVectorImpl<uint8_t> &Opcodes) {
1279 FlushPendingOffset();
1280 SPOffset = SPOffset - Offset;
1281 UnwindOpAsm.EmitRaw(Opcodes);
1282}
1283
Tim Northover5cc3dc82012-12-07 16:50:23 +00001284namespace llvm {
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001285
1286MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
Rafael Espindolab4eec1d2014-02-05 18:00:21 +00001287 bool isVerboseAsm, bool useCFI,
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001288 bool useDwarfDirectory,
1289 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
1290 MCAsmBackend *TAB, bool ShowInst) {
Rafael Espindola24ea09e2014-01-26 06:06:37 +00001291 MCStreamer *S =
Rafael Espindolab4eec1d2014-02-05 18:00:21 +00001292 llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useCFI, useDwarfDirectory,
1293 InstPrint, CE, TAB, ShowInst);
Rafael Espindola24ea09e2014-01-26 06:06:37 +00001294 new ARMTargetAsmStreamer(*S, OS, *InstPrint, isVerboseAsm);
1295 return S;
Rafael Espindolaa17151a2013-10-08 13:08:17 +00001296}
1297
Tim Northover5cc3dc82012-12-07 16:50:23 +00001298 MCELFStreamer* createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,
1299 raw_ostream &OS, MCCodeEmitter *Emitter,
1300 bool RelaxAll, bool NoExecStack,
1301 bool IsThumb) {
Rafael Espindola24ea09e2014-01-26 06:06:37 +00001302 ARMELFStreamer *S = new ARMELFStreamer(Context, TAB, OS, Emitter, IsThumb);
1303 new ARMTargetELFStreamer(*S);
Rafael Espindolaac4ad252013-10-05 16:42:21 +00001304 // FIXME: This should eventually end up somewhere else where more
1305 // intelligent flag decisions can be made. For now we are just maintaining
1306 // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default.
1307 S->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
1308
Tim Northover5cc3dc82012-12-07 16:50:23 +00001309 if (RelaxAll)
1310 S->getAssembler().setRelaxAll(true);
1311 if (NoExecStack)
1312 S->getAssembler().setNoExecStack(true);
1313 return S;
1314 }
1315
1316}
1317
1318