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