LLVM 24.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/STLExtras.h"
14#include "llvm/ADT/StringRef.h"
15#include "llvm/ADT/Twine.h"
17#include "llvm/Config/config.h"
18#include "llvm/MC/MCAsmInfo.h"
19#include "llvm/MC/MCContext.h"
20#include "llvm/MC/MCExpr.h"
24#include "llvm/MC/MCSection.h"
25#include "llvm/MC/MCStreamer.h"
26#include "llvm/MC/MCSymbol.h"
30#include "llvm/Support/LEB128.h"
32#include "llvm/Support/Path.h"
35#include <cassert>
36#include <cstdint>
37#include <optional>
38#include <string>
39#include <utility>
40#include <vector>
41
42using namespace llvm;
43
45 MCSymbol *Start = S.getContext().createTempSymbol("debug_list_header_start");
46 MCSymbol *End = S.getContext().createTempSymbol("debug_list_header_end");
47 auto DwarfFormat = S.getContext().getDwarfFormat();
48 if (DwarfFormat == dwarf::DWARF64) {
49 S.AddComment("DWARF64 mark");
51 }
52 S.AddComment("Length");
55 S.emitLabel(Start);
56 S.AddComment("Version");
58 S.AddComment("Address size");
60 S.AddComment("Segment selector size");
61 S.emitInt8(0);
62 return End;
63}
64
65static inline uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta) {
66 unsigned MinInsnLength = Context.getAsmInfo().getMinInstAlignment();
67 if (MinInsnLength == 1)
68 return AddrDelta;
69 if (AddrDelta % MinInsnLength != 0) {
70 // TODO: report this error, but really only once.
71 ;
72 }
73 return AddrDelta / MinInsnLength;
74}
75
77 UseRelocs = Ctx.getAsmInfo().doesDwarfUseRelocationsAcrossSections();
78 if (UseRelocs) {
79 MCSection *DwarfLineStrSection =
80 Ctx.getObjectFileInfo()->getDwarfLineStrSection();
81 assert(DwarfLineStrSection && "DwarfLineStrSection must not be NULL");
82 LineStrLabel = DwarfLineStrSection->getBeginSymbol();
83 }
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 LineEntry.Subsection = MCOS->getCurrentSection().second;
106
107 // clear DwarfLocSeen saying the current .loc info is now used.
109
110 // Add the line entry to this section's entries.
111 MCOS->getContext()
114 .addLineEntry(LineEntry, Section);
115}
116
117//
118// This helper routine returns an expression of End - Start - IntVal .
119//
120static inline const MCExpr *makeEndMinusStartExpr(MCContext &Ctx,
121 const MCSymbol &Start,
122 const MCSymbol &End,
123 int IntVal) {
124 const MCExpr *Res = MCSymbolRefExpr::create(&End, Ctx);
125 const MCExpr *RHS = MCSymbolRefExpr::create(&Start, 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
133 auto *Sec = &EndLabel->getSection();
134 // The line table may be empty, which we should skip adding an end entry.
135 // There are three cases:
136 // (1) MCAsmStreamer - emitDwarfLocDirective emits a location directive in
137 // place instead of adding a line entry.
138 // (2) MCObjectStreamer - if a function has incomplete debug info where
139 // instructions don't have DILocations, the line entries are missing.
140 // (3) It's also possible that there are no prior line entries if the section
141 // itself is empty before this end label.
142 auto I = MCLineDivisions.find(Sec);
143 if (I == MCLineDivisions.end()) // If section not found, do nothing.
144 return;
145
146 auto &Entries = I->second;
147 // If no entries in this section's list, nothing to base the end entry on.
148 if (Entries.empty())
149 return;
150
151 // Create the end entry based on the last existing entry.
152 MCDwarfLineEntry EndEntry = Entries.back();
153
154 // An end entry is just for marking the end of a sequence of code locations.
155 // It should not carry forward a LineStreamLabel from a previous special entry
156 // if Entries.back() happened to be such an entry. So here we clear
157 // LineStreamLabel.
158 EndEntry.LineStreamLabel = nullptr;
159 EndEntry.setEndLabel(EndLabel);
160 // EndEntry is cloned from the last entry, which may be in a higher-numbered
161 // subsection, e.g. from a .loc in inline asm. EndLabel is a CU range end
162 // label, which the code generator emits in subsection 0.
163 EndEntry.Subsection = 0;
164 Entries.push_back(EndEntry);
165}
166
167//
168// This emits the Dwarf line table for the specified section from the entries
169// in the LineSection.
170//
172 MCStreamer *MCOS, MCSection *Section,
174 // Entries are recorded in emission order, but subsections are laid out after
175 // subsection 0 in increasing order of their numbers. Emit the entries in
176 // layout order so that addresses only increase within a sequence. Sort a
177 // copy only if needed.
178 auto BySubsection = [](const MCDwarfLineEntry &A, const MCDwarfLineEntry &B) {
179 return A.Subsection < B.Subsection;
180 };
181 ArrayRef<MCDwarfLineEntry> LineEntries = Entries;
183 if (!llvm::is_sorted(Entries, BySubsection)) {
184 Sorted = Entries;
185 llvm::stable_sort(Sorted, BySubsection);
186 LineEntries = Sorted;
187 }
188
189 unsigned FileNum, LastLine, Column, Flags, Isa, Discriminator;
190 bool IsAtStartSeq;
191 MCSymbol *PrevLabel;
192 auto init = [&]() {
193 FileNum = 1;
194 LastLine = 1;
195 Column = 0;
197 Isa = 0;
198 Discriminator = 0;
199 PrevLabel = nullptr;
200 IsAtStartSeq = true;
201 };
202 init();
203
204 // Loop through each MCDwarfLineEntry and encode the dwarf line number table.
205 for (auto It = LineEntries.begin(); It != LineEntries.end(); ++It) {
206 auto LineEntry = *It;
207 MCSymbol *CurrLabel = LineEntry.getLabel();
208 const MCAsmInfo &asmInfo = MCOS->getContext().getAsmInfo();
209
210 if (LineEntry.LineStreamLabel) {
211 if (!IsAtStartSeq) {
212 auto *Label = CurrLabel;
213 auto NextIt = It + 1;
214 // LineEntry with a null Label is probably a fake LineEntry we added
215 // when `-emit-func-debug-line-table-offsets` in order to terminate the
216 // sequence. Look for the next Label if possible, otherwise we will set
217 // the PC to the end of the section.
218 if (!Label && NextIt != LineEntries.end()) {
219 Label = NextIt->getLabel();
220 }
221 MCOS->emitDwarfLineEndEntry(Section, PrevLabel,
222 /*EndLabel =*/Label);
223 init();
224 }
225 MCOS->emitLabel(LineEntry.LineStreamLabel, LineEntry.StreamLabelDefLoc);
226 continue;
227 }
228
229 if (LineEntry.IsEndEntry) {
230 MCOS->emitDwarfAdvanceLineAddr(INT64_MAX, PrevLabel, CurrLabel,
231 asmInfo.getCodePointerSize());
232 init();
233 continue;
234 }
235
236 int64_t LineDelta = static_cast<int64_t>(LineEntry.getLine()) - LastLine;
237
238 if (FileNum != LineEntry.getFileNum()) {
239 FileNum = LineEntry.getFileNum();
240 MCOS->emitInt8(dwarf::DW_LNS_set_file);
241 MCOS->emitULEB128IntValue(FileNum);
242 }
243 if (Column != LineEntry.getColumn()) {
244 Column = LineEntry.getColumn();
245 MCOS->emitInt8(dwarf::DW_LNS_set_column);
246 MCOS->emitULEB128IntValue(Column);
247 }
248 if (Discriminator != LineEntry.getDiscriminator() &&
249 MCOS->getContext().getDwarfVersion() >= 4) {
250 Discriminator = LineEntry.getDiscriminator();
251 unsigned Size = getULEB128Size(Discriminator);
252 MCOS->emitInt8(dwarf::DW_LNS_extended_op);
253 MCOS->emitULEB128IntValue(Size + 1);
254 MCOS->emitInt8(dwarf::DW_LNE_set_discriminator);
255 MCOS->emitULEB128IntValue(Discriminator);
256 }
257 if (Isa != LineEntry.getIsa()) {
258 Isa = LineEntry.getIsa();
259 MCOS->emitInt8(dwarf::DW_LNS_set_isa);
260 MCOS->emitULEB128IntValue(Isa);
261 }
262 if ((LineEntry.getFlags() ^ Flags) & DWARF2_FLAG_IS_STMT) {
263 Flags = LineEntry.getFlags();
264 MCOS->emitInt8(dwarf::DW_LNS_negate_stmt);
265 }
266 if (LineEntry.getFlags() & DWARF2_FLAG_BASIC_BLOCK)
267 MCOS->emitInt8(dwarf::DW_LNS_set_basic_block);
268 if (LineEntry.getFlags() & DWARF2_FLAG_PROLOGUE_END)
269 MCOS->emitInt8(dwarf::DW_LNS_set_prologue_end);
270 if (LineEntry.getFlags() & DWARF2_FLAG_EPILOGUE_BEGIN)
271 MCOS->emitInt8(dwarf::DW_LNS_set_epilogue_begin);
272
273 // At this point we want to emit/create the sequence to encode the delta in
274 // line numbers and the increment of the address from the previous Label
275 // and the current Label.
276 MCOS->emitDwarfAdvanceLineAddr(LineDelta, PrevLabel, CurrLabel,
277 asmInfo.getCodePointerSize());
278
279 Discriminator = 0;
280 LastLine = LineEntry.getLine();
281 PrevLabel = CurrLabel;
282 IsAtStartSeq = false;
283 }
284
285 // Generate DWARF line end entry.
286 // We do not need this for DwarfDebug that explicitly terminates the line
287 // table using ranges whenever CU or section changes, unless entries from a
288 // higher-numbered subsection follow the last explicit end entry. The MC path
289 // does not track ranges nor terminate the line table. In those cases,
290 // conservatively use the section end symbol to end the line table.
291 if (!IsAtStartSeq)
292 MCOS->emitDwarfLineEndEntry(Section, PrevLabel);
293}
294
296 SMLoc DefLoc,
297 StringRef Name) {
298 auto &ctx = MCOS->getContext();
299 auto *LineStreamLabel = ctx.getOrCreateSymbol(Name);
300 auto *LineSym = ctx.createTempSymbol();
301 MCOS->emitLabel(LineSym);
302 const MCDwarfLoc &DwarfLoc = ctx.getCurrentDwarfLoc();
303
304 // Create a 'fake' line entry by having LineStreamLabel be non-null. This
305 // won't actually emit any line information, it will reset the line table
306 // sequence and emit a label at the start of the new line table sequence.
307 MCDwarfLineEntry LineEntry(LineSym, DwarfLoc, LineStreamLabel, DefLoc);
308 LineEntry.Subsection = MCOS->getCurrentSection().second;
310}
311
312//
313// This emits the Dwarf file and the line tables.
314//
316 MCContext &context = MCOS->getContext();
317
318 auto &LineTables = context.getMCDwarfLineTables();
319
320 // Bail out early so we don't switch to the debug_line section needlessly and
321 // in doing so create an unnecessary (if empty) section.
322 if (LineTables.empty())
323 return;
324
325 // In a v5 non-split line table, put the strings in a separate section.
326 std::optional<MCDwarfLineStr> LineStr;
327 if (context.getDwarfVersion() >= 5)
328 LineStr.emplace(context);
329
330 // Switch to the section where the table will be emitted into.
332
333 // Handle the rest of the Compile Units.
334 for (const auto &CUIDTablePair : LineTables) {
335 CUIDTablePair.second.emitCU(MCOS, Params, LineStr);
336 }
337
338 if (LineStr)
339 LineStr->emitSection(MCOS);
340}
341
343 MCSection *Section) const {
344 if (!HasSplitLineTable)
345 return;
346 std::optional<MCDwarfLineStr> NoLineStr(std::nullopt);
347 MCOS.switchSection(Section);
348 MCOS.emitLabel(Header.Emit(&MCOS, Params, {}, NoLineStr).second);
349}
350
351std::pair<MCSymbol *, MCSymbol *>
353 std::optional<MCDwarfLineStr> &LineStr) const {
354 static const char StandardOpcodeLengths[] = {
355 0, // length of DW_LNS_copy
356 1, // length of DW_LNS_advance_pc
357 1, // length of DW_LNS_advance_line
358 1, // length of DW_LNS_set_file
359 1, // length of DW_LNS_set_column
360 0, // length of DW_LNS_negate_stmt
361 0, // length of DW_LNS_set_basic_block
362 0, // length of DW_LNS_const_add_pc
363 1, // length of DW_LNS_fixed_advance_pc
364 0, // length of DW_LNS_set_prologue_end
365 0, // length of DW_LNS_set_epilogue_begin
366 1 // DW_LNS_set_isa
367 };
368 assert(std::size(StandardOpcodeLengths) >=
369 (Params.DWARF2LineOpcodeBase - 1U));
370 return Emit(MCOS, Params,
371 ArrayRef(StandardOpcodeLengths, Params.DWARF2LineOpcodeBase - 1),
372 LineStr);
373}
374
375static const MCExpr *forceExpAbs(MCStreamer &OS, const MCExpr* Expr) {
376 MCContext &Context = OS.getContext();
378 if (!Context.getAsmInfo().doesSetDirectiveSuppressReloc())
379 return Expr;
380
381 // On Mach-O, try to avoid a relocation by using a set directive.
382 MCSymbol *ABS = Context.createTempSymbol();
383 OS.emitAssignment(ABS, Expr);
384 return MCSymbolRefExpr::create(ABS, Context);
385}
386
387static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size) {
388 const MCExpr *ABS = forceExpAbs(OS, Value);
389 OS.emitValue(ABS, Size);
390}
391
393 // Switch to the .debug_line_str section.
394 MCOS->switchSection(
397 MCOS->emitBinaryData(Data.str());
398}
399
401 // Emit the strings without perturbing the offsets we used.
402 if (!LineStrings.isFinalized())
403 LineStrings.finalizeInOrder();
405 Data.resize(LineStrings.getSize());
406 LineStrings.write((uint8_t *)Data.data());
407 return Data;
408}
409
411 return LineStrings.add(Path);
412}
413
415 int RefSize =
417 size_t Offset = addString(Path);
418 if (UseRelocs)
419 MCOS->emitDwarfSectionOffset(LineStrLabel, Offset, RefSize);
420 else
421 MCOS->emitIntValue(Offset, RefSize);
422}
423
424void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const {
425 // First the directory table.
426 for (auto &Dir : MCDwarfDirs) {
427 MCOS->emitBytes(Dir); // The DirectoryName, and...
428 MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
429 }
430 MCOS->emitInt8(0); // Terminate the directory list.
431
432 // Second the file table.
433 for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
434 assert(!MCDwarfFiles[i].Name.empty());
435 MCOS->emitBytes(MCDwarfFiles[i].Name); // FileName and...
436 MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
437 MCOS->emitULEB128IntValue(MCDwarfFiles[i].DirIndex); // Directory number.
438 MCOS->emitInt8(0); // Last modification timestamp (always 0).
439 MCOS->emitInt8(0); // File size (always 0).
440 }
441 MCOS->emitInt8(0); // Terminate the file list.
442}
443
445 bool EmitMD5, bool HasAnySource,
446 std::optional<MCDwarfLineStr> &LineStr) {
447 assert(!DwarfFile.Name.empty());
448 if (LineStr)
449 LineStr->emitRef(MCOS, DwarfFile.Name);
450 else {
451 MCOS->emitBytes(DwarfFile.Name); // FileName and...
452 MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
453 }
454 MCOS->emitULEB128IntValue(DwarfFile.DirIndex); // Directory number.
455 if (EmitMD5) {
456 const MD5::MD5Result &Cksum = *DwarfFile.Checksum;
457 MCOS->emitBinaryData(
458 StringRef(reinterpret_cast<const char *>(Cksum.data()), Cksum.size()));
459 }
460 if (HasAnySource) {
461 // From https://dwarfstd.org/issues/180201.1.html
462 // * The value is an empty null-terminated string if no source is available
463 StringRef Source = DwarfFile.Source.value_or(StringRef());
464 // * If the source is available but is an empty file then the value is a
465 // null-terminated single "\n".
466 if (DwarfFile.Source && DwarfFile.Source->empty())
467 Source = "\n";
468 if (LineStr)
469 LineStr->emitRef(MCOS, Source);
470 else {
471 MCOS->emitBytes(Source); // Source and...
472 MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
473 }
474 }
475}
476
477void MCDwarfLineTableHeader::emitV5FileDirTables(
478 MCStreamer *MCOS, std::optional<MCDwarfLineStr> &LineStr) const {
479 // The directory format, which is just a list of the directory paths. In a
480 // non-split object, these are references to .debug_line_str; in a split
481 // object, they are inline strings.
482 MCOS->emitInt8(1);
483 MCOS->emitULEB128IntValue(dwarf::DW_LNCT_path);
484 MCOS->emitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
485 : dwarf::DW_FORM_string);
486 MCOS->emitULEB128IntValue(MCDwarfDirs.size() + 1);
487 // Try not to emit an empty compilation directory.
488 SmallString<256> Dir;
489 StringRef CompDir = MCOS->getContext().getCompilationDir();
490 if (!CompilationDir.empty()) {
491 Dir = CompilationDir;
492 MCOS->getContext().remapDebugPath(Dir);
493 CompDir = Dir.str();
494 if (LineStr)
495 CompDir = LineStr->getSaver().save(CompDir);
496 }
497 if (LineStr) {
498 // Record path strings, emit references here.
499 LineStr->emitRef(MCOS, CompDir);
500 for (const auto &Dir : MCDwarfDirs)
501 LineStr->emitRef(MCOS, Dir);
502 } else {
503 // The list of directory paths. Compilation directory comes first.
504 MCOS->emitBytes(CompDir);
505 MCOS->emitBytes(StringRef("\0", 1));
506 for (const auto &Dir : MCDwarfDirs) {
507 MCOS->emitBytes(Dir); // The DirectoryName, and...
508 MCOS->emitBytes(StringRef("\0", 1)); // its null terminator.
509 }
510 }
511
512 // The file format, which is the inline null-terminated filename and a
513 // directory index. We don't track file size/timestamp so don't emit them
514 // in the v5 table. Emit MD5 checksums and source if we have them.
515 uint64_t Entries = 2;
516 if (HasAllMD5)
517 Entries += 1;
518 if (HasAnySource)
519 Entries += 1;
520 MCOS->emitInt8(Entries);
521 MCOS->emitULEB128IntValue(dwarf::DW_LNCT_path);
522 MCOS->emitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
523 : dwarf::DW_FORM_string);
524 MCOS->emitULEB128IntValue(dwarf::DW_LNCT_directory_index);
525 MCOS->emitULEB128IntValue(dwarf::DW_FORM_udata);
526 if (HasAllMD5) {
527 MCOS->emitULEB128IntValue(dwarf::DW_LNCT_MD5);
528 MCOS->emitULEB128IntValue(dwarf::DW_FORM_data16);
529 }
530 if (HasAnySource) {
531 MCOS->emitULEB128IntValue(dwarf::DW_LNCT_LLVM_source);
532 MCOS->emitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
533 : dwarf::DW_FORM_string);
534 }
535 // Then the counted list of files. The root file is file #0, then emit the
536 // files as provide by .file directives.
537 // MCDwarfFiles has an unused element [0] so use size() not size()+1.
538 // But sometimes MCDwarfFiles is empty, in which case we still emit one file.
539 MCOS->emitULEB128IntValue(MCDwarfFiles.empty() ? 1 : MCDwarfFiles.size());
540 // To accommodate assembler source written for DWARF v4 but trying to emit
541 // v5: If we didn't see a root file explicitly, replicate file #1.
542 assert((!RootFile.Name.empty() || MCDwarfFiles.size() >= 1) &&
543 "No root file and no .file directives");
544 emitOneV5FileEntry(MCOS, RootFile.Name.empty() ? MCDwarfFiles[1] : RootFile,
545 HasAllMD5, HasAnySource, LineStr);
546 for (unsigned i = 1; i < MCDwarfFiles.size(); ++i)
547 emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasAllMD5, HasAnySource, LineStr);
548}
549
550std::pair<MCSymbol *, MCSymbol *>
552 ArrayRef<char> StandardOpcodeLengths,
553 std::optional<MCDwarfLineStr> &LineStr) const {
554 MCContext &context = MCOS->getContext();
555
556 // Create a symbol at the beginning of the line table.
557 MCSymbol *LineStartSym = Label;
558 if (!LineStartSym)
559 LineStartSym = context.createTempSymbol();
560
561 // Set the value of the symbol, as we are at the start of the line table.
562 MCOS->emitDwarfLineStartLabel(LineStartSym);
563
564 unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(context.getDwarfFormat());
565
566 MCSymbol *LineEndSym = MCOS->emitDwarfUnitLength("debug_line", "unit length");
567
568 // Next 2 bytes is the Version.
569 unsigned LineTableVersion = context.getDwarfVersion();
570 MCOS->emitInt16(LineTableVersion);
571
572 // In v5, we get address info next.
573 if (LineTableVersion >= 5) {
574 MCOS->emitInt8(context.getAsmInfo().getCodePointerSize());
575 MCOS->emitInt8(0); // Segment selector; same as EmitGenDwarfAranges.
576 }
577
578 // Create symbols for the start/end of the prologue.
579 MCSymbol *ProStartSym = context.createTempSymbol("prologue_start");
580 MCSymbol *ProEndSym = context.createTempSymbol("prologue_end");
581
582 // Length of the prologue, is the next 4 bytes (8 bytes for DWARF64). This is
583 // actually the length from after the length word, to the end of the prologue.
584 MCOS->emitAbsoluteSymbolDiff(ProEndSym, ProStartSym, OffsetSize);
585
586 MCOS->emitLabel(ProStartSym);
587
588 // Parameters of the state machine, are next.
589 MCOS->emitInt8(context.getAsmInfo().getMinInstAlignment());
590 // maximum_operations_per_instruction
591 // For non-VLIW architectures this field is always 1.
592 // FIXME: VLIW architectures need to update this field accordingly.
593 if (LineTableVersion >= 4)
594 MCOS->emitInt8(1);
596 MCOS->emitInt8(Params.DWARF2LineBase);
597 MCOS->emitInt8(Params.DWARF2LineRange);
598 MCOS->emitInt8(StandardOpcodeLengths.size() + 1);
599
600 // Standard opcode lengths
601 for (char Length : StandardOpcodeLengths)
602 MCOS->emitInt8(Length);
603
604 // Put out the directory and file tables. The formats vary depending on
605 // the version.
606 if (LineTableVersion >= 5)
607 emitV5FileDirTables(MCOS, LineStr);
608 else
609 emitV2FileDirTables(MCOS);
610
611 // This is the end of the prologue, so set the value of the symbol at the
612 // end of the prologue (that was used in a previous expression).
613 MCOS->emitLabel(ProEndSym);
614
615 return std::make_pair(LineStartSym, LineEndSym);
616}
617
619 std::optional<MCDwarfLineStr> &LineStr) const {
620 MCSymbol *LineEndSym = Header.Emit(MCOS, Params, LineStr).second;
621
622 // Put out the line tables.
623 for (const auto &LineSec : MCLineSections.getMCLineEntries())
624 emitOne(MCOS, LineSec.first, LineSec.second);
625
626 // This is the end of the section, so set the value of the symbol at the end
627 // of this section (that was used in a previous expression).
628 MCOS->emitLabel(LineEndSym);
629}
630
633 std::optional<MD5::MD5Result> Checksum,
634 std::optional<StringRef> Source,
635 uint16_t DwarfVersion, unsigned FileNumber) {
636 return Header.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
637 FileNumber);
638}
639
640static bool isRootFile(const MCDwarfFile &RootFile, StringRef &Directory,
641 StringRef &FileName,
642 std::optional<MD5::MD5Result> Checksum) {
643 if (RootFile.Name.empty() || StringRef(RootFile.Name) != FileName)
644 return false;
645 return RootFile.Checksum == Checksum;
646}
647
650 std::optional<MD5::MD5Result> Checksum,
651 std::optional<StringRef> Source,
652 uint16_t DwarfVersion, unsigned FileNumber) {
653 if (Directory == CompilationDir)
654 Directory = "";
655 if (FileName.empty()) {
656 FileName = "<stdin>";
657 Directory = "";
658 }
659 assert(!FileName.empty());
660 // Keep track of whether any or all files have an MD5 checksum.
661 // If any files have embedded source, they all must.
662 if (MCDwarfFiles.empty()) {
663 trackMD5Usage(Checksum.has_value());
664 HasAnySource |= Source.has_value();
665 }
666 if (FileNumber == 0) {
667 if (DwarfVersion >= 5 &&
668 isRootFile(RootFile, Directory, FileName, Checksum))
669 return 0;
670 // File numbers start with 1 and/or after any file numbers
671 // allocated by inline-assembler .file directives.
672 FileNumber = MCDwarfFiles.empty() ? 1 : MCDwarfFiles.size();
673 SmallString<256> Buffer;
674 auto IterBool = SourceIdMap.insert(
675 std::make_pair((Directory + Twine('\0') + FileName).toStringRef(Buffer),
676 FileNumber));
677 if (!IterBool.second)
678 return IterBool.first->second;
679 }
680 // Make space for this FileNumber in the MCDwarfFiles vector if needed.
681 if (FileNumber >= MCDwarfFiles.size())
682 MCDwarfFiles.resize(FileNumber + 1);
683
684 // Get the new MCDwarfFile slot for this FileNumber.
685 MCDwarfFile &File = MCDwarfFiles[FileNumber];
686
687 // It is an error to see the same number more than once.
688 if (!File.Name.empty())
689 return make_error<StringError>("file number already allocated",
691
692 if (Directory.empty()) {
693 // Separate the directory part from the basename of the FileName.
694 StringRef tFileName = sys::path::filename(FileName);
695 if (!tFileName.empty()) {
696 Directory = sys::path::parent_path(FileName);
697 if (!Directory.empty())
698 FileName = tFileName;
699 }
700 }
701
702 // Find or make an entry in the MCDwarfDirs vector for this Directory.
703 // Capture directory name.
704 unsigned DirIndex;
705 if (Directory.empty()) {
706 // For FileNames with no directories a DirIndex of 0 is used.
707 DirIndex = 0;
708 } else {
709 DirIndex = llvm::find(MCDwarfDirs, Directory) - MCDwarfDirs.begin();
710 if (DirIndex >= MCDwarfDirs.size())
711 MCDwarfDirs.push_back(std::string(Directory));
712 // The DirIndex is one based, as DirIndex of 0 is used for FileNames with
713 // no directories. MCDwarfDirs[] is unlike MCDwarfFiles[] in that the
714 // directory names are stored at MCDwarfDirs[DirIndex-1] where FileNames
715 // are stored at MCDwarfFiles[FileNumber].Name .
716 DirIndex++;
717 }
718
719 File.Name = std::string(FileName);
720 File.DirIndex = DirIndex;
721 File.Checksum = Checksum;
722 trackMD5Usage(Checksum.has_value());
723 File.Source = Source;
724 if (Source.has_value())
725 HasAnySource = true;
726
727 // return the allocated FileNumber.
728 return FileNumber;
729}
730
731/// Utility function to emit the encoding to a streamer.
733 int64_t LineDelta, uint64_t AddrDelta) {
734 MCContext &Context = MCOS->getContext();
736 MCDwarfLineAddr::encode(Context, Params, LineDelta, AddrDelta, Tmp);
737 MCOS->emitBytes(Tmp);
738}
739
740/// Given a special op, return the address skip amount (in units of
741/// DWARF2_LINE_MIN_INSN_LENGTH).
743 return (op - Params.DWARF2LineOpcodeBase) / Params.DWARF2LineRange;
744}
745
746/// Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
748 int64_t LineDelta, uint64_t AddrDelta,
750 uint64_t Temp, Opcode;
751 bool NeedCopy = false;
752
753 // The maximum address skip amount that can be encoded with a special op.
754 uint64_t MaxSpecialAddrDelta = SpecialAddr(Params, 255);
755
756 // Scale the address delta by the minimum instruction length.
757 AddrDelta = ScaleAddrDelta(Context, AddrDelta);
758
759 // A LineDelta of INT64_MAX is a signal that this is actually a
760 // DW_LNE_end_sequence. We cannot use special opcodes here, since we want the
761 // end_sequence to emit the matrix entry.
762 if (LineDelta == INT64_MAX) {
763 if (AddrDelta == MaxSpecialAddrDelta)
764 Out.push_back(dwarf::DW_LNS_const_add_pc);
765 else if (AddrDelta) {
766 Out.push_back(dwarf::DW_LNS_advance_pc);
768 }
769 Out.push_back(dwarf::DW_LNS_extended_op);
770 Out.push_back(1);
771 Out.push_back(dwarf::DW_LNE_end_sequence);
772 return;
773 }
774
775 // Bias the line delta by the base.
776 Temp = LineDelta - Params.DWARF2LineBase;
777
778 // If the line increment is out of range of a special opcode, we must encode
779 // it with DW_LNS_advance_line.
780 if (Temp >= Params.DWARF2LineRange ||
781 Temp + Params.DWARF2LineOpcodeBase > 255) {
782 Out.push_back(dwarf::DW_LNS_advance_line);
783 appendLEB128<LEB128Sign::Signed>(Out, LineDelta);
784
785 LineDelta = 0;
786 Temp = 0 - Params.DWARF2LineBase;
787 NeedCopy = true;
788 }
789
790 // Use DW_LNS_copy instead of a "line +0, addr +0" special opcode.
791 if (LineDelta == 0 && AddrDelta == 0) {
792 Out.push_back(dwarf::DW_LNS_copy);
793 return;
794 }
795
796 // Bias the opcode by the special opcode base.
797 Temp += Params.DWARF2LineOpcodeBase;
798
799 // Avoid overflow when addr_delta is large.
800 if (AddrDelta < 256 + MaxSpecialAddrDelta) {
801 // Try using a special opcode.
802 Opcode = Temp + AddrDelta * Params.DWARF2LineRange;
803 if (Opcode <= 255) {
804 Out.push_back(Opcode);
805 return;
806 }
807
808 // Try using DW_LNS_const_add_pc followed by special op.
809 Opcode = Temp + (AddrDelta - MaxSpecialAddrDelta) * Params.DWARF2LineRange;
810 if (Opcode <= 255) {
811 Out.push_back(dwarf::DW_LNS_const_add_pc);
812 Out.push_back(Opcode);
813 return;
814 }
815 }
816
817 // Otherwise use DW_LNS_advance_pc.
818 Out.push_back(dwarf::DW_LNS_advance_pc);
820
821 if (NeedCopy)
822 Out.push_back(dwarf::DW_LNS_copy);
823 else {
824 assert(Temp <= 255 && "Buggy special opcode encoding.");
825 Out.push_back(Temp);
826 }
827}
828
829// Utility function to write a tuple for .debug_abbrev.
830static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form) {
831 MCOS->emitULEB128IntValue(Name);
832 MCOS->emitULEB128IntValue(Form);
833}
834
835// When generating dwarf for assembly source files this emits
836// the data for .debug_abbrev section which contains three DIEs.
837static void EmitGenDwarfAbbrev(MCStreamer *MCOS) {
838 MCContext &context = MCOS->getContext();
840
841 // DW_TAG_compile_unit DIE abbrev (1).
842 MCOS->emitULEB128IntValue(1);
843 MCOS->emitULEB128IntValue(dwarf::DW_TAG_compile_unit);
845 dwarf::Form SecOffsetForm =
846 context.getDwarfVersion() >= 4
847 ? dwarf::DW_FORM_sec_offset
848 : (context.getDwarfFormat() == dwarf::DWARF64 ? dwarf::DW_FORM_data8
849 : dwarf::DW_FORM_data4);
850 EmitAbbrev(MCOS, dwarf::DW_AT_stmt_list, SecOffsetForm);
851 if (context.getGenDwarfSectionSyms().size() > 1 &&
852 context.getDwarfVersion() >= 3) {
853 EmitAbbrev(MCOS, dwarf::DW_AT_ranges, SecOffsetForm);
854 } else {
855 EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
856 EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr);
857 }
858 EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
859 if (!context.getCompilationDir().empty())
860 EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
861 StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
862 if (!DwarfDebugFlags.empty())
863 EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string);
864 EmitAbbrev(MCOS, dwarf::DW_AT_producer, dwarf::DW_FORM_string);
865
866 if (context.getDwarfVersion() >= 6)
867 EmitAbbrev(MCOS, dwarf::DW_AT_language_name, dwarf::DW_FORM_data2);
868 else
869 EmitAbbrev(MCOS, dwarf::DW_AT_language, dwarf::DW_FORM_data2);
870
871 EmitAbbrev(MCOS, 0, 0);
872
873 // DW_TAG_label DIE abbrev (2).
874 MCOS->emitULEB128IntValue(2);
875 MCOS->emitULEB128IntValue(dwarf::DW_TAG_label);
877 EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
878 EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4);
879 EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4);
880 EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
881 EmitAbbrev(MCOS, 0, 0);
882
883 // Terminate the abbreviations for this compilation unit.
884 MCOS->emitInt8(0);
885}
886
887// When generating dwarf for assembly source files this emits the data for
888// .debug_aranges section. This section contains a header and a table of pairs
889// of PointerSize'ed values for the address and size of section(s) with line
890// table entries.
892 const MCSymbol *InfoSectionSymbol) {
893 MCContext &context = MCOS->getContext();
894
895 auto &Sections = context.getGenDwarfSectionSyms();
896
898
899 unsigned UnitLengthBytes =
901 unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(context.getDwarfFormat());
902
903 // This will be the length of the .debug_aranges section, first account for
904 // the size of each item in the header (see below where we emit these items).
905 int Length = UnitLengthBytes + 2 + OffsetSize + 1 + 1;
906
907 // Figure the padding after the header before the table of address and size
908 // pairs who's values are PointerSize'ed.
909 const MCAsmInfo &asmInfo = context.getAsmInfo();
910 int AddrSize = asmInfo.getCodePointerSize();
911 int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1));
912 if (Pad == 2 * AddrSize)
913 Pad = 0;
914 Length += Pad;
915
916 // Add the size of the pair of PointerSize'ed values for the address and size
917 // of each section we have in the table.
918 Length += 2 * AddrSize * Sections.size();
919 // And the pair of terminating zeros.
920 Length += 2 * AddrSize;
921
922 // Emit the header for this section.
923 if (context.getDwarfFormat() == dwarf::DWARF64)
924 // The DWARF64 mark.
926 // The 4 (8 for DWARF64) byte length not including the length of the unit
927 // length field itself.
928 MCOS->emitIntValue(Length - UnitLengthBytes, OffsetSize);
929 // The 2 byte version, which is 2.
930 MCOS->emitInt16(2);
931 // The 4 (8 for DWARF64) byte offset to the compile unit in the .debug_info
932 // from the start of the .debug_info.
933 if (InfoSectionSymbol)
934 MCOS->emitDwarfSectionOffset(InfoSectionSymbol, /*Offset=*/0, OffsetSize);
935 else
936 MCOS->emitIntValue(0, OffsetSize);
937 // The 1 byte size of an address.
938 MCOS->emitInt8(AddrSize);
939 // The 1 byte size of a segment descriptor, we use a value of zero.
940 MCOS->emitInt8(0);
941 // Align the header with the padding if needed, before we put out the table.
942 for(int i = 0; i < Pad; i++)
943 MCOS->emitInt8(0);
944
945 // Now emit the table of pairs of PointerSize'ed values for the section
946 // addresses and sizes.
947 for (MCSection *Sec : Sections) {
948 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
949 MCSymbol *EndSymbol = Sec->getEndSymbol(context);
950 assert(StartSymbol && "StartSymbol must not be NULL");
951 assert(EndSymbol && "EndSymbol must not be NULL");
952
953 const MCExpr *Addr = MCSymbolRefExpr::create(StartSymbol, context);
954 const MCExpr *Size =
955 makeEndMinusStartExpr(context, *StartSymbol, *EndSymbol, 0);
956 MCOS->emitValue(Addr, AddrSize);
957 emitAbsValue(*MCOS, Size, AddrSize);
958 }
959
960 // And finally the pair of terminating zeros.
961 MCOS->emitIntValue(0, AddrSize);
962 MCOS->emitIntValue(0, AddrSize);
963}
964
965// When generating dwarf for assembly source files this emits the data for
966// .debug_info section which contains three parts. The header, the compile_unit
967// DIE and a list of label DIEs.
968static void EmitGenDwarfInfo(MCStreamer *MCOS,
969 const MCSymbol *AbbrevSectionSymbol,
970 const MCSymbol *LineSectionSymbol,
971 const MCSymbol *RangesSymbol) {
972 MCContext &context = MCOS->getContext();
973
975
976 // Create a symbol at the start and end of this section used in here for the
977 // expression to calculate the length in the header.
978 MCSymbol *InfoStart = context.createTempSymbol();
979 MCOS->emitLabel(InfoStart);
980 MCSymbol *InfoEnd = context.createTempSymbol();
981
982 // First part: the header.
983
984 unsigned UnitLengthBytes =
986 unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(context.getDwarfFormat());
987
988 if (context.getDwarfFormat() == dwarf::DWARF64)
989 // Emit DWARF64 mark.
991
992 // The 4 (8 for DWARF64) byte total length of the information for this
993 // compilation unit, not including the unit length field itself.
994 const MCExpr *Length =
995 makeEndMinusStartExpr(context, *InfoStart, *InfoEnd, UnitLengthBytes);
996 emitAbsValue(*MCOS, Length, OffsetSize);
997
998 // The 2 byte DWARF version.
999 MCOS->emitInt16(context.getDwarfVersion());
1000
1001 // The DWARF v5 header has unit type, address size, abbrev offset.
1002 // Earlier versions have abbrev offset, address size.
1003 const MCAsmInfo &AsmInfo = context.getAsmInfo();
1004 int AddrSize = AsmInfo.getCodePointerSize();
1005 if (context.getDwarfVersion() >= 5) {
1006 MCOS->emitInt8(dwarf::DW_UT_compile);
1007 MCOS->emitInt8(AddrSize);
1008 }
1009 // The 4 (8 for DWARF64) byte offset to the debug abbrevs from the start of
1010 // the .debug_abbrev.
1011 if (AbbrevSectionSymbol)
1012 MCOS->emitDwarfSectionOffset(AbbrevSectionSymbol, /*Offset=*/0, OffsetSize);
1013 else
1014 // Since the abbrevs are at the start of the section, the offset is zero.
1015 MCOS->emitIntValue(0, OffsetSize);
1016 if (context.getDwarfVersion() <= 4)
1017 MCOS->emitInt8(AddrSize);
1018
1019 // Second part: the compile_unit DIE.
1020
1021 // The DW_TAG_compile_unit DIE abbrev (1).
1022 MCOS->emitULEB128IntValue(1);
1023
1024 // DW_AT_stmt_list, a 4 (8 for DWARF64) byte offset from the start of the
1025 // .debug_line section.
1026 if (LineSectionSymbol)
1027 MCOS->emitDwarfSectionOffset(LineSectionSymbol, /*Offset=*/0, OffsetSize);
1028 else
1029 // The line table is at the start of the section, so the offset is zero.
1030 MCOS->emitIntValue(0, OffsetSize);
1031
1032 if (RangesSymbol) {
1033 // There are multiple sections containing code, so we must use
1034 // .debug_ranges/.debug_rnglists. AT_ranges, the 4/8 byte offset from the
1035 // start of the .debug_ranges/.debug_rnglists.
1036 MCOS->emitSymbolValue(RangesSymbol, OffsetSize);
1037 } else {
1038 // If we only have one non-empty code section, we can use the simpler
1039 // AT_low_pc and AT_high_pc attributes.
1040
1041 // Find the first (and only) non-empty text section
1042 auto &Sections = context.getGenDwarfSectionSyms();
1043 const auto TextSection = Sections.begin();
1044 assert(TextSection != Sections.end() && "No text section found");
1045
1046 MCSymbol *StartSymbol = (*TextSection)->getBeginSymbol();
1047 MCSymbol *EndSymbol = (*TextSection)->getEndSymbol(context);
1048 assert(StartSymbol && "StartSymbol must not be NULL");
1049 assert(EndSymbol && "EndSymbol must not be NULL");
1050
1051 // AT_low_pc, the first address of the default .text section.
1052 const MCExpr *Start = MCSymbolRefExpr::create(StartSymbol, context);
1053 MCOS->emitValue(Start, AddrSize);
1054
1055 // AT_high_pc, the last address of the default .text section.
1056 const MCExpr *End = MCSymbolRefExpr::create(EndSymbol, context);
1057 MCOS->emitValue(End, AddrSize);
1058 }
1059
1060 // AT_name, the name of the source file. Reconstruct from the first directory
1061 // and file table entries.
1062 const SmallVectorImpl<std::string> &MCDwarfDirs = context.getMCDwarfDirs();
1063 if (MCDwarfDirs.size() > 0) {
1064 MCOS->emitBytes(MCDwarfDirs[0]);
1066 }
1067 const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles = context.getMCDwarfFiles();
1068 // MCDwarfFiles might be empty if we have an empty source file.
1069 // If it's not empty, [0] is unused and [1] is the first actual file.
1070 assert(MCDwarfFiles.empty() || MCDwarfFiles.size() >= 2);
1071 const MCDwarfFile &RootFile =
1072 MCDwarfFiles.empty()
1073 ? context.getMCDwarfLineTable(/*CUID=*/0).getRootFile()
1074 : MCDwarfFiles[1];
1075 MCOS->emitBytes(RootFile.Name);
1076 MCOS->emitInt8(0); // NULL byte to terminate the string.
1077
1078 // AT_comp_dir, the working directory the assembly was done in.
1079 if (!context.getCompilationDir().empty()) {
1080 MCOS->emitBytes(context.getCompilationDir());
1081 MCOS->emitInt8(0); // NULL byte to terminate the string.
1082 }
1083
1084 // AT_APPLE_flags, the command line arguments of the assembler tool.
1085 StringRef DwarfDebugFlags = context.getDwarfDebugFlags();
1086 if (!DwarfDebugFlags.empty()){
1087 MCOS->emitBytes(DwarfDebugFlags);
1088 MCOS->emitInt8(0); // NULL byte to terminate the string.
1089 }
1090
1091 // AT_producer, the version of the assembler tool.
1092 StringRef DwarfDebugProducer = context.getDwarfDebugProducer();
1093 if (!DwarfDebugProducer.empty())
1094 MCOS->emitBytes(DwarfDebugProducer);
1095 else
1096 MCOS->emitBytes(StringRef("llvm-mc (based on LLVM " PACKAGE_VERSION ")"));
1097 MCOS->emitInt8(0); // NULL byte to terminate the string.
1098
1099 if (context.getDwarfVersion() >= 6) {
1100 // AT_language_name, a 4 byte value.
1101 MCOS->emitInt16(dwarf::DW_LNAME_Assembly);
1102 } else {
1103 // AT_language, a 4 byte value. We use DW_LANG_Mips_Assembler as the dwarf2
1104 // draft has no standard code for assembler.
1105 // FIXME: dwarf4 has DW_LANG_Assembly which we could use instead.
1106 MCOS->emitInt16(dwarf::DW_LANG_Mips_Assembler);
1107 }
1108
1109 // Third part: the list of label DIEs.
1110
1111 // Loop on saved info for dwarf labels and create the DIEs for them.
1112 const std::vector<MCGenDwarfLabelEntry> &Entries =
1114 for (const auto &Entry : Entries) {
1115 // The DW_TAG_label DIE abbrev (2).
1116 MCOS->emitULEB128IntValue(2);
1117
1118 // AT_name, of the label without any leading underbar.
1119 MCOS->emitBytes(Entry.getName());
1120 MCOS->emitInt8(0); // NULL byte to terminate the string.
1121
1122 // AT_decl_file, index into the file table.
1123 MCOS->emitInt32(Entry.getFileNumber());
1124
1125 // AT_decl_line, source line number.
1126 MCOS->emitInt32(Entry.getLineNumber());
1127
1128 // AT_low_pc, start address of the label.
1129 const auto *AT_low_pc = MCSymbolRefExpr::create(Entry.getLabel(), context);
1130 MCOS->emitValue(AT_low_pc, AddrSize);
1131 }
1132
1133 // Add the NULL DIE terminating the Compile Unit DIE's.
1134 MCOS->emitInt8(0);
1135
1136 // Now set the value of the symbol at the end of the info section.
1137 MCOS->emitLabel(InfoEnd);
1138}
1139
1140// When generating dwarf for assembly source files this emits the data for
1141// .debug_ranges section. We only emit one range list, which spans all of the
1142// executable sections of this file.
1144 MCContext &context = MCOS->getContext();
1145 auto &Sections = context.getGenDwarfSectionSyms();
1146
1147 const MCAsmInfo &AsmInfo = context.getAsmInfo();
1148 int AddrSize = AsmInfo.getCodePointerSize();
1149 MCSymbol *RangesSymbol;
1150
1151 if (MCOS->getContext().getDwarfVersion() >= 5) {
1153 MCSymbol *EndSymbol = mcdwarf::emitListsTableHeaderStart(*MCOS);
1154 MCOS->AddComment("Offset entry count");
1155 MCOS->emitInt32(0);
1156 RangesSymbol = context.createTempSymbol("debug_rnglist0_start");
1157 MCOS->emitLabel(RangesSymbol);
1158 for (MCSection *Sec : Sections) {
1159 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
1160 const MCSymbol *EndSymbol = Sec->getEndSymbol(context);
1161 const MCExpr *SectionStartAddr =
1162 MCSymbolRefExpr::create(StartSymbol, context);
1163 const MCExpr *SectionSize =
1164 makeEndMinusStartExpr(context, *StartSymbol, *EndSymbol, 0);
1165 MCOS->emitInt8(dwarf::DW_RLE_start_length);
1166 MCOS->emitValue(SectionStartAddr, AddrSize);
1167 MCOS->emitULEB128Value(SectionSize);
1168 }
1169 MCOS->emitInt8(dwarf::DW_RLE_end_of_list);
1170 MCOS->emitLabel(EndSymbol);
1171 } else {
1173 RangesSymbol = context.createTempSymbol("debug_ranges_start");
1174 MCOS->emitLabel(RangesSymbol);
1175 for (MCSection *Sec : Sections) {
1176 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
1177 const MCSymbol *EndSymbol = Sec->getEndSymbol(context);
1178
1179 // Emit a base address selection entry for the section start.
1180 const MCExpr *SectionStartAddr =
1181 MCSymbolRefExpr::create(StartSymbol, context);
1182 MCOS->emitFill(AddrSize, 0xFF);
1183 MCOS->emitValue(SectionStartAddr, AddrSize);
1184
1185 // Emit a range list entry spanning this section.
1186 const MCExpr *SectionSize =
1187 makeEndMinusStartExpr(context, *StartSymbol, *EndSymbol, 0);
1188 MCOS->emitIntValue(0, AddrSize);
1189 emitAbsValue(*MCOS, SectionSize, AddrSize);
1190 }
1191
1192 // Emit end of list entry
1193 MCOS->emitIntValue(0, AddrSize);
1194 MCOS->emitIntValue(0, AddrSize);
1195 }
1196
1197 return RangesSymbol;
1198}
1199
1200//
1201// When generating dwarf for assembly source files this emits the Dwarf
1202// sections.
1203//
1205 MCContext &context = MCOS->getContext();
1206
1207 // Create the dwarf sections in this order (.debug_line already created).
1208 const MCAsmInfo &AsmInfo = context.getAsmInfo();
1209 bool CreateDwarfSectionSymbols =
1211 MCSymbol *LineSectionSymbol = nullptr;
1212 if (CreateDwarfSectionSymbols)
1213 LineSectionSymbol = MCOS->getDwarfLineTableSymbol(0);
1214 MCSymbol *AbbrevSectionSymbol = nullptr;
1215 MCSymbol *InfoSectionSymbol = nullptr;
1216 MCSymbol *RangesSymbol = nullptr;
1217
1218 // Create end symbols for each section, and remove empty sections
1219 MCOS->getContext().finalizeDwarfSections(*MCOS);
1220
1221 // If there are no sections to generate debug info for, we don't need
1222 // to do anything
1223 if (MCOS->getContext().getGenDwarfSectionSyms().empty())
1224 return;
1225
1226 // We only use the .debug_ranges section if we have multiple code sections,
1227 // and we are emitting a DWARF version which supports it.
1228 const bool UseRangesSection =
1229 MCOS->getContext().getGenDwarfSectionSyms().size() > 1 &&
1230 MCOS->getContext().getDwarfVersion() >= 3;
1231 CreateDwarfSectionSymbols |= UseRangesSection;
1232
1234 if (CreateDwarfSectionSymbols) {
1235 InfoSectionSymbol = context.createTempSymbol();
1236 MCOS->emitLabel(InfoSectionSymbol);
1237 }
1239 if (CreateDwarfSectionSymbols) {
1240 AbbrevSectionSymbol = context.createTempSymbol();
1241 MCOS->emitLabel(AbbrevSectionSymbol);
1242 }
1243
1245
1246 // Output the data for .debug_aranges section.
1247 EmitGenDwarfAranges(MCOS, InfoSectionSymbol);
1248
1249 if (UseRangesSection) {
1250 RangesSymbol = emitGenDwarfRanges(MCOS);
1251 assert(RangesSymbol);
1252 }
1253
1254 // Output the data for .debug_abbrev section.
1255 EmitGenDwarfAbbrev(MCOS);
1256
1257 // Output the data for .debug_info section.
1258 EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol, RangesSymbol);
1259}
1260
1261//
1262// When generating dwarf for assembly source files this is called when symbol
1263// for a label is created. If this symbol is not a temporary and is in the
1264// section that dwarf is being generated for, save the needed info to create
1265// a dwarf label.
1266//
1269 // We won't create dwarf labels for temporary symbols.
1270 if (Symbol->isTemporary())
1271 return;
1272 MCContext &context = MCOS->getContext();
1273 // We won't create dwarf labels for symbols in sections that we are not
1274 // generating debug info for.
1275 if (!context.getGenDwarfSectionSyms().count(MCOS->getCurrentSectionOnly()))
1276 return;
1277
1278 // The dwarf label's name does not have the symbol name's leading
1279 // underbar if any.
1280 StringRef Name = Symbol->getName();
1281 if (Name.starts_with("_"))
1282 Name = Name.substr(1, Name.size()-1);
1283
1284 // Get the dwarf file number to be used for the dwarf label.
1285 unsigned FileNumber = context.getGenDwarfFileNumber();
1286
1287 // Finding the line number is the expensive part which is why we just don't
1288 // pass it in as for some symbols we won't create a dwarf label.
1289 unsigned CurBuffer = SrcMgr.FindBufferContainingLoc(Loc);
1290 unsigned LineNumber = SrcMgr.FindLineNumber(Loc, CurBuffer);
1291
1292 // We create a temporary symbol for use for the AT_high_pc and AT_low_pc
1293 // values so that they don't have things like an ARM thumb bit from the
1294 // original symbol. So when used they won't get a low bit set after
1295 // relocation.
1296 MCSymbol *Label = context.createTempSymbol();
1297 MCOS->emitLabel(Label);
1298
1299 // Create and entry for the info and add it to the other entries.
1301 MCGenDwarfLabelEntry(Name, FileNumber, LineNumber, Label));
1302}
1303
1304void MCCFIInstruction::replaceRegister(unsigned FromReg, unsigned ToReg) {
1305 auto ReplaceReg = [=](unsigned &Reg) {
1306 if (Reg == FromReg)
1307 Reg = ToReg;
1308 };
1309 auto Visitor = makeVisitor(
1310 [=](CommonFields &F) {
1311 ReplaceReg(F.Register);
1312 ReplaceReg(F.Register2);
1313 },
1314 [](EscapeFields &) {}, [](LabelFields &) {},
1315 [=](RegisterPairFields &F) {
1316 ReplaceReg(F.Register);
1317 ReplaceReg(F.Reg1);
1318 ReplaceReg(F.Reg2);
1319 },
1320 [=](VectorRegistersFields &F) {
1321 ReplaceReg(F.Register);
1322 for (VectorRegisterWithLane &VRL : F.VectorRegisters)
1323 ReplaceReg(VRL.Register);
1324 },
1325 [=](VectorOffsetFields &F) {
1326 ReplaceReg(F.Register);
1327 ReplaceReg(F.MaskRegister);
1328 },
1330 ReplaceReg(F.Register);
1331 ReplaceReg(F.SpillRegister);
1332 ReplaceReg(F.MaskRegister);
1333 },
1334 [](LLVMSetRAStateFields &) {
1335 llvm_unreachable(".cfi_set_ra_state does not have registers");
1336 });
1337 std::visit(Visitor, ExtraFields);
1338}
1339
1340static int getDataAlignmentFactor(MCStreamer &streamer) {
1341 MCContext &context = streamer.getContext();
1342 const MCAsmInfo &asmInfo = context.getAsmInfo();
1343 int size = asmInfo.getCalleeSaveStackSlotSize();
1344 if (asmInfo.isStackGrowthDirectionUp())
1345 return size;
1346 else
1347 return -size;
1348}
1349
1350static unsigned getSizeForEncoding(MCStreamer &streamer,
1351 unsigned symbolEncoding) {
1352 MCContext &context = streamer.getContext();
1353 unsigned format = symbolEncoding & 0x0f;
1354 switch (format) {
1355 default: llvm_unreachable("Unknown Encoding");
1358 return context.getAsmInfo().getCodePointerSize();
1361 return 2;
1364 return 4;
1367 return 8;
1368 }
1369}
1370
1371static void emitFDESymbol(MCObjectStreamer &streamer, const MCSymbol &symbol,
1372 unsigned symbolEncoding, bool isEH) {
1373 MCContext &context = streamer.getContext();
1374 const MCAsmInfo &asmInfo = context.getAsmInfo();
1375 const MCExpr *v =
1376 asmInfo.getExprForFDESymbol(&symbol, symbolEncoding, streamer);
1377 unsigned size = getSizeForEncoding(streamer, symbolEncoding);
1378 if (asmInfo.doDwarfFDESymbolsUseAbsDiff() && isEH)
1379 emitAbsValue(streamer, v, size);
1380 else
1381 streamer.emitValue(v, size);
1382}
1383
1384static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol,
1385 unsigned symbolEncoding) {
1386 MCContext &context = streamer.getContext();
1387 const MCAsmInfo &asmInfo = context.getAsmInfo();
1388 const MCExpr *v =
1389 asmInfo.getExprForPersonalitySymbol(&symbol, symbolEncoding, streamer);
1390 unsigned size = getSizeForEncoding(streamer, symbolEncoding);
1391 streamer.emitValue(v, size);
1392}
1393
1394namespace {
1395
1396class FrameEmitterImpl {
1397 int64_t CFAOffset = 0;
1398 int64_t InitialCFAOffset = 0;
1399 SmallVector<int64_t, 0> SavedCFAOffsets;
1400 bool IsEH;
1401 MCObjectStreamer &Streamer;
1402
1403public:
1404 FrameEmitterImpl(bool IsEH, MCObjectStreamer &Streamer)
1405 : IsEH(IsEH), Streamer(Streamer) {}
1406
1407 /// Emit the unwind information in a compact way.
1408 void EmitCompactUnwind(const MCDwarfFrameInfo &frame);
1409
1410 const MCSymbol &EmitCIE(const MCDwarfFrameInfo &F);
1411 void EmitFDE(const MCSymbol &cieStart, const MCDwarfFrameInfo &frame,
1412 bool LastInSection, const MCSymbol &SectionStart);
1413 void emitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
1414 MCSymbol *BaseLabel);
1415 void emitCFIInstruction(const MCCFIInstruction &Instr);
1416};
1417
1418} // end anonymous namespace
1419
1420static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding) {
1421 Streamer.emitInt8(Encoding);
1422}
1423
1424static void encodeDwarfRegisterLocation(int DwarfReg, raw_ostream &OS) {
1425 assert(DwarfReg >= 0);
1426 if (DwarfReg < 32) {
1427 OS << uint8_t(dwarf::DW_OP_reg0 + DwarfReg);
1428 } else {
1429 OS << uint8_t(dwarf::DW_OP_regx);
1430 encodeULEB128(DwarfReg, OS);
1431 }
1432}
1433
1434void FrameEmitterImpl::emitCFIInstruction(const MCCFIInstruction &Instr) {
1435 int dataAlignmentFactor = getDataAlignmentFactor(Streamer);
1436 auto *MRI = Streamer.getContext().getRegisterInfo();
1437
1438 switch (Instr.getOperation()) {
1440 unsigned Reg1 = Instr.getRegister();
1441 unsigned Reg2 = Instr.getRegister2();
1442 if (!IsEH) {
1443 Reg1 = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg1);
1444 Reg2 = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg2);
1445 }
1446 Streamer.emitInt8(dwarf::DW_CFA_register);
1447 Streamer.emitULEB128IntValue(Reg1);
1448 Streamer.emitULEB128IntValue(Reg2);
1449 return;
1450 }
1452 Streamer.emitInt8(dwarf::DW_CFA_GNU_window_save);
1453 return;
1454
1456 Streamer.emitInt8(dwarf::DW_CFA_AARCH64_negate_ra_state);
1457 return;
1458
1460 Streamer.emitInt8(dwarf::DW_CFA_AARCH64_negate_ra_state_with_pc);
1461 return;
1462
1464 Streamer.emitInt8(dwarf::DW_CFA_AARCH64_set_ra_state);
1465 Streamer.emitULEB128IntValue(Instr.getRASignState());
1466 if (MCSymbol *PACSym = Instr.getRASignSymbol()) {
1467 MCContext &Ctx = Streamer.getContext();
1468 const MCExpr *Diff = MCBinaryExpr::createSub(
1469 MCSymbolRefExpr::create(PACSym, Ctx),
1470 MCSymbolRefExpr::create(Instr.getLabel(), Ctx), Ctx);
1471 const MCExpr *Factored = MCBinaryExpr::createDiv(
1472 Diff,
1474 Ctx);
1475 Streamer.emitSLEB128Value(Factored);
1476 } else {
1477 Streamer.emitSLEB128IntValue(Instr.getRASignOffset());
1478 }
1479 return;
1480 }
1482 unsigned Reg = Instr.getRegister();
1483 Streamer.emitInt8(dwarf::DW_CFA_undefined);
1484 Streamer.emitULEB128IntValue(Reg);
1485 return;
1486 }
1489 const bool IsRelative =
1491
1492 Streamer.emitInt8(dwarf::DW_CFA_def_cfa_offset);
1493
1494 if (IsRelative)
1495 CFAOffset += Instr.getOffset();
1496 else
1497 CFAOffset = Instr.getOffset();
1498
1499 Streamer.emitULEB128IntValue(CFAOffset);
1500
1501 return;
1502 }
1504 unsigned Reg = Instr.getRegister();
1505 if (!IsEH)
1506 Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1507 Streamer.emitInt8(dwarf::DW_CFA_def_cfa);
1508 Streamer.emitULEB128IntValue(Reg);
1509 CFAOffset = Instr.getOffset();
1510 Streamer.emitULEB128IntValue(CFAOffset);
1511
1512 return;
1513 }
1515 unsigned Reg = Instr.getRegister();
1516 if (!IsEH)
1517 Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1518 Streamer.emitInt8(dwarf::DW_CFA_def_cfa_register);
1519 Streamer.emitULEB128IntValue(Reg);
1520
1521 return;
1522 }
1523 // TODO: Implement `_sf` variants if/when they need to be emitted.
1525 unsigned Reg = Instr.getRegister();
1526 if (!IsEH)
1527 Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1528 Streamer.emitIntValue(dwarf::DW_CFA_LLVM_def_aspace_cfa, 1);
1529 Streamer.emitULEB128IntValue(Reg);
1530 CFAOffset = Instr.getOffset();
1531 Streamer.emitULEB128IntValue(CFAOffset);
1532 Streamer.emitULEB128IntValue(Instr.getAddressSpace());
1533
1534 return;
1535 }
1538 const bool IsRelative =
1539 Instr.getOperation() == MCCFIInstruction::OpRelOffset;
1540
1541 unsigned Reg = Instr.getRegister();
1542 if (!IsEH)
1543 Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1544
1545 int64_t Offset = Instr.getOffset();
1546 if (IsRelative)
1547 Offset -= CFAOffset;
1548 Offset = Offset / dataAlignmentFactor;
1549
1550 if (Offset < 0) {
1551 Streamer.emitInt8(dwarf::DW_CFA_offset_extended_sf);
1552 Streamer.emitULEB128IntValue(Reg);
1553 Streamer.emitSLEB128IntValue(Offset);
1554 } else if (Reg < 64) {
1555 Streamer.emitInt8(dwarf::DW_CFA_offset + Reg);
1556 Streamer.emitULEB128IntValue(Offset);
1557 } else {
1558 Streamer.emitInt8(dwarf::DW_CFA_offset_extended);
1559 Streamer.emitULEB128IntValue(Reg);
1560 Streamer.emitULEB128IntValue(Offset);
1561 }
1562 return;
1563 }
1565 Streamer.emitInt8(dwarf::DW_CFA_remember_state);
1566 SavedCFAOffsets.push_back(CFAOffset);
1567 return;
1569 Streamer.emitInt8(dwarf::DW_CFA_restore_state);
1570 CFAOffset = SavedCFAOffsets.pop_back_val();
1571 return;
1573 unsigned Reg = Instr.getRegister();
1574 Streamer.emitInt8(dwarf::DW_CFA_same_value);
1575 Streamer.emitULEB128IntValue(Reg);
1576 return;
1577 }
1579 unsigned Reg = Instr.getRegister();
1580 if (!IsEH)
1581 Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1582 if (Reg < 64) {
1583 Streamer.emitInt8(dwarf::DW_CFA_restore | Reg);
1584 } else {
1585 Streamer.emitInt8(dwarf::DW_CFA_restore_extended);
1586 Streamer.emitULEB128IntValue(Reg);
1587 }
1588 return;
1589 }
1591 Streamer.emitInt8(dwarf::DW_CFA_GNU_args_size);
1592 Streamer.emitULEB128IntValue(Instr.getOffset());
1593 return;
1594
1596 Streamer.emitBytes(Instr.getValues());
1597 return;
1598
1600 Streamer.emitLabel(Instr.getCfiLabel(), Instr.getLoc());
1601 return;
1603 unsigned Reg = Instr.getRegister();
1604 if (!IsEH)
1605 Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1606
1607 int64_t Offset = Instr.getOffset();
1608 Offset = Offset / dataAlignmentFactor;
1609
1610 if (Offset < 0) {
1611 Streamer.emitInt8(dwarf::DW_CFA_val_offset_sf);
1612 Streamer.emitULEB128IntValue(Reg);
1613 Streamer.emitSLEB128IntValue(Offset);
1614 } else {
1615 Streamer.emitInt8(dwarf::DW_CFA_val_offset);
1616 Streamer.emitULEB128IntValue(Reg);
1617 Streamer.emitULEB128IntValue(Offset);
1618 }
1619 return;
1620 }
1622 // CFI for a register spilled to a pair of SGPRs is implemented as an
1623 // expression(E) rule where E is a composite location description with
1624 // multiple parts each referencing SGPR register location storage with a bit
1625 // offset of 0. In other words we generate the following DWARF:
1626 //
1627 // DW_CFA_expression: <Reg>,
1628 // (DW_OP_regx <SGPRPair[0]>) (DW_OP_piece <Size>)
1629 // (DW_OP_regx <SGPRPair[1]>) (DW_OP_piece <Size>)
1630 //
1631 // The memory location description for the current CFA is pushed on the
1632 // stack before E is evaluated, but we choose not to drop it as it would
1633 // require a longer expression E and DWARF defines the result of the
1634 // evaulation to be the location description on the top of the stack (i.e.
1635 // the implictly pushed one is just ignored.)
1636
1637 const auto &Fields =
1639
1641 raw_svector_ostream OSBlock(Block);
1642 encodeDwarfRegisterLocation(Fields.Reg1, OSBlock);
1643 if (Fields.Reg1SizeInBits % 8 == 0) {
1644 OSBlock << uint8_t(dwarf::DW_OP_piece);
1645 encodeULEB128(Fields.Reg1SizeInBits / 8, OSBlock);
1646 } else {
1647 OSBlock << uint8_t(dwarf::DW_OP_bit_piece);
1648 encodeULEB128(Fields.Reg1SizeInBits, OSBlock);
1649 encodeULEB128(0, OSBlock);
1650 }
1651 encodeDwarfRegisterLocation(Fields.Reg2, OSBlock);
1652 if (Fields.Reg2SizeInBits % 8 == 0) {
1653 OSBlock << uint8_t(dwarf::DW_OP_piece);
1654 encodeULEB128(Fields.Reg2SizeInBits / 8, OSBlock);
1655 } else {
1656 OSBlock << uint8_t(dwarf::DW_OP_bit_piece);
1657 encodeULEB128(Fields.Reg2SizeInBits, OSBlock);
1658 encodeULEB128(0, OSBlock);
1659 }
1660
1661 Streamer.emitInt8(dwarf::DW_CFA_expression);
1662 Streamer.emitULEB128IntValue(Fields.Register);
1663 Streamer.emitULEB128IntValue(Block.size());
1664 Streamer.emitBinaryData(StringRef(&Block[0], Block.size()));
1665 return;
1666 }
1668 // CFI for an SGPR spilled to a multiple lanes of VGPRs is implemented as an
1669 // expression(E) rule where E is a composite location description with
1670 // multiple parts each referencing VGPR register location storage with a bit
1671 // offset of the lane index multiplied by the size of a lane. In other words
1672 // we generate the following DWARF:
1673 //
1674 // DW_CFA_expression: <SGPR>,
1675 // (DW_OP_regx <VGPR[0]>) (DW_OP_bit_piece <Size>, <Lane[0]>*<Size>)
1676 // (DW_OP_regx <VGPR[1]>) (DW_OP_bit_piece <Size>, <Lane[1]>*<Size>)
1677 // ...
1678 // (DW_OP_regx <VGPR[N]>) (DW_OP_bit_piece <Size>, <Lane[N]>*<Size>)
1679 //
1680 // However if we're only using a single lane then we can emit a slightly
1681 // more optimal form:
1682 //
1683 // DW_CFA_expression: <SGPR>,
1684 // (DW_OP_regx <VGPR[0]>) (DW_OP_LLVM_offset_uconst <Lane[0]>*<Size>)
1685 //
1686 // The memory location description for the current CFA is pushed on the
1687 // stack before E is evaluated, but we choose not to drop it as it would
1688 // require a longer expression E and DWARF defines the result of the
1689 // evaulation to be the location description on the top of the stack (i.e.
1690 // the implictly pushed one is just ignored.)
1691
1692 const auto &Fields =
1694 auto &VRs = Fields.VectorRegisters;
1695
1697 raw_svector_ostream OSBlock(Block);
1698
1699 if (VRs.size() == 1 && VRs[0].SizeInBits % 8 == 0) {
1700 encodeDwarfRegisterLocation(VRs[0].Register, OSBlock);
1701 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1702 << uint8_t(dwarf::DW_OP_LLVM_offset_uconst);
1703 encodeULEB128(static_cast<uint64_t>(VRs[0].SizeInBits / 8) * VRs[0].Lane,
1704 OSBlock);
1705 } else {
1706 for (const auto &VR : VRs) {
1707 // TODO: Detect when we can merge multiple adjacent pieces, or even
1708 // reduce this to a register location description (when all pieces are
1709 // adjacent).
1710 encodeDwarfRegisterLocation(VR.Register, OSBlock);
1711 OSBlock << uint8_t(dwarf::DW_OP_bit_piece);
1712 encodeULEB128(VR.SizeInBits, OSBlock);
1713 encodeULEB128(static_cast<uint64_t>(VR.SizeInBits) * VR.Lane, OSBlock);
1714 }
1715 }
1716
1717 Streamer.emitInt8(dwarf::DW_CFA_expression);
1718 Streamer.emitULEB128IntValue(Fields.Register);
1719 Streamer.emitULEB128IntValue(Block.size());
1720 Streamer.emitBinaryData(StringRef(&Block[0], Block.size()));
1721 return;
1722 }
1724 // CFI for a vector register spilled to memory is implemented as an
1725 // expression(E) rule where E is a location description.
1726 //
1727 // DW_CFA_expression: <VGPR>,
1728 // (DW_OP_regx <VGPR>)
1729 // (DW_OP_swap)
1730 // (DW_OP_LLVM_offset_uconst <Offset>)
1731 // (DW_OP_LLVM_call_frame_entry_reg <Mask>)
1732 // (DW_OP_deref_size <MaskSize>)
1733 // (DW_OP_LLVM_select_bit_piece <VGPRSize> <MaskSize>)
1734
1735 const auto &Fields =
1737
1739 raw_svector_ostream OSBlock(Block);
1740 encodeDwarfRegisterLocation(Fields.Register, OSBlock);
1741 OSBlock << uint8_t(dwarf::DW_OP_swap);
1742 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1743 << uint8_t(dwarf::DW_OP_LLVM_offset_uconst);
1744 encodeULEB128(Fields.Offset, OSBlock);
1745 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1746 << uint8_t(dwarf::DW_OP_LLVM_call_frame_entry_reg);
1747 encodeULEB128(Fields.MaskRegister, OSBlock);
1748 OSBlock << uint8_t(dwarf::DW_OP_deref_size);
1749 OSBlock << uint8_t(Fields.MaskRegisterSizeInBits / 8);
1750 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1751 << uint8_t(dwarf::DW_OP_LLVM_select_bit_piece);
1752 encodeULEB128(Fields.RegisterSizeInBits, OSBlock);
1753 encodeULEB128(Fields.MaskRegisterSizeInBits, OSBlock);
1754
1755 Streamer.emitInt8(dwarf::DW_CFA_expression);
1756 Streamer.emitULEB128IntValue(Fields.Register);
1757 Streamer.emitULEB128IntValue(Block.size());
1758 Streamer.emitBinaryData(StringRef(&Block[0], Block.size()));
1759 return;
1760 }
1762 // CFI for a VGPR/AGPR partially spilled to another VGPR/AGPR dependent on
1763 // an EXEC mask is implemented as an expression(E) rule where E is a
1764 // location description.
1765 //
1766 // DW_CFA_expression: <GPR>,
1767 // (DW_OP_regx <GPR>)
1768 // (DW_OP_regx <Spill GPR>)
1769 // (DW_OP_LLVM_call_frame_entry_reg <Mask>)
1770 // (DW_OP_deref_size <MaskSize>)
1771 // (DW_OP_LLVM_select_bit_piece <GPR lane size> <MaskSize>)
1772
1773 const auto Fields =
1775
1777 raw_svector_ostream OSBlock(Block);
1778 encodeDwarfRegisterLocation(Fields.Register, OSBlock);
1779 encodeDwarfRegisterLocation(Fields.SpillRegister, OSBlock);
1780 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1781 << uint8_t(dwarf::DW_OP_LLVM_call_frame_entry_reg);
1782 encodeULEB128(Fields.MaskRegister, OSBlock);
1783 OSBlock << uint8_t(dwarf::DW_OP_deref_size)
1784 << uint8_t(Fields.MaskRegisterSizeInBits / 8);
1785 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1786 << uint8_t(dwarf::DW_OP_LLVM_select_bit_piece);
1787 encodeULEB128(Fields.SpillRegisterLaneSizeInBits, OSBlock);
1788 encodeULEB128(Fields.MaskRegisterSizeInBits, OSBlock);
1789
1790 Streamer.emitInt8(dwarf::DW_CFA_expression);
1791 Streamer.emitULEB128IntValue(Fields.Register);
1792 Streamer.emitULEB128IntValue(Block.size());
1793 Streamer.emitBinaryData(StringRef(&Block[0], Block.size()));
1794 return;
1795 }
1796 }
1797
1798 llvm_unreachable("Unhandled case in switch");
1799}
1800
1801/// Emit frame instructions to describe the layout of the frame.
1802void FrameEmitterImpl::emitCFIInstructions(ArrayRef<MCCFIInstruction> Instrs,
1803 MCSymbol *BaseLabel) {
1804 for (const MCCFIInstruction &Instr : Instrs) {
1805 MCSymbol *Label = Instr.getLabel();
1806 // Throw out move if the label is invalid.
1807 if (Label && !Label->isDefined()) continue; // Not emitted, in dead code.
1808
1809 // Advance row if new location.
1810 if (BaseLabel && Label) {
1811 MCSymbol *ThisSym = Label;
1812 if (ThisSym != BaseLabel) {
1813 Streamer.emitDwarfAdvanceFrameAddr(BaseLabel, ThisSym, Instr.getLoc());
1814 BaseLabel = ThisSym;
1815 }
1816 }
1817
1818 emitCFIInstruction(Instr);
1819 }
1820}
1821
1822/// Emit the unwind information in a compact way.
1823void FrameEmitterImpl::EmitCompactUnwind(const MCDwarfFrameInfo &Frame) {
1824 MCContext &Context = Streamer.getContext();
1825 const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
1826
1827 // range-start range-length compact-unwind-enc personality-func lsda
1828 // _foo LfooEnd-_foo 0x00000023 0 0
1829 // _bar LbarEnd-_bar 0x00000025 __gxx_personality except_tab1
1830 //
1831 // .section __LD,__compact_unwind,regular,debug
1832 //
1833 // # compact unwind for _foo
1834 // .quad _foo
1835 // .set L1,LfooEnd-_foo
1836 // .long L1
1837 // .long 0x01010001
1838 // .quad 0
1839 // .quad 0
1840 //
1841 // # compact unwind for _bar
1842 // .quad _bar
1843 // .set L2,LbarEnd-_bar
1844 // .long L2
1845 // .long 0x01020011
1846 // .quad __gxx_personality
1847 // .quad except_tab1
1848
1849 uint32_t Encoding = Frame.CompactUnwindEncoding;
1850 if (!Encoding) return;
1851 bool DwarfEHFrameOnly = (Encoding == MOFI->getCompactUnwindDwarfEHFrameOnly());
1852
1853 // The encoding needs to know we have an LSDA.
1854 if (!DwarfEHFrameOnly && Frame.Lsda)
1855 Encoding |= 0x40000000;
1856
1857 // Range Start
1858 unsigned FDEEncoding = MOFI->getFDEEncoding();
1859 unsigned Size = getSizeForEncoding(Streamer, FDEEncoding);
1860 Streamer.emitSymbolValue(Frame.Begin, Size);
1861
1862 // Range Length
1863 const MCExpr *Range =
1864 makeEndMinusStartExpr(Context, *Frame.Begin, *Frame.End, 0);
1866
1867 // Compact Encoding
1869 Streamer.emitIntValue(Encoding, Size);
1870
1871 // Personality Function
1873 if (!DwarfEHFrameOnly && Frame.Personality)
1874 Streamer.emitSymbolValue(Frame.Personality, Size);
1875 else
1876 Streamer.emitIntValue(0, Size); // No personality fn
1877
1878 // LSDA
1880 if (!DwarfEHFrameOnly && Frame.Lsda)
1881 Streamer.emitSymbolValue(Frame.Lsda, Size);
1882 else
1883 Streamer.emitIntValue(0, Size); // No LSDA
1884}
1885
1886static unsigned getCIEVersion(bool IsEH, unsigned DwarfVersion) {
1887 if (IsEH)
1888 return 1;
1889 switch (DwarfVersion) {
1890 case 2:
1891 return 1;
1892 case 3:
1893 return 3;
1894 case 4:
1895 case 5:
1896 case 6:
1897 return 4;
1898 }
1899 llvm_unreachable("Unknown version");
1900}
1901
1902const MCSymbol &FrameEmitterImpl::EmitCIE(const MCDwarfFrameInfo &Frame) {
1903 MCContext &context = Streamer.getContext();
1904 const MCRegisterInfo *MRI = context.getRegisterInfo();
1905 const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
1906
1907 MCSymbol *sectionStart = context.createTempSymbol();
1908 Streamer.emitLabel(sectionStart);
1909
1910 MCSymbol *sectionEnd = context.createTempSymbol();
1911
1913 unsigned UnitLengthBytes = dwarf::getUnitLengthFieldByteSize(Format);
1914 unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(Format);
1915 bool IsDwarf64 = Format == dwarf::DWARF64;
1916
1917 if (IsDwarf64)
1918 // DWARF64 mark
1920
1921 // Length
1922 const MCExpr *Length = makeEndMinusStartExpr(context, *sectionStart,
1923 *sectionEnd, UnitLengthBytes);
1924 emitAbsValue(Streamer, Length, OffsetSize);
1925
1926 // CIE ID
1927 uint64_t CIE_ID =
1928 IsEH ? 0 : (IsDwarf64 ? dwarf::DW64_CIE_ID : dwarf::DW_CIE_ID);
1929 Streamer.emitIntValue(CIE_ID, OffsetSize);
1930
1931 // Version
1932 uint8_t CIEVersion = getCIEVersion(IsEH, context.getDwarfVersion());
1933 Streamer.emitInt8(CIEVersion);
1934
1935 if (IsEH) {
1936 SmallString<8> Augmentation;
1937 Augmentation += "z";
1938 if (Frame.Personality)
1939 Augmentation += "P";
1940 if (Frame.Lsda)
1941 Augmentation += "L";
1942 Augmentation += "R";
1943 if (Frame.IsSignalFrame)
1944 Augmentation += "S";
1945 if (Frame.IsBKeyFrame)
1946 Augmentation += "B";
1947 if (Frame.IsMTETaggedFrame)
1948 Augmentation += "G";
1949 if (Frame.IsNonHintPAuthFrame)
1950 Augmentation += "N";
1951 Streamer.emitBytes(Augmentation);
1952 }
1953 Streamer.emitInt8(0);
1954
1955 if (CIEVersion >= 4) {
1956 // Address Size
1957 Streamer.emitInt8(context.getAsmInfo().getCodePointerSize());
1958
1959 // Segment Descriptor Size
1960 Streamer.emitInt8(0);
1961 }
1962
1963 // Code Alignment Factor
1964 Streamer.emitULEB128IntValue(context.getAsmInfo().getMinInstAlignment());
1965
1966 // Data Alignment Factor
1967 Streamer.emitSLEB128IntValue(getDataAlignmentFactor(Streamer));
1968
1969 // Return Address Register
1970 unsigned RAReg = Frame.RAReg;
1971 if (RAReg == static_cast<unsigned>(INT_MAX))
1972 RAReg = MRI->getDwarfRegNum(MRI->getRARegister(), IsEH);
1973
1974 if (CIEVersion == 1) {
1975 assert(RAReg <= 255 &&
1976 "DWARF 2 encodes return_address_register in one byte");
1977 Streamer.emitInt8(RAReg);
1978 } else {
1979 Streamer.emitULEB128IntValue(RAReg);
1980 }
1981
1982 // Augmentation Data Length (optional)
1983 unsigned augmentationLength = 0;
1984 if (IsEH) {
1985 if (Frame.Personality) {
1986 // Personality Encoding
1987 augmentationLength += 1;
1988 // Personality
1989 augmentationLength +=
1991 }
1992 if (Frame.Lsda)
1993 augmentationLength += 1;
1994 // Encoding of the FDE pointers
1995 augmentationLength += 1;
1996
1997 Streamer.emitULEB128IntValue(augmentationLength);
1998
1999 // Augmentation Data (optional)
2000 if (Frame.Personality) {
2001 // Personality Encoding
2003 // Personality
2005 }
2006
2007 if (Frame.Lsda)
2009
2010 // Encoding of the FDE pointers
2012 }
2013
2014 // Initial Instructions
2015
2016 const MCAsmInfo &MAI = context.getAsmInfo();
2017 if (!Frame.IsSimple) {
2018 const std::vector<MCCFIInstruction> &Instructions =
2020 emitCFIInstructions(Instructions, nullptr);
2021 }
2022
2023 InitialCFAOffset = CFAOffset;
2024
2025 // Padding
2026 Streamer.emitValueToAlignment(Align(IsEH ? 4 : MAI.getCodePointerSize()));
2027
2028 Streamer.emitLabel(sectionEnd);
2029 return *sectionStart;
2030}
2031
2032void FrameEmitterImpl::EmitFDE(const MCSymbol &cieStart,
2033 const MCDwarfFrameInfo &frame,
2034 bool LastInSection,
2035 const MCSymbol &SectionStart) {
2036 MCContext &context = Streamer.getContext();
2037 MCSymbol *fdeStart = context.createTempSymbol();
2038 MCSymbol *fdeEnd = context.createTempSymbol();
2039 const MCObjectFileInfo *MOFI = context.getObjectFileInfo();
2040
2041 CFAOffset = InitialCFAOffset;
2042 SavedCFAOffsets.clear();
2043
2045 unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(Format);
2046
2047 if (Format == dwarf::DWARF64)
2048 // DWARF64 mark
2050
2051 // Length
2052 const MCExpr *Length = makeEndMinusStartExpr(context, *fdeStart, *fdeEnd, 0);
2053 emitAbsValue(Streamer, Length, OffsetSize);
2054
2055 Streamer.emitLabel(fdeStart);
2056
2057 // CIE Pointer
2058 const MCAsmInfo &asmInfo = context.getAsmInfo();
2059 if (IsEH) {
2060 const MCExpr *offset =
2061 makeEndMinusStartExpr(context, cieStart, *fdeStart, 0);
2062 emitAbsValue(Streamer, offset, OffsetSize);
2063 } else if (!asmInfo.doesDwarfUseRelocationsAcrossSections()) {
2064 const MCExpr *offset =
2065 makeEndMinusStartExpr(context, SectionStart, cieStart, 0);
2066 emitAbsValue(Streamer, offset, OffsetSize);
2067 } else {
2068 Streamer.emitDwarfSectionOffset(&cieStart, /*Offset=*/0, OffsetSize);
2069 }
2070
2071 // PC Begin
2072 unsigned PCEncoding =
2073 IsEH ? MOFI->getFDEEncoding() : (unsigned)dwarf::DW_EH_PE_absptr;
2074 unsigned PCSize = getSizeForEncoding(Streamer, PCEncoding);
2075 emitFDESymbol(Streamer, *frame.Begin, PCEncoding, IsEH);
2076
2077 // PC Range
2078 const MCExpr *Range =
2079 makeEndMinusStartExpr(context, *frame.Begin, *frame.End, 0);
2080 emitAbsValue(Streamer, Range, PCSize);
2081
2082 if (IsEH) {
2083 // Augmentation Data Length
2084 unsigned augmentationLength = 0;
2085
2086 if (frame.Lsda)
2087 augmentationLength += getSizeForEncoding(Streamer, frame.LsdaEncoding);
2088
2089 Streamer.emitULEB128IntValue(augmentationLength);
2090
2091 // Augmentation Data
2092 if (frame.Lsda)
2093 emitFDESymbol(Streamer, *frame.Lsda, frame.LsdaEncoding, true);
2094 }
2095
2096 // Call Frame Instructions
2097 emitCFIInstructions(frame.Instructions, frame.Begin);
2098
2099 // Padding
2100 // The size of a .eh_frame section has to be a multiple of the alignment
2101 // since a null CIE is interpreted as the end. Old systems overaligned
2102 // .eh_frame, so we do too and account for it in the last FDE.
2103 unsigned Alignment = LastInSection ? asmInfo.getCodePointerSize() : PCSize;
2104 Streamer.emitValueToAlignment(Align(Alignment));
2105
2106 Streamer.emitLabel(fdeEnd);
2107}
2108
2109namespace {
2110
2111struct CIEKey {
2112 CIEKey() = default;
2113
2114 explicit CIEKey(const MCDwarfFrameInfo &Frame, bool IsEH)
2115 : Personality(Frame.Personality),
2116 PersonalityEncoding(Frame.PersonalityEncoding),
2117 LsdaEncoding(Frame.LsdaEncoding), IsSignalFrame(Frame.IsSignalFrame),
2118 IsSimple(Frame.IsSimple), RAReg(Frame.RAReg),
2119 IsBKeyFrame(Frame.IsBKeyFrame),
2120 IsMTETaggedFrame(Frame.IsMTETaggedFrame),
2121 IsNonHintPAuthFrame(Frame.IsNonHintPAuthFrame), IsEH(IsEH) {}
2122
2123 StringRef PersonalityName() const {
2124 if (!Personality)
2125 return StringRef();
2126 return Personality->getName();
2127 }
2128
2129 bool operator<(const CIEKey &Other) const {
2130 assert(IsEH == Other.IsEH);
2131 if (!IsEH)
2132 return std::make_tuple(RAReg, IsSimple) <
2133 std::make_tuple(Other.RAReg, Other.IsSimple);
2134
2135 return std::make_tuple(PersonalityName(), PersonalityEncoding, LsdaEncoding,
2136 IsSignalFrame, IsSimple, RAReg, IsBKeyFrame,
2137 IsMTETaggedFrame, IsNonHintPAuthFrame) <
2138 std::make_tuple(Other.PersonalityName(), Other.PersonalityEncoding,
2139 Other.LsdaEncoding, Other.IsSignalFrame,
2140 Other.IsSimple, Other.RAReg, Other.IsBKeyFrame,
2141 Other.IsMTETaggedFrame, Other.IsNonHintPAuthFrame);
2142 }
2143
2144 bool operator==(const CIEKey &Other) const {
2145 assert(IsEH == Other.IsEH);
2146 if (!IsEH)
2147 return RAReg == Other.RAReg && IsSimple == Other.IsSimple;
2148
2149 return Personality == Other.Personality &&
2150 PersonalityEncoding == Other.PersonalityEncoding &&
2151 LsdaEncoding == Other.LsdaEncoding &&
2152 IsSignalFrame == Other.IsSignalFrame && IsSimple == Other.IsSimple &&
2153 RAReg == Other.RAReg && IsBKeyFrame == Other.IsBKeyFrame &&
2154 IsMTETaggedFrame == Other.IsMTETaggedFrame &&
2155 IsNonHintPAuthFrame == Other.IsNonHintPAuthFrame;
2156 }
2157 bool operator!=(const CIEKey &Other) const { return !(*this == Other); }
2158
2159 const MCSymbol *Personality = nullptr;
2160 unsigned PersonalityEncoding = 0;
2161 unsigned LsdaEncoding = -1;
2162 bool IsSignalFrame = false;
2163 bool IsSimple = false;
2164 unsigned RAReg = UINT_MAX;
2165 bool IsBKeyFrame = false;
2166 bool IsMTETaggedFrame = false;
2167 bool IsNonHintPAuthFrame = false;
2168 bool IsEH = false;
2169};
2170
2171} // end anonymous namespace
2172
2174 MCContext &Context = Streamer.getContext();
2175 const MCObjectFileInfo *MOFI = Context.getObjectFileInfo();
2176 const MCAsmInfo &AsmInfo = Context.getAsmInfo();
2177 FrameEmitterImpl Emitter(IsEH, Streamer);
2178 ArrayRef<MCDwarfFrameInfo> FrameArray = Streamer.getDwarfFrameInfos();
2179
2180 // Emit the compact unwind info if available.
2181 bool NeedsEHFrameSection = !MOFI->getSupportsCompactUnwindWithoutEHFrame();
2182 if (IsEH && MOFI->getCompactUnwindSection()) {
2183 Streamer.generateCompactUnwindEncodings();
2184 bool SectionEmitted = false;
2185 for (const MCDwarfFrameInfo &Frame : FrameArray) {
2186 if (Frame.CompactUnwindEncoding == 0) continue;
2187 if (!SectionEmitted) {
2188 Streamer.switchSection(MOFI->getCompactUnwindSection());
2189 Streamer.emitValueToAlignment(Align(AsmInfo.getCodePointerSize()));
2190 SectionEmitted = true;
2191 }
2192 NeedsEHFrameSection |=
2193 Frame.CompactUnwindEncoding ==
2195 Emitter.EmitCompactUnwind(Frame);
2196 }
2197 }
2198
2199 // Compact unwind information can be emitted in the eh_frame section or the
2200 // debug_frame section. Skip emitting FDEs and CIEs when the compact unwind
2201 // doesn't need an eh_frame section and the emission location is the eh_frame
2202 // section.
2203 if (!NeedsEHFrameSection && IsEH) return;
2204
2205 MCSection &Section =
2206 IsEH ? *const_cast<MCObjectFileInfo *>(MOFI)->getEHFrameSection()
2207 : *MOFI->getDwarfFrameSection();
2208
2209 Streamer.switchSection(&Section);
2210 MCSymbol *SectionStart = Context.createTempSymbol();
2211 Streamer.emitLabel(SectionStart);
2212
2213 bool CanOmitDwarf = MOFI->getOmitDwarfIfHaveCompactUnwind();
2214 // Sort the FDEs by their corresponding CIE before we emit them.
2215 // This isn't technically necessary according to the DWARF standard,
2216 // but the Android libunwindstack rejects eh_frame sections where
2217 // an FDE refers to a CIE other than the closest previous CIE.
2219 llvm::make_pointer_range(FrameArray));
2221 Frames, [IsEH](const MCDwarfFrameInfo *X, const MCDwarfFrameInfo *Y) {
2222 return CIEKey(*X, IsEH) < CIEKey(*Y, IsEH);
2223 });
2224 CIEKey LastKey;
2225 const MCSymbol *LastCIEStart = nullptr;
2226 for (auto I = Frames.begin(), E = Frames.end(); I != E;) {
2227 const MCDwarfFrameInfo &Frame = **I;
2228 ++I;
2229 if (CanOmitDwarf && Frame.CompactUnwindEncoding !=
2230 MOFI->getCompactUnwindDwarfEHFrameOnly() && IsEH)
2231 // CIEs and FDEs can be emitted in either the eh_frame section or the
2232 // debug_frame section, on some platforms (e.g. AArch64) the target object
2233 // file supports emitting a compact_unwind section without an associated
2234 // eh_frame section. If the eh_frame section is not needed, and the
2235 // location where the CIEs and FDEs are to be emitted is the eh_frame
2236 // section, do not emit anything.
2237 continue;
2238
2239 CIEKey Key(Frame, IsEH);
2240 if (!LastCIEStart || Key != LastKey) {
2241 LastKey = Key;
2242 LastCIEStart = &Emitter.EmitCIE(Frame);
2243 }
2244
2245 Emitter.EmitFDE(*LastCIEStart, Frame, I == E, *SectionStart);
2246 }
2247}
2248
2250 uint64_t AddrDelta,
2251 SmallVectorImpl<char> &Out) {
2252 // Scale the address delta by the minimum instruction length.
2253 AddrDelta = ScaleAddrDelta(Context, AddrDelta);
2254 if (AddrDelta == 0)
2255 return;
2256
2257 llvm::endianness E = Context.getAsmInfo().isLittleEndian()
2260
2261 if (isUIntN(6, AddrDelta)) {
2262 uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
2263 Out.push_back(Opcode);
2264 } else if (isUInt<8>(AddrDelta)) {
2265 Out.push_back(dwarf::DW_CFA_advance_loc1);
2266 Out.push_back(AddrDelta);
2267 } else if (isUInt<16>(AddrDelta)) {
2268 Out.push_back(dwarf::DW_CFA_advance_loc2);
2269 support::endian::write<uint16_t>(Out, AddrDelta, E);
2270 } else {
2271 assert(isUInt<32>(AddrDelta));
2272 Out.push_back(dwarf::DW_CFA_advance_loc4);
2273 support::endian::write<uint32_t>(Out, AddrDelta, E);
2274 }
2275}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
dxil container DXContainer Global Emitter
This file contains constants used for implementing Dwarf debug support.
#define op(i)
static void emitFDESymbol(MCObjectStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding, bool isEH)
Definition MCDwarf.cpp:1371
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:742
static void EmitGenDwarfAranges(MCStreamer *MCOS, const MCSymbol *InfoSectionSymbol)
Definition MCDwarf.cpp:891
static bool isRootFile(const MCDwarfFile &RootFile, StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum)
Definition MCDwarf.cpp:640
static uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta)
Definition MCDwarf.cpp:65
static const MCExpr * forceExpAbs(MCStreamer &OS, const MCExpr *Expr)
Definition MCDwarf.cpp:375
static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size)
Definition MCDwarf.cpp:387
static void encodeDwarfRegisterLocation(int DwarfReg, raw_ostream &OS)
Definition MCDwarf.cpp:1424
static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile, bool EmitMD5, bool HasAnySource, std::optional< MCDwarfLineStr > &LineStr)
Definition MCDwarf.cpp:444
static const MCExpr * makeEndMinusStartExpr(MCContext &Ctx, const MCSymbol &Start, const MCSymbol &End, int IntVal)
Definition MCDwarf.cpp:120
static unsigned getCIEVersion(bool IsEH, unsigned DwarfVersion)
Definition MCDwarf.cpp:1886
static void EmitGenDwarfInfo(MCStreamer *MCOS, const MCSymbol *AbbrevSectionSymbol, const MCSymbol *LineSectionSymbol, const MCSymbol *RangesSymbol)
Definition MCDwarf.cpp:968
static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form)
Definition MCDwarf.cpp:830
static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding)
Definition MCDwarf.cpp:1384
static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding)
Definition MCDwarf.cpp:1420
static int getDataAlignmentFactor(MCStreamer &streamer)
Definition MCDwarf.cpp:1340
static MCSymbol * emitGenDwarfRanges(MCStreamer *MCOS)
Definition MCDwarf.cpp:1143
static void EmitGenDwarfAbbrev(MCStreamer *MCOS)
Definition MCDwarf.cpp:837
static unsigned getSizeForEncoding(MCStreamer &streamer, unsigned symbolEncoding)
Definition MCDwarf.cpp:1350
#define DWARF2_FLAG_IS_STMT
Definition MCDwarf.h:119
#define DWARF2_FLAG_BASIC_BLOCK
Definition MCDwarf.h:120
#define DWARF2_LINE_DEFAULT_IS_STMT
Definition MCDwarf.h:117
#define DWARF2_FLAG_PROLOGUE_END
Definition MCDwarf.h:121
#define DWARF2_FLAG_EPILOGUE_BEGIN
Definition MCDwarf.h:122
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr MCPhysReg RAReg
MachineRegisterInfo & MRI
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallString class.
This file defines the SmallVector class.
std::unique_ptr< MCStreamer > && Streamer
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
Value * RHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
Tagged union holding either a T or a Error.
Definition Error.h:485
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:67
unsigned getMinInstAlignment() const
Definition MCAsmInfo.h:558
const std::vector< MCCFIInstruction > & getInitialFrameState() const
Definition MCAsmInfo.h:723
bool doesDwarfUseRelocationsAcrossSections() const
Definition MCAsmInfo.h:705
const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition MCAsmInfo.cpp:54
bool isStackGrowthDirectionUp() const
True if target stack grow up.
Definition MCAsmInfo.h:469
unsigned getCalleeSaveStackSlotSize() const
Get the callee-saved register stack slot size in bytes.
Definition MCAsmInfo.h:461
bool doDwarfFDESymbolsUseAbsDiff() const
Definition MCAsmInfo.h:709
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition MCAsmInfo.cpp:48
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition MCAsmInfo.h:457
static const MCBinaryExpr * createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:352
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:201
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:427
@ Sub
Subtraction.
Definition MCExpr.h:323
LLVM_ABI void replaceRegister(unsigned FromReg, unsigned ToReg)
Replaces in place all references to FromReg with ToReg.
Definition MCDwarf.cpp:1304
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:83
const MCObjectFileInfo * getObjectFileInfo() const
Definition MCContext.h:411
LLVM_ABI void remapDebugPath(SmallVectorImpl< char > &Path)
Remap one path in-place as per the debug prefix map.
const SetVector< MCSection * > & getGenDwarfSectionSyms()
Definition MCContext.h:784
const SmallVectorImpl< std::string > & getMCDwarfDirs(unsigned CUID=0)
Definition MCContext.h:726
StringRef getDwarfDebugProducer()
Definition MCContext.h:806
StringRef getDwarfDebugFlags()
Definition MCContext.h:803
bool getDwarfLocSeen()
Definition MCContext.h:767
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
Definition MCContext.h:677
void clearDwarfLocSeen()
Definition MCContext.h:765
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition MCContext.h:712
unsigned getDwarfCompileUnitID()
Definition MCContext.h:730
const MCRegisterInfo * getRegisterInfo() const
Definition MCContext.h:409
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles(unsigned CUID=0)
Definition MCContext.h:722
const std::map< unsigned, MCDwarfLineTable > & getMCDwarfLineTables() const
Definition MCContext.h:708
unsigned getGenDwarfFileNumber()
Definition MCContext.h:772
uint16_t getDwarfVersion() const
Definition MCContext.h:812
LLVM_ABI void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E)
Definition MCContext.h:798
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
const MCDwarfLoc & getCurrentDwarfLoc()
Definition MCContext.h:768
dwarf::DwarfFormat getDwarfFormat() const
Definition MCContext.h:809
const MCAsmInfo & getAsmInfo() const
Definition MCContext.h:407
const std::vector< MCGenDwarfLabelEntry > & getMCGenDwarfLabelEntries() const
Definition MCContext.h:794
LLVM_ABI void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params, MCSection *Section) const
Definition MCDwarf.cpp:342
static LLVM_ABI void emit(MCObjectStreamer &streamer, bool isEH)
Definition MCDwarf.cpp:2173
static LLVM_ABI void encodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Definition MCDwarf.cpp:2249
static LLVM_ABI void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
Definition MCDwarf.cpp:732
static LLVM_ABI void encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Definition MCDwarf.cpp:747
Instances of this class represent the line information for the dwarf line table entries.
Definition MCDwarf.h:190
void setEndLabel(MCSymbol *EndLabel)
Definition MCDwarf.h:223
MCDwarfLineEntry(MCSymbol *label, const MCDwarfLoc loc, MCSymbol *lineStreamLabel=nullptr, SMLoc streamLabelDefLoc={})
Definition MCDwarf.h:199
MCSymbol * LineStreamLabel
Definition MCDwarf.h:210
static LLVM_ABI void make(MCStreamer *MCOS, MCSection *Section)
Definition MCDwarf.cpp:91
LLVM_ABI void emitSection(MCStreamer *MCOS)
Emit the .debug_line_str section if appropriate.
Definition MCDwarf.cpp:392
LLVM_ABI MCDwarfLineStr(MCContext &Ctx)
Construct an instance that can emit .debug_line_str (for use in a normal v5 line table).
Definition MCDwarf.cpp:76
LLVM_ABI SmallString< 0 > getFinalizedData()
Returns finalized section.
Definition MCDwarf.cpp:400
LLVM_ABI void emitRef(MCStreamer *MCOS, StringRef Path)
Emit a reference to the string.
Definition MCDwarf.cpp:414
LLVM_ABI size_t addString(StringRef Path)
Adds path Path to the line string.
Definition MCDwarf.cpp:410
LLVM_ABI void endCurrentSeqAndEmitLineStreamLabel(MCStreamer *MCOS, SMLoc DefLoc, StringRef Name)
Definition MCDwarf.cpp:295
MCDwarfFile & getRootFile()
Definition MCDwarf.h:424
const MCLineSection & getMCLineSections() const
Definition MCDwarf.h:454
static LLVM_ABI void emit(MCStreamer *MCOS, MCDwarfLineTableParams Params)
Definition MCDwarf.cpp:315
static LLVM_ABI void emitOne(MCStreamer *MCOS, MCSection *Section, const MCLineSection::MCDwarfLineEntryCollection &LineEntries)
Definition MCDwarf.cpp:171
LLVM_ABI 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:632
LLVM_ABI void emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params, std::optional< MCDwarfLineStr > &LineStr) const
Definition MCDwarf.cpp:618
Instances of this class represent the information from a dwarf .loc directive.
Definition MCDwarf.h:107
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
static LLVM_ABI void Emit(MCStreamer *MCOS)
Definition MCDwarf.cpp:1204
MCGenDwarfLabelEntry(StringRef name, unsigned fileNumber, unsigned lineNumber, MCSymbol *label)
Definition MCDwarf.h:497
static LLVM_ABI void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
Definition MCDwarf.cpp:1267
LLVM_ABI void addEndEntry(MCSymbol *EndLabel)
Definition MCDwarf.cpp:132
void addLineEntry(const MCDwarfLineEntry &LineEntry, MCSection *Sec)
Definition MCDwarf.h:244
std::vector< MCDwarfLineEntry > MCDwarfLineEntryCollection
Definition MCDwarf.h:252
MCSection * getDwarfRangesSection() const
bool getSupportsCompactUnwindWithoutEHFrame() const
MCSection * getDwarfLineStrSection() const
unsigned getCompactUnwindDwarfEHFrameOnly() const
MCSection * getDwarfRnglistsSection() const
MCSection * getDwarfLineSection() const
MCSection * getDwarfInfoSection() const
MCSection * getDwarfFrameSection() const
unsigned getFDEEncoding() const
MCSection * getDwarfAbbrevSection() const
bool getOmitDwarfIfHaveCompactUnwind() const
MCSection * getDwarfARangesSection() const
MCSection * getCompactUnwindSection() const
Streaming object file generation interface.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:580
MCSymbol * getBeginSymbol()
Definition MCSection.h:653
Streaming machine code generation interface.
Definition MCStreamer.h:222
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void emitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
virtual void emitDwarfUnitLength(uint64_t Length, const Twine &Comment)
Emit a unit length field.
void emitSymbolValue(const MCSymbol *Sym, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
MCContext & getContext() const
Definition MCStreamer.h:326
virtual void AddComment(const Twine &T, bool EOL=true)
Add a textual comment.
Definition MCStreamer.h:404
void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
virtual void emitDwarfLineStartLabel(MCSymbol *StartSym)
Emit the debug line start label.
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
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.
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...
void emitInt16(uint64_t Value)
Definition MCStreamer.h:768
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
virtual void emitULEB128Value(const MCExpr *Value)
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
void emitInt32(uint64_t Value)
Definition MCStreamer.h:769
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Definition MCStreamer.h:433
MCSection * getCurrentSectionOnly() const
Definition MCStreamer.h:438
virtual void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel, MCSymbol *EndLabel=nullptr)
Emit the debug line end entry.
void emitInt8(uint64_t Value)
Definition MCStreamer.h:767
void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
void emitDwarfSectionOffset(const MCSymbol *Sym, uint64_t Offset, unsigned Size)
Emit the offset of Sym + Offset from the start of its DWARF section as a section-relative relocation.
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:213
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition MCSymbol.h:251
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Represents a location in source code.
Definition SMLoc.h:22
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition SourceMgr.h:34
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:589
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an SmallVector or SmallString.
#define INT64_MAX
Definition DataTypes.h:71
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const uint32_t DW_CIE_ID
Special ID values that distinguish a CIE from a FDE in DWARF CFI.
Definition Dwarf.h:98
uint8_t getUnitLengthFieldByteSize(DwarfFormat Format)
Get the byte size of the unit length field depending on the DWARF format.
Definition Dwarf.h:1250
const uint64_t DW64_CIE_ID
Definition Dwarf.h:99
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition Dwarf.h:93
@ DWARF64
Definition Dwarf.h:93
@ DWARF32
Definition Dwarf.h:93
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
Definition Dwarf.h:1208
@ DW_CHILDREN_no
Definition Dwarf.h:968
@ DW_EH_PE_signed
Definition Dwarf.h:981
@ DW_CHILDREN_yes
Definition Dwarf.h:969
@ DW_EH_PE_sdata4
Definition Dwarf.h:979
@ DW_EH_PE_udata2
Definition Dwarf.h:974
@ DW_EH_PE_sdata8
Definition Dwarf.h:980
@ DW_EH_PE_absptr
Definition Dwarf.h:971
@ DW_EH_PE_sdata2
Definition Dwarf.h:978
@ DW_EH_PE_udata4
Definition Dwarf.h:975
@ DW_EH_PE_udata8
Definition Dwarf.h:976
@ DW_LENGTH_DWARF64
Indicator of 64-bit DWARF format.
Definition Dwarf.h:57
LLVM_ABI MCSymbol * emitListsTableHeaderStart(MCStreamer &S)
Definition MCDwarf.cpp:44
NodeAddr< InstrNode * > Instr
Definition RDFGraph.h:389
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition Endian.h:82
LLVM_ABI StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
Definition Path.cpp:626
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
Definition Path.cpp:478
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
Definition Path.cpp:594
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
@ Length
Definition DWP.cpp:577
bool operator<(int64_t V1, const APSInt &V2)
Definition APSInt.h:360
void stable_sort(R &&Range)
Definition STLExtras.h:2132
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:1781
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:1685
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2139
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition MathExtras.h:244
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
LLVM_ABI SourceMgr SrcMgr
Definition Error.cpp:24
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition STLExtras.h:1986
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:102
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
@ Other
Any other memory.
Definition ModRef.h:68
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition LEB128.cpp:19
ArrayRef(const T &OneElt) -> ArrayRef< T >
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
Definition iterator.h:368
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:79
void appendLEB128(SmallVectorImpl< U > &Buffer, T Value)
Definition LEB128.h:280
constexpr decltype(auto) makeVisitor(CallableTs &&...Callables)
Returns an opaquely-typed Callable object whose operator() overload set is the sum of the operator() ...
Definition STLExtras.h:1535
endianness
Definition bit.h:71
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Held in ExtraFields when OpLLVMSetRAState.
Definition MCDwarf.h:602
Held in ExtraFields when OpLLVMRegisterPair.
Definition MCDwarf.h:570
Held in ExtraFields when OpLLVMVectorOffset.
Definition MCDwarf.h:586
Held in ExtraFields when OpLLVMVectorRegisterMask.
Definition MCDwarf.h:594
Held in ExtraFields when OpLLVMVectorRegisters.
Definition MCDwarf.h:581
std::vector< VectorRegisterWithLane > VectorRegisters
Definition MCDwarf.h:583
Instances of this class represent the name of the dwarf .file directive and its associated dwarf file...
Definition MCDwarf.h:89
std::optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
Definition MCDwarf.h:98
std::string Name
Definition MCDwarf.h:91
const MCSymbol * Personality
Definition MCDwarf.h:907
unsigned PersonalityEncoding
Definition MCDwarf.h:912
uint64_t CompactUnwindEncoding
Definition MCDwarf.h:914
std::vector< MCCFIInstruction > Instructions
Definition MCDwarf.h:909
const MCSymbol * Lsda
Definition MCDwarf.h:908
void trackMD5Usage(bool MD5Used)
Definition MCDwarf.h:314
SmallVector< MCDwarfFile, 3 > MCDwarfFiles
Definition MCDwarf.h:284
SmallVector< std::string, 3 > MCDwarfDirs
Definition MCDwarf.h:283
LLVM_ABI std::pair< MCSymbol *, MCSymbol * > Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, std::optional< MCDwarfLineStr > &LineStr) const
Definition MCDwarf.cpp:352
StringMap< unsigned > SourceIdMap
Definition MCDwarf.h:285
LLVM_ABI 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:649
uint8_t DWARF2LineOpcodeBase
First special line opcode - leave room for the standard opcodes.
Definition MCDwarf.h:273
uint8_t DWARF2LineRange
Range of line offsets in a special line info. opcode.
Definition MCDwarf.h:278
int8_t DWARF2LineBase
Minimum line offset in a special line info.
Definition MCDwarf.h:276