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