LLVM  7.0.0svn
MCDwarf.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCDwarf.cpp - MCDwarf implementation ------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/MC/MCDwarf.h"
11 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/Hashing.h"
14 #include "llvm/ADT/Optional.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Twine.h"
21 #include "llvm/Config/config.h"
22 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCExpr.h"
27 #include "llvm/MC/MCRegisterInfo.h"
28 #include "llvm/MC/MCSection.h"
29 #include "llvm/MC/MCStreamer.h"
30 #include "llvm/MC/MCSymbol.h"
32 #include "llvm/Support/Casting.h"
33 #include "llvm/Support/Endian.h"
36 #include "llvm/Support/LEB128.h"
38 #include "llvm/Support/Path.h"
39 #include "llvm/Support/SourceMgr.h"
41 #include <cassert>
42 #include <cstdint>
43 #include <string>
44 #include <utility>
45 #include <vector>
46 
47 using namespace llvm;
48 
49 /// Manage the .debug_line_str section contents, if we use it.
51  MCSymbol *LineStrLabel = nullptr;
53  bool UseRelocs = false;
54 
55 public:
56  /// Construct an instance that can emit .debug_line_str (for use in a normal
57  /// v5 line table).
58  explicit MCDwarfLineStr(MCContext &Ctx) {
60  if (UseRelocs)
61  LineStrLabel =
63  }
64 
65  /// Emit a reference to the string.
66  void emitRef(MCStreamer *MCOS, StringRef Path);
67 
68  /// Emit the .debug_line_str section if appropriate.
69  void emitSection(MCStreamer *MCOS);
70 };
71 
72 static inline uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta) {
73  unsigned MinInsnLength = Context.getAsmInfo()->getMinInstAlignment();
74  if (MinInsnLength == 1)
75  return AddrDelta;
76  if (AddrDelta % MinInsnLength != 0) {
77  // TODO: report this error, but really only once.
78  ;
79  }
80  return AddrDelta / MinInsnLength;
81 }
82 
83 //
84 // This is called when an instruction is assembled into the specified section
85 // and if there is information from the last .loc directive that has yet to have
86 // a line entry made for it is made.
87 //
89  if (!MCOS->getContext().getDwarfLocSeen())
90  return;
91 
92  // Create a symbol at in the current section for use in the line entry.
93  MCSymbol *LineSym = MCOS->getContext().createTempSymbol();
94  // Set the value of the symbol to use for the MCDwarfLineEntry.
95  MCOS->EmitLabel(LineSym);
96 
97  // Get the current .loc info saved in the context.
98  const MCDwarfLoc &DwarfLoc = MCOS->getContext().getCurrentDwarfLoc();
99 
100  // Create a (local) line entry with the symbol and the current .loc info.
101  MCDwarfLineEntry LineEntry(LineSym, DwarfLoc);
102 
103  // clear DwarfLocSeen saying the current .loc info is now used.
104  MCOS->getContext().clearDwarfLocSeen();
105 
106  // Add the line entry to this section's entries.
107  MCOS->getContext()
109  .getMCLineSections()
110  .addLineEntry(LineEntry, Section);
111 }
112 
113 //
114 // This helper routine returns an expression of End - Start + IntVal .
115 //
116 static inline const MCExpr *MakeStartMinusEndExpr(const MCStreamer &MCOS,
117  const MCSymbol &Start,
118  const MCSymbol &End,
119  int IntVal) {
121  const MCExpr *Res =
122  MCSymbolRefExpr::create(&End, Variant, MCOS.getContext());
123  const MCExpr *RHS =
124  MCSymbolRefExpr::create(&Start, Variant, MCOS.getContext());
125  const MCExpr *Res1 =
127  const MCExpr *Res2 =
128  MCConstantExpr::create(IntVal, MCOS.getContext());
129  const MCExpr *Res3 =
131  return Res3;
132 }
133 
134 //
135 // This helper routine returns an expression of Start + IntVal .
136 //
137 static inline const MCExpr *
138 makeStartPlusIntExpr(MCContext &Ctx, const MCSymbol &Start, int IntVal) {
140  const MCExpr *LHS = MCSymbolRefExpr::create(&Start, Variant, Ctx);
141  const MCExpr *RHS = MCConstantExpr::create(IntVal, Ctx);
142  const MCExpr *Res = MCBinaryExpr::create(MCBinaryExpr::Add, LHS, RHS, Ctx);
143  return Res;
144 }
145 
146 //
147 // This emits the Dwarf line table for the specified section from the entries
148 // in the LineSection.
149 //
150 static inline void
152  const MCLineSection::MCDwarfLineEntryCollection &LineEntries) {
153  unsigned FileNum = 1;
154  unsigned LastLine = 1;
155  unsigned Column = 0;
156  unsigned Flags = DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0;
157  unsigned Isa = 0;
158  unsigned Discriminator = 0;
159  MCSymbol *LastLabel = nullptr;
160 
161  // Loop through each MCDwarfLineEntry and encode the dwarf line number table.
162  for (const MCDwarfLineEntry &LineEntry : LineEntries) {
163  int64_t LineDelta = static_cast<int64_t>(LineEntry.getLine()) - LastLine;
164 
165  if (FileNum != LineEntry.getFileNum()) {
166  FileNum = LineEntry.getFileNum();
167  MCOS->EmitIntValue(dwarf::DW_LNS_set_file, 1);
168  MCOS->EmitULEB128IntValue(FileNum);
169  }
170  if (Column != LineEntry.getColumn()) {
171  Column = LineEntry.getColumn();
172  MCOS->EmitIntValue(dwarf::DW_LNS_set_column, 1);
173  MCOS->EmitULEB128IntValue(Column);
174  }
175  if (Discriminator != LineEntry.getDiscriminator() &&
176  MCOS->getContext().getDwarfVersion() >= 4) {
177  Discriminator = LineEntry.getDiscriminator();
178  unsigned Size = getULEB128Size(Discriminator);
179  MCOS->EmitIntValue(dwarf::DW_LNS_extended_op, 1);
180  MCOS->EmitULEB128IntValue(Size + 1);
181  MCOS->EmitIntValue(dwarf::DW_LNE_set_discriminator, 1);
182  MCOS->EmitULEB128IntValue(Discriminator);
183  }
184  if (Isa != LineEntry.getIsa()) {
185  Isa = LineEntry.getIsa();
186  MCOS->EmitIntValue(dwarf::DW_LNS_set_isa, 1);
187  MCOS->EmitULEB128IntValue(Isa);
188  }
189  if ((LineEntry.getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) {
190  Flags = LineEntry.getFlags();
191  MCOS->EmitIntValue(dwarf::DW_LNS_negate_stmt, 1);
192  }
193  if (LineEntry.getFlags() & DWARF2_FLAG_BASIC_BLOCK)
194  MCOS->EmitIntValue(dwarf::DW_LNS_set_basic_block, 1);
195  if (LineEntry.getFlags() & DWARF2_FLAG_PROLOGUE_END)
196  MCOS->EmitIntValue(dwarf::DW_LNS_set_prologue_end, 1);
197  if (LineEntry.getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN)
198  MCOS->EmitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1);
199 
200  MCSymbol *Label = LineEntry.getLabel();
201 
202  // At this point we want to emit/create the sequence to encode the delta in
203  // line numbers and the increment of the address from the previous Label
204  // and the current Label.
205  const MCAsmInfo *asmInfo = MCOS->getContext().getAsmInfo();
206  MCOS->EmitDwarfAdvanceLineAddr(LineDelta, LastLabel, Label,
207  asmInfo->getCodePointerSize());
208 
209  Discriminator = 0;
210  LastLine = LineEntry.getLine();
211  LastLabel = Label;
212  }
213 
214  // Emit a DW_LNE_end_sequence for the end of the section.
215  // Use the section end label to compute the address delta and use INT64_MAX
216  // as the line delta which is the signal that this is actually a
217  // DW_LNE_end_sequence.
218  MCSymbol *SectionEnd = MCOS->endSection(Section);
219 
220  // Switch back the dwarf line section, in case endSection had to switch the
221  // section.
222  MCContext &Ctx = MCOS->getContext();
224 
225  const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
226  MCOS->EmitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
227  AsmInfo->getCodePointerSize());
228 }
229 
230 //
231 // This emits the Dwarf file and the line tables.
232 //
234  MCDwarfLineTableParams Params) {
235  MCContext &context = MCOS->getContext();
236 
237  auto &LineTables = context.getMCDwarfLineTables();
238 
239  // Bail out early so we don't switch to the debug_line section needlessly and
240  // in doing so create an unnecessary (if empty) section.
241  if (LineTables.empty())
242  return;
243 
244  // In a v5 non-split line table, put the strings in a separate section.
245  Optional<MCDwarfLineStr> LineStr;
246  if (context.getDwarfVersion() >= 5)
247  LineStr = MCDwarfLineStr(context);
248 
249  // Switch to the section where the table will be emitted into.
251 
252  // Handle the rest of the Compile Units.
253  for (const auto &CUIDTablePair : LineTables)
254  CUIDTablePair.second.EmitCU(MCOS, Params, LineStr);
255 
256  if (LineStr)
257  LineStr->emitSection(MCOS);
258 }
259 
261  MCSection *Section) const {
262  if (Header.MCDwarfFiles.empty())
263  return;
264  Optional<MCDwarfLineStr> NoLineStr(None);
265  MCOS.SwitchSection(Section);
266  MCOS.EmitLabel(Header.Emit(&MCOS, Params, None, NoLineStr).second);
267 }
268 
269 std::pair<MCSymbol *, MCSymbol *>
271  Optional<MCDwarfLineStr> &LineStr) const {
272  static const char StandardOpcodeLengths[] = {
273  0, // length of DW_LNS_copy
274  1, // length of DW_LNS_advance_pc
275  1, // length of DW_LNS_advance_line
276  1, // length of DW_LNS_set_file
277  1, // length of DW_LNS_set_column
278  0, // length of DW_LNS_negate_stmt
279  0, // length of DW_LNS_set_basic_block
280  0, // length of DW_LNS_const_add_pc
281  1, // length of DW_LNS_fixed_advance_pc
282  0, // length of DW_LNS_set_prologue_end
283  0, // length of DW_LNS_set_epilogue_begin
284  1 // DW_LNS_set_isa
285  };
286  assert(array_lengthof(StandardOpcodeLengths) >=
287  (Params.DWARF2LineOpcodeBase - 1U));
288  return Emit(
289  MCOS, Params,
290  makeArrayRef(StandardOpcodeLengths, Params.DWARF2LineOpcodeBase - 1),
291  LineStr);
292 }
293 
294 static const MCExpr *forceExpAbs(MCStreamer &OS, const MCExpr* Expr) {
295  MCContext &Context = OS.getContext();
296  assert(!isa<MCSymbolRefExpr>(Expr));
297  if (Context.getAsmInfo()->hasAggressiveSymbolFolding())
298  return Expr;
299 
300  MCSymbol *ABS = Context.createTempSymbol();
301  OS.EmitAssignment(ABS, Expr);
302  return MCSymbolRefExpr::create(ABS, Context);
303 }
304 
305 static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size) {
306  const MCExpr *ABS = forceExpAbs(OS, Value);
307  OS.EmitValue(ABS, Size);
308 }
309 
311  // Switch to the .debug_line_str section.
312  MCOS->SwitchSection(
314  // Emit the strings without perturbing the offsets we used.
315  LineStrings.finalizeInOrder();
317  Data.resize(LineStrings.getSize());
318  LineStrings.write((uint8_t *)Data.data());
319  MCOS->EmitBinaryData(Data.str());
320 }
321 
323  int RefSize = 4; // FIXME: Support DWARF-64
324  size_t Offset = LineStrings.add(Path);
325  if (UseRelocs) {
326  MCContext &Ctx = MCOS->getContext();
327  MCOS->EmitValue(makeStartPlusIntExpr(Ctx, *LineStrLabel, Offset), RefSize);
328  } else
329  MCOS->EmitIntValue(Offset, RefSize);
330 }
331 
332 void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const {
333  // First the directory table.
334  for (auto &Dir : MCDwarfDirs) {
335  MCOS->EmitBytes(Dir); // The DirectoryName, and...
336  MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
337  }
338  MCOS->EmitIntValue(0, 1); // Terminate the directory list.
339 
340  // Second the file table.
341  for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
342  assert(!MCDwarfFiles[i].Name.empty());
343  MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName and...
344  MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
345  MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex); // Directory number.
346  MCOS->EmitIntValue(0, 1); // Last modification timestamp (always 0).
347  MCOS->EmitIntValue(0, 1); // File size (always 0).
348  }
349  MCOS->EmitIntValue(0, 1); // Terminate the file list.
350 }
351 
353  bool EmitMD5, bool HasSource,
354  Optional<MCDwarfLineStr> &LineStr) {
355  assert(!DwarfFile.Name.empty());
356  if (LineStr)
357  LineStr->emitRef(MCOS, DwarfFile.Name);
358  else {
359  MCOS->EmitBytes(DwarfFile.Name); // FileName and...
360  MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
361  }
362  MCOS->EmitULEB128IntValue(DwarfFile.DirIndex); // Directory number.
363  if (EmitMD5) {
364  MD5::MD5Result *Cksum = DwarfFile.Checksum;
365  MCOS->EmitBinaryData(
366  StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()),
367  Cksum->Bytes.size()));
368  }
369  if (HasSource) {
370  if (LineStr)
371  LineStr->emitRef(MCOS, DwarfFile.Source.getValueOr(StringRef()));
372  else {
373  MCOS->EmitBytes(
374  DwarfFile.Source.getValueOr(StringRef())); // Source and...
375  MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
376  }
377  }
378 }
379 
380 void MCDwarfLineTableHeader::emitV5FileDirTables(
381  MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr,
382  StringRef CtxCompilationDir) const {
383  // The directory format, which is just a list of the directory paths. In a
384  // non-split object, these are references to .debug_line_str; in a split
385  // object, they are inline strings.
386  MCOS->EmitIntValue(1, 1);
387  MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_path);
388  MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
389  : dwarf::DW_FORM_string);
390  MCOS->EmitULEB128IntValue(MCDwarfDirs.size() + 1);
391  // Try not to emit an empty compilation directory.
392  const StringRef &CompDir =
393  CompilationDir.empty() ? CtxCompilationDir : CompilationDir;
394  if (LineStr) {
395  // Record path strings, emit references here.
396  LineStr->emitRef(MCOS, CompDir);
397  for (auto &Dir : MCDwarfDirs)
398  LineStr->emitRef(MCOS, Dir);
399  } else {
400  // The list of directory paths. Compilation directory comes first.
401  MCOS->EmitBytes(CompDir);
402  MCOS->EmitBytes(StringRef("\0", 1));
403  for (auto &Dir : MCDwarfDirs) {
404  MCOS->EmitBytes(Dir); // The DirectoryName, and...
405  MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.
406  }
407  }
408 
409  // The file format, which is the inline null-terminated filename and a
410  // directory index. We don't track file size/timestamp so don't emit them
411  // in the v5 table. Emit MD5 checksums and source if we have them.
412  uint64_t Entries = 2;
413  if (HasAllMD5)
414  Entries += 1;
415  if (HasSource)
416  Entries += 1;
417  MCOS->EmitIntValue(Entries, 1);
418  MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_path);
419  MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
420  : dwarf::DW_FORM_string);
421  MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_directory_index);
422  MCOS->EmitULEB128IntValue(dwarf::DW_FORM_udata);
423  if (HasAllMD5) {
424  MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_MD5);
425  MCOS->EmitULEB128IntValue(dwarf::DW_FORM_data16);
426  }
427  if (HasSource) {
428  MCOS->EmitULEB128IntValue(dwarf::DW_LNCT_LLVM_source);
429  MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
430  : dwarf::DW_FORM_string);
431  }
432  // Then the counted list of files. The root file is file #0, then emit the
433  // files as provide by .file directives. To accommodate assembler source
434  // written for DWARF v4 but trying to emit v5, if we didn't see a root file
435  // explicitly, replicate file #1.
436  MCOS->EmitULEB128IntValue(MCDwarfFiles.size());
437  emitOneV5FileEntry(MCOS, RootFile.Name.empty() ? MCDwarfFiles[1] : RootFile,
438  HasAllMD5, HasSource, LineStr);
439  for (unsigned i = 1; i < MCDwarfFiles.size(); ++i)
440  emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasAllMD5, HasSource, LineStr);
441 }
442 
443 std::pair<MCSymbol *, MCSymbol *>
445  ArrayRef<char> StandardOpcodeLengths,
446  Optional<MCDwarfLineStr> &LineStr) const {
447  MCContext &context = MCOS->getContext();
448 
449  // Create a symbol at the beginning of the line table.
450  MCSymbol *LineStartSym = Label;
451  if (!LineStartSym)
452  LineStartSym = context.createTempSymbol();
453  // Set the value of the symbol, as we are at the start of the line table.
454  MCOS->EmitLabel(LineStartSym);
455 
456  // Create a symbol for the end of the section (to be set when we get there).
457  MCSymbol *LineEndSym = context.createTempSymbol();
458 
459  // The first 4 bytes is the total length of the information for this
460  // compilation unit (not including these 4 bytes for the length).
461  emitAbsValue(*MCOS,
462  MakeStartMinusEndExpr(*MCOS, *LineStartSym, *LineEndSym, 4), 4);
463 
464  // Next 2 bytes is the Version.
465  // FIXME: On Darwin we still default to V2.
466  unsigned LineTableVersion = context.getDwarfVersion();
467  if (context.getObjectFileInfo()->getTargetTriple().isOSDarwin())
468  LineTableVersion = 2;
469  MCOS->EmitIntValue(LineTableVersion, 2);
470 
471  // Keep track of the bytes between the very start and where the header length
472  // comes out.
473  unsigned PreHeaderLengthBytes = 4 + 2;
474 
475  // In v5, we get address info next.
476  if (LineTableVersion >= 5) {
477  MCOS->EmitIntValue(context.getAsmInfo()->getCodePointerSize(), 1);
478  MCOS->EmitIntValue(0, 1); // Segment selector; same as EmitGenDwarfAranges.
479  PreHeaderLengthBytes += 2;
480  }
481 
482  // Create a symbol for the end of the prologue (to be set when we get there).
483  MCSymbol *ProEndSym = context.createTempSymbol(); // Lprologue_end
484 
485  // Length of the prologue, is the next 4 bytes. This is actually the length
486  // from after the length word, to the end of the prologue.
487  emitAbsValue(*MCOS,
488  MakeStartMinusEndExpr(*MCOS, *LineStartSym, *ProEndSym,
489  (PreHeaderLengthBytes + 4)),
490  4);
491 
492  // Parameters of the state machine, are next.
493  MCOS->EmitIntValue(context.getAsmInfo()->getMinInstAlignment(), 1);
494  // maximum_operations_per_instruction
495  // For non-VLIW architectures this field is always 1.
496  // FIXME: VLIW architectures need to update this field accordingly.
497  if (LineTableVersion >= 4)
498  MCOS->EmitIntValue(1, 1);
500  MCOS->EmitIntValue(Params.DWARF2LineBase, 1);
501  MCOS->EmitIntValue(Params.DWARF2LineRange, 1);
502  MCOS->EmitIntValue(StandardOpcodeLengths.size() + 1, 1);
503 
504  // Standard opcode lengths
505  for (char Length : StandardOpcodeLengths)
506  MCOS->EmitIntValue(Length, 1);
507 
508  // Put out the directory and file tables. The formats vary depending on
509  // the version.
510  if (LineTableVersion >= 5)
511  emitV5FileDirTables(MCOS, LineStr, context.getCompilationDir());
512  else
513  emitV2FileDirTables(MCOS);
514 
515  // This is the end of the prologue, so set the value of the symbol at the
516  // end of the prologue (that was used in a previous expression).
517  MCOS->EmitLabel(ProEndSym);
518 
519  return std::make_pair(LineStartSym, LineEndSym);
520 }
521 
523  MCDwarfLineTableParams Params,
524  Optional<MCDwarfLineStr> &LineStr) const {
525  MCSymbol *LineEndSym = Header.Emit(MCOS, Params, LineStr).second;
526 
527  // Put out the line tables.
528  for (const auto &LineSec : MCLineSections.getMCLineEntries())
529  EmitDwarfLineTable(MCOS, LineSec.first, LineSec.second);
530 
531  // This is the end of the section, so set the value of the symbol at the end
532  // of this section (that was used in a previous expression).
533  MCOS->EmitLabel(LineEndSym);
534 }
535 
537  StringRef &FileName,
538  MD5::MD5Result *Checksum,
540  unsigned FileNumber) {
541  return Header.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
542 }
543 
546  StringRef &FileName,
547  MD5::MD5Result *Checksum,
549  unsigned FileNumber) {
550  if (Directory == CompilationDir)
551  Directory = "";
552  if (FileName.empty()) {
553  FileName = "<stdin>";
554  Directory = "";
555  }
556  assert(!FileName.empty());
557  // Keep track of whether any or all files have an MD5 checksum.
558  // If any files have embedded source, they all must.
559  if (MCDwarfFiles.empty()) {
560  trackMD5Usage(Checksum);
561  HasSource = (Source != None);
562  }
563  if (FileNumber == 0) {
564  // File numbers start with 1 and/or after any file numbers
565  // allocated by inline-assembler .file directives.
566  FileNumber = MCDwarfFiles.empty() ? 1 : MCDwarfFiles.size();
567  SmallString<256> Buffer;
568  auto IterBool = SourceIdMap.insert(
569  std::make_pair((Directory + Twine('\0') + FileName).toStringRef(Buffer),
570  FileNumber));
571  if (!IterBool.second)
572  return IterBool.first->second;
573  }
574  // Make space for this FileNumber in the MCDwarfFiles vector if needed.
575  if (FileNumber >= MCDwarfFiles.size())
576  MCDwarfFiles.resize(FileNumber + 1);
577 
578  // Get the new MCDwarfFile slot for this FileNumber.
579  MCDwarfFile &File = MCDwarfFiles[FileNumber];
580 
581  // It is an error to see the same number more than once.
582  if (!File.Name.empty())
583  return make_error<StringError>("file number already allocated",
585 
586  // If any files have embedded source, they all must.
587  if (HasSource != (Source != None))
588  return make_error<StringError>("inconsistent use of embedded source",
590 
591  if (Directory.empty()) {
592  // Separate the directory part from the basename of the FileName.
593  StringRef tFileName = sys::path::filename(FileName);
594  if (!tFileName.empty()) {
595  Directory = sys::path::parent_path(FileName);
596  if (!Directory.empty())
597  FileName = tFileName;
598  }
599  }
600 
601  // Find or make an entry in the MCDwarfDirs vector for this Directory.
602  // Capture directory name.
603  unsigned DirIndex;
604  if (Directory.empty()) {
605  // For FileNames with no directories a DirIndex of 0 is used.
606  DirIndex = 0;
607  } else {
608  DirIndex = 0;
609  for (unsigned End = MCDwarfDirs.size(); DirIndex < End; DirIndex++) {
610  if (Directory == MCDwarfDirs[DirIndex])
611  break;
612  }
613  if (DirIndex >= MCDwarfDirs.size())
614  MCDwarfDirs.push_back(Directory);
615  // The DirIndex is one based, as DirIndex of 0 is used for FileNames with
616  // no directories. MCDwarfDirs[] is unlike MCDwarfFiles[] in that the
617  // directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
618  // are stored at MCDwarfFiles[FileNumber].Name .
619  DirIndex++;
620  }
621 
622  File.Name = FileName;
623  File.DirIndex = DirIndex;
624  File.Checksum = Checksum;
625  trackMD5Usage(Checksum);
626  File.Source = Source;
627  if (Source)
628  HasSource = true;
629 
630  // return the allocated FileNumber.
631  return FileNumber;
632 }
633 
634 /// Utility function to emit the encoding to a streamer.
636  int64_t LineDelta, uint64_t AddrDelta) {
637  MCContext &Context = MCOS->getContext();
638  SmallString<256> Tmp;
639  raw_svector_ostream OS(Tmp);
640  MCDwarfLineAddr::Encode(Context, Params, LineDelta, AddrDelta, OS);
641  MCOS->EmitBytes(OS.str());
642 }
643 
644 /// Given a special op, return the address skip amount (in units of
645 /// DWARF2_LINE_MIN_INSN_LENGTH).
646 static uint64_t SpecialAddr(MCDwarfLineTableParams Params, uint64_t op) {
647  return (op - Params.DWARF2LineOpcodeBase) / Params.DWARF2LineRange;
648 }
649 
650 /// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
652  int64_t LineDelta, uint64_t AddrDelta,
653  raw_ostream &OS) {
654  uint64_t Temp, Opcode;
655  bool NeedCopy = false;
656 
657  // The maximum address skip amount that can be encoded with a special op.
658  uint64_t MaxSpecialAddrDelta = SpecialAddr(Params, 255);
659 
660  // Scale the address delta by the minimum instruction length.
661  AddrDelta = ScaleAddrDelta(Context, AddrDelta);
662 
663  // A LineDelta of INT64_MAX is a signal that this is actually a
664  // DW_LNE_end_sequence. We cannot use special opcodes here, since we want the
665  // end_sequence to emit the matrix entry.
666  if (LineDelta == INT64_MAX) {
667  if (AddrDelta == MaxSpecialAddrDelta)
668  OS << char(dwarf::DW_LNS_const_add_pc);
669  else if (AddrDelta) {
670  OS << char(dwarf::DW_LNS_advance_pc);
671  encodeULEB128(AddrDelta, OS);
672  }
673  OS << char(dwarf::DW_LNS_extended_op);
674  OS << char(1);
675  OS << char(dwarf::DW_LNE_end_sequence);
676  return;
677  }
678 
679  // Bias the line delta by the base.
680  Temp = LineDelta - Params.DWARF2LineBase;
681 
682  // If the line increment is out of range of a special opcode, we must encode
683  // it with DW_LNS_advance_line.
684  if (Temp >= Params.DWARF2LineRange ||
685  Temp + Params.DWARF2LineOpcodeBase > 255) {
686  OS << char(dwarf::DW_LNS_advance_line);
687  encodeSLEB128(LineDelta, OS);
688 
689  LineDelta = 0;
690  Temp = 0 - Params.DWARF2LineBase;
691  NeedCopy = true;
692  }
693 
694  // Use DW_LNS_copy instead of a "line +0, addr +0" special opcode.
695  if (LineDelta == 0 && AddrDelta == 0) {
696  OS << char(dwarf::DW_LNS_copy);
697  return;
698  }
699 
700  // Bias the opcode by the special opcode base.
701  Temp += Params.DWARF2LineOpcodeBase;
702 
703  // Avoid overflow when addr_delta is large.
704  if (AddrDelta < 256 + MaxSpecialAddrDelta) {
705  // Try using a special opcode.
706  Opcode = Temp + AddrDelta * Params.DWARF2LineRange;
707  if (Opcode <= 255) {
708  OS << char(Opcode);
709  return;
710  }
711 
712  // Try using DW_LNS_const_add_pc followed by special op.
713  Opcode = Temp + (AddrDelta - MaxSpecialAddrDelta) * Params.DWARF2LineRange;
714  if (Opcode <= 255) {
715  OS << char(dwarf::DW_LNS_const_add_pc);
716  OS << char(Opcode);
717  return;
718  }
719  }
720 
721  // Otherwise use DW_LNS_advance_pc.
722  OS << char(dwarf::DW_LNS_advance_pc);
723  encodeULEB128(AddrDelta, OS);
724 
725  if (NeedCopy)
726  OS << char(dwarf::DW_LNS_copy);
727  else {
728  assert(Temp <= 255 && "Buggy special opcode encoding.");
729  OS << char(Temp);
730  }
731 }
732 
733 // Utility function to write a tuple for .debug_abbrev.
734 static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form) {
735  MCOS->EmitULEB128IntValue(Name);
736  MCOS->EmitULEB128IntValue(Form);
737 }
738 
739 // When generating dwarf for assembly source files this emits
740 // the data for .debug_abbrev section which contains three DIEs.
741 static void EmitGenDwarfAbbrev(MCStreamer *MCOS) {
742  MCContext &context = MCOS->getContext();
744 
745  // DW_TAG_compile_unit DIE abbrev (1).
746  MCOS->EmitULEB128IntValue(1);
747  MCOS->EmitULEB128IntValue(dwarf::DW_TAG_compile_unit);
749  EmitAbbrev(MCOS, dwarf::DW_AT_stmt_list, context.getDwarfVersion() >= 4
750  ? dwarf::DW_FORM_sec_offset
751  : dwarf::DW_FORM_data4);
752  if (context.getGenDwarfSectionSyms().size() > 1 &&
753  context.getDwarfVersion() >= 3) {
754  EmitAbbrev(MCOS, dwarf::DW_AT_ranges, context.getDwarfVersion() >= 4
755  ? dwarf::DW_FORM_sec_offset
756  : dwarf::DW_FORM_data4);
757  } else {
758  EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
759  EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr);
760  }
761  EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
762  if (!context.getCompilationDir().empty())
763  EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
764  StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
765  if (!DwarfDebugFlags.empty())
766  EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string);
767  EmitAbbrev(MCOS, dwarf::DW_AT_producer, dwarf::DW_FORM_string);
768  EmitAbbrev(MCOS, dwarf::DW_AT_language, dwarf::DW_FORM_data2);
769  EmitAbbrev(MCOS, 0, 0);
770 
771  // DW_TAG_label DIE abbrev (2).
772  MCOS->EmitULEB128IntValue(2);
773  MCOS->EmitULEB128IntValue(dwarf::DW_TAG_label);
775  EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
776  EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4);
777  EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4);
778  EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
779  EmitAbbrev(MCOS, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag);
780  EmitAbbrev(MCOS, 0, 0);
781 
782  // DW_TAG_unspecified_parameters DIE abbrev (3).
783  MCOS->EmitULEB128IntValue(3);
784  MCOS->EmitULEB128IntValue(dwarf::DW_TAG_unspecified_parameters);
786  EmitAbbrev(MCOS, 0, 0);
787 
788  // Terminate the abbreviations for this compilation unit.
789  MCOS->EmitIntValue(0, 1);
790 }
791 
792 // When generating dwarf for assembly source files this emits the data for
793 // .debug_aranges section. This section contains a header and a table of pairs
794 // of PointerSize'ed values for the address and size of section(s) with line
795 // table entries.
796 static void EmitGenDwarfAranges(MCStreamer *MCOS,
797  const MCSymbol *InfoSectionSymbol) {
798  MCContext &context = MCOS->getContext();
799 
800  auto &Sections = context.getGenDwarfSectionSyms();
801 
803 
804  // This will be the length of the .debug_aranges section, first account for
805  // the size of each item in the header (see below where we emit these items).
806  int Length = 4 + 2 + 4 + 1 + 1;
807 
808  // Figure the padding after the header before the table of address and size
809  // pairs who's values are PointerSize'ed.
810  const MCAsmInfo *asmInfo = context.getAsmInfo();
811  int AddrSize = asmInfo->getCodePointerSize();
812  int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1));
813  if (Pad == 2 * AddrSize)
814  Pad = 0;
815  Length += Pad;
816 
817  // Add the size of the pair of PointerSize'ed values for the address and size
818  // of each section we have in the table.
819  Length += 2 * AddrSize * Sections.size();
820  // And the pair of terminating zeros.
821  Length += 2 * AddrSize;
822 
823  // Emit the header for this section.
824  // The 4 byte length not including the 4 byte value for the length.
825  MCOS->EmitIntValue(Length - 4, 4);
826  // The 2 byte version, which is 2.
827  MCOS->EmitIntValue(2, 2);
828  // The 4 byte offset to the compile unit in the .debug_info from the start
829  // of the .debug_info.
830  if (InfoSectionSymbol)
831  MCOS->EmitSymbolValue(InfoSectionSymbol, 4,
833  else
834  MCOS->EmitIntValue(0, 4);
835  // The 1 byte size of an address.
836  MCOS->EmitIntValue(AddrSize, 1);
837  // The 1 byte size of a segment descriptor, we use a value of zero.
838  MCOS->EmitIntValue(0, 1);
839  // Align the header with the padding if needed, before we put out the table.
840  for(int i = 0; i < Pad; i++)
841  MCOS->EmitIntValue(0, 1);
842 
843  // Now emit the table of pairs of PointerSize'ed values for the section
844  // addresses and sizes.
845  for (MCSection *Sec : Sections) {
846  const MCSymbol *StartSymbol = Sec->getBeginSymbol();
847  MCSymbol *EndSymbol = Sec->getEndSymbol(context);
848  assert(StartSymbol && "StartSymbol must not be NULL");
849  assert(EndSymbol && "EndSymbol must not be NULL");
850 
851  const MCExpr *Addr = MCSymbolRefExpr::create(
852  StartSymbol, MCSymbolRefExpr::VK_None, context);
853  const MCExpr *Size = MakeStartMinusEndExpr(*MCOS,
854  *StartSymbol, *EndSymbol, 0);
855  MCOS->EmitValue(Addr, AddrSize);
856  emitAbsValue(*MCOS, Size, AddrSize);
857  }
858 
859  // And finally the pair of terminating zeros.
860  MCOS->EmitIntValue(0, AddrSize);
861  MCOS->EmitIntValue(0, AddrSize);
862 }
863 
864 // When generating dwarf for assembly source files this emits the data for
865 // .debug_info section which contains three parts. The header, the compile_unit
866 // DIE and a list of label DIEs.
867 static void EmitGenDwarfInfo(MCStreamer *MCOS,
868  const MCSymbol *AbbrevSectionSymbol,
869  const MCSymbol *LineSectionSymbol,
870  const MCSymbol *RangesSectionSymbol) {
871  MCContext &context = MCOS->getContext();
872 
874 
875  // Create a symbol at the start and end of this section used in here for the
876  // expression to calculate the length in the header.
877  MCSymbol *InfoStart = context.createTempSymbol();
878  MCOS->EmitLabel(InfoStart);
879  MCSymbol *InfoEnd = context.createTempSymbol();
880 
881  // First part: the header.
882 
883  // The 4 byte total length of the information for this compilation unit, not
884  // including these 4 bytes.
885  const MCExpr *Length = MakeStartMinusEndExpr(*MCOS, *InfoStart, *InfoEnd, 4);
886  emitAbsValue(*MCOS, Length, 4);
887 
888  // The 2 byte DWARF version.
889  MCOS->EmitIntValue(context.getDwarfVersion(), 2);
890 
891  // The DWARF v5 header has unit type, address size, abbrev offset.
892  // Earlier versions have abbrev offset, address size.
893  const MCAsmInfo &AsmInfo = *context.getAsmInfo();
894  int AddrSize = AsmInfo.getCodePointerSize();
895  if (context.getDwarfVersion() >= 5) {
896  MCOS->EmitIntValue(dwarf::DW_UT_compile, 1);
897  MCOS->EmitIntValue(AddrSize, 1);
898  }
899  // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev,
900  // it is at the start of that section so this is zero.
901  if (AbbrevSectionSymbol == nullptr)
902  MCOS->EmitIntValue(0, 4);
903  else
904  MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4,
906  if (context.getDwarfVersion() <= 4)
907  MCOS->EmitIntValue(AddrSize, 1);
908 
909  // Second part: the compile_unit DIE.
910 
911  // The DW_TAG_compile_unit DIE abbrev (1).
912  MCOS->EmitULEB128IntValue(1);
913 
914  // DW_AT_stmt_list, a 4 byte offset from the start of the .debug_line section,
915  // which is at the start of that section so this is zero.
916  if (LineSectionSymbol)
917  MCOS->EmitSymbolValue(LineSectionSymbol, 4,
919  else
920  MCOS->EmitIntValue(0, 4);
921 
922  if (RangesSectionSymbol) {
923  // There are multiple sections containing code, so we must use the
924  // .debug_ranges sections.
925 
926  // AT_ranges, the 4 byte offset from the start of the .debug_ranges section
927  // to the address range list for this compilation unit.
928  MCOS->EmitSymbolValue(RangesSectionSymbol, 4);
929  } else {
930  // If we only have one non-empty code section, we can use the simpler
931  // AT_low_pc and AT_high_pc attributes.
932 
933  // Find the first (and only) non-empty text section
934  auto &Sections = context.getGenDwarfSectionSyms();
935  const auto TextSection = Sections.begin();
936  assert(TextSection != Sections.end() && "No text section found");
937 
938  MCSymbol *StartSymbol = (*TextSection)->getBeginSymbol();
939  MCSymbol *EndSymbol = (*TextSection)->getEndSymbol(context);
940  assert(StartSymbol && "StartSymbol must not be NULL");
941  assert(EndSymbol && "EndSymbol must not be NULL");
942 
943  // AT_low_pc, the first address of the default .text section.
944  const MCExpr *Start = MCSymbolRefExpr::create(
945  StartSymbol, MCSymbolRefExpr::VK_None, context);
946  MCOS->EmitValue(Start, AddrSize);
947 
948  // AT_high_pc, the last address of the default .text section.
950  EndSymbol, MCSymbolRefExpr::VK_None, context);
951  MCOS->EmitValue(End, AddrSize);
952  }
953 
954  // AT_name, the name of the source file. Reconstruct from the first directory
955  // and file table entries.
956  const SmallVectorImpl<std::string> &MCDwarfDirs = context.getMCDwarfDirs();
957  if (MCDwarfDirs.size() > 0) {
958  MCOS->EmitBytes(MCDwarfDirs[0]);
960  }
961  const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles =
962  MCOS->getContext().getMCDwarfFiles();
963  MCOS->EmitBytes(MCDwarfFiles[1].Name);
964  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
965 
966  // AT_comp_dir, the working directory the assembly was done in.
967  if (!context.getCompilationDir().empty()) {
968  MCOS->EmitBytes(context.getCompilationDir());
969  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
970  }
971 
972  // AT_APPLE_flags, the command line arguments of the assembler tool.
973  StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
974  if (!DwarfDebugFlags.empty()){
975  MCOS->EmitBytes(DwarfDebugFlags);
976  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
977  }
978 
979  // AT_producer, the version of the assembler tool.
980  StringRef DwarfDebugProducer = context.getDwarfDebugProducer();
981  if (!DwarfDebugProducer.empty())
982  MCOS->EmitBytes(DwarfDebugProducer);
983  else
984  MCOS->EmitBytes(StringRef("llvm-mc (based on LLVM " PACKAGE_VERSION ")"));
985  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
986 
987  // AT_language, a 4 byte value. We use DW_LANG_Mips_Assembler as the dwarf2
988  // draft has no standard code for assembler.
989  MCOS->EmitIntValue(dwarf::DW_LANG_Mips_Assembler, 2);
990 
991  // Third part: the list of label DIEs.
992 
993  // Loop on saved info for dwarf labels and create the DIEs for them.
994  const std::vector<MCGenDwarfLabelEntry> &Entries =
996  for (const auto &Entry : Entries) {
997  // The DW_TAG_label DIE abbrev (2).
998  MCOS->EmitULEB128IntValue(2);
999 
1000  // AT_name, of the label without any leading underbar.
1001  MCOS->EmitBytes(Entry.getName());
1002  MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
1003 
1004  // AT_decl_file, index into the file table.
1005  MCOS->EmitIntValue(Entry.getFileNumber(), 4);
1006 
1007  // AT_decl_line, source line number.
1008  MCOS->EmitIntValue(Entry.getLineNumber(), 4);
1009 
1010  // AT_low_pc, start address of the label.
1011  const MCExpr *AT_low_pc = MCSymbolRefExpr::create(Entry.getLabel(),
1012  MCSymbolRefExpr::VK_None, context);
1013  MCOS->EmitValue(AT_low_pc, AddrSize);
1014 
1015  // DW_AT_prototyped, a one byte flag value of 0 saying we have no prototype.
1016  MCOS->EmitIntValue(0, 1);
1017 
1018  // The DW_TAG_unspecified_parameters DIE abbrev (3).
1019  MCOS->EmitULEB128IntValue(3);
1020 
1021  // Add the NULL DIE terminating the DW_TAG_unspecified_parameters DIE's.
1022  MCOS->EmitIntValue(0, 1);
1023  }
1024 
1025  // Add the NULL DIE terminating the Compile Unit DIE's.
1026  MCOS->EmitIntValue(0, 1);
1027 
1028  // Now set the value of the symbol at the end of the info section.
1029  MCOS->EmitLabel(InfoEnd);
1030 }
1031 
1032 // When generating dwarf for assembly source files this emits the data for
1033 // .debug_ranges section. We only emit one range list, which spans all of the
1034 // executable sections of this file.
1035 static void EmitGenDwarfRanges(MCStreamer *MCOS) {
1036  MCContext &context = MCOS->getContext();
1037  auto &Sections = context.getGenDwarfSectionSyms();
1038 
1039  const MCAsmInfo *AsmInfo = context.getAsmInfo();
1040  int AddrSize = AsmInfo->getCodePointerSize();
1041 
1043 
1044  for (MCSection *Sec : Sections) {
1045  const MCSymbol *StartSymbol = Sec->getBeginSymbol();
1046  MCSymbol *EndSymbol = Sec->getEndSymbol(context);
1047  assert(StartSymbol && "StartSymbol must not be NULL");
1048  assert(EndSymbol && "EndSymbol must not be NULL");
1049 
1050  // Emit a base address selection entry for the start of this section
1051  const MCExpr *SectionStartAddr = MCSymbolRefExpr::create(
1052  StartSymbol, MCSymbolRefExpr::VK_None, context);
1053  MCOS->emitFill(AddrSize, 0xFF);
1054  MCOS->EmitValue(SectionStartAddr, AddrSize);
1055 
1056  // Emit a range list entry spanning this section
1057  const MCExpr *SectionSize = MakeStartMinusEndExpr(*MCOS,
1058  *StartSymbol, *EndSymbol, 0);
1059  MCOS->EmitIntValue(0, AddrSize);
1060  emitAbsValue(*MCOS, SectionSize, AddrSize);
1061  }
1062 
1063  // Emit end of list entry
1064  MCOS->EmitIntValue(0, AddrSize);
1065  MCOS->EmitIntValue(0, AddrSize);
1066 }
1067 
1068 //
1069 // When generating dwarf for assembly source files this emits the Dwarf
1070 // sections.
1071 //
1073  MCContext &context = MCOS->getContext();
1074 
1075  // Create the dwarf sections in this order (.debug_line already created).
1076  const MCAsmInfo *AsmInfo = context.getAsmInfo();
1077  bool CreateDwarfSectionSymbols =
1079  MCSymbol *LineSectionSymbol = nullptr;
1080  if (CreateDwarfSectionSymbols)
1081  LineSectionSymbol = MCOS->getDwarfLineTableSymbol(0);
1082  MCSymbol *AbbrevSectionSymbol = nullptr;
1083  MCSymbol *InfoSectionSymbol = nullptr;
1084  MCSymbol *RangesSectionSymbol = nullptr;
1085 
1086  // Create end symbols for each section, and remove empty sections
1087  MCOS->getContext().finalizeDwarfSections(*MCOS);
1088 
1089  // If there are no sections to generate debug info for, we don't need
1090  // to do anything
1091  if (MCOS->getContext().getGenDwarfSectionSyms().empty())
1092  return;
1093 
1094  // We only use the .debug_ranges section if we have multiple code sections,
1095  // and we are emitting a DWARF version which supports it.
1096  const bool UseRangesSection =
1097  MCOS->getContext().getGenDwarfSectionSyms().size() > 1 &&
1098  MCOS->getContext().getDwarfVersion() >= 3;
1099  CreateDwarfSectionSymbols |= UseRangesSection;
1100 
1102  if (CreateDwarfSectionSymbols) {
1103  InfoSectionSymbol = context.createTempSymbol();
1104  MCOS->EmitLabel(InfoSectionSymbol);
1105  }
1107  if (CreateDwarfSectionSymbols) {
1108  AbbrevSectionSymbol = context.createTempSymbol();
1109  MCOS->EmitLabel(AbbrevSectionSymbol);
1110  }
1111  if (UseRangesSection) {
1113  if (CreateDwarfSectionSymbols) {
1114  RangesSectionSymbol = context.createTempSymbol();
1115  MCOS->EmitLabel(RangesSectionSymbol);
1116  }
1117  }
1118 
1119  assert((RangesSectionSymbol != nullptr) || !UseRangesSection);
1120 
1122 
1123  // Output the data for .debug_aranges section.
1124  EmitGenDwarfAranges(MCOS, InfoSectionSymbol);
1125 
1126  if (UseRangesSection)
1127  EmitGenDwarfRanges(MCOS);
1128 
1129  // Output the data for .debug_abbrev section.
1130  EmitGenDwarfAbbrev(MCOS);
1131 
1132  // Output the data for .debug_info section.
1133  EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol,
1134  RangesSectionSymbol);
1135 }
1136 
1137 //
1138 // When generating dwarf for assembly source files this is called when symbol
1139 // for a label is created. If this symbol is not a temporary and is in the
1140 // section that dwarf is being generated for, save the needed info to create
1141 // a dwarf label.
1142 //
1144  SourceMgr &SrcMgr, SMLoc &Loc) {
1145  // We won't create dwarf labels for temporary symbols.
1146  if (Symbol->isTemporary())
1147  return;
1148  MCContext &context = MCOS->getContext();
1149  // We won't create dwarf labels for symbols in sections that we are not
1150  // generating debug info for.
1151  if (!context.getGenDwarfSectionSyms().count(MCOS->getCurrentSectionOnly()))
1152  return;
1153 
1154  // The dwarf label's name does not have the symbol name's leading
1155  // underbar if any.
1156  StringRef Name = Symbol->getName();
1157  if (Name.startswith("_"))
1158  Name = Name.substr(1, Name.size()-1);
1159 
1160  // Get the dwarf file number to be used for the dwarf label.
1161  unsigned FileNumber = context.getGenDwarfFileNumber();
1162 
1163  // Finding the line number is the expensive part which is why we just don't
1164  // pass it in as for some symbols we won't create a dwarf label.
1165  unsigned CurBuffer = SrcMgr.FindBufferContainingLoc(Loc);
1166  unsigned LineNumber = SrcMgr.FindLineNumber(Loc, CurBuffer);
1167 
1168  // We create a temporary symbol for use for the AT_high_pc and AT_low_pc
1169  // values so that they don't have things like an ARM thumb bit from the
1170  // original symbol. So when used they won't get a low bit set after
1171  // relocation.
1172  MCSymbol *Label = context.createTempSymbol();
1173  MCOS->EmitLabel(Label);
1174 
1175  // Create and entry for the info and add it to the other entries.
1177  MCGenDwarfLabelEntry(Name, FileNumber, LineNumber, Label));
1178 }
1179 
1180 static int getDataAlignmentFactor(MCStreamer &streamer) {
1181  MCContext &context = streamer.getContext();
1182  const MCAsmInfo *asmInfo = context.getAsmInfo();
1183  int size = asmInfo->getCalleeSaveStackSlotSize();
1184  if (asmInfo->isStackGrowthDirectionUp())
1185  return size;
1186  else
1187  return -size;
1188 }
1189 
1190 static unsigned getSizeForEncoding(MCStreamer &streamer,
1191  unsigned symbolEncoding) {
1192  MCContext &context = streamer.getContext();
1193  unsigned format = symbolEncoding & 0x0f;
1194  switch (format) {
1195  default: llvm_unreachable("Unknown Encoding");
1198  return context.getAsmInfo()->getCodePointerSize();
1201  return 2;
1204  return 4;
1207  return 8;
1208  }
1209 }
1210 
1211 static void emitFDESymbol(MCObjectStreamer &streamer, const MCSymbol &symbol,
1212  unsigned symbolEncoding, bool isEH) {
1213  MCContext &context = streamer.getContext();
1214  const MCAsmInfo *asmInfo = context.getAsmInfo();
1215  const MCExpr *v = asmInfo->getExprForFDESymbol(&symbol,
1216  symbolEncoding,
1217  streamer);
1218  unsigned size = getSizeForEncoding(streamer, symbolEncoding);
1219  if (asmInfo->doDwarfFDESymbolsUseAbsDiff() && isEH)
1220  emitAbsValue(streamer, v, size);
1221  else
1222  streamer.EmitValue(v, size);
1223 }
1224 
1225 static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol,
1226  unsigned symbolEncoding) {
1227  MCContext &context = streamer.getContext();
1228  const MCAsmInfo *asmInfo = context.getAsmInfo();
1229  const MCExpr *v = asmInfo->getExprForPersonalitySymbol(&symbol,
1230  symbolEncoding,
1231  streamer);
1232  unsigned size = getSizeForEncoding(streamer, symbolEncoding);
1233  streamer.EmitValue(v, size);
1234 }
1235 
1236 namespace {
1237 
1238 class FrameEmitterImpl {
1239  int CFAOffset = 0;
1240  int InitialCFAOffset = 0;
1241  bool IsEH;
1242  MCObjectStreamer &Streamer;
1243 
1244 public:
1245  FrameEmitterImpl(bool IsEH, MCObjectStreamer &Streamer)
1246  : IsEH(IsEH), Streamer(Streamer) {}
1247 
1248  /// Emit the unwind information in a compact way.
1249  void EmitCompactUnwind(const MCDwarfFrameInfo &frame);
1250 
1251  const MCSymbol &EmitCIE(const MCDwarfFrameInfo &F);
1252  void EmitFDE(const MCSymbol &cieStart, const MCDwarfFrameInfo &frame,
1253  bool LastInSection, const MCSymbol &SectionStart);
1254  void EmitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
1255  MCSymbol *BaseLabel);
1256  void EmitCFIInstruction(const MCCFIInstruction &Instr);
1257 };
1258 
1259 } // end anonymous namespace
1260 
1261 static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding) {
1262  Streamer.EmitIntValue(Encoding, 1);
1263 }
1264 
1265 void FrameEmitterImpl::EmitCFIInstruction(const MCCFIInstruction &Instr) {
1266  int dataAlignmentFactor = getDataAlignmentFactor(Streamer);
1267  auto *MRI = Streamer.getContext().getRegisterInfo();
1268 
1269  switch (Instr.getOperation()) {
1271  unsigned Reg1 = Instr.getRegister();
1272  unsigned Reg2 = Instr.getRegister2();
1273  if (!IsEH) {
1274  Reg1 = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg1);
1275  Reg2 = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg2);
1276  }
1277  Streamer.EmitIntValue(dwarf::DW_CFA_register, 1);
1278  Streamer.EmitULEB128IntValue(Reg1);
1279  Streamer.EmitULEB128IntValue(Reg2);
1280  return;
1281  }
1283  Streamer.EmitIntValue(dwarf::DW_CFA_GNU_window_save, 1);
1284  return;
1285 
1287  unsigned Reg = Instr.getRegister();
1288  Streamer.EmitIntValue(dwarf::DW_CFA_undefined, 1);
1289  Streamer.EmitULEB128IntValue(Reg);
1290  return;
1291  }
1294  const bool IsRelative =
1296 
1297  Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_offset, 1);
1298 
1299  if (IsRelative)
1300  CFAOffset += Instr.getOffset();
1301  else
1302  CFAOffset = -Instr.getOffset();
1303 
1304  Streamer.EmitULEB128IntValue(CFAOffset);
1305 
1306  return;
1307  }
1309  unsigned Reg = Instr.getRegister();
1310  if (!IsEH)
1311  Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1312  Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa, 1);
1313  Streamer.EmitULEB128IntValue(Reg);
1314  CFAOffset = -Instr.getOffset();
1315  Streamer.EmitULEB128IntValue(CFAOffset);
1316 
1317  return;
1318  }
1320  unsigned Reg = Instr.getRegister();
1321  if (!IsEH)
1322  Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1323  Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_register, 1);
1324  Streamer.EmitULEB128IntValue(Reg);
1325 
1326  return;
1327  }
1330  const bool IsRelative =
1332 
1333  unsigned Reg = Instr.getRegister();
1334  if (!IsEH)
1335  Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1336 
1337  int Offset = Instr.getOffset();
1338  if (IsRelative)
1339  Offset -= CFAOffset;
1340  Offset = Offset / dataAlignmentFactor;
1341 
1342  if (Offset < 0) {
1343  Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended_sf, 1);
1344  Streamer.EmitULEB128IntValue(Reg);
1345  Streamer.EmitSLEB128IntValue(Offset);
1346  } else if (Reg < 64) {
1347  Streamer.EmitIntValue(dwarf::DW_CFA_offset + Reg, 1);
1348  Streamer.EmitULEB128IntValue(Offset);
1349  } else {
1350  Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended, 1);
1351  Streamer.EmitULEB128IntValue(Reg);
1352  Streamer.EmitULEB128IntValue(Offset);
1353  }
1354  return;
1355  }
1357  Streamer.EmitIntValue(dwarf::DW_CFA_remember_state, 1);
1358  return;
1360  Streamer.EmitIntValue(dwarf::DW_CFA_restore_state, 1);
1361  return;
1363  unsigned Reg = Instr.getRegister();
1364  Streamer.EmitIntValue(dwarf::DW_CFA_same_value, 1);
1365  Streamer.EmitULEB128IntValue(Reg);
1366  return;
1367  }
1369  unsigned Reg = Instr.getRegister();
1370  if (!IsEH)
1371  Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1372  Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
1373  return;
1374  }
1376  Streamer.EmitIntValue(dwarf::DW_CFA_GNU_args_size, 1);
1377  Streamer.EmitULEB128IntValue(Instr.getOffset());
1378  return;
1379 
1381  Streamer.EmitBytes(Instr.getValues());
1382  return;
1383  }
1384  llvm_unreachable("Unhandled case in switch");
1385 }
1386 
1387 /// Emit frame instructions to describe the layout of the frame.
1388 void FrameEmitterImpl::EmitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
1389  MCSymbol *BaseLabel) {
1390  for (const MCCFIInstruction &Instr : Instrs) {
1391  MCSymbol *Label = Instr.getLabel();
1392  // Throw out move if the label is invalid.
1393  if (Label && !Label->isDefined()) continue; // Not emitted, in dead code.
1394 
1395  // Advance row if new location.
1396  if (BaseLabel && Label) {
1397  MCSymbol *ThisSym = Label;
1398  if (ThisSym != BaseLabel) {
1399  Streamer.EmitDwarfAdvanceFrameAddr(BaseLabel, ThisSym);
1400  BaseLabel = ThisSym;
1401  }
1402  }
1403 
1404  EmitCFIInstruction(Instr);
1405  }
1406 }
1407 
1408 /// Emit the unwind information in a compact way.
1409 void FrameEmitterImpl::EmitCompactUnwind(const MCDwarfFrameInfo &Frame) {
1410  MCContext &Context = Streamer.getContext();
1411  const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
1412 
1413  // range-start range-length compact-unwind-enc personality-func lsda
1414  // _foo LfooEnd-_foo 0x00000023 0 0
1415  // _bar LbarEnd-_bar 0x00000025 __gxx_personality except_tab1
1416  //
1417  // .section __LD,__compact_unwind,regular,debug
1418  //
1419  // # compact unwind for _foo
1420  // .quad _foo
1421  // .set L1,LfooEnd-_foo
1422  // .long L1
1423  // .long 0x01010001
1424  // .quad 0
1425  // .quad 0
1426  //
1427  // # compact unwind for _bar
1428  // .quad _bar
1429  // .set L2,LbarEnd-_bar
1430  // .long L2
1431  // .long 0x01020011
1432  // .quad __gxx_personality
1433  // .quad except_tab1
1434 
1435  uint32_t Encoding = Frame.CompactUnwindEncoding;
1436  if (!Encoding) return;
1437  bool DwarfEHFrameOnly = (Encoding == MOFI->getCompactUnwindDwarfEHFrameOnly());
1438 
1439  // The encoding needs to know we have an LSDA.
1440  if (!DwarfEHFrameOnly && Frame.Lsda)
1441  Encoding |= 0x40000000;
1442 
1443  // Range Start
1444  unsigned FDEEncoding = MOFI->getFDEEncoding();
1445  unsigned Size = getSizeForEncoding(Streamer, FDEEncoding);
1446  Streamer.EmitSymbolValue(Frame.Begin, Size);
1447 
1448  // Range Length
1449  const MCExpr *Range = MakeStartMinusEndExpr(Streamer, *Frame.Begin,
1450  *Frame.End, 0);
1451  emitAbsValue(Streamer, Range, 4);
1452 
1453  // Compact Encoding
1454  Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_udata4);
1455  Streamer.EmitIntValue(Encoding, Size);
1456 
1457  // Personality Function
1458  Size = getSizeForEncoding(Streamer, dwarf::DW_EH_PE_absptr);
1459  if (!DwarfEHFrameOnly && Frame.Personality)
1460  Streamer.EmitSymbolValue(Frame.Personality, Size);
1461  else
1462  Streamer.EmitIntValue(0, Size); // No personality fn
1463 
1464  // LSDA
1465  Size = getSizeForEncoding(Streamer, Frame.LsdaEncoding);
1466  if (!DwarfEHFrameOnly && Frame.Lsda)
1467  Streamer.EmitSymbolValue(Frame.Lsda, Size);
1468  else
1469  Streamer.EmitIntValue(0, Size); // No LSDA
1470 }
1471 
1472 static unsigned getCIEVersion(bool IsEH, unsigned DwarfVersion) {
1473  if (IsEH)
1474  return 1;
1475  switch (DwarfVersion) {
1476  case 2:
1477  return 1;
1478  case 3:
1479  return 3;
1480  case 4:
1481  case 5:
1482  return 4;
1483  }
1484  llvm_unreachable("Unknown version");
1485 }
1486 
1487 const MCSymbol &FrameEmitterImpl::EmitCIE(const MCDwarfFrameInfo &Frame) {
1488  MCContext &context = Streamer.getContext();
1489  const MCRegisterInfo *MRI = context.getRegisterInfo();
1490  const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
1491 
1492  MCSymbol *sectionStart = context.createTempSymbol();
1493  Streamer.EmitLabel(sectionStart);
1494 
1495  MCSymbol *sectionEnd = context.createTempSymbol();
1496 
1497  // Length
1498  const MCExpr *Length =
1499  MakeStartMinusEndExpr(Streamer, *sectionStart, *sectionEnd, 4);
1500  emitAbsValue(Streamer, Length, 4);
1501 
1502  // CIE ID
1503  unsigned CIE_ID = IsEH ? 0 : -1;
1504  Streamer.EmitIntValue(CIE_ID, 4);
1505 
1506  // Version
1507  uint8_t CIEVersion = getCIEVersion(IsEH, context.getDwarfVersion());
1508  Streamer.EmitIntValue(CIEVersion, 1);
1509 
1510  // Augmentation String
1511  SmallString<8> Augmentation;
1512  if (IsEH) {
1513  Augmentation += "z";
1514  if (Frame.Personality)
1515  Augmentation += "P";
1516  if (Frame.Lsda)
1517  Augmentation += "L";
1518  Augmentation += "R";
1519  if (Frame.IsSignalFrame)
1520  Augmentation += "S";
1521  Streamer.EmitBytes(Augmentation);
1522  }
1523  Streamer.EmitIntValue(0, 1);
1524 
1525  if (CIEVersion >= 4) {
1526  // Address Size
1527  Streamer.EmitIntValue(context.getAsmInfo()->getCodePointerSize(), 1);
1528 
1529  // Segment Descriptor Size
1530  Streamer.EmitIntValue(0, 1);
1531  }
1532 
1533  // Code Alignment Factor
1534  Streamer.EmitULEB128IntValue(context.getAsmInfo()->getMinInstAlignment());
1535 
1536  // Data Alignment Factor
1537  Streamer.EmitSLEB128IntValue(getDataAlignmentFactor(Streamer));
1538 
1539  // Return Address Register
1540  unsigned RAReg = Frame.RAReg;
1541  if (RAReg == static_cast<unsigned>(INT_MAX))
1542  RAReg = MRI->getDwarfRegNum(MRI->getRARegister(), IsEH);
1543 
1544  if (CIEVersion == 1) {
1545  assert(RAReg <= 255 &&
1546  "DWARF 2 encodes return_address_register in one byte");
1547  Streamer.EmitIntValue(RAReg, 1);
1548  } else {
1549  Streamer.EmitULEB128IntValue(RAReg);
1550  }
1551 
1552  // Augmentation Data Length (optional)
1553  unsigned augmentationLength = 0;
1554  if (IsEH) {
1555  if (Frame.Personality) {
1556  // Personality Encoding
1557  augmentationLength += 1;
1558  // Personality
1559  augmentationLength +=
1560  getSizeForEncoding(Streamer, Frame.PersonalityEncoding);
1561  }
1562  if (Frame.Lsda)
1563  augmentationLength += 1;
1564  // Encoding of the FDE pointers
1565  augmentationLength += 1;
1566 
1567  Streamer.EmitULEB128IntValue(augmentationLength);
1568 
1569  // Augmentation Data (optional)
1570  if (Frame.Personality) {
1571  // Personality Encoding
1572  emitEncodingByte(Streamer, Frame.PersonalityEncoding);
1573  // Personality
1574  EmitPersonality(Streamer, *Frame.Personality, Frame.PersonalityEncoding);
1575  }
1576 
1577  if (Frame.Lsda)
1578  emitEncodingByte(Streamer, Frame.LsdaEncoding);
1579 
1580  // Encoding of the FDE pointers
1581  emitEncodingByte(Streamer, MOFI->getFDEEncoding());
1582  }
1583 
1584  // Initial Instructions
1585 
1586  const MCAsmInfo *MAI = context.getAsmInfo();
1587  if (!Frame.IsSimple) {
1588  const std::vector<MCCFIInstruction> &Instructions =
1589  MAI->getInitialFrameState();
1590  EmitCFIInstructions(Instructions, nullptr);
1591  }
1592 
1593  InitialCFAOffset = CFAOffset;
1594 
1595  // Padding
1596  Streamer.EmitValueToAlignment(IsEH ? 4 : MAI->getCodePointerSize());
1597 
1598  Streamer.EmitLabel(sectionEnd);
1599  return *sectionStart;
1600 }
1601 
1602 void FrameEmitterImpl::EmitFDE(const MCSymbol &cieStart,
1603  const MCDwarfFrameInfo &frame,
1604  bool LastInSection,
1605  const MCSymbol &SectionStart) {
1606  MCContext &context = Streamer.getContext();
1607  MCSymbol *fdeStart = context.createTempSymbol();
1608  MCSymbol *fdeEnd = context.createTempSymbol();
1609  const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
1610 
1611  CFAOffset = InitialCFAOffset;
1612 
1613  // Length
1614  const MCExpr *Length = MakeStartMinusEndExpr(Streamer, *fdeStart, *fdeEnd, 0);
1615  emitAbsValue(Streamer, Length, 4);
1616 
1617  Streamer.EmitLabel(fdeStart);
1618 
1619  // CIE Pointer
1620  const MCAsmInfo *asmInfo = context.getAsmInfo();
1621  if (IsEH) {
1622  const MCExpr *offset =
1623  MakeStartMinusEndExpr(Streamer, cieStart, *fdeStart, 0);
1624  emitAbsValue(Streamer, offset, 4);
1625  } else if (!asmInfo->doesDwarfUseRelocationsAcrossSections()) {
1626  const MCExpr *offset =
1627  MakeStartMinusEndExpr(Streamer, SectionStart, cieStart, 0);
1628  emitAbsValue(Streamer, offset, 4);
1629  } else {
1630  Streamer.EmitSymbolValue(&cieStart, 4);
1631  }
1632 
1633  // PC Begin
1634  unsigned PCEncoding =
1636  unsigned PCSize = getSizeForEncoding(Streamer, PCEncoding);
1637  emitFDESymbol(Streamer, *frame.Begin, PCEncoding, IsEH);
1638 
1639  // PC Range
1640  const MCExpr *Range =
1641  MakeStartMinusEndExpr(Streamer, *frame.Begin, *frame.End, 0);
1642  emitAbsValue(Streamer, Range, PCSize);
1643 
1644  if (IsEH) {
1645  // Augmentation Data Length
1646  unsigned augmentationLength = 0;
1647 
1648  if (frame.Lsda)
1649  augmentationLength += getSizeForEncoding(Streamer, frame.LsdaEncoding);
1650 
1651  Streamer.EmitULEB128IntValue(augmentationLength);
1652 
1653  // Augmentation Data
1654  if (frame.Lsda)
1655  emitFDESymbol(Streamer, *frame.Lsda, frame.LsdaEncoding, true);
1656  }
1657 
1658  // Call Frame Instructions
1659  EmitCFIInstructions(frame.Instructions, frame.Begin);
1660 
1661  // Padding
1662  // The size of a .eh_frame section has to be a multiple of the alignment
1663  // since a null CIE is interpreted as the end. Old systems overaligned
1664  // .eh_frame, so we do too and account for it in the last FDE.
1665  unsigned Align = LastInSection ? asmInfo->getCodePointerSize() : PCSize;
1666  Streamer.EmitValueToAlignment(Align);
1667 
1668  Streamer.EmitLabel(fdeEnd);
1669 }
1670 
1671 namespace {
1672 
1673 struct CIEKey {
1674  static const CIEKey getEmptyKey() {
1675  return CIEKey(nullptr, 0, -1, false, false, static_cast<unsigned>(INT_MAX));
1676  }
1677 
1678  static const CIEKey getTombstoneKey() {
1679  return CIEKey(nullptr, -1, 0, false, false, static_cast<unsigned>(INT_MAX));
1680  }
1681 
1682  CIEKey(const MCSymbol *Personality, unsigned PersonalityEncoding,
1683  unsigned LSDAEncoding, bool IsSignalFrame, bool IsSimple,
1684  unsigned RAReg)
1685  : Personality(Personality), PersonalityEncoding(PersonalityEncoding),
1686  LsdaEncoding(LSDAEncoding), IsSignalFrame(IsSignalFrame),
1687  IsSimple(IsSimple), RAReg(RAReg) {}
1688 
1689  explicit CIEKey(const MCDwarfFrameInfo &Frame)
1690  : Personality(Frame.Personality),
1691  PersonalityEncoding(Frame.PersonalityEncoding),
1692  LsdaEncoding(Frame.LsdaEncoding), IsSignalFrame(Frame.IsSignalFrame),
1693  IsSimple(Frame.IsSimple), RAReg(Frame.RAReg) {}
1694 
1695  const MCSymbol *Personality;
1696  unsigned PersonalityEncoding;
1697  unsigned LsdaEncoding;
1698  bool IsSignalFrame;
1699  bool IsSimple;
1700  unsigned RAReg;
1701 };
1702 
1703 } // end anonymous namespace
1704 
1705 namespace llvm {
1706 
1707 template <> struct DenseMapInfo<CIEKey> {
1708  static CIEKey getEmptyKey() { return CIEKey::getEmptyKey(); }
1709  static CIEKey getTombstoneKey() { return CIEKey::getTombstoneKey(); }
1710 
1711  static unsigned getHashValue(const CIEKey &Key) {
1712  return static_cast<unsigned>(
1713  hash_combine(Key.Personality, Key.PersonalityEncoding, Key.LsdaEncoding,
1714  Key.IsSignalFrame, Key.IsSimple, Key.RAReg));
1715  }
1716 
1717  static bool isEqual(const CIEKey &LHS, const CIEKey &RHS) {
1718  return LHS.Personality == RHS.Personality &&
1719  LHS.PersonalityEncoding == RHS.PersonalityEncoding &&
1720  LHS.LsdaEncoding == RHS.LsdaEncoding &&
1721  LHS.IsSignalFrame == RHS.IsSignalFrame &&
1722  LHS.IsSimple == RHS.IsSimple &&
1723  LHS.RAReg == RHS.RAReg;
1724  }
1725 };
1726 
1727 } // end namespace llvm
1728 
1730  bool IsEH) {
1731  Streamer.generateCompactUnwindEncodings(MAB);
1732 
1733  MCContext &Context = Streamer.getContext();
1734  const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
1735  const MCAsmInfo *AsmInfo = Context.getAsmInfo();
1736  FrameEmitterImpl Emitter(IsEH, Streamer);
1737  ArrayRef<MCDwarfFrameInfo> FrameArray = Streamer.getDwarfFrameInfos();
1738 
1739  // Emit the compact unwind info if available.
1740  bool NeedsEHFrameSection = !MOFI->getSupportsCompactUnwindWithoutEHFrame();
1741  if (IsEH && MOFI->getCompactUnwindSection()) {
1742  bool SectionEmitted = false;
1743  for (const MCDwarfFrameInfo &Frame : FrameArray) {
1744  if (Frame.CompactUnwindEncoding == 0) continue;
1745  if (!SectionEmitted) {
1746  Streamer.SwitchSection(MOFI->getCompactUnwindSection());
1747  Streamer.EmitValueToAlignment(AsmInfo->getCodePointerSize());
1748  SectionEmitted = true;
1749  }
1750  NeedsEHFrameSection |=
1751  Frame.CompactUnwindEncoding ==
1753  Emitter.EmitCompactUnwind(Frame);
1754  }
1755  }
1756 
1757  if (!NeedsEHFrameSection) return;
1758 
1759  MCSection &Section =
1760  IsEH ? *const_cast<MCObjectFileInfo *>(MOFI)->getEHFrameSection()
1761  : *MOFI->getDwarfFrameSection();
1762 
1763  Streamer.SwitchSection(&Section);
1764  MCSymbol *SectionStart = Context.createTempSymbol();
1765  Streamer.EmitLabel(SectionStart);
1766 
1768 
1769  const MCSymbol *DummyDebugKey = nullptr;
1770  bool CanOmitDwarf = MOFI->getOmitDwarfIfHaveCompactUnwind();
1771  for (auto I = FrameArray.begin(), E = FrameArray.end(); I != E;) {
1772  const MCDwarfFrameInfo &Frame = *I;
1773  ++I;
1774  if (CanOmitDwarf && Frame.CompactUnwindEncoding !=
1776  // Don't generate an EH frame if we don't need one. I.e., it's taken care
1777  // of by the compact unwind encoding.
1778  continue;
1779 
1780  CIEKey Key(Frame);
1781  const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey;
1782  if (!CIEStart)
1783  CIEStart = &Emitter.EmitCIE(Frame);
1784 
1785  Emitter.EmitFDE(*CIEStart, Frame, I == E, *SectionStart);
1786  }
1787 }
1788 
1790  uint64_t AddrDelta) {
1791  MCContext &Context = Streamer.getContext();
1792  SmallString<256> Tmp;
1793  raw_svector_ostream OS(Tmp);
1794  MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OS);
1795  Streamer.EmitBytes(OS.str());
1796 }
1797 
1799  uint64_t AddrDelta,
1800  raw_ostream &OS) {
1801  // Scale the address delta by the minimum instruction length.
1802  AddrDelta = ScaleAddrDelta(Context, AddrDelta);
1803 
1806  if (AddrDelta == 0) {
1807  } else if (isUIntN(6, AddrDelta)) {
1808  uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
1809  OS << Opcode;
1810  } else if (isUInt<8>(AddrDelta)) {
1811  OS << uint8_t(dwarf::DW_CFA_advance_loc1);
1812  OS << uint8_t(AddrDelta);
1813  } else if (isUInt<16>(AddrDelta)) {
1814  OS << uint8_t(dwarf::DW_CFA_advance_loc2);
1815  support::endian::write<uint16_t>(OS, AddrDelta, E);
1816  } else {
1817  assert(isUInt<32>(AddrDelta));
1818  OS << uint8_t(dwarf::DW_CFA_advance_loc4);
1819  support::endian::write<uint32_t>(OS, AddrDelta, E);
1820  }
1821 }
static const MCExpr * forceExpAbs(MCStreamer &OS, const MCExpr *Expr)
Definition: MCDwarf.cpp:294
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:290
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E)
Definition: MCContext.h:601
constexpr bool isUInt< 32 >(uint64_t x)
Definition: MathExtras.h:341
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:468
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static int getDataAlignmentFactor(MCStreamer &streamer)
Definition: MCDwarf.cpp:1180
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
Definition: SourceMgr.cpp:61
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
LLVMContext & Context
static CIEKey getTombstoneKey()
Definition: MCDwarf.cpp:1709
#define DWARF2_FLAG_PROLOGUE_END
Definition: MCDwarf.h:82
static void Make(MCObjectStreamer *MCOS, MCSection *Section)
Definition: MCDwarf.cpp:88
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:321
Optional< StringRef > Source
The source code of the file.
Definition: MCDwarf.h:63
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
Definition: MCStreamer.cpp:147
MCSection * getDwarfLineSection() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
iterator begin() const
Definition: ArrayRef.h:137
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:137
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles(unsigned CUID=0)
Definition: MCContext.h:523
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
SourceMgr SrcMgr
Definition: Error.cpp:23
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:954
unsigned Reg
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
bool needsDwarfSectionOffsetDirective() const
Definition: MCAsmInfo.h:458
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1789
MCSection * getDwarfLineStrSection() const
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:504
F(f)
MCSection * getDwarfARangesSection() const
MCDwarfLineStr(MCContext &Ctx)
Construct an instance that can emit .debug_line_str (for use in a normal v5 line table).
Definition: MCDwarf.cpp:58
uint16_t getDwarfVersion() const
Definition: MCContext.h:617
#define op(i)
static void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
Definition: MCDwarf.cpp:635
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
Definition: MCStreamer.cpp:221
bool getSupportsCompactUnwindWithoutEHFrame() const
static void EmitGenDwarfInfo(MCStreamer *MCOS, const MCSymbol *AbbrevSectionSymbol, const MCSymbol *LineSectionSymbol, const MCSymbol *RangesSectionSymbol)
Definition: MCDwarf.cpp:867
unsigned LsdaEncoding
Definition: MCDwarf.h:581
StringRef getDwarfDebugFlags()
Definition: MCContext.h:606
std::vector< MCDwarfLineEntry > MCDwarfLineEntryCollection
Definition: MCDwarf.h:182
static void Encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Definition: MCDwarf.cpp:651
void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize)
std::vector< MCCFIInstruction > Instructions
Definition: MCDwarf.h:578
const std::vector< MCGenDwarfLabelEntry > & getMCGenDwarfLabelEntries() const
Definition: MCContext.h:597
MCContext & getContext() const
Definition: MCStreamer.h:250
#define DWARF2_FLAG_IS_STMT
Definition: MCDwarf.h:80
StringRef getDwarfDebugProducer()
Definition: MCContext.h:609
std::string Name
Definition: MCDwarf.h:52
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:79
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth...
Definition: ISDOpcodes.h:369
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionStartEndSyms, to avoid generating useless debug info for them...
Definition: MCContext.cpp:568
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
#define INT64_MAX
Definition: DataTypes.h:77
MCSymbol * Begin
Definition: MCDwarf.h:574
uint8_t DWARF2LineRange
Range of line offsets in a special line info. opcode.
Definition: MCDwarf.h:208
const MCSymbol * Lsda
Definition: MCDwarf.h:577
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
unsigned getCompactUnwindDwarfEHFrameOnly() const
static void emitFDESymbol(MCObjectStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding, bool isEH)
Definition: MCDwarf.cpp:1211
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:513
MCSection * getDwarfFrameSection() const
const SmallVectorImpl< std::string > & getMCDwarfDirs(unsigned CUID=0)
Definition: MCContext.h:527
bool hasAggressiveSymbolFolding() const
Definition: MCAsmInfo.h:517
bool getOmitDwarfIfHaveCompactUnwind() const
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:849
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:267
Context object for machine code objects.
Definition: MCContext.h:63
Key
PAL metadata keys.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
static void EmitGenDwarfAbbrev(MCStreamer *MCOS)
Definition: MCDwarf.cpp:741
void write(raw_ostream &OS) const
Utility for building string tables with deduplicated suffixes.
unsigned getDwarfCompileUnitID()
Definition: MCContext.h:538
size_t add(CachedHashStringRef S)
Add a string to the builder.
const std::map< unsigned, MCDwarfLineTable > & getMCDwarfLineTables() const
Definition: MCContext.h:509
Streaming object file generation interface.
bool doesDwarfUseRelocationsAcrossSections() const
Definition: MCAsmInfo.h:579
Instances of this class represent the information from a dwarf .loc directive.
Definition: MCDwarf.h:68
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
MCSection * getCompactUnwindSection() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
virtual void EmitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
Definition: MCStreamer.cpp:955
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:598
unsigned getGenDwarfFileNumber()
Definition: MCContext.h:581
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:112
MCSymbol * getLabel() const
Definition: MCDwarf.h:543
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:143
MCSection * getDwarfAbbrevSection() const
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:153
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
static uint64_t SpecialAddr(MCDwarfLineTableParams Params, uint64_t op)
Given a special op, return the address skip amount (in units of DWARF2_LINE_MIN_INSN_LENGTH).
Definition: MCDwarf.cpp:646
static unsigned getSizeForEncoding(MCStreamer &streamer, unsigned symbolEncoding)
Definition: MCDwarf.cpp:1190
Streaming machine code generation interface.
Definition: MCStreamer.h:183
static unsigned getCIEVersion(bool IsEH, unsigned DwarfVersion)
Definition: MCDwarf.cpp:1472
static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form)
Definition: MCDwarf.cpp:734
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:217
uint8_t DWARF2LineOpcodeBase
First special line opcode - leave room for the standard opcodes.
Definition: MCDwarf.h:203
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
constexpr bool isUInt< 8 >(uint64_t x)
Definition: MathExtras.h:335
unsigned const MachineRegisterInfo * MRI
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
unsigned getRegister2() const
Definition: MCDwarf.h:553
void finalizeInOrder()
Finalize the string table without reording it.
#define DWARF2_FLAG_EPILOGUE_BEGIN
Definition: MCDwarf.h:83
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:976
static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size)
Definition: MCDwarf.cpp:305
unsigned getFDEEncoding() const
static void EmitDwarfLineTable(MCObjectStreamer *MCOS, MCSection *Section, const MCLineSection::MCDwarfLineEntryCollection &LineEntries)
Definition: MCDwarf.cpp:151
int getOffset() const
Definition: MCDwarf.h:558
static void EmitGenDwarfAranges(MCStreamer *MCOS, const MCSymbol *InfoSectionSymbol)
Definition: MCDwarf.cpp:796
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Definition: MCSymbol.h:220
OpType getOperation() const
Definition: MCDwarf.h:542
static const unsigned End
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:294
#define DWARF2_FLAG_BASIC_BLOCK
Definition: MCDwarf.h:81
bool doDwarfFDESymbolsUseAbsDiff() const
Definition: MCAsmInfo.h:583
const MCDwarfLoc & getCurrentDwarfLoc()
Definition: MCContext.h:577
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
Definition: Path.cpp:482
unsigned PersonalityEncoding
Definition: MCDwarf.h:580
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile, bool EmitMD5, bool HasSource, Optional< MCDwarfLineStr > &LineStr)
Definition: MCDwarf.cpp:352
StringRef getValues() const
Definition: MCDwarf.h:565
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
Definition: StringExtras.h:53
int8_t DWARF2LineBase
Minimum line offset in a special line info.
Definition: MCDwarf.h:206
StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
Definition: Path.cpp:617
void generateCompactUnwindEncodings(MCAsmBackend *MAB)
Definition: MCStreamer.cpp:104
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void clearDwarfLocSeen()
Definition: MCContext.h:574
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition: LEB128.cpp:20
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
Definition: MCContext.h:488
unsigned getRegister() const
Definition: MCDwarf.h:545
const SetVector< MCSection * > & getGenDwarfSectionSyms()
Definition: MCContext.h:587
const std::vector< MCCFIInstruction > & getInitialFrameState() const
Definition: MCAsmInfo.h:594
void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params, MCSection *Section) const
Definition: MCDwarf.cpp:260
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1032
static unsigned getHashValue(const CIEKey &Key)
Definition: MCDwarf.cpp:1711
void EmitCU(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params, Optional< MCDwarfLineStr > &LineStr) const
Definition: MCDwarf.cpp:522
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:81
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned FileNumber=0)
Definition: MCDwarf.cpp:536
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition: LEB128.h:24
unsigned getMinInstAlignment() const
Definition: MCAsmInfo.h:467
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLExtras.h:787
static bool isEqual(const CIEKey &LHS, const CIEKey &RHS)
Definition: MCDwarf.cpp:1717
iterator end() const
Definition: ArrayRef.h:138
MCSymbol * getBeginSymbol()
Definition: MCSection.h:106
const Triple & getTargetTriple() const
StringRef str()
Return a StringRef for the vector contents.
Definition: raw_ostream.h:529
static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, raw_ostream &OS)
Definition: MCDwarf.cpp:1798
MCSection * getDwarfInfoSection() const
uint32_t CompactUnwindEncoding
Definition: MCDwarf.h:582
static void EmitGenDwarfRanges(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1035
bool getDwarfLocSeen()
Definition: MCContext.h:576
This file contains constants used for implementing Dwarf debug support.
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:248
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:337
static CIEKey getEmptyKey()
Definition: MCDwarf.cpp:1708
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:602
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1072
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:479
#define DWARF2_LINE_DEFAULT_IS_STMT
Definition: MCDwarf.h:78
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
Definition: SourceMgr.h:177
bool isStackGrowthDirectionUp() const
True if target stack grow up.
Definition: MCAsmInfo.h:399
static uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta)
Definition: MCDwarf.cpp:72
Instances of this class represent the line information for the dwarf line table entries.
Definition: MCDwarf.h:151
static void Emit(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params)
Definition: MCDwarf.cpp:233
static const MCExpr * MakeStartMinusEndExpr(const MCStreamer &MCOS, const MCSymbol &Start, const MCSymbol &End, int IntVal)
Definition: MCDwarf.cpp:116
pointer data()
Return a pointer to the vector&#39;s buffer, even if empty().
Definition: SmallVector.h:144
static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding)
Definition: MCDwarf.cpp:1225
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:581
static void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
Definition: MCDwarf.cpp:1143
const MCSymbol * Personality
Definition: MCDwarf.h:576
#define I(x, y, z)
Definition: MD5.cpp:58
static const MCExpr * makeStartPlusIntExpr(MCContext &Ctx, const MCSymbol &Start, int IntVal)
Definition: MCDwarf.cpp:138
unsigned getCalleeSaveStackSlotSize() const
Get the callee-saved register stack slot size in bytes.
Definition: MCAsmInfo.h:391
bool isLittleEndian() const
True if the target is little endian.
Definition: MCAsmInfo.h:396
Manage the .debug_line_str section contents, if we use it.
Definition: MCDwarf.cpp:50
constexpr bool isUInt< 16 >(uint64_t x)
Definition: MathExtras.h:338
void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
Definition: MCStreamer.cpp:184
MD5::MD5Result * Checksum
The MD5 checksum, if there is one.
Definition: MCDwarf.h:59
unsigned getRARegister() const
This method should return the register where the return address can be found.
MCSymbol * endSection(MCSection *Section)
Definition: MCStreamer.cpp:990
unsigned DirIndex
Definition: MCDwarf.h:55
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:387
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void emitRef(MCStreamer *MCOS, StringRef Path)
Emit a reference to the string.
Definition: MCDwarf.cpp:322
std::array< uint8_t, 16 > Bytes
Definition: MD5.h:56
const MCRegisterInfo * getRegisterInfo() const
Definition: MCContext.h:292
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
ArrayRef< MCDwarfFrameInfo > getDwarfFrameInfos() const
Definition: MCStreamer.h:262
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:322
static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding)
Definition: MCDwarf.cpp:1261
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
Subtraction.
Definition: MCExpr.h:439
void emitSection(MCStreamer *MCOS)
Emit the .debug_line_str section if appropriate.
Definition: MCDwarf.cpp:310
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1729
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Instances of this class represent the name of the dwarf .file directive and its associated dwarf file...
Definition: MCDwarf.h:50
MCSection * getDwarfRangesSection() const
void EmitULEB128IntValue(uint64_t Value)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:127
Represents a location in source code.
Definition: SMLoc.h:24
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, MD5::MD5Result *Checksum, Optional< StringRef > &Source, unsigned FileNumber=0)
Definition: MCDwarf.cpp:545
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:385
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:164
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition: MCAsmInfo.cpp:86
std::pair< MCSymbol *, MCSymbol * > Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, Optional< MCDwarfLineStr > &LineStr) const
Definition: MCDwarf.cpp:270
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:73
void resize(size_type N)
Definition: SmallVector.h:352