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