LLVM  16.0.0git
ARMELFStreamer.cpp
Go to the documentation of this file.
1 //===- lib/MC/ARMELFStreamer.cpp - ELF Object Output for ARM --------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file assembles .s files and emits ARM ELF .o object files. Different
10 // from generic ELF streamer in emitting mapping symbols ($a, $t and $d) to
11 // delimit regions of data and code.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "ARMRegisterInfo.h"
16 #include "ARMUnwindOpAsm.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringExtras.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ADT/Twine.h"
23 #include "llvm/BinaryFormat/ELF.h"
24 #include "llvm/MC/MCAsmBackend.h"
25 #include "llvm/MC/MCAsmInfo.h"
26 #include "llvm/MC/MCAssembler.h"
27 #include "llvm/MC/MCCodeEmitter.h"
28 #include "llvm/MC/MCContext.h"
29 #include "llvm/MC/MCELFStreamer.h"
30 #include "llvm/MC/MCExpr.h"
31 #include "llvm/MC/MCFixup.h"
32 #include "llvm/MC/MCFragment.h"
33 #include "llvm/MC/MCInst.h"
34 #include "llvm/MC/MCInstPrinter.h"
35 #include "llvm/MC/MCObjectWriter.h"
36 #include "llvm/MC/MCRegisterInfo.h"
37 #include "llvm/MC/MCSection.h"
38 #include "llvm/MC/MCSectionELF.h"
39 #include "llvm/MC/MCStreamer.h"
41 #include "llvm/MC/MCSymbol.h"
42 #include "llvm/MC/MCSymbolELF.h"
43 #include "llvm/MC/SectionKind.h"
45 #include "llvm/Support/ARMEHABI.h"
46 #include "llvm/Support/Casting.h"
51 #include <algorithm>
52 #include <cassert>
53 #include <climits>
54 #include <cstddef>
55 #include <cstdint>
56 #include <string>
57 
58 using namespace llvm;
59 
60 static std::string GetAEABIUnwindPersonalityName(unsigned Index) {
62  "Invalid personality index");
63  return (Twine("__aeabi_unwind_cpp_pr") + Twine(Index)).str();
64 }
65 
66 namespace {
67 
68 class ARMELFStreamer;
69 
70 class ARMTargetAsmStreamer : public ARMTargetStreamer {
72  MCInstPrinter &InstPrinter;
73  bool IsVerboseAsm;
74 
75  void emitFnStart() override;
76  void emitFnEnd() override;
77  void emitCantUnwind() override;
78  void emitPersonality(const MCSymbol *Personality) override;
79  void emitPersonalityIndex(unsigned Index) override;
80  void emitHandlerData() override;
81  void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0) override;
82  void emitMovSP(unsigned Reg, int64_t Offset = 0) override;
83  void emitPad(int64_t Offset) override;
84  void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
85  bool isVector) override;
86  void emitUnwindRaw(int64_t Offset,
87  const SmallVectorImpl<uint8_t> &Opcodes) override;
88 
89  void switchVendor(StringRef Vendor) override;
90  void emitAttribute(unsigned Attribute, unsigned Value) override;
91  void emitTextAttribute(unsigned Attribute, StringRef String) override;
92  void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
93  StringRef StringValue) override;
94  void emitArch(ARM::ArchKind Arch) override;
95  void emitArchExtension(uint64_t ArchExt) override;
96  void emitObjectArch(ARM::ArchKind Arch) override;
97  void emitFPU(unsigned FPU) override;
98  void emitInst(uint32_t Inst, char Suffix = '\0') override;
99  void finishAttributeSection() override;
100 
101  void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE) override;
102  void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) override;
103 
104  void emitARMWinCFIAllocStack(unsigned Size, bool Wide) override;
105  void emitARMWinCFISaveRegMask(unsigned Mask, bool Wide) override;
106  void emitARMWinCFISaveSP(unsigned Reg) override;
107  void emitARMWinCFISaveFRegs(unsigned First, unsigned Last) override;
108  void emitARMWinCFISaveLR(unsigned Offset) override;
109  void emitARMWinCFIPrologEnd(bool Fragment) override;
110  void emitARMWinCFINop(bool Wide) override;
111  void emitARMWinCFIEpilogStart(unsigned Condition) override;
112  void emitARMWinCFIEpilogEnd() override;
113  void emitARMWinCFICustom(unsigned Opcode) override;
114 
115 public:
116  ARMTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS,
117  MCInstPrinter &InstPrinter, bool VerboseAsm);
118 };
119 
120 ARMTargetAsmStreamer::ARMTargetAsmStreamer(MCStreamer &S,
122  MCInstPrinter &InstPrinter,
123  bool VerboseAsm)
124  : ARMTargetStreamer(S), OS(OS), InstPrinter(InstPrinter),
125  IsVerboseAsm(VerboseAsm) {}
126 
127 void ARMTargetAsmStreamer::emitFnStart() { OS << "\t.fnstart\n"; }
128 void ARMTargetAsmStreamer::emitFnEnd() { OS << "\t.fnend\n"; }
129 void ARMTargetAsmStreamer::emitCantUnwind() { OS << "\t.cantunwind\n"; }
130 
131 void ARMTargetAsmStreamer::emitPersonality(const MCSymbol *Personality) {
132  OS << "\t.personality " << Personality->getName() << '\n';
133 }
134 
135 void ARMTargetAsmStreamer::emitPersonalityIndex(unsigned Index) {
136  OS << "\t.personalityindex " << Index << '\n';
137 }
138 
139 void ARMTargetAsmStreamer::emitHandlerData() { OS << "\t.handlerdata\n"; }
140 
141 void ARMTargetAsmStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
142  int64_t Offset) {
143  OS << "\t.setfp\t";
144  InstPrinter.printRegName(OS, FpReg);
145  OS << ", ";
146  InstPrinter.printRegName(OS, SpReg);
147  if (Offset)
148  OS << ", #" << Offset;
149  OS << '\n';
150 }
151 
152 void ARMTargetAsmStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
153  assert((Reg != ARM::SP && Reg != ARM::PC) &&
154  "the operand of .movsp cannot be either sp or pc");
155 
156  OS << "\t.movsp\t";
157  InstPrinter.printRegName(OS, Reg);
158  if (Offset)
159  OS << ", #" << Offset;
160  OS << '\n';
161 }
162 
163 void ARMTargetAsmStreamer::emitPad(int64_t Offset) {
164  OS << "\t.pad\t#" << Offset << '\n';
165 }
166 
167 void ARMTargetAsmStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
168  bool isVector) {
169  assert(RegList.size() && "RegList should not be empty");
170  if (isVector)
171  OS << "\t.vsave\t{";
172  else
173  OS << "\t.save\t{";
174 
175  InstPrinter.printRegName(OS, RegList[0]);
176 
177  for (unsigned i = 1, e = RegList.size(); i != e; ++i) {
178  OS << ", ";
179  InstPrinter.printRegName(OS, RegList[i]);
180  }
181 
182  OS << "}\n";
183 }
184 
185 void ARMTargetAsmStreamer::switchVendor(StringRef Vendor) {}
186 
187 void ARMTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
188  OS << "\t.eabi_attribute\t" << Attribute << ", " << Twine(Value);
189  if (IsVerboseAsm) {
192  if (!Name.empty())
193  OS << "\t@ " << Name;
194  }
195  OS << "\n";
196 }
197 
198 void ARMTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
199  StringRef String) {
200  switch (Attribute) {
202  OS << "\t.cpu\t" << String.lower();
203  break;
204  default:
205  OS << "\t.eabi_attribute\t" << Attribute << ", \"";
207  OS.write_escaped(String);
208  else
209  OS << String;
210  OS << "\"";
211  if (IsVerboseAsm) {
214  if (!Name.empty())
215  OS << "\t@ " << Name;
216  }
217  break;
218  }
219  OS << "\n";
220 }
221 
222 void ARMTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
223  unsigned IntValue,
224  StringRef StringValue) {
225  switch (Attribute) {
226  default: llvm_unreachable("unsupported multi-value attribute in asm mode");
228  OS << "\t.eabi_attribute\t" << Attribute << ", " << IntValue;
229  if (!StringValue.empty())
230  OS << ", \"" << StringValue << "\"";
231  if (IsVerboseAsm)
232  OS << "\t@ "
235  break;
236  }
237  OS << "\n";
238 }
239 
240 void ARMTargetAsmStreamer::emitArch(ARM::ArchKind Arch) {
241  OS << "\t.arch\t" << ARM::getArchName(Arch) << "\n";
242 }
243 
244 void ARMTargetAsmStreamer::emitArchExtension(uint64_t ArchExt) {
245  OS << "\t.arch_extension\t" << ARM::getArchExtName(ArchExt) << "\n";
246 }
247 
248 void ARMTargetAsmStreamer::emitObjectArch(ARM::ArchKind Arch) {
249  OS << "\t.object_arch\t" << ARM::getArchName(Arch) << '\n';
250 }
251 
252 void ARMTargetAsmStreamer::emitFPU(unsigned FPU) {
253  OS << "\t.fpu\t" << ARM::getFPUName(FPU) << "\n";
254 }
255 
256 void ARMTargetAsmStreamer::finishAttributeSection() {}
257 
258 void ARMTargetAsmStreamer::annotateTLSDescriptorSequence(
259  const MCSymbolRefExpr *S) {
260  OS << "\t.tlsdescseq\t" << S->getSymbol().getName() << "\n";
261 }
262 
263 void ARMTargetAsmStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {
264  const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
265 
266  OS << "\t.thumb_set\t";
267  Symbol->print(OS, MAI);
268  OS << ", ";
269  Value->print(OS, MAI);
270  OS << '\n';
271 }
272 
273 void ARMTargetAsmStreamer::emitInst(uint32_t Inst, char Suffix) {
274  OS << "\t.inst";
275  if (Suffix)
276  OS << "." << Suffix;
277  OS << "\t0x" << Twine::utohexstr(Inst) << "\n";
278 }
279 
280 void ARMTargetAsmStreamer::emitUnwindRaw(int64_t Offset,
281  const SmallVectorImpl<uint8_t> &Opcodes) {
282  OS << "\t.unwind_raw " << Offset;
283  for (uint8_t Opcode : Opcodes)
284  OS << ", 0x" << Twine::utohexstr(Opcode);
285  OS << '\n';
286 }
287 
288 void ARMTargetAsmStreamer::emitARMWinCFIAllocStack(unsigned Size, bool Wide) {
289  if (Wide)
290  OS << "\t.seh_stackalloc_w\t" << Size << "\n";
291  else
292  OS << "\t.seh_stackalloc\t" << Size << "\n";
293 }
294 
295 static void printRegs(formatted_raw_ostream &OS, ListSeparator &LS, int First,
296  int Last) {
297  if (First != Last)
298  OS << LS << "r" << First << "-r" << Last;
299  else
300  OS << LS << "r" << First;
301 }
302 
303 void ARMTargetAsmStreamer::emitARMWinCFISaveRegMask(unsigned Mask, bool Wide) {
304  if (Wide)
305  OS << "\t.seh_save_regs_w\t";
306  else
307  OS << "\t.seh_save_regs\t";
308  ListSeparator LS;
309  int First = -1;
310  OS << "{";
311  for (int I = 0; I <= 12; I++) {
312  if (Mask & (1 << I)) {
313  if (First < 0)
314  First = I;
315  } else {
316  if (First >= 0) {
317  printRegs(OS, LS, First, I - 1);
318  First = -1;
319  }
320  }
321  }
322  if (First >= 0)
323  printRegs(OS, LS, First, 12);
324  if (Mask & (1 << 14))
325  OS << LS << "lr";
326  OS << "}\n";
327 }
328 
329 void ARMTargetAsmStreamer::emitARMWinCFISaveSP(unsigned Reg) {
330  OS << "\t.seh_save_sp\tr" << Reg << "\n";
331 }
332 
333 void ARMTargetAsmStreamer::emitARMWinCFISaveFRegs(unsigned First,
334  unsigned Last) {
335  if (First != Last)
336  OS << "\t.seh_save_fregs\t{d" << First << "-d" << Last << "}\n";
337  else
338  OS << "\t.seh_save_fregs\t{d" << First << "}\n";
339 }
340 
341 void ARMTargetAsmStreamer::emitARMWinCFISaveLR(unsigned Offset) {
342  OS << "\t.seh_save_lr\t" << Offset << "\n";
343 }
344 
345 void ARMTargetAsmStreamer::emitARMWinCFIPrologEnd(bool Fragment) {
346  if (Fragment)
347  OS << "\t.seh_endprologue_fragment\n";
348  else
349  OS << "\t.seh_endprologue\n";
350 }
351 
352 void ARMTargetAsmStreamer::emitARMWinCFINop(bool Wide) {
353  if (Wide)
354  OS << "\t.seh_nop_w\n";
355  else
356  OS << "\t.seh_nop\n";
357 }
358 
359 void ARMTargetAsmStreamer::emitARMWinCFIEpilogStart(unsigned Condition) {
360  if (Condition == ARMCC::AL)
361  OS << "\t.seh_startepilogue\n";
362  else
363  OS << "\t.seh_startepilogue_cond\t"
364  << ARMCondCodeToString(static_cast<ARMCC::CondCodes>(Condition)) << "\n";
365 }
366 
367 void ARMTargetAsmStreamer::emitARMWinCFIEpilogEnd() {
368  OS << "\t.seh_endepilogue\n";
369 }
370 
371 void ARMTargetAsmStreamer::emitARMWinCFICustom(unsigned Opcode) {
372  int I;
373  for (I = 3; I > 0; I--)
374  if (Opcode & (0xffu << (8 * I)))
375  break;
376  ListSeparator LS;
377  OS << "\t.seh_custom\t";
378  for (; I >= 0; I--)
379  OS << LS << ((Opcode >> (8 * I)) & 0xff);
380  OS << "\n";
381 }
382 
383 class ARMTargetELFStreamer : public ARMTargetStreamer {
384 private:
385  StringRef CurrentVendor;
386  unsigned FPU = ARM::FK_INVALID;
387  ARM::ArchKind Arch = ARM::ArchKind::INVALID;
388  ARM::ArchKind EmittedArch = ARM::ArchKind::INVALID;
389 
390  MCSection *AttributeSection = nullptr;
391 
392  void emitArchDefaultAttributes();
393  void emitFPUDefaultAttributes();
394 
395  ARMELFStreamer &getStreamer();
396 
397  void emitFnStart() override;
398  void emitFnEnd() override;
399  void emitCantUnwind() override;
400  void emitPersonality(const MCSymbol *Personality) override;
401  void emitPersonalityIndex(unsigned Index) override;
402  void emitHandlerData() override;
403  void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset = 0) override;
404  void emitMovSP(unsigned Reg, int64_t Offset = 0) override;
405  void emitPad(int64_t Offset) override;
406  void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
407  bool isVector) override;
408  void emitUnwindRaw(int64_t Offset,
409  const SmallVectorImpl<uint8_t> &Opcodes) override;
410 
411  void switchVendor(StringRef Vendor) override;
412  void emitAttribute(unsigned Attribute, unsigned Value) override;
413  void emitTextAttribute(unsigned Attribute, StringRef String) override;
414  void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
415  StringRef StringValue) override;
416  void emitArch(ARM::ArchKind Arch) override;
417  void emitObjectArch(ARM::ArchKind Arch) override;
418  void emitFPU(unsigned FPU) override;
419  void emitInst(uint32_t Inst, char Suffix = '\0') override;
420  void finishAttributeSection() override;
421  void emitLabel(MCSymbol *Symbol) override;
422 
423  void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE) override;
424  void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) override;
425 
426  // Reset state between object emissions
427  void reset() override;
428 
429 public:
430  ARMTargetELFStreamer(MCStreamer &S)
431  : ARMTargetStreamer(S), CurrentVendor("aeabi") {}
432 };
433 
434 /// Extend the generic ELFStreamer class so that it can emit mapping symbols at
435 /// the appropriate points in the object files. These symbols are defined in the
436 /// ARM ELF ABI: infocenter.arm.com/help/topic/com.arm.../IHI0044D_aaelf.pdf.
437 ///
438 /// In brief: $a, $t or $d should be emitted at the start of each contiguous
439 /// region of ARM code, Thumb code or data in a section. In practice, this
440 /// emission does not rely on explicit assembler directives but on inherent
441 /// properties of the directives doing the emission (e.g. ".byte" is data, "add
442 /// r0, r0, r0" an instruction).
443 ///
444 /// As a result this system is orthogonal to the DataRegion infrastructure used
445 /// by MachO. Beware!
446 class ARMELFStreamer : public MCELFStreamer {
447 public:
448  friend class ARMTargetELFStreamer;
449 
450  ARMELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
451  std::unique_ptr<MCObjectWriter> OW,
452  std::unique_ptr<MCCodeEmitter> Emitter, bool IsThumb,
453  bool IsAndroid)
454  : MCELFStreamer(Context, std::move(TAB), std::move(OW),
455  std::move(Emitter)),
456  IsThumb(IsThumb), IsAndroid(IsAndroid) {
457  EHReset();
458  }
459 
460  ~ARMELFStreamer() override = default;
461 
462  void finishImpl() override;
463 
464  // ARM exception handling directives
465  void emitFnStart();
466  void emitFnEnd();
467  void emitCantUnwind();
468  void emitPersonality(const MCSymbol *Per);
469  void emitPersonalityIndex(unsigned index);
470  void emitHandlerData();
471  void emitSetFP(unsigned NewFpReg, unsigned NewSpReg, int64_t Offset = 0);
472  void emitMovSP(unsigned Reg, int64_t Offset = 0);
473  void emitPad(int64_t Offset);
474  void emitRegSave(const SmallVectorImpl<unsigned> &RegList, bool isVector);
475  void emitUnwindRaw(int64_t Offset, const SmallVectorImpl<uint8_t> &Opcodes);
476  void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
477  SMLoc Loc) override {
478  emitDataMappingSymbol();
479  MCObjectStreamer::emitFill(NumBytes, FillValue, Loc);
480  }
481 
482  void changeSection(MCSection *Section, const MCExpr *Subsection) override {
483  LastMappingSymbols[getCurrentSection().first] = std::move(LastEMSInfo);
485  auto LastMappingSymbol = LastMappingSymbols.find(Section);
486  if (LastMappingSymbol != LastMappingSymbols.end()) {
487  LastEMSInfo = std::move(LastMappingSymbol->second);
488  return;
489  }
490  LastEMSInfo.reset(new ElfMappingSymbolInfo(SMLoc(), nullptr, 0));
491  }
492 
493  /// This function is the one used to emit instruction data into the ELF
494  /// streamer. We override it to add the appropriate mapping symbol if
495  /// necessary.
496  void emitInstruction(const MCInst &Inst,
497  const MCSubtargetInfo &STI) override {
498  if (IsThumb)
499  EmitThumbMappingSymbol();
500  else
501  EmitARMMappingSymbol();
502 
504  }
505 
506  void emitInst(uint32_t Inst, char Suffix) {
507  unsigned Size;
508  char Buffer[4];
509  const bool LittleEndian = getContext().getAsmInfo()->isLittleEndian();
510 
511  switch (Suffix) {
512  case '\0':
513  Size = 4;
514 
515  assert(!IsThumb);
516  EmitARMMappingSymbol();
517  for (unsigned II = 0, IE = Size; II != IE; II++) {
518  const unsigned I = LittleEndian ? (Size - II - 1) : II;
519  Buffer[Size - II - 1] = uint8_t(Inst >> I * CHAR_BIT);
520  }
521 
522  break;
523  case 'n':
524  case 'w':
525  Size = (Suffix == 'n' ? 2 : 4);
526 
527  assert(IsThumb);
528  EmitThumbMappingSymbol();
529  // Thumb wide instructions are emitted as a pair of 16-bit words of the
530  // appropriate endianness.
531  for (unsigned II = 0, IE = Size; II != IE; II = II + 2) {
532  const unsigned I0 = LittleEndian ? II + 0 : II + 1;
533  const unsigned I1 = LittleEndian ? II + 1 : II + 0;
534  Buffer[Size - II - 2] = uint8_t(Inst >> I0 * CHAR_BIT);
535  Buffer[Size - II - 1] = uint8_t(Inst >> I1 * CHAR_BIT);
536  }
537 
538  break;
539  default:
540  llvm_unreachable("Invalid Suffix");
541  }
542 
544  }
545 
546  /// This is one of the functions used to emit data into an ELF section, so the
547  /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
548  /// necessary.
549  void emitBytes(StringRef Data) override {
550  emitDataMappingSymbol();
552  }
553 
554  void FlushPendingMappingSymbol() {
555  if (!LastEMSInfo->hasInfo())
556  return;
557  ElfMappingSymbolInfo *EMS = LastEMSInfo.get();
558  EmitMappingSymbol("$d", EMS->Loc, EMS->F, EMS->Offset);
559  EMS->resetInfo();
560  }
561 
562  /// This is one of the functions used to emit data into an ELF section, so the
563  /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if
564  /// necessary.
565  void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override {
566  if (const MCSymbolRefExpr *SRE = dyn_cast_or_null<MCSymbolRefExpr>(Value)) {
567  if (SRE->getKind() == MCSymbolRefExpr::VK_ARM_SBREL && !(Size == 4)) {
568  getContext().reportError(Loc, "relocated expression must be 32-bit");
569  return;
570  }
572  }
573 
574  emitDataMappingSymbol();
576  }
577 
578  void emitAssemblerFlag(MCAssemblerFlag Flag) override {
580 
581  switch (Flag) {
582  case MCAF_SyntaxUnified:
583  return; // no-op here.
584  case MCAF_Code16:
585  IsThumb = true;
586  return; // Change to Thumb mode
587  case MCAF_Code32:
588  IsThumb = false;
589  return; // Change to ARM mode
590  case MCAF_Code64:
591  return;
593  return;
594  }
595  }
596 
597  /// If a label is defined before the .type directive sets the label's type
598  /// then the label can't be recorded as thumb function when the label is
599  /// defined. We override emitSymbolAttribute() which is called as part of the
600  /// parsing of .type so that if the symbol has already been defined we can
601  /// record the label as Thumb. FIXME: there is a corner case where the state
602  /// is changed in between the label definition and the .type directive, this
603  /// is not expected to occur in practice and handling it would require the
604  /// backend to track IsThumb for every label.
607 
608  if (!IsThumb)
609  return Val;
610 
611  unsigned Type = cast<MCSymbolELF>(Symbol)->getType();
612  if ((Type == ELF::STT_FUNC || Type == ELF::STT_GNU_IFUNC) &&
613  Symbol->isDefined())
615 
616  return Val;
617  };
618 
619 private:
620  enum ElfMappingSymbol {
621  EMS_None,
622  EMS_ARM,
623  EMS_Thumb,
624  EMS_Data
625  };
626 
627  struct ElfMappingSymbolInfo {
628  explicit ElfMappingSymbolInfo(SMLoc Loc, MCFragment *F, uint64_t O)
629  : Loc(Loc), F(F), Offset(O), State(EMS_None) {}
630  void resetInfo() {
631  F = nullptr;
632  Offset = 0;
633  }
634  bool hasInfo() { return F != nullptr; }
635  SMLoc Loc;
636  MCFragment *F;
638  ElfMappingSymbol State;
639  };
640 
641  void emitDataMappingSymbol() {
642  if (LastEMSInfo->State == EMS_Data)
643  return;
644  else if (LastEMSInfo->State == EMS_None) {
645  // This is a tentative symbol, it won't really be emitted until it's
646  // actually needed.
647  ElfMappingSymbolInfo *EMS = LastEMSInfo.get();
648  auto *DF = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
649  if (!DF)
650  return;
651  EMS->Loc = SMLoc();
652  EMS->F = getCurrentFragment();
653  EMS->Offset = DF->getContents().size();
654  LastEMSInfo->State = EMS_Data;
655  return;
656  }
657  EmitMappingSymbol("$d");
658  LastEMSInfo->State = EMS_Data;
659  }
660 
661  void EmitThumbMappingSymbol() {
662  if (LastEMSInfo->State == EMS_Thumb)
663  return;
664  FlushPendingMappingSymbol();
665  EmitMappingSymbol("$t");
666  LastEMSInfo->State = EMS_Thumb;
667  }
668 
669  void EmitARMMappingSymbol() {
670  if (LastEMSInfo->State == EMS_ARM)
671  return;
672  FlushPendingMappingSymbol();
673  EmitMappingSymbol("$a");
674  LastEMSInfo->State = EMS_ARM;
675  }
676 
677  void EmitMappingSymbol(StringRef Name) {
678  auto *Symbol = cast<MCSymbolELF>(getContext().getOrCreateSymbol(
679  Name + "." + Twine(MappingSymbolCounter++)));
680  emitLabel(Symbol);
681 
682  Symbol->setType(ELF::STT_NOTYPE);
683  Symbol->setBinding(ELF::STB_LOCAL);
684  }
685 
686  void EmitMappingSymbol(StringRef Name, SMLoc Loc, MCFragment *F,
687  uint64_t Offset) {
688  auto *Symbol = cast<MCSymbolELF>(getContext().getOrCreateSymbol(
689  Name + "." + Twine(MappingSymbolCounter++)));
690  emitLabelAtPos(Symbol, Loc, F, Offset);
691  Symbol->setType(ELF::STT_NOTYPE);
692  Symbol->setBinding(ELF::STB_LOCAL);
693  }
694 
695  void emitThumbFunc(MCSymbol *Func) override {
698  }
699 
700  // Helper functions for ARM exception handling directives
701  void EHReset();
702 
703  // Reset state between object emissions
704  void reset() override;
705 
706  void EmitPersonalityFixup(StringRef Name);
707  void FlushPendingOffset();
708  void FlushUnwindOpcodes(bool NoHandlerData);
709 
710  void SwitchToEHSection(StringRef Prefix, unsigned Type, unsigned Flags,
711  SectionKind Kind, const MCSymbol &Fn);
712  void SwitchToExTabSection(const MCSymbol &FnStart);
713  void SwitchToExIdxSection(const MCSymbol &FnStart);
714 
715  void EmitFixup(const MCExpr *Expr, MCFixupKind Kind);
716 
717  bool IsThumb;
718  bool IsAndroid;
719  int64_t MappingSymbolCounter = 0;
720 
722  LastMappingSymbols;
723 
724  std::unique_ptr<ElfMappingSymbolInfo> LastEMSInfo;
725 
726  // ARM Exception Handling Frame Information
727  MCSymbol *ExTab;
728  MCSymbol *FnStart;
729  const MCSymbol *Personality;
730  unsigned PersonalityIndex;
731  unsigned FPReg; // Frame pointer register
732  int64_t FPOffset; // Offset: (final frame pointer) - (initial $sp)
733  int64_t SPOffset; // Offset: (final $sp) - (initial $sp)
734  int64_t PendingOffset; // Offset: (final $sp) - (emitted $sp)
735  bool UsedFP;
736  bool CantUnwind;
737  SmallVector<uint8_t, 64> Opcodes;
738  UnwindOpcodeAssembler UnwindOpAsm;
739 };
740 
741 } // end anonymous namespace
742 
743 ARMELFStreamer &ARMTargetELFStreamer::getStreamer() {
744  return static_cast<ARMELFStreamer &>(Streamer);
745 }
746 
747 void ARMTargetELFStreamer::emitFnStart() { getStreamer().emitFnStart(); }
748 void ARMTargetELFStreamer::emitFnEnd() { getStreamer().emitFnEnd(); }
749 void ARMTargetELFStreamer::emitCantUnwind() { getStreamer().emitCantUnwind(); }
750 
751 void ARMTargetELFStreamer::emitPersonality(const MCSymbol *Personality) {
752  getStreamer().emitPersonality(Personality);
753 }
754 
755 void ARMTargetELFStreamer::emitPersonalityIndex(unsigned Index) {
756  getStreamer().emitPersonalityIndex(Index);
757 }
758 
759 void ARMTargetELFStreamer::emitHandlerData() {
760  getStreamer().emitHandlerData();
761 }
762 
763 void ARMTargetELFStreamer::emitSetFP(unsigned FpReg, unsigned SpReg,
764  int64_t Offset) {
765  getStreamer().emitSetFP(FpReg, SpReg, Offset);
766 }
767 
768 void ARMTargetELFStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
769  getStreamer().emitMovSP(Reg, Offset);
770 }
771 
772 void ARMTargetELFStreamer::emitPad(int64_t Offset) {
773  getStreamer().emitPad(Offset);
774 }
775 
776 void ARMTargetELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
777  bool isVector) {
778  getStreamer().emitRegSave(RegList, isVector);
779 }
780 
781 void ARMTargetELFStreamer::emitUnwindRaw(int64_t Offset,
782  const SmallVectorImpl<uint8_t> &Opcodes) {
783  getStreamer().emitUnwindRaw(Offset, Opcodes);
784 }
785 
786 void ARMTargetELFStreamer::switchVendor(StringRef Vendor) {
787  assert(!Vendor.empty() && "Vendor cannot be empty.");
788 
789  if (CurrentVendor == Vendor)
790  return;
791 
792  if (!CurrentVendor.empty())
793  finishAttributeSection();
794 
795  assert(getStreamer().Contents.empty() &&
796  ".ARM.attributes should be flushed before changing vendor");
797  CurrentVendor = Vendor;
798 
799 }
800 
801 void ARMTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
802  getStreamer().setAttributeItem(Attribute, Value,
803  /* OverwriteExisting= */ true);
804 }
805 
806 void ARMTargetELFStreamer::emitTextAttribute(unsigned Attribute,
807  StringRef Value) {
808  getStreamer().setAttributeItem(Attribute, Value,
809  /* OverwriteExisting= */ true);
810 }
811 
812 void ARMTargetELFStreamer::emitIntTextAttribute(unsigned Attribute,
813  unsigned IntValue,
814  StringRef StringValue) {
815  getStreamer().setAttributeItems(Attribute, IntValue, StringValue,
816  /* OverwriteExisting= */ true);
817 }
818 
819 void ARMTargetELFStreamer::emitArch(ARM::ArchKind Value) {
820  Arch = Value;
821 }
822 
823 void ARMTargetELFStreamer::emitObjectArch(ARM::ArchKind Value) {
824  EmittedArch = Value;
825 }
826 
827 void ARMTargetELFStreamer::emitArchDefaultAttributes() {
828  using namespace ARMBuildAttrs;
829  ARMELFStreamer &S = getStreamer();
830 
831  S.setAttributeItem(CPU_name, ARM::getCPUAttr(Arch), false);
832 
833  if (EmittedArch == ARM::ArchKind::INVALID)
834  S.setAttributeItem(CPU_arch, ARM::getArchAttr(Arch), false);
835  else
836  S.setAttributeItem(CPU_arch, ARM::getArchAttr(EmittedArch), false);
837 
838  switch (Arch) {
839  case ARM::ArchKind::ARMV4:
840  S.setAttributeItem(ARM_ISA_use, Allowed, false);
841  break;
842 
843  case ARM::ArchKind::ARMV4T:
844  case ARM::ArchKind::ARMV5T:
845  case ARM::ArchKind::XSCALE:
846  case ARM::ArchKind::ARMV5TE:
847  case ARM::ArchKind::ARMV6:
848  S.setAttributeItem(ARM_ISA_use, Allowed, false);
849  S.setAttributeItem(THUMB_ISA_use, Allowed, false);
850  break;
851 
852  case ARM::ArchKind::ARMV6T2:
853  S.setAttributeItem(ARM_ISA_use, Allowed, false);
854  S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
855  break;
856 
857  case ARM::ArchKind::ARMV6K:
858  case ARM::ArchKind::ARMV6KZ:
859  S.setAttributeItem(ARM_ISA_use, Allowed, false);
860  S.setAttributeItem(THUMB_ISA_use, Allowed, false);
861  S.setAttributeItem(Virtualization_use, AllowTZ, false);
862  break;
863 
864  case ARM::ArchKind::ARMV6M:
865  S.setAttributeItem(THUMB_ISA_use, Allowed, false);
866  break;
867 
868  case ARM::ArchKind::ARMV7A:
869  S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
870  S.setAttributeItem(ARM_ISA_use, Allowed, false);
871  S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
872  break;
873 
874  case ARM::ArchKind::ARMV7R:
875  S.setAttributeItem(CPU_arch_profile, RealTimeProfile, false);
876  S.setAttributeItem(ARM_ISA_use, Allowed, false);
877  S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
878  break;
879 
880  case ARM::ArchKind::ARMV7EM:
881  case ARM::ArchKind::ARMV7M:
882  S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false);
883  S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
884  break;
885 
886  case ARM::ArchKind::ARMV8A:
887  case ARM::ArchKind::ARMV8_1A:
888  case ARM::ArchKind::ARMV8_2A:
889  case ARM::ArchKind::ARMV8_3A:
890  case ARM::ArchKind::ARMV8_4A:
891  case ARM::ArchKind::ARMV8_5A:
892  case ARM::ArchKind::ARMV8_6A:
893  case ARM::ArchKind::ARMV8_7A:
894  case ARM::ArchKind::ARMV8_8A:
895  case ARM::ArchKind::ARMV8_9A:
896  case ARM::ArchKind::ARMV9A:
897  case ARM::ArchKind::ARMV9_1A:
898  case ARM::ArchKind::ARMV9_2A:
899  case ARM::ArchKind::ARMV9_3A:
900  case ARM::ArchKind::ARMV9_4A:
901  S.setAttributeItem(CPU_arch_profile, ApplicationProfile, false);
902  S.setAttributeItem(ARM_ISA_use, Allowed, false);
903  S.setAttributeItem(THUMB_ISA_use, AllowThumb32, false);
904  S.setAttributeItem(MPextension_use, Allowed, false);
905  S.setAttributeItem(Virtualization_use, AllowTZVirtualization, false);
906  break;
907 
908  case ARM::ArchKind::ARMV8MBaseline:
909  case ARM::ArchKind::ARMV8MMainline:
910  S.setAttributeItem(THUMB_ISA_use, AllowThumbDerived, false);
911  S.setAttributeItem(CPU_arch_profile, MicroControllerProfile, false);
912  break;
913 
914  case ARM::ArchKind::IWMMXT:
915  S.setAttributeItem(ARM_ISA_use, Allowed, false);
916  S.setAttributeItem(THUMB_ISA_use, Allowed, false);
917  S.setAttributeItem(WMMX_arch, AllowWMMXv1, false);
918  break;
919 
920  case ARM::ArchKind::IWMMXT2:
921  S.setAttributeItem(ARM_ISA_use, Allowed, false);
922  S.setAttributeItem(THUMB_ISA_use, Allowed, false);
923  S.setAttributeItem(WMMX_arch, AllowWMMXv2, false);
924  break;
925 
926  default:
927  report_fatal_error("Unknown Arch: " + Twine(ARM::getArchName(Arch)));
928  break;
929  }
930 }
931 
932 void ARMTargetELFStreamer::emitFPU(unsigned Value) {
933  FPU = Value;
934 }
935 
936 void ARMTargetELFStreamer::emitFPUDefaultAttributes() {
937  ARMELFStreamer &S = getStreamer();
938 
939  switch (FPU) {
940  case ARM::FK_VFP:
941  case ARM::FK_VFPV2:
943  /* OverwriteExisting= */ false);
944  break;
945 
946  case ARM::FK_VFPV3:
948  /* OverwriteExisting= */ false);
949  break;
950 
951  case ARM::FK_VFPV3_FP16:
953  /* OverwriteExisting= */ false);
955  /* OverwriteExisting= */ false);
956  break;
957 
958  case ARM::FK_VFPV3_D16:
960  /* OverwriteExisting= */ false);
961  break;
962 
963  case ARM::FK_VFPV3_D16_FP16:
965  /* OverwriteExisting= */ false);
967  /* OverwriteExisting= */ false);
968  break;
969 
970  case ARM::FK_VFPV3XD:
972  /* OverwriteExisting= */ false);
973  break;
974  case ARM::FK_VFPV3XD_FP16:
976  /* OverwriteExisting= */ false);
978  /* OverwriteExisting= */ false);
979  break;
980 
981  case ARM::FK_VFPV4:
983  /* OverwriteExisting= */ false);
984  break;
985 
986  // ABI_HardFP_use is handled in ARMAsmPrinter, so _SP_D16 is treated the same
987  // as _D16 here.
988  case ARM::FK_FPV4_SP_D16:
989  case ARM::FK_VFPV4_D16:
991  /* OverwriteExisting= */ false);
992  break;
993 
994  case ARM::FK_FP_ARMV8:
996  /* OverwriteExisting= */ false);
997  break;
998 
999  // FPV5_D16 is identical to FP_ARMV8 except for the number of D registers, so
1000  // uses the FP_ARMV8_D16 build attribute.
1001  case ARM::FK_FPV5_SP_D16:
1002  case ARM::FK_FPV5_D16:
1004  /* OverwriteExisting= */ false);
1005  break;
1006 
1007  case ARM::FK_NEON:
1009  /* OverwriteExisting= */ false);
1010  S.setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
1012  /* OverwriteExisting= */ false);
1013  break;
1014 
1015  case ARM::FK_NEON_FP16:
1017  /* OverwriteExisting= */ false);
1018  S.setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
1020  /* OverwriteExisting= */ false);
1022  /* OverwriteExisting= */ false);
1023  break;
1024 
1025  case ARM::FK_NEON_VFPV4:
1027  /* OverwriteExisting= */ false);
1028  S.setAttributeItem(ARMBuildAttrs::Advanced_SIMD_arch,
1030  /* OverwriteExisting= */ false);
1031  break;
1032 
1033  case ARM::FK_NEON_FP_ARMV8:
1034  case ARM::FK_CRYPTO_NEON_FP_ARMV8:
1036  /* OverwriteExisting= */ false);
1037  // 'Advanced_SIMD_arch' must be emitted not here, but within
1038  // ARMAsmPrinter::emitAttributes(), depending on hasV8Ops() and hasV8_1a()
1039  break;
1040 
1041  case ARM::FK_SOFTVFP:
1042  case ARM::FK_NONE:
1043  break;
1044 
1045  default:
1046  report_fatal_error("Unknown FPU: " + Twine(FPU));
1047  break;
1048  }
1049 }
1050 
1051 void ARMTargetELFStreamer::finishAttributeSection() {
1052  ARMELFStreamer &S = getStreamer();
1053 
1054  if (FPU != ARM::FK_INVALID)
1055  emitFPUDefaultAttributes();
1056 
1057  if (Arch != ARM::ArchKind::INVALID)
1058  emitArchDefaultAttributes();
1059 
1060  if (S.Contents.empty())
1061  return;
1062 
1063  auto LessTag = [](const MCELFStreamer::AttributeItem &LHS,
1064  const MCELFStreamer::AttributeItem &RHS) -> bool {
1065  // The conformance tag must be emitted first when serialised into an
1066  // object file. Specifically, the addenda to the ARM ABI states that
1067  // (2.3.7.4):
1068  //
1069  // "To simplify recognition by consumers in the common case of claiming
1070  // conformity for the whole file, this tag should be emitted first in a
1071  // file-scope sub-subsection of the first public subsection of the
1072  // attributes section."
1073  //
1074  // So it is special-cased in this comparison predicate when the
1075  // attributes are sorted in finishAttributeSection().
1076  return (RHS.Tag != ARMBuildAttrs::conformance) &&
1077  ((LHS.Tag == ARMBuildAttrs::conformance) || (LHS.Tag < RHS.Tag));
1078  };
1079  llvm::sort(S.Contents, LessTag);
1080 
1081  S.emitAttributesSection(CurrentVendor, ".ARM.attributes",
1082  ELF::SHT_ARM_ATTRIBUTES, AttributeSection);
1083 
1084  FPU = ARM::FK_INVALID;
1085 }
1086 
1087 void ARMTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
1088  ARMELFStreamer &Streamer = getStreamer();
1089  if (!Streamer.IsThumb)
1090  return;
1091 
1092  Streamer.getAssembler().registerSymbol(*Symbol);
1093  unsigned Type = cast<MCSymbolELF>(Symbol)->getType();
1095  Streamer.emitThumbFunc(Symbol);
1096 }
1097 
1098 void ARMTargetELFStreamer::annotateTLSDescriptorSequence(
1099  const MCSymbolRefExpr *S) {
1100  getStreamer().EmitFixup(S, FK_Data_4);
1101 }
1102 
1103 void ARMTargetELFStreamer::emitThumbSet(MCSymbol *Symbol, const MCExpr *Value) {
1104  if (const MCSymbolRefExpr *SRE = dyn_cast<MCSymbolRefExpr>(Value)) {
1105  const MCSymbol &Sym = SRE->getSymbol();
1106  if (!Sym.isDefined()) {
1107  getStreamer().emitAssignment(Symbol, Value);
1108  return;
1109  }
1110  }
1111 
1112  getStreamer().emitThumbFunc(Symbol);
1113  getStreamer().emitAssignment(Symbol, Value);
1114 }
1115 
1116 void ARMTargetELFStreamer::emitInst(uint32_t Inst, char Suffix) {
1117  getStreamer().emitInst(Inst, Suffix);
1118 }
1119 
1120 void ARMTargetELFStreamer::reset() { AttributeSection = nullptr; }
1121 
1122 void ARMELFStreamer::finishImpl() {
1123  MCTargetStreamer &TS = *getTargetStreamer();
1124  ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1125  ATS.finishAttributeSection();
1126 
1127  MCELFStreamer::finishImpl();
1128 }
1129 
1130 void ARMELFStreamer::reset() {
1131  MCTargetStreamer &TS = *getTargetStreamer();
1132  ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1133  ATS.reset();
1134  MappingSymbolCounter = 0;
1135  MCELFStreamer::reset();
1136  LastMappingSymbols.clear();
1137  LastEMSInfo.reset();
1138  // MCELFStreamer clear's the assembler's e_flags. However, for
1139  // arm we manually set the ABI version on streamer creation, so
1140  // do the same here
1141  getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
1142 }
1143 
1144 inline void ARMELFStreamer::SwitchToEHSection(StringRef Prefix,
1145  unsigned Type,
1146  unsigned Flags,
1147  SectionKind Kind,
1148  const MCSymbol &Fn) {
1149  const MCSectionELF &FnSection =
1150  static_cast<const MCSectionELF &>(Fn.getSection());
1151 
1152  // Create the name for new section
1153  StringRef FnSecName(FnSection.getName());
1154  SmallString<128> EHSecName(Prefix);
1155  if (FnSecName != ".text") {
1156  EHSecName += FnSecName;
1157  }
1158 
1159  // Get .ARM.extab or .ARM.exidx section
1160  const MCSymbolELF *Group = FnSection.getGroup();
1161  if (Group)
1162  Flags |= ELF::SHF_GROUP;
1163  MCSectionELF *EHSection = getContext().getELFSection(
1164  EHSecName, Type, Flags, 0, Group, /*IsComdat=*/true,
1165  FnSection.getUniqueID(),
1166  static_cast<const MCSymbolELF *>(FnSection.getBeginSymbol()));
1167 
1168  assert(EHSection && "Failed to get the required EH section");
1169 
1170  // Switch to .ARM.extab or .ARM.exidx section
1171  switchSection(EHSection);
1172  emitValueToAlignment(Align(4), 0, 1, 0);
1173 }
1174 
1175 inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) {
1176  SwitchToEHSection(".ARM.extab", ELF::SHT_PROGBITS, ELF::SHF_ALLOC,
1177  SectionKind::getData(), FnStart);
1178 }
1179 
1180 inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {
1181  SwitchToEHSection(".ARM.exidx", ELF::SHT_ARM_EXIDX,
1183  SectionKind::getData(), FnStart);
1184 }
1185 
1186 void ARMELFStreamer::EmitFixup(const MCExpr *Expr, MCFixupKind Kind) {
1187  MCDataFragment *Frag = getOrCreateDataFragment();
1188  Frag->getFixups().push_back(MCFixup::create(Frag->getContents().size(), Expr,
1189  Kind));
1190 }
1191 
1192 void ARMELFStreamer::EHReset() {
1193  ExTab = nullptr;
1194  FnStart = nullptr;
1195  Personality = nullptr;
1196  PersonalityIndex = ARM::EHABI::NUM_PERSONALITY_INDEX;
1197  FPReg = ARM::SP;
1198  FPOffset = 0;
1199  SPOffset = 0;
1200  PendingOffset = 0;
1201  UsedFP = false;
1202  CantUnwind = false;
1203 
1204  Opcodes.clear();
1205  UnwindOpAsm.Reset();
1206 }
1207 
1208 void ARMELFStreamer::emitFnStart() {
1209  assert(FnStart == nullptr);
1210  FnStart = getContext().createTempSymbol();
1211  emitLabel(FnStart);
1212 }
1213 
1214 void ARMELFStreamer::emitFnEnd() {
1215  assert(FnStart && ".fnstart must precedes .fnend");
1216 
1217  // Emit unwind opcodes if there is no .handlerdata directive
1218  if (!ExTab && !CantUnwind)
1219  FlushUnwindOpcodes(true);
1220 
1221  // Emit the exception index table entry
1222  SwitchToExIdxSection(*FnStart);
1223 
1224  // The EHABI requires a dependency preserving R_ARM_NONE relocation to the
1225  // personality routine to protect it from an arbitrary platform's static
1226  // linker garbage collection. We disable this for Android where the unwinder
1227  // is either dynamically linked or directly references the personality
1228  // routine.
1229  if (PersonalityIndex < ARM::EHABI::NUM_PERSONALITY_INDEX && !IsAndroid)
1230  EmitPersonalityFixup(GetAEABIUnwindPersonalityName(PersonalityIndex));
1231 
1232  const MCSymbolRefExpr *FnStartRef =
1233  MCSymbolRefExpr::create(FnStart,
1234  MCSymbolRefExpr::VK_ARM_PREL31,
1235  getContext());
1236 
1237  emitValue(FnStartRef, 4);
1238 
1239  if (CantUnwind) {
1240  emitInt32(ARM::EHABI::EXIDX_CANTUNWIND);
1241  } else if (ExTab) {
1242  // Emit a reference to the unwind opcodes in the ".ARM.extab" section.
1243  const MCSymbolRefExpr *ExTabEntryRef =
1244  MCSymbolRefExpr::create(ExTab,
1245  MCSymbolRefExpr::VK_ARM_PREL31,
1246  getContext());
1247  emitValue(ExTabEntryRef, 4);
1248  } else {
1249  // For the __aeabi_unwind_cpp_pr0, we have to emit the unwind opcodes in
1250  // the second word of exception index table entry. The size of the unwind
1251  // opcodes should always be 4 bytes.
1252  assert(PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0 &&
1253  "Compact model must use __aeabi_unwind_cpp_pr0 as personality");
1254  assert(Opcodes.size() == 4u &&
1255  "Unwind opcode size for __aeabi_unwind_cpp_pr0 must be equal to 4");
1256  uint64_t Intval = Opcodes[0] |
1257  Opcodes[1] << 8 |
1258  Opcodes[2] << 16 |
1259  Opcodes[3] << 24;
1260  emitIntValue(Intval, Opcodes.size());
1261  }
1262 
1263  // Switch to the section containing FnStart
1264  switchSection(&FnStart->getSection());
1265 
1266  // Clean exception handling frame information
1267  EHReset();
1268 }
1269 
1270 void ARMELFStreamer::emitCantUnwind() { CantUnwind = true; }
1271 
1272 // Add the R_ARM_NONE fixup at the same position
1273 void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {
1274  const MCSymbol *PersonalitySym = getContext().getOrCreateSymbol(Name);
1275 
1276  const MCSymbolRefExpr *PersonalityRef = MCSymbolRefExpr::create(
1277  PersonalitySym, MCSymbolRefExpr::VK_ARM_NONE, getContext());
1278 
1279  visitUsedExpr(*PersonalityRef);
1280  MCDataFragment *DF = getOrCreateDataFragment();
1281  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
1282  PersonalityRef,
1283  MCFixup::getKindForSize(4, false)));
1284 }
1285 
1286 void ARMELFStreamer::FlushPendingOffset() {
1287  if (PendingOffset != 0) {
1288  UnwindOpAsm.EmitSPOffset(-PendingOffset);
1289  PendingOffset = 0;
1290  }
1291 }
1292 
1293 void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
1294  // Emit the unwind opcode to restore $sp.
1295  if (UsedFP) {
1296  const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1297  int64_t LastRegSaveSPOffset = SPOffset - PendingOffset;
1298  UnwindOpAsm.EmitSPOffset(LastRegSaveSPOffset - FPOffset);
1299  UnwindOpAsm.EmitSetSP(MRI->getEncodingValue(FPReg));
1300  } else {
1301  FlushPendingOffset();
1302  }
1303 
1304  // Finalize the unwind opcode sequence
1305  UnwindOpAsm.Finalize(PersonalityIndex, Opcodes);
1306 
1307  // For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx
1308  // section. Thus, we don't have to create an entry in the .ARM.extab
1309  // section.
1310  if (NoHandlerData && PersonalityIndex == ARM::EHABI::AEABI_UNWIND_CPP_PR0)
1311  return;
1312 
1313  // Switch to .ARM.extab section.
1314  SwitchToExTabSection(*FnStart);
1315 
1316  // Create .ARM.extab label for offset in .ARM.exidx
1317  assert(!ExTab);
1318  ExTab = getContext().createTempSymbol();
1319  emitLabel(ExTab);
1320 
1321  // Emit personality
1322  if (Personality) {
1323  const MCSymbolRefExpr *PersonalityRef =
1324  MCSymbolRefExpr::create(Personality,
1325  MCSymbolRefExpr::VK_ARM_PREL31,
1326  getContext());
1327 
1328  emitValue(PersonalityRef, 4);
1329  }
1330 
1331  // Emit unwind opcodes
1332  assert((Opcodes.size() % 4) == 0 &&
1333  "Unwind opcode size for __aeabi_cpp_unwind_pr0 must be multiple of 4");
1334  for (unsigned I = 0; I != Opcodes.size(); I += 4) {
1335  uint64_t Intval = Opcodes[I] |
1336  Opcodes[I + 1] << 8 |
1337  Opcodes[I + 2] << 16 |
1338  Opcodes[I + 3] << 24;
1339  emitInt32(Intval);
1340  }
1341 
1342  // According to ARM EHABI section 9.2, if the __aeabi_unwind_cpp_pr1() or
1343  // __aeabi_unwind_cpp_pr2() is used, then the handler data must be emitted
1344  // after the unwind opcodes. The handler data consists of several 32-bit
1345  // words, and should be terminated by zero.
1346  //
1347  // In case that the .handlerdata directive is not specified by the
1348  // programmer, we should emit zero to terminate the handler data.
1349  if (NoHandlerData && !Personality)
1350  emitInt32(0);
1351 }
1352 
1353 void ARMELFStreamer::emitHandlerData() { FlushUnwindOpcodes(false); }
1354 
1355 void ARMELFStreamer::emitPersonality(const MCSymbol *Per) {
1356  Personality = Per;
1357  UnwindOpAsm.setPersonality(Per);
1358 }
1359 
1360 void ARMELFStreamer::emitPersonalityIndex(unsigned Index) {
1361  assert(Index < ARM::EHABI::NUM_PERSONALITY_INDEX && "invalid index");
1362  PersonalityIndex = Index;
1363 }
1364 
1365 void ARMELFStreamer::emitSetFP(unsigned NewFPReg, unsigned NewSPReg,
1366  int64_t Offset) {
1367  assert((NewSPReg == ARM::SP || NewSPReg == FPReg) &&
1368  "the operand of .setfp directive should be either $sp or $fp");
1369 
1370  UsedFP = true;
1371  FPReg = NewFPReg;
1372 
1373  if (NewSPReg == ARM::SP)
1374  FPOffset = SPOffset + Offset;
1375  else
1376  FPOffset += Offset;
1377 }
1378 
1379 void ARMELFStreamer::emitMovSP(unsigned Reg, int64_t Offset) {
1380  assert((Reg != ARM::SP && Reg != ARM::PC) &&
1381  "the operand of .movsp cannot be either sp or pc");
1382  assert(FPReg == ARM::SP && "current FP must be SP");
1383 
1384  FlushPendingOffset();
1385 
1386  FPReg = Reg;
1387  FPOffset = SPOffset + Offset;
1388 
1389  const MCRegisterInfo *MRI = getContext().getRegisterInfo();
1390  UnwindOpAsm.EmitSetSP(MRI->getEncodingValue(FPReg));
1391 }
1392 
1393 void ARMELFStreamer::emitPad(int64_t Offset) {
1394  // Track the change of the $sp offset
1395  SPOffset -= Offset;
1396 
1397  // To squash multiple .pad directives, we should delay the unwind opcode
1398  // until the .save, .vsave, .handlerdata, or .fnend directives.
1399  PendingOffset -= Offset;
1400 }
1401 
1402 static std::pair<unsigned, unsigned>
1403 collectHWRegs(const MCRegisterInfo &MRI, unsigned Idx,
1404  const SmallVectorImpl<unsigned> &RegList, bool IsVector,
1405  uint32_t &Mask_) {
1406  uint32_t Mask = 0;
1407  unsigned Count = 0;
1408  while (Idx > 0) {
1409  unsigned Reg = RegList[Idx - 1];
1410  if (Reg == ARM::RA_AUTH_CODE)
1411  break;
1412  Reg = MRI.getEncodingValue(Reg);
1413  assert(Reg < (IsVector ? 32U : 16U) && "Register out of range");
1414  unsigned Bit = (1u << Reg);
1415  if ((Mask & Bit) == 0) {
1416  Mask |= Bit;
1417  ++Count;
1418  }
1419  --Idx;
1420  }
1421 
1422  Mask_ = Mask;
1423  return {Idx, Count};
1424 }
1425 
1426 void ARMELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
1427  bool IsVector) {
1428  uint32_t Mask;
1429  unsigned Idx, Count;
1430  const MCRegisterInfo &MRI = *getContext().getRegisterInfo();
1431 
1432  // Collect the registers in the register list. Issue unwinding instructions in
1433  // three parts: ordinary hardware registers, return address authentication
1434  // code pseudo register, the rest of the registers. The RA PAC is kept in an
1435  // architectural register (usually r12), but we treat it as a special case in
1436  // order to distinguish between that register containing RA PAC or a general
1437  // value.
1438  Idx = RegList.size();
1439  while (Idx > 0) {
1440  std::tie(Idx, Count) = collectHWRegs(MRI, Idx, RegList, IsVector, Mask);
1441  if (Count) {
1442  // Track the change the $sp offset: For the .save directive, the
1443  // corresponding push instruction will decrease the $sp by (4 * Count).
1444  // For the .vsave directive, the corresponding vpush instruction will
1445  // decrease $sp by (8 * Count).
1446  SPOffset -= Count * (IsVector ? 8 : 4);
1447 
1448  // Emit the opcode
1449  FlushPendingOffset();
1450  if (IsVector)
1451  UnwindOpAsm.EmitVFPRegSave(Mask);
1452  else
1453  UnwindOpAsm.EmitRegSave(Mask);
1454  } else if (Idx > 0 && RegList[Idx - 1] == ARM::RA_AUTH_CODE) {
1455  --Idx;
1456  SPOffset -= 4;
1457  FlushPendingOffset();
1458  UnwindOpAsm.EmitRegSave(0);
1459  }
1460  }
1461 }
1462 
1463 void ARMELFStreamer::emitUnwindRaw(int64_t Offset,
1464  const SmallVectorImpl<uint8_t> &Opcodes) {
1465  FlushPendingOffset();
1466  SPOffset = SPOffset - Offset;
1467  UnwindOpAsm.EmitRaw(Opcodes);
1468 }
1469 
1470 namespace llvm {
1471 
1474  MCInstPrinter *InstPrint,
1475  bool isVerboseAsm) {
1476  return new ARMTargetAsmStreamer(S, OS, *InstPrint, isVerboseAsm);
1477 }
1478 
1480  return new ARMTargetStreamer(S);
1481 }
1482 
1484  return new ARMTargetELFStreamer(S);
1485 }
1486 
1488  std::unique_ptr<MCAsmBackend> TAB,
1489  std::unique_ptr<MCObjectWriter> OW,
1490  std::unique_ptr<MCCodeEmitter> Emitter,
1491  bool RelaxAll, bool IsThumb,
1492  bool IsAndroid) {
1493  ARMELFStreamer *S =
1494  new ARMELFStreamer(Context, std::move(TAB), std::move(OW),
1495  std::move(Emitter), IsThumb, IsAndroid);
1496  // FIXME: This should eventually end up somewhere else where more
1497  // intelligent flag decisions can be made. For now we are just maintaining
1498  // the status quo for ARM and setting EF_ARM_EABI_VER5 as the default.
1499  S->getAssembler().setELFHeaderEFlags(ELF::EF_ARM_EABI_VER5);
1500 
1501  if (RelaxAll)
1502  S->getAssembler().setRelaxAll(true);
1503  return S;
1504 }
1505 
1506 } // end namespace llvm
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
llvm::MCTargetStreamer::getStreamer
MCStreamer & getStreamer()
Definition: MCStreamer.h:101
i
i
Definition: README.txt:29
llvm::ARMTargetStreamer::emitCantUnwind
virtual void emitCantUnwind()
Definition: ARMTargetStreamer.cpp:92
llvm::MCSectionELF::getUniqueID
unsigned getUniqueID() const
Definition: MCSectionELF.h:87
llvm::ARMBuildAttrs::ARM_ISA_use
@ ARM_ISA_use
Definition: ARMBuildAttributes.h:41
ARMEHABI.h
llvm::ARMBuildAttrs::WMMX_arch
@ WMMX_arch
Definition: ARMBuildAttributes.h:44
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MCTargetStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol)
Definition: MCStreamer.cpp:53
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::AArch64CC::AL
@ AL
Definition: AArch64BaseInfo.h:269
llvm::ARMTargetStreamer::emitFnEnd
virtual void emitFnEnd()
Definition: ARMTargetStreamer.cpp:91
llvm::dxil::ParameterKind::I1
@ I1
llvm::MCELFStreamer::emitLabel
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Definition: MCELFStreamer.cpp:101
llvm::ARMBuildAttrs::Advanced_SIMD_arch
@ Advanced_SIMD_arch
Definition: ARMBuildAttributes.h:45
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:161
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
llvm::Attribute
Definition: Attributes.h:66
llvm::PseudoProbeReservedId::Last
@ Last
llvm::ARMTargetStreamer
Definition: MCStreamer.h:135
StringRef.h
llvm::ARMBuildAttrs::AllowHPFP
@ AllowHPFP
Definition: ARMBuildAttributes.h:223
llvm::UnwindOpcodeAssembler
Definition: ARMUnwindOpAsm.h:25
llvm::ARMTargetStreamer::emitPersonality
virtual void emitPersonality(const MCSymbol *Personality)
Definition: ARMTargetStreamer.cpp:93
MCCodeEmitter.h
llvm::ARMBuildAttrs::AllowFPARMv8A
@ AllowFPARMv8A
Definition: ARMBuildAttributes.h:140
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
MCSectionELF.h
llvm::MCSection::getBeginSymbol
MCSymbol * getBeginSymbol()
Definition: MCSection.h:129
llvm::ARMBuildAttrs::ApplicationProfile
@ ApplicationProfile
Definition: ARMBuildAttributes.h:117
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::ARMBuildAttrs::CPU_arch_profile
@ CPU_arch_profile
Definition: ARMBuildAttributes.h:40
llvm::createARMNullTargetStreamer
MCTargetStreamer * createARMNullTargetStreamer(MCStreamer &S)
Definition: ARMELFStreamer.cpp:1479
llvm::MCELFStreamer::changeSection
void changeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
Definition: MCELFStreamer.cpp:147
llvm::ELF::EF_ARM_EABI_VER5
@ EF_ARM_EABI_VER5
Definition: ELF.h:444
ErrorHandling.h
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition: X86DisassemblerDecoder.h:462
MCFragment.h
llvm::MCAssembler::setIsThumbFunc
void setIsThumbFunc(const MCSymbol *Func)
Flag a function symbol as the target of a .thumb_func directive.
Definition: MCAssembler.h:273
llvm::MCSectionELF::getGroup
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:76
llvm::ARMBuildAttrs::also_compatible_with
@ also_compatible_with
Definition: ARMBuildAttributes.h:75
llvm::ARMBuildAttrs::AllowWMMXv1
@ AllowWMMXv1
Definition: ARMBuildAttributes.h:145
MCAssembler.h
llvm::ARMBuildAttrs::AllowNeon
@ AllowNeon
Definition: ARMBuildAttributes.h:149
llvm::ARM::getCPUAttr
StringRef getCPUAttr(ArchKind AK)
Definition: ARMTargetParser.cpp:327
llvm::ELF::STT_NOTYPE
@ STT_NOTYPE
Definition: ELF.h:1229
llvm::ARMBuildAttrs::MPextension_use
@ MPextension_use
Definition: ARMBuildAttributes.h:69
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
llvm::ELF::SHT_ARM_ATTRIBUTES
@ SHT_ARM_ATTRIBUTES
Definition: ELF.h:1035
llvm::MCSymbol::isDefined
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:243
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:980
llvm::AArch64::getArchExtName
StringRef getArchExtName(unsigned ArchExtKind)
llvm::MCStreamer::getCurrentSection
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition: MCStreamer.h:384
llvm::ARMBuildAttrs::AllowFPv4A
@ AllowFPv4A
Definition: ARMBuildAttributes.h:138
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::MCEncodedFragmentWithFixups::getFixups
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:222
llvm::MCSectionELF
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:26
TargetParser.h
llvm::MCAssemblerFlag
MCAssemblerFlag
Definition: MCDirectives.h:51
llvm::ARMBuildAttrs::AllowFPv3A
@ AllowFPv3A
Definition: ARMBuildAttributes.h:136
llvm::ARMTargetStreamer::reset
virtual void reset()
Reset any state between object emissions, i.e.
Definition: ARMTargetStreamer.cpp:51
llvm::MCELFStreamer::reset
void reset() override
state management
Definition: MCELFStreamer.h:40
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::ARMTargetStreamer::emitPad
virtual void emitPad(int64_t Offset)
Definition: ARMTargetStreamer.cpp:99
llvm::ARMBuildAttrs::AllowFPv2
@ AllowFPv2
Definition: ARMBuildAttributes.h:135
MCELFStreamer.h
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::ARMBuildAttrs::AllowTZ
@ AllowTZ
Definition: ARMBuildAttributes.h:243
llvm::MCSymbolAttr
MCSymbolAttr
Definition: MCDirectives.h:18
llvm::ELF::STT_FUNC
@ STT_FUNC
Definition: ELF.h:1231
llvm::ARMBuildAttrs::conformance
@ conformance
Definition: ARMBuildAttributes.h:76
llvm::MCSymbolELF
Definition: MCSymbolELF.h:14
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
llvm::BitmaskEnumDetail::Mask
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
llvm::MCFragment
Definition: MCFragment.h:30
FormattedStream.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::ARM::getArchAttr
unsigned getArchAttr(ArchKind AK)
Definition: ARMTargetParser.cpp:335
llvm::FK_Data_4
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:25
llvm::ARMTargetStreamer::emitRegSave
virtual void emitRegSave(const SmallVectorImpl< unsigned > &RegList, bool isVector)
Definition: ARMTargetStreamer.cpp:100
Emitter
dxil DXContainer Global Emitter
Definition: DXContainerGlobals.cpp:67
llvm::ARMBuildAttrs::compatibility
@ compatibility
Definition: ARMBuildAttributes.h:65
ELF.h
llvm::MCELFStreamer
Definition: MCELFStreamer.h:31
llvm::MCSymbol::getSection
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:262
MCAsmBackend.h
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
ARMUnwindOpAsm.h
llvm::ARMTargetStreamer::emitInst
virtual void emitInst(uint32_t Inst, char Suffix='\0')
Definition: ARMTargetStreamer.cpp:53
llvm::ARMBuildAttrs::AllowThumbDerived
@ AllowThumbDerived
Definition: ARMBuildAttributes.h:132
SmallString.h
Twine.h
MCSymbolELF.h
MCContext.h
llvm::MCObjectStreamer::emitInstruction
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Definition: MCObjectStreamer.cpp:409
MCSymbol.h
llvm::ARMBuildAttrs::Allowed
@ Allowed
Definition: ARMBuildAttributes.h:126
llvm::ARMBuildAttrs::FP_arch
@ FP_arch
Definition: ARMBuildAttributes.h:43
llvm::MCAF_Code16
@ MCAF_Code16
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:54
llvm::ARMTargetStreamer::emitArch
virtual void emitArch(ARM::ArchKind Arch)
Definition: ARMTargetStreamer.cpp:112
MCInst.h
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
First
into llvm powi allowing the code generator to produce balanced multiplication trees First
Definition: README.txt:54
MCSubtargetInfo.h
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:147
llvm::ARMBuildAttrs::RealTimeProfile
@ RealTimeProfile
Definition: ARMBuildAttributes.h:118
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
llvm::createARMObjectTargetELFStreamer
MCTargetStreamer * createARMObjectTargetELFStreamer(MCStreamer &S)
Definition: ARMELFStreamer.cpp:1483
llvm::ARMBuildAttrs::AllowFPv4B
@ AllowFPv4B
Definition: ARMBuildAttributes.h:139
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:93
llvm::MCSymbol::getName
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:198
Align
uint64_t Align
Definition: ELFObjHandler.cpp:82
llvm::MCELFStreamer::emitLabelAtPos
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F, uint64_t Offset) override
Definition: MCELFStreamer.cpp:111
llvm::MCObjectStreamer::getCurrentFragment
MCFragment * getCurrentFragment() const
Definition: MCObjectStreamer.cpp:201
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
MCInstPrinter.h
collectHWRegs
static std::pair< unsigned, unsigned > collectHWRegs(const MCRegisterInfo &MRI, unsigned Idx, const SmallVectorImpl< unsigned > &RegList, bool IsVector, uint32_t &Mask_)
Definition: ARMELFStreamer.cpp:1403
DF
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
llvm::SmallString< 128 >
llvm::ARM_PROC::IE
@ IE
Definition: ARMBaseInfo.h:27
llvm::MCELFStreamer::emitThumbFunc
void emitThumbFunc(MCSymbol *Func) override
Note in the output that the specified Func is a Thumb mode function (ARM target only).
Definition: MCELFStreamer.cpp:717
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1682
llvm::ARMTargetStreamer::emitSetFP
virtual void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset=0)
Definition: ARMTargetStreamer.cpp:96
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
llvm::ELF::SHF_LINK_ORDER
@ SHF_LINK_ORDER
Definition: ELF.h:1079
llvm::ELF::STT_GNU_IFUNC
@ STT_GNU_IFUNC
Definition: ELF.h:1236
llvm::MCELFStreamer::finishImpl
void finishImpl() override
Streamer specific finalization.
Definition: MCELFStreamer.cpp:699
llvm::ARMBuildAttrs::getARMAttributeTags
const TagNameMap & getARMAttributeTags()
Definition: ARMBuildAttrs.cpp:76
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::ARMBuildAttrs::THUMB_ISA_use
@ THUMB_ISA_use
Definition: ARMBuildAttributes.h:42
llvm::ARMTargetStreamer::emitObjectArch
virtual void emitObjectArch(ARM::ArchKind Arch)
Definition: ARMTargetStreamer.cpp:114
llvm::MCAF_SubsectionsViaSymbols
@ MCAF_SubsectionsViaSymbols
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:53
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
index
splat index
Definition: README_ALTIVEC.txt:181
uint64_t
llvm::MCContext::getAsmInfo
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:447
llvm::MCInstPrinter
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:43
llvm::createARMTargetAsmStreamer
MCTargetStreamer * createARMTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, bool isVerboseAsm)
Definition: ARMELFStreamer.cpp:1472
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:53
llvm::DenseMap
Definition: DenseMap.h:714
llvm::ARMTargetStreamer::emitHandlerData
virtual void emitHandlerData()
Definition: ARMTargetStreamer.cpp:95
I
#define I(x, y, z)
Definition: MD5.cpp:58
StringExtras.h
llvm::AArch64::getArchName
StringRef getArchName(ArchKind AK)
Definition: AArch64TargetParser.cpp:92
MCRegisterInfo.h
llvm::Value::print
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Definition: AsmWriter.cpp:4676
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:1064
llvm::ARMBuildAttrs::AllowWMMXv2
@ AllowWMMXv2
Definition: ARMBuildAttributes.h:146
llvm::formatted_raw_ostream
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
Definition: FormattedStream.h:30
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ARMBuildAttrs::MicroControllerProfile
@ MicroControllerProfile
Definition: ARMBuildAttributes.h:119
llvm::MCContext::reportError
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1055
llvm::ELF::SHT_ARM_EXIDX
@ SHT_ARM_EXIDX
Definition: ELF.h:1031
llvm::ARMTargetStreamer::switchVendor
virtual void switchVendor(StringRef Vendor)
Definition: ARMTargetStreamer.cpp:105
llvm::ARM::EHABI::AEABI_UNWIND_CPP_PR0
@ AEABI_UNWIND_CPP_PR0
Definition: ARMEHABI.h:127
llvm::ARMTargetStreamer::emitThumbSet
virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value)
Definition: ARMTargetStreamer.cpp:119
llvm::ARMTargetStreamer::emitIntTextAttribute
virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue="")
Definition: ARMTargetStreamer.cpp:109
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
MCSection.h
llvm::FK_NONE
@ FK_NONE
A no-op fixup.
Definition: MCFixup.h:22
llvm::createARMELFStreamer
MCELFStreamer * createARMELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, bool RelaxAll, bool IsThumb, bool IsAndroid)
Definition: ARMELFStreamer.cpp:1487
llvm::MCObjectStreamer::getAssembler
MCAssembler & getAssembler()
Definition: MCObjectStreamer.h:128
llvm::MCELFStreamer::emitValueImpl
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
Definition: MCELFStreamer.cpp:359
llvm::MCObjectStreamer::getOrCreateDataFragment
MCDataFragment * getOrCreateDataFragment(const MCSubtargetInfo *STI=nullptr)
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment.
Definition: MCObjectStreamer.cpp:225
MCAsmInfo.h
llvm::ARMTargetStreamer::emitPersonalityIndex
virtual void emitPersonalityIndex(unsigned Index)
Definition: ARMTargetStreamer.cpp:94
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
GetAEABIUnwindPersonalityName
static std::string GetAEABIUnwindPersonalityName(unsigned Index)
Definition: ARMELFStreamer.cpp:60
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
uint32_t
MCFixup.h
llvm::ARMBuildAttrs::AllowNeon2
@ AllowNeon2
Definition: ARMBuildAttributes.h:150
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::ARMBuildAttrs::AllowFPARMv8B
@ AllowFPARMv8B
Definition: ARMBuildAttributes.h:141
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
llvm::LoongArch::FK_INVALID
@ FK_INVALID
Definition: LoongArchTargetParser.h:26
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::MCObjectStreamer::emitFill
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
Definition: MCObjectStreamer.cpp:845
llvm::MCELFStreamer::AttributeItem
ELF object attributes section emission support.
Definition: MCELFStreamer.h:91
llvm::MCSection::getName
StringRef getName() const
Definition: MCSection.h:124
llvm::MCAF_Code32
@ MCAF_Code32
.code32 (X86) / .code 32 (ARM)
Definition: MCDirectives.h:55
llvm::MCAF_Code64
@ MCAF_Code64
.code64 (X86)
Definition: MCDirectives.h:56
MCObjectWriter.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
ARMRegisterInfo.h
llvm::MCAF_SyntaxUnified
@ MCAF_SyntaxUnified
.syntax (ARM/ELF)
Definition: MCDirectives.h:52
llvm::ARMBuildAttrs::Virtualization_use
@ Virtualization_use
Definition: ARMBuildAttributes.h:77
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::ARMTargetStreamer::emitTextAttribute
virtual void emitTextAttribute(unsigned Attribute, StringRef String)
Definition: ARMTargetStreamer.cpp:107
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::ARM::ArchKind
ArchKind
Definition: ARMTargetParser.h:96
std
Definition: BitVector.h:851
llvm::ARMTargetStreamer::emitUnwindRaw
virtual void emitUnwindRaw(int64_t StackOffset, const SmallVectorImpl< uint8_t > &Opcodes)
Definition: ARMTargetStreamer.cpp:102
llvm::ARM::EHABI::EXIDX_CANTUNWIND
@ EXIDX_CANTUNWIND
Special entry for the function never unwind.
Definition: ARMEHABI.h:35
llvm::ARMTargetStreamer::emitMovSP
virtual void emitMovSP(unsigned Reg, int64_t Offset=0)
Definition: ARMTargetStreamer.cpp:98
llvm::AArch64CC::LS
@ LS
Definition: AArch64BaseInfo.h:264
Casting.h
llvm::MCELFStreamer::emitSymbolAttribute
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
Definition: MCELFStreamer.cpp:193
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::MCELFStreamer::emitAssemblerFlag
void emitAssemblerFlag(MCAssemblerFlag Flag) override
Note in the output the specified Flag.
Definition: MCELFStreamer.cpp:122
llvm::ARMTargetStreamer::emitAttribute
virtual void emitAttribute(unsigned Attribute, unsigned Value)
Definition: ARMTargetStreamer.cpp:106
llvm::MCAsmInfo::isLittleEndian
bool isLittleEndian() const
True if the target is little endian.
Definition: MCAsmInfo.h:557
llvm::ARMBuildAttrs::CPU_arch
@ CPU_arch
Definition: ARMBuildAttributes.h:39
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:614
llvm::ARMCC::CondCodes
CondCodes
Definition: ARMBaseInfo.h:30
SectionKind.h
ARMBuildAttributes.h
llvm::MCSA_ELF_TypeFunction
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
Definition: MCDirectives.h:23
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
llvm::ARMTargetStreamer::emitFnStart
virtual void emitFnStart()
Definition: ARMTargetStreamer.cpp:90
llvm::ARM::getFPUName
StringRef getFPUName(unsigned FPUKind)
Definition: ARMTargetParser.cpp:246
llvm::MCFixupKind
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:21
llvm::MCObjectStreamer::emitBytes
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
Definition: MCObjectStreamer.cpp:637
llvm::LegalityPredicates::isVector
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
Definition: LegalityPredicates.cpp:73
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:293
SmallVector.h
MCStreamer.h
llvm::ARMBuildAttrs::FP_HP_extension
@ FP_HP_extension
Definition: ARMBuildAttributes.h:67
llvm::tgtok::Bit
@ Bit
Definition: TGLexer.h:50
llvm::ELF::STB_LOCAL
@ STB_LOCAL
Definition: ELF.h:1217
llvm::ELF::SHF_GROUP
@ SHF_GROUP
Definition: ELF.h:1086
llvm::SmallVectorImpl< unsigned >
llvm::ARMBuildAttrs::CPU_name
@ CPU_name
Definition: ARMBuildAttributes.h:38
llvm::omp::RTLDependInfoFields::Flags
@ Flags
llvm::ARMTargetStreamer::finishAttributeSection
virtual void finishAttributeSection()
Definition: ARMTargetStreamer.cpp:116
llvm::ARMBuildAttrs::AllowThumb32
@ AllowThumb32
Definition: ARMBuildAttributes.h:131
InlinePriorityMode::Size
@ Size
llvm::ARMBuildAttrs::AllowFPv3B
@ AllowFPv3B
Definition: ARMBuildAttributes.h:137
llvm::pdb::String
@ String
Definition: PDBTypes.h:408
raw_ostream.h
llvm::ARM::EHABI::NUM_PERSONALITY_INDEX
@ NUM_PERSONALITY_INDEX
Definition: ARMEHABI.h:131
llvm::ARMCondCodeToString
static const char * ARMCondCodeToString(ARMCC::CondCodes CC)
Definition: ARMBaseInfo.h:146
llvm::MCDataFragment
Fragment for data and encoded instructions.
Definition: MCFragment.h:241
llvm::ARMBuildAttrs::AllowTZVirtualization
@ AllowTZVirtualization
Definition: ARMBuildAttributes.h:245
MCExpr.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
llvm::ARMTargetStreamer::emitFPU
virtual void emitFPU(unsigned FPU)
Definition: ARMTargetStreamer.cpp:115
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::MCEncodedFragmentWithContents::getContents
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:196
llvm::ELFAttrs::attrTypeAsString
StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap, bool hasTagPrefix=true)
Definition: ELFAttributes.cpp:14
llvm::ARMTargetStreamer::annotateTLSDescriptorSequence
virtual void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE)
Definition: ARMTargetStreamer.cpp:117