LLVM 17.0.0git
DWARFStreamer.cpp
Go to the documentation of this file.
1//===- DwarfStreamer.cpp --------------------------------------------------===//
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
16#include "llvm/MC/MCDwarf.h"
18#include "llvm/MC/MCSection.h"
19#include "llvm/MC/MCStreamer.h"
25#include "llvm/Support/LEB128.h"
28
29namespace llvm {
30
32 StringRef Swift5ReflectionSegmentName) {
33 std::string ErrorStr;
34 std::string TripleName;
35 StringRef Context = "dwarf streamer init";
36
37 // Get the target.
38 const Target *TheTarget =
39 TargetRegistry::lookupTarget(TripleName, TheTriple, ErrorStr);
40 if (!TheTarget)
41 return error(ErrorStr, Context), false;
42 TripleName = TheTriple.getTriple();
43
44 // Create all the MC Objects.
45 MRI.reset(TheTarget->createMCRegInfo(TripleName));
46 if (!MRI)
47 return error(Twine("no register info for target ") + TripleName, Context),
48 false;
49
51 MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
52 if (!MAI)
53 return error("no asm info for target " + TripleName, Context), false;
54
55 MSTI.reset(TheTarget->createMCSubtargetInfo(TripleName, "", ""));
56 if (!MSTI)
57 return error("no subtarget info for target " + TripleName, Context), false;
58
59 MC.reset(new MCContext(TheTriple, MAI.get(), MRI.get(), MSTI.get(), nullptr,
60 nullptr, true, Swift5ReflectionSegmentName));
61 MOFI.reset(TheTarget->createMCObjectFileInfo(*MC, /*PIC=*/false, false));
62 MC->setObjectFileInfo(MOFI.get());
63
64 MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions);
65 if (!MAB)
66 return error("no asm backend for target " + TripleName, Context), false;
67
68 MII.reset(TheTarget->createMCInstrInfo());
69 if (!MII)
70 return error("no instr info info for target " + TripleName, Context), false;
71
72 MCE = TheTarget->createMCCodeEmitter(*MII, *MC);
73 if (!MCE)
74 return error("no code emitter for target " + TripleName, Context), false;
75
76 switch (OutFileType) {
78 MIP = TheTarget->createMCInstPrinter(TheTriple, MAI->getAssemblerDialect(),
79 *MAI, *MII, *MRI);
80 MS = TheTarget->createAsmStreamer(
81 *MC, std::make_unique<formatted_raw_ostream>(OutFile), true, true, MIP,
82 std::unique_ptr<MCCodeEmitter>(MCE), std::unique_ptr<MCAsmBackend>(MAB),
83 true);
84 break;
85 }
87 MS = TheTarget->createMCObjectStreamer(
88 TheTriple, *MC, std::unique_ptr<MCAsmBackend>(MAB),
89 MAB->createObjectWriter(OutFile), std::unique_ptr<MCCodeEmitter>(MCE),
90 *MSTI, MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible,
91 /*DWARFMustBeAtTheEnd*/ false);
92 break;
93 }
94 }
95
96 if (!MS)
97 return error("no object streamer for target " + TripleName, Context), false;
98
99 // Finally create the AsmPrinter we'll use to emit the DIEs.
100 TM.reset(TheTarget->createTargetMachine(TripleName, "", "", TargetOptions(),
101 std::nullopt));
102 if (!TM)
103 return error("no target machine for target " + TripleName, Context), false;
104
105 Asm.reset(TheTarget->createAsmPrinter(*TM, std::unique_ptr<MCStreamer>(MS)));
106 if (!Asm)
107 return error("no asm printer for target " + TripleName, Context), false;
108 Asm->setDwarfUsesRelocationsAcrossSections(false);
109
110 RangesSectionSize = 0;
111 RngListsSectionSize = 0;
112 LocSectionSize = 0;
113 LocListsSectionSize = 0;
114 LineSectionSize = 0;
115 FrameSectionSize = 0;
116 DebugInfoSectionSize = 0;
117 MacInfoSectionSize = 0;
118 MacroSectionSize = 0;
119
120 return true;
121}
122
124
125void DwarfStreamer::switchToDebugInfoSection(unsigned DwarfVersion) {
126 MS->switchSection(MOFI->getDwarfInfoSection());
127 MC->setDwarfVersion(DwarfVersion);
128}
129
130/// Emit the compilation unit header for \p Unit in the debug_info section.
131///
132/// A Dwarf 4 section header is encoded as:
133/// uint32_t Unit length (omitting this field)
134/// uint16_t Version
135/// uint32_t Abbreviation table offset
136/// uint8_t Address size
137/// Leading to a total of 11 bytes.
138///
139/// A Dwarf 5 section header is encoded as:
140/// uint32_t Unit length (omitting this field)
141/// uint16_t Version
142/// uint8_t Unit type
143/// uint8_t Address size
144/// uint32_t Abbreviation table offset
145/// Leading to a total of 12 bytes.
147 unsigned DwarfVersion) {
148 switchToDebugInfoSection(DwarfVersion);
149
150 /// The start of the unit within its section.
151 Unit.setLabelBegin(Asm->createTempSymbol("cu_begin"));
152 Asm->OutStreamer->emitLabel(Unit.getLabelBegin());
153
154 // Emit size of content not including length itself. The size has already
155 // been computed in CompileUnit::computeOffsets(). Subtract 4 to that size to
156 // account for the length field.
157 Asm->emitInt32(Unit.getNextUnitOffset() - Unit.getStartOffset() - 4);
158 Asm->emitInt16(DwarfVersion);
159
160 if (DwarfVersion >= 5) {
161 Asm->emitInt8(dwarf::DW_UT_compile);
162 Asm->emitInt8(Unit.getOrigUnit().getAddressByteSize());
163 // We share one abbreviations table across all units so it's always at the
164 // start of the section.
165 Asm->emitInt32(0);
166 DebugInfoSectionSize += 12;
167 } else {
168 // We share one abbreviations table across all units so it's always at the
169 // start of the section.
170 Asm->emitInt32(0);
171 Asm->emitInt8(Unit.getOrigUnit().getAddressByteSize());
172 DebugInfoSectionSize += 11;
173 }
174
175 // Remember this CU.
176 EmittedUnits.push_back({Unit.getUniqueID(), Unit.getLabelBegin()});
177}
178
179/// Emit the \p Abbrevs array as the shared abbreviation table
180/// for the linked Dwarf file.
182 const std::vector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
183 unsigned DwarfVersion) {
184 MS->switchSection(MOFI->getDwarfAbbrevSection());
185 MC->setDwarfVersion(DwarfVersion);
186 Asm->emitDwarfAbbrevs(Abbrevs);
187}
188
189/// Recursively emit the DIE tree rooted at \p Die.
191 MS->switchSection(MOFI->getDwarfInfoSection());
192 Asm->emitDwarfDIE(Die);
193 DebugInfoSectionSize += Die.getSize();
194}
195
196/// Emit contents of section SecName From Obj.
198 MCSection *Section =
200 .Case("debug_line", MC->getObjectFileInfo()->getDwarfLineSection())
201 .Case("debug_loc", MC->getObjectFileInfo()->getDwarfLocSection())
202 .Case("debug_ranges",
203 MC->getObjectFileInfo()->getDwarfRangesSection())
204 .Case("debug_frame", MC->getObjectFileInfo()->getDwarfFrameSection())
205 .Case("debug_aranges",
206 MC->getObjectFileInfo()->getDwarfARangesSection())
207 .Case("debug_addr", MC->getObjectFileInfo()->getDwarfAddrSection())
208 .Case("debug_rnglists",
209 MC->getObjectFileInfo()->getDwarfRnglistsSection())
210 .Case("debug_loclists",
211 MC->getObjectFileInfo()->getDwarfLoclistsSection())
212 .Default(nullptr);
213
214 if (Section) {
215 MS->switchSection(Section);
216
217 MS->emitBytes(SecData);
218 }
219}
220
221/// Emit DIE containing warnings.
223 switchToDebugInfoSection(/* Version */ 2);
224 auto &Asm = getAsmPrinter();
225 Asm.emitInt32(11 + Die.getSize() - 4);
226 Asm.emitInt16(2);
227 Asm.emitInt32(0);
228 Asm.emitInt8(MC->getTargetTriple().isArch64Bit() ? 8 : 4);
229 DebugInfoSectionSize += 11;
230 emitDIE(Die);
231}
232
233/// Emit the debug_str section stored in \p Pool.
235 Asm->OutStreamer->switchSection(MOFI->getDwarfStrSection());
236 std::vector<DwarfStringPoolEntryRef> Entries = Pool.getEntriesForEmission();
237 for (auto Entry : Entries) {
238 // Emit the string itself.
239 Asm->OutStreamer->emitBytes(Entry.getString());
240 // Emit a null terminator.
241 Asm->emitInt8(0);
242 }
243
244#if 0
245 if (DwarfVersion >= 5) {
246 // Emit an empty string offset section.
247 Asm->OutStreamer->switchSection(MOFI->getDwarfStrOffSection());
248 Asm->emitDwarfUnitLength(4, "Length of String Offsets Set");
249 Asm->emitInt16(DwarfVersion);
250 Asm->emitInt16(0);
251 }
252#endif
253}
254
257 if (EmittedUnits.empty())
258 return;
259
260 // Build up data structures needed to emit this section.
261 std::vector<MCSymbol *> CompUnits;
262 DenseMap<unsigned, size_t> UniqueIdToCuMap;
263 unsigned Id = 0;
264 for (auto &CU : EmittedUnits) {
265 CompUnits.push_back(CU.LabelBegin);
266 // We might be omitting CUs, so we need to remap them.
267 UniqueIdToCuMap[CU.ID] = Id++;
268 }
269
270 Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection());
272 Asm.get(), Table, CompUnits,
273 [&UniqueIdToCuMap](const DWARF5AccelTableStaticData &Entry) {
274 return UniqueIdToCuMap[Entry.getCUIndex()];
275 });
276}
277
280 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelNamespaceSection());
281 auto *SectionBegin = Asm->createTempSymbol("namespac_begin");
282 Asm->OutStreamer->emitLabel(SectionBegin);
283 emitAppleAccelTable(Asm.get(), Table, "namespac", SectionBegin);
284}
285
288 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelNamesSection());
289 auto *SectionBegin = Asm->createTempSymbol("names_begin");
290 Asm->OutStreamer->emitLabel(SectionBegin);
291 emitAppleAccelTable(Asm.get(), Table, "names", SectionBegin);
292}
293
296 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelObjCSection());
297 auto *SectionBegin = Asm->createTempSymbol("objc_begin");
298 Asm->OutStreamer->emitLabel(SectionBegin);
299 emitAppleAccelTable(Asm.get(), Table, "objc", SectionBegin);
300}
301
304 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelTypesSection());
305 auto *SectionBegin = Asm->createTempSymbol("types_begin");
306 Asm->OutStreamer->emitLabel(SectionBegin);
307 emitAppleAccelTable(Asm.get(), Table, "types", SectionBegin);
308}
309
310/// Emit the swift_ast section stored in \p Buffers.
312 MCSection *SwiftASTSection = MOFI->getDwarfSwiftASTSection();
313 SwiftASTSection->setAlignment(Align(32));
314 MS->switchSection(SwiftASTSection);
315 MS->emitBytes(Buffer);
316}
317
320 StringRef Buffer, uint32_t Alignment, uint32_t Size) {
321 MCSection *ReflectionSection =
322 MOFI->getSwift5ReflectionSection(ReflSectionKind);
323 if (ReflectionSection == nullptr)
324 return;
325 ReflectionSection->setAlignment(Align(Alignment));
326 MS->switchSection(ReflectionSection);
327 MS->emitBytes(Buffer);
328}
329
331 const CompileUnit &Unit, const AddressRanges &LinkedRanges) {
332 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
333
334 // Make .debug_aranges to be current section.
335 MS->switchSection(MC->getObjectFileInfo()->getDwarfARangesSection());
336
337 // Emit Header.
338 MCSymbol *BeginLabel = Asm->createTempSymbol("Barange");
339 MCSymbol *EndLabel = Asm->createTempSymbol("Earange");
340
341 unsigned HeaderSize =
342 sizeof(int32_t) + // Size of contents (w/o this field
343 sizeof(int16_t) + // DWARF ARange version number
344 sizeof(int32_t) + // Offset of CU in the .debug_info section
345 sizeof(int8_t) + // Pointer Size (in bytes)
346 sizeof(int8_t); // Segment Size (in bytes)
347
348 unsigned TupleSize = AddressSize * 2;
349 unsigned Padding = offsetToAlignment(HeaderSize, Align(TupleSize));
350
351 Asm->emitLabelDifference(EndLabel, BeginLabel, 4); // Arange length
352 Asm->OutStreamer->emitLabel(BeginLabel);
353 Asm->emitInt16(dwarf::DW_ARANGES_VERSION); // Version number
354 Asm->emitInt32(Unit.getStartOffset()); // Corresponding unit's offset
355 Asm->emitInt8(AddressSize); // Address size
356 Asm->emitInt8(0); // Segment size
357
358 Asm->OutStreamer->emitFill(Padding, 0x0);
359
360 // Emit linked ranges.
361 for (const AddressRange &Range : LinkedRanges) {
362 MS->emitIntValue(Range.start(), AddressSize);
363 MS->emitIntValue(Range.end() - Range.start(), AddressSize);
364 }
365
366 // Emit terminator.
367 Asm->OutStreamer->emitIntValue(0, AddressSize);
368 Asm->OutStreamer->emitIntValue(0, AddressSize);
369 Asm->OutStreamer->emitLabel(EndLabel);
370}
371
372void DwarfStreamer::emitDwarfDebugRangesTableFragment(
373 const CompileUnit &Unit, const AddressRanges &LinkedRanges,
374 PatchLocation Patch) {
375 Patch.set(RangesSectionSize);
376
377 // Make .debug_ranges to be current section.
378 MS->switchSection(MC->getObjectFileInfo()->getDwarfRangesSection());
379 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
380
381 // Emit ranges.
382 uint64_t BaseAddress = 0;
383 if (std::optional<uint64_t> LowPC = Unit.getLowPc())
384 BaseAddress = *LowPC;
385
386 for (const AddressRange &Range : LinkedRanges) {
387 MS->emitIntValue(Range.start() - BaseAddress, AddressSize);
388 MS->emitIntValue(Range.end() - BaseAddress, AddressSize);
389
390 RangesSectionSize += AddressSize;
391 RangesSectionSize += AddressSize;
392 }
393
394 // Add the terminator entry.
395 MS->emitIntValue(0, AddressSize);
396 MS->emitIntValue(0, AddressSize);
397
398 RangesSectionSize += AddressSize;
399 RangesSectionSize += AddressSize;
400}
401
402MCSymbol *
404 if (Unit.getOrigUnit().getVersion() < 5)
405 return nullptr;
406
407 // Make .debug_rnglists to be current section.
408 MS->switchSection(MC->getObjectFileInfo()->getDwarfRnglistsSection());
409
410 MCSymbol *BeginLabel = Asm->createTempSymbol("Brnglists");
411 MCSymbol *EndLabel = Asm->createTempSymbol("Ernglists");
412 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
413
414 // Length
415 Asm->emitLabelDifference(EndLabel, BeginLabel, sizeof(uint32_t));
416 Asm->OutStreamer->emitLabel(BeginLabel);
417 RngListsSectionSize += sizeof(uint32_t);
418
419 // Version.
420 MS->emitInt16(5);
421 RngListsSectionSize += sizeof(uint16_t);
422
423 // Address size.
424 MS->emitInt8(AddressSize);
425 RngListsSectionSize++;
426
427 // Seg_size
428 MS->emitInt8(0);
429 RngListsSectionSize++;
430
431 // Offset entry count
432 MS->emitInt32(0);
433 RngListsSectionSize += sizeof(uint32_t);
434
435 return EndLabel;
436}
437
439 const CompileUnit &Unit, const AddressRanges &LinkedRanges,
440 PatchLocation Patch) {
441 if (Unit.getOrigUnit().getVersion() < 5) {
442 emitDwarfDebugRangesTableFragment(Unit, LinkedRanges, Patch);
443 return;
444 }
445
446 emitDwarfDebugRngListsTableFragment(Unit, LinkedRanges, Patch);
447}
448
450 MCSymbol *EndLabel) {
451 if (Unit.getOrigUnit().getVersion() < 5)
452 return;
453
454 // Make .debug_rnglists to be current section.
455 MS->switchSection(MC->getObjectFileInfo()->getDwarfRnglistsSection());
456
457 if (EndLabel != nullptr)
458 Asm->OutStreamer->emitLabel(EndLabel);
459}
460
461void DwarfStreamer::emitDwarfDebugRngListsTableFragment(
462 const CompileUnit &Unit, const AddressRanges &LinkedRanges,
463 PatchLocation Patch) {
464 Patch.set(RngListsSectionSize);
465
466 // Make .debug_rnglists to be current section.
467 MS->switchSection(MC->getObjectFileInfo()->getDwarfRnglistsSection());
468
469 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
470
471 for (const AddressRange &Range : LinkedRanges) {
472 // Emit type of entry.
473 MS->emitInt8(dwarf::DW_RLE_start_length);
474 RngListsSectionSize += 1;
475
476 // Emit start address.
477 MS->emitIntValue(Range.start(), AddressSize);
478 RngListsSectionSize += AddressSize;
479
480 // Emit length of the range.
481 RngListsSectionSize += MS->emitSLEB128IntValue(Range.end() - Range.start());
482 }
483
484 // Emit the terminator entry.
485 MS->emitInt8(dwarf::DW_RLE_end_of_list);
486 RngListsSectionSize += 1;
487}
488
489/// Emit debug locations(.debug_loc, .debug_loclists) header.
491 if (Unit.getOrigUnit().getVersion() < 5)
492 return nullptr;
493
494 // Make .debug_loclists the current section.
495 MS->switchSection(MC->getObjectFileInfo()->getDwarfLoclistsSection());
496
497 MCSymbol *BeginLabel = Asm->createTempSymbol("Bloclists");
498 MCSymbol *EndLabel = Asm->createTempSymbol("Eloclists");
499 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
500
501 // Length
502 Asm->emitLabelDifference(EndLabel, BeginLabel, sizeof(uint32_t));
503 Asm->OutStreamer->emitLabel(BeginLabel);
504 LocListsSectionSize += sizeof(uint32_t);
505
506 // Version.
507 MS->emitInt16(5);
508 LocListsSectionSize += sizeof(uint16_t);
509
510 // Address size.
511 MS->emitInt8(AddressSize);
512 LocListsSectionSize++;
513
514 // Seg_size
515 MS->emitInt8(0);
516 LocListsSectionSize++;
517
518 // Offset entry count
519 MS->emitInt32(0);
520 LocListsSectionSize += sizeof(uint32_t);
521
522 return EndLabel;
523}
524
525/// Emit debug locations(.debug_loc, .debug_loclists) fragment.
527 const CompileUnit &Unit,
528 const DWARFLocationExpressionsVector &LinkedLocationExpression,
529 PatchLocation Patch) {
530 if (Unit.getOrigUnit().getVersion() < 5) {
531 emitDwarfDebugLocTableFragment(Unit, LinkedLocationExpression, Patch);
532 return;
533 }
534
535 emitDwarfDebugLocListsTableFragment(Unit, LinkedLocationExpression, Patch);
536}
537
538/// Emit debug locations(.debug_loc, .debug_loclists) footer.
540 MCSymbol *EndLabel) {
541 if (Unit.getOrigUnit().getVersion() < 5)
542 return;
543
544 // Make .debug_loclists the current section.
545 MS->switchSection(MC->getObjectFileInfo()->getDwarfLoclistsSection());
546
547 if (EndLabel != nullptr)
548 Asm->OutStreamer->emitLabel(EndLabel);
549}
550
551/// Emit piece of .debug_loc for \p LinkedLocationExpression.
552void DwarfStreamer::emitDwarfDebugLocTableFragment(
553 const CompileUnit &Unit,
554 const DWARFLocationExpressionsVector &LinkedLocationExpression,
555 PatchLocation Patch) {
556 Patch.set(LocSectionSize);
557
558 // Make .debug_loc to be current section.
559 MS->switchSection(MC->getObjectFileInfo()->getDwarfLocSection());
560 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
561
562 // Emit ranges.
563 uint64_t BaseAddress = 0;
564 if (std::optional<uint64_t> LowPC = Unit.getLowPc())
565 BaseAddress = *LowPC;
566
567 for (const DWARFLocationExpression &LocExpression :
568 LinkedLocationExpression) {
569 if (LocExpression.Range) {
570 MS->emitIntValue(LocExpression.Range->LowPC - BaseAddress, AddressSize);
571 MS->emitIntValue(LocExpression.Range->HighPC - BaseAddress, AddressSize);
572
573 LocSectionSize += AddressSize;
574 LocSectionSize += AddressSize;
575 }
576
577 Asm->OutStreamer->emitIntValue(LocExpression.Expr.size(), 2);
578 Asm->OutStreamer->emitBytes(StringRef(
579 (const char *)LocExpression.Expr.data(), LocExpression.Expr.size()));
580 LocSectionSize += LocExpression.Expr.size() + 2;
581 }
582
583 // Add the terminator entry.
584 MS->emitIntValue(0, AddressSize);
585 MS->emitIntValue(0, AddressSize);
586
587 LocSectionSize += AddressSize;
588 LocSectionSize += AddressSize;
589}
590
591/// Emit piece of .debug_loclists for \p LinkedLocationExpression.
592void DwarfStreamer::emitDwarfDebugLocListsTableFragment(
593 const CompileUnit &Unit,
594 const DWARFLocationExpressionsVector &LinkedLocationExpression,
595 PatchLocation Patch) {
596 Patch.set(LocListsSectionSize);
597
598 // Make .debug_loclists the current section.
599 MS->switchSection(MC->getObjectFileInfo()->getDwarfLoclistsSection());
600
601 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
602
603 for (const DWARFLocationExpression &LocExpression :
604 LinkedLocationExpression) {
605 if (LocExpression.Range) {
606 // Emit type of entry.
607 MS->emitInt8(dwarf::DW_LLE_start_length);
608 LocListsSectionSize += 1;
609
610 // Emit start address.
611 MS->emitIntValue(LocExpression.Range->LowPC, AddressSize);
612 LocListsSectionSize += AddressSize;
613
614 // Emit length of the range.
615 LocListsSectionSize += MS->emitSLEB128IntValue(
616 LocExpression.Range->HighPC - LocExpression.Range->LowPC);
617 } else {
618 // Emit type of entry.
619 MS->emitInt8(dwarf::DW_LLE_default_location);
620 LocListsSectionSize += 1;
621 }
622
623 LocListsSectionSize += MS->emitULEB128IntValue(LocExpression.Expr.size());
624 Asm->OutStreamer->emitBytes(StringRef(
625 (const char *)LocExpression.Expr.data(), LocExpression.Expr.size()));
626 LocListsSectionSize += LocExpression.Expr.size();
627 }
628
629 // Emit the terminator entry.
630 MS->emitInt8(dwarf::DW_LLE_end_of_list);
631 LocListsSectionSize += 1;
632}
633
635 StringRef PrologueBytes,
636 unsigned MinInstLength,
637 std::vector<DWARFDebugLine::Row> &Rows,
638 unsigned PointerSize) {
639 // Switch to the section where the table will be emitted into.
640 MS->switchSection(MC->getObjectFileInfo()->getDwarfLineSection());
641 MCSymbol *LineStartSym = MC->createTempSymbol();
642 MCSymbol *LineEndSym = MC->createTempSymbol();
643
644 // The first 4 bytes is the total length of the information for this
645 // compilation unit (not including these 4 bytes for the length).
646 Asm->emitLabelDifference(LineEndSym, LineStartSym, 4);
647 Asm->OutStreamer->emitLabel(LineStartSym);
648 // Copy Prologue.
649 MS->emitBytes(PrologueBytes);
650 LineSectionSize += PrologueBytes.size() + 4;
651
652 SmallString<128> EncodingBuffer;
653 raw_svector_ostream EncodingOS(EncodingBuffer);
654
655 if (Rows.empty()) {
656 // We only have the dummy entry, dsymutil emits an entry with a 0
657 // address in that case.
658 MCDwarfLineAddr::Encode(*MC, Params, std::numeric_limits<int64_t>::max(), 0,
659 EncodingOS);
660 MS->emitBytes(EncodingOS.str());
661 LineSectionSize += EncodingBuffer.size();
662 MS->emitLabel(LineEndSym);
663 return;
664 }
665
666 // Line table state machine fields
667 unsigned FileNum = 1;
668 unsigned LastLine = 1;
669 unsigned Column = 0;
670 unsigned IsStatement = 1;
671 unsigned Isa = 0;
672 uint64_t Address = -1ULL;
673
674 unsigned RowsSinceLastSequence = 0;
675
676 for (DWARFDebugLine::Row &Row : Rows) {
677 int64_t AddressDelta;
678 if (Address == -1ULL) {
679 MS->emitIntValue(dwarf::DW_LNS_extended_op, 1);
680 MS->emitULEB128IntValue(PointerSize + 1);
681 MS->emitIntValue(dwarf::DW_LNE_set_address, 1);
682 MS->emitIntValue(Row.Address.Address, PointerSize);
683 LineSectionSize += 2 + PointerSize + getULEB128Size(PointerSize + 1);
684 AddressDelta = 0;
685 } else {
686 AddressDelta = (Row.Address.Address - Address) / MinInstLength;
687 }
688
689 // FIXME: code copied and transformed from MCDwarf.cpp::EmitDwarfLineTable.
690 // We should find a way to share this code, but the current compatibility
691 // requirement with classic dsymutil makes it hard. Revisit that once this
692 // requirement is dropped.
693
694 if (FileNum != Row.File) {
695 FileNum = Row.File;
696 MS->emitIntValue(dwarf::DW_LNS_set_file, 1);
697 MS->emitULEB128IntValue(FileNum);
698 LineSectionSize += 1 + getULEB128Size(FileNum);
699 }
700 if (Column != Row.Column) {
701 Column = Row.Column;
702 MS->emitIntValue(dwarf::DW_LNS_set_column, 1);
703 MS->emitULEB128IntValue(Column);
704 LineSectionSize += 1 + getULEB128Size(Column);
705 }
706
707 // FIXME: We should handle the discriminator here, but dsymutil doesn't
708 // consider it, thus ignore it for now.
709
710 if (Isa != Row.Isa) {
711 Isa = Row.Isa;
712 MS->emitIntValue(dwarf::DW_LNS_set_isa, 1);
713 MS->emitULEB128IntValue(Isa);
714 LineSectionSize += 1 + getULEB128Size(Isa);
715 }
716 if (IsStatement != Row.IsStmt) {
717 IsStatement = Row.IsStmt;
718 MS->emitIntValue(dwarf::DW_LNS_negate_stmt, 1);
719 LineSectionSize += 1;
720 }
721 if (Row.BasicBlock) {
722 MS->emitIntValue(dwarf::DW_LNS_set_basic_block, 1);
723 LineSectionSize += 1;
724 }
725
726 if (Row.PrologueEnd) {
727 MS->emitIntValue(dwarf::DW_LNS_set_prologue_end, 1);
728 LineSectionSize += 1;
729 }
730
731 if (Row.EpilogueBegin) {
732 MS->emitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1);
733 LineSectionSize += 1;
734 }
735
736 int64_t LineDelta = int64_t(Row.Line) - LastLine;
737 if (!Row.EndSequence) {
738 MCDwarfLineAddr::Encode(*MC, Params, LineDelta, AddressDelta, EncodingOS);
739 MS->emitBytes(EncodingOS.str());
740 LineSectionSize += EncodingBuffer.size();
741 EncodingBuffer.resize(0);
742 Address = Row.Address.Address;
743 LastLine = Row.Line;
744 RowsSinceLastSequence++;
745 } else {
746 if (LineDelta) {
747 MS->emitIntValue(dwarf::DW_LNS_advance_line, 1);
748 MS->emitSLEB128IntValue(LineDelta);
749 LineSectionSize += 1 + getSLEB128Size(LineDelta);
750 }
751 if (AddressDelta) {
752 MS->emitIntValue(dwarf::DW_LNS_advance_pc, 1);
754 LineSectionSize += 1 + getULEB128Size(AddressDelta);
755 }
756 MCDwarfLineAddr::Encode(*MC, Params, std::numeric_limits<int64_t>::max(),
757 0, EncodingOS);
758 MS->emitBytes(EncodingOS.str());
759 LineSectionSize += EncodingBuffer.size();
760 EncodingBuffer.resize(0);
761 Address = -1ULL;
762 LastLine = FileNum = IsStatement = 1;
763 RowsSinceLastSequence = Column = Isa = 0;
764 }
765 }
766
767 if (RowsSinceLastSequence) {
768 MCDwarfLineAddr::Encode(*MC, Params, std::numeric_limits<int64_t>::max(), 0,
769 EncodingOS);
770 MS->emitBytes(EncodingOS.str());
771 LineSectionSize += EncodingBuffer.size();
772 EncodingBuffer.resize(0);
773 }
774
775 MS->emitLabel(LineEndSym);
776}
777
778/// Copy the debug_line over to the updated binary while unobfuscating the file
779/// names and directories.
781 MS->switchSection(MC->getObjectFileInfo()->getDwarfLineSection());
782 StringRef Contents = Data.getData();
783
784 // We have to deconstruct the line table header, because it contains to
785 // length fields that will need to be updated when we change the length of
786 // the files and directories in there.
787 unsigned UnitLength = Data.getU32(&Offset);
788 uint64_t UnitEnd = Offset + UnitLength;
789 MCSymbol *BeginLabel = MC->createTempSymbol();
790 MCSymbol *EndLabel = MC->createTempSymbol();
791 unsigned Version = Data.getU16(&Offset);
792
793 if (Version > 5) {
794 warn("Unsupported line table version: dropping contents and not "
795 "unobfsucating line table.");
796 return;
797 }
798
799 Asm->emitLabelDifference(EndLabel, BeginLabel, 4);
800 Asm->OutStreamer->emitLabel(BeginLabel);
801 Asm->emitInt16(Version);
802 LineSectionSize += 6;
803
804 MCSymbol *HeaderBeginLabel = MC->createTempSymbol();
805 MCSymbol *HeaderEndLabel = MC->createTempSymbol();
806 Asm->emitLabelDifference(HeaderEndLabel, HeaderBeginLabel, 4);
807 Asm->OutStreamer->emitLabel(HeaderBeginLabel);
808 Offset += 4;
809 LineSectionSize += 4;
810
811 uint64_t AfterHeaderLengthOffset = Offset;
812 // Skip to the directories.
813 Offset += (Version >= 4) ? 5 : 4;
814 unsigned OpcodeBase = Data.getU8(&Offset);
815 Offset += OpcodeBase - 1;
816 Asm->OutStreamer->emitBytes(Contents.slice(AfterHeaderLengthOffset, Offset));
817 LineSectionSize += Offset - AfterHeaderLengthOffset;
818
819 // Offset points to the first directory.
820 while (const char *Dir = Data.getCStr(&Offset)) {
821 if (Dir[0] == 0)
822 break;
823
824 StringRef Translated = Translator(Dir);
825 Asm->OutStreamer->emitBytes(Translated);
826 Asm->emitInt8(0);
827 LineSectionSize += Translated.size() + 1;
828 }
829 Asm->emitInt8(0);
830 LineSectionSize += 1;
831
832 while (const char *File = Data.getCStr(&Offset)) {
833 if (File[0] == 0)
834 break;
835
836 StringRef Translated = Translator(File);
837 Asm->OutStreamer->emitBytes(Translated);
838 Asm->emitInt8(0);
839 LineSectionSize += Translated.size() + 1;
840
841 uint64_t OffsetBeforeLEBs = Offset;
842 Asm->emitULEB128(Data.getULEB128(&Offset));
843 Asm->emitULEB128(Data.getULEB128(&Offset));
844 Asm->emitULEB128(Data.getULEB128(&Offset));
845 LineSectionSize += Offset - OffsetBeforeLEBs;
846 }
847 Asm->emitInt8(0);
848 LineSectionSize += 1;
849
850 Asm->OutStreamer->emitLabel(HeaderEndLabel);
851
852 // Copy the actual line table program over.
853 Asm->OutStreamer->emitBytes(Contents.slice(Offset, UnitEnd));
854 LineSectionSize += UnitEnd - Offset;
855
856 Asm->OutStreamer->emitLabel(EndLabel);
857 Offset = UnitEnd;
858}
859
860/// Emit the pubnames or pubtypes section contribution for \p
861/// Unit into \p Sec. The data is provided in \p Names.
862void DwarfStreamer::emitPubSectionForUnit(
863 MCSection *Sec, StringRef SecName, const CompileUnit &Unit,
864 const std::vector<CompileUnit::AccelInfo> &Names) {
865 if (Names.empty())
866 return;
867
868 // Start the dwarf pubnames section.
869 Asm->OutStreamer->switchSection(Sec);
870 MCSymbol *BeginLabel = Asm->createTempSymbol("pub" + SecName + "_begin");
871 MCSymbol *EndLabel = Asm->createTempSymbol("pub" + SecName + "_end");
872
873 bool HeaderEmitted = false;
874 // Emit the pubnames for this compilation unit.
875 for (const auto &Name : Names) {
876 if (Name.SkipPubSection)
877 continue;
878
879 if (!HeaderEmitted) {
880 // Emit the header.
881 Asm->emitLabelDifference(EndLabel, BeginLabel, 4); // Length
882 Asm->OutStreamer->emitLabel(BeginLabel);
883 Asm->emitInt16(dwarf::DW_PUBNAMES_VERSION); // Version
884 Asm->emitInt32(Unit.getStartOffset()); // Unit offset
885 Asm->emitInt32(Unit.getNextUnitOffset() - Unit.getStartOffset()); // Size
886 HeaderEmitted = true;
887 }
888 Asm->emitInt32(Name.Die->getOffset());
889
890 // Emit the string itself.
891 Asm->OutStreamer->emitBytes(Name.Name.getString());
892 // Emit a null terminator.
893 Asm->emitInt8(0);
894 }
895
896 if (!HeaderEmitted)
897 return;
898 Asm->emitInt32(0); // End marker.
899 Asm->OutStreamer->emitLabel(EndLabel);
900}
901
902/// Emit .debug_pubnames for \p Unit.
904 emitPubSectionForUnit(MC->getObjectFileInfo()->getDwarfPubNamesSection(),
905 "names", Unit, Unit.getPubnames());
906}
907
908/// Emit .debug_pubtypes for \p Unit.
910 emitPubSectionForUnit(MC->getObjectFileInfo()->getDwarfPubTypesSection(),
911 "types", Unit, Unit.getPubtypes());
912}
913
914/// Emit a CIE into the debug_frame section.
916 MS->switchSection(MC->getObjectFileInfo()->getDwarfFrameSection());
917
918 MS->emitBytes(CIEBytes);
919 FrameSectionSize += CIEBytes.size();
920}
921
922/// Emit a FDE into the debug_frame section. \p FDEBytes
923/// contains the FDE data without the length, CIE offset and address
924/// which will be replaced with the parameter values.
925void DwarfStreamer::emitFDE(uint32_t CIEOffset, uint32_t AddrSize,
926 uint64_t Address, StringRef FDEBytes) {
927 MS->switchSection(MC->getObjectFileInfo()->getDwarfFrameSection());
928
929 MS->emitIntValue(FDEBytes.size() + 4 + AddrSize, 4);
930 MS->emitIntValue(CIEOffset, 4);
931 MS->emitIntValue(Address, AddrSize);
932 MS->emitBytes(FDEBytes);
933 FrameSectionSize += FDEBytes.size() + 8 + AddrSize;
934}
935
937 const Offset2UnitMap &UnitMacroMap,
938 OffsetsStringPool &StringPool) {
939 assert(Context != nullptr && "Empty DWARF context");
940
941 // Check for .debug_macinfo table.
942 if (const DWARFDebugMacro *Table = Context->getDebugMacinfo()) {
943 MS->switchSection(MC->getObjectFileInfo()->getDwarfMacinfoSection());
944 emitMacroTableImpl(Table, UnitMacroMap, StringPool, MacInfoSectionSize);
945 }
946
947 // Check for .debug_macro table.
948 if (const DWARFDebugMacro *Table = Context->getDebugMacro()) {
949 MS->switchSection(MC->getObjectFileInfo()->getDwarfMacroSection());
950 emitMacroTableImpl(Table, UnitMacroMap, StringPool, MacroSectionSize);
951 }
952}
953
954void DwarfStreamer::emitMacroTableImpl(const DWARFDebugMacro *MacroTable,
955 const Offset2UnitMap &UnitMacroMap,
956 OffsetsStringPool &StringPool,
957 uint64_t &OutOffset) {
958 bool DefAttributeIsReported = false;
959 bool UndefAttributeIsReported = false;
960 bool ImportAttributeIsReported = false;
961 for (const DWARFDebugMacro::MacroList &List : MacroTable->MacroLists) {
962 Offset2UnitMap::const_iterator UnitIt = UnitMacroMap.find(List.Offset);
963 if (UnitIt == UnitMacroMap.end()) {
964 warn(formatv(
965 "couldn`t find compile unit for the macro table with offset = {0:x}",
966 List.Offset));
967 continue;
968 }
969
970 // Skip macro table if the unit was not cloned.
971 DIE *OutputUnitDIE = UnitIt->second->getOutputUnitDIE();
972 if (OutputUnitDIE == nullptr)
973 continue;
974
975 // Update macro attribute of cloned compile unit with the proper offset to
976 // the macro table.
977 bool hasDWARFv5Header = false;
978 for (auto &V : OutputUnitDIE->values()) {
979 if (V.getAttribute() == dwarf::DW_AT_macro_info) {
980 V = DIEValue(V.getAttribute(), V.getForm(), DIEInteger(OutOffset));
981 break;
982 } else if (V.getAttribute() == dwarf::DW_AT_macros) {
983 hasDWARFv5Header = true;
984 V = DIEValue(V.getAttribute(), V.getForm(), DIEInteger(OutOffset));
985 break;
986 }
987 }
988
989 // Write DWARFv5 header.
990 if (hasDWARFv5Header) {
991 // Write header version.
992 MS->emitIntValue(List.Header.Version, sizeof(List.Header.Version));
993 OutOffset += sizeof(List.Header.Version);
994
995 uint8_t Flags = List.Header.Flags;
996
997 // Check for OPCODE_OPERANDS_TABLE.
998 if (Flags &
999 DWARFDebugMacro::HeaderFlagMask::MACRO_OPCODE_OPERANDS_TABLE) {
1000 Flags &= ~DWARFDebugMacro::HeaderFlagMask::MACRO_OPCODE_OPERANDS_TABLE;
1001 warn("opcode_operands_table is not supported yet.");
1002 }
1003
1004 // Check for DEBUG_LINE_OFFSET.
1005 std::optional<uint64_t> StmtListOffset;
1006 if (Flags & DWARFDebugMacro::HeaderFlagMask::MACRO_DEBUG_LINE_OFFSET) {
1007 // Get offset to the line table from the cloned compile unit.
1008 for (auto &V : OutputUnitDIE->values()) {
1009 if (V.getAttribute() == dwarf::DW_AT_stmt_list) {
1010 StmtListOffset = V.getDIEInteger().getValue();
1011 break;
1012 }
1013 }
1014
1015 if (!StmtListOffset) {
1016 Flags &= ~DWARFDebugMacro::HeaderFlagMask::MACRO_DEBUG_LINE_OFFSET;
1017 warn("couldn`t find line table for macro table.");
1018 }
1019 }
1020
1021 // Write flags.
1022 MS->emitIntValue(Flags, sizeof(Flags));
1023 OutOffset += sizeof(Flags);
1024
1025 // Write offset to line table.
1026 if (StmtListOffset) {
1027 MS->emitIntValue(*StmtListOffset, List.Header.getOffsetByteSize());
1028 OutOffset += List.Header.getOffsetByteSize();
1029 }
1030 }
1031
1032 // Write macro entries.
1033 for (const DWARFDebugMacro::Entry &MacroEntry : List.Macros) {
1034 if (MacroEntry.Type == 0) {
1035 OutOffset += MS->emitULEB128IntValue(MacroEntry.Type);
1036 continue;
1037 }
1038
1039 uint8_t MacroType = MacroEntry.Type;
1040 switch (MacroType) {
1041 default: {
1042 bool HasVendorSpecificExtension =
1043 (!hasDWARFv5Header && MacroType == dwarf::DW_MACINFO_vendor_ext) ||
1044 (hasDWARFv5Header && (MacroType >= dwarf::DW_MACRO_lo_user &&
1045 MacroType <= dwarf::DW_MACRO_hi_user));
1046
1047 if (HasVendorSpecificExtension) {
1048 // Write macinfo type.
1049 MS->emitIntValue(MacroType, 1);
1050 OutOffset++;
1051
1052 // Write vendor extension constant.
1053 OutOffset += MS->emitULEB128IntValue(MacroEntry.ExtConstant);
1054
1055 // Write vendor extension string.
1056 StringRef String = MacroEntry.ExtStr;
1057 MS->emitBytes(String);
1058 MS->emitIntValue(0, 1);
1059 OutOffset += String.size() + 1;
1060 } else
1061 warn("unknown macro type. skip.");
1062 } break;
1063 // debug_macro and debug_macinfo share some common encodings.
1064 // DW_MACRO_define == DW_MACINFO_define
1065 // DW_MACRO_undef == DW_MACINFO_undef
1066 // DW_MACRO_start_file == DW_MACINFO_start_file
1067 // DW_MACRO_end_file == DW_MACINFO_end_file
1068 // For readibility/uniformity we are using DW_MACRO_*.
1069 case dwarf::DW_MACRO_define:
1070 case dwarf::DW_MACRO_undef: {
1071 // Write macinfo type.
1072 MS->emitIntValue(MacroType, 1);
1073 OutOffset++;
1074
1075 // Write source line.
1076 OutOffset += MS->emitULEB128IntValue(MacroEntry.Line);
1077
1078 // Write macro string.
1079 StringRef String = MacroEntry.MacroStr;
1080 MS->emitBytes(String);
1081 MS->emitIntValue(0, 1);
1082 OutOffset += String.size() + 1;
1083 } break;
1084 case dwarf::DW_MACRO_define_strp:
1085 case dwarf::DW_MACRO_undef_strp:
1086 case dwarf::DW_MACRO_define_strx:
1087 case dwarf::DW_MACRO_undef_strx: {
1088 assert(UnitIt->second->getOrigUnit().getVersion() >= 5);
1089
1090 // DW_MACRO_*_strx forms are not supported currently.
1091 // Convert to *_strp.
1092 switch (MacroType) {
1093 case dwarf::DW_MACRO_define_strx: {
1094 MacroType = dwarf::DW_MACRO_define_strp;
1095 if (!DefAttributeIsReported) {
1096 warn("DW_MACRO_define_strx unsupported yet. Convert to "
1097 "DW_MACRO_define_strp.");
1098 DefAttributeIsReported = true;
1099 }
1100 } break;
1101 case dwarf::DW_MACRO_undef_strx: {
1102 MacroType = dwarf::DW_MACRO_undef_strp;
1103 if (!UndefAttributeIsReported) {
1104 warn("DW_MACRO_undef_strx unsupported yet. Convert to "
1105 "DW_MACRO_undef_strp.");
1106 UndefAttributeIsReported = true;
1107 }
1108 } break;
1109 default:
1110 // Nothing to do.
1111 break;
1112 }
1113
1114 // Write macinfo type.
1115 MS->emitIntValue(MacroType, 1);
1116 OutOffset++;
1117
1118 // Write source line.
1119 OutOffset += MS->emitULEB128IntValue(MacroEntry.Line);
1120
1121 // Write macro string.
1122 DwarfStringPoolEntryRef EntryRef =
1123 StringPool.getEntry(MacroEntry.MacroStr);
1124 MS->emitIntValue(EntryRef.getOffset(), List.Header.getOffsetByteSize());
1125 OutOffset += List.Header.getOffsetByteSize();
1126 break;
1127 }
1128 case dwarf::DW_MACRO_start_file: {
1129 // Write macinfo type.
1130 MS->emitIntValue(MacroType, 1);
1131 OutOffset++;
1132 // Write source line.
1133 OutOffset += MS->emitULEB128IntValue(MacroEntry.Line);
1134 // Write source file id.
1135 OutOffset += MS->emitULEB128IntValue(MacroEntry.File);
1136 } break;
1137 case dwarf::DW_MACRO_end_file: {
1138 // Write macinfo type.
1139 MS->emitIntValue(MacroType, 1);
1140 OutOffset++;
1141 } break;
1142 case dwarf::DW_MACRO_import:
1143 case dwarf::DW_MACRO_import_sup: {
1144 if (!ImportAttributeIsReported) {
1145 warn("DW_MACRO_import and DW_MACRO_import_sup are unsupported yet. "
1146 "remove.");
1147 ImportAttributeIsReported = true;
1148 }
1149 } break;
1150 }
1151 }
1152 }
1153}
1154
1155} // namespace llvm
std::string Name
uint64_t Size
LLVMContext & Context
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
#define error(X)
@ Flags
Definition: TextStubV5.cpp:93
@ Names
Definition: TextStubV5.cpp:106
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
Definition: AccelTable.h:195
A class that represents an address range.
Definition: AddressRanges.h:22
The AddressRanges class helps normalize address range collections.
Stores all information relating to a compile unit, be it in its original instance in the object file ...
A structured debug information entry.
Definition: DIE.h:744
unsigned getSize() const
Definition: DIE.h:787
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:46
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
void emitMacroTables(DWARFContext *Context, const Offset2UnitMap &UnitMacroMap, OffsetsStringPool &StringPool) override
Emit all available macro tables(DWARFv4 and DWARFv5).
void emitAppleNamespaces(AccelTable< AppleAccelTableStaticOffsetData > &Table) override
Emit Apple namespaces accelerator table.
void emitStrings(const NonRelocatableStringpool &Pool) override
Emit the string table described by Pool.
void emitAppleNames(AccelTable< AppleAccelTableStaticOffsetData > &Table) override
Emit Apple names accelerator table.
void emitDwarfDebugArangesTable(const CompileUnit &Unit, const AddressRanges &LinkedRanges) override
Emit .debug_aranges entries for Unit.
void emitPaperTrailWarningsDie(DIE &Die) override
Emit DIE containing warnings.
void emitDwarfDebugRangeListFragment(const CompileUnit &Unit, const AddressRanges &LinkedRanges, PatchLocation Patch) override
Emit debug ranges(.debug_ranges, .debug_rnglists) fragment.
void emitAppleObjc(AccelTable< AppleAccelTableStaticOffsetData > &Table) override
Emit Apple Objective-C accelerator table.
void emitDwarfDebugRangeListFooter(const CompileUnit &Unit, MCSymbol *EndLabel) override
Emit debug ranges(.debug_ranges, .debug_rnglists) footer.
void emitAppleTypes(AccelTable< AppleAccelTableStaticTypeData > &Table) override
Emit Apple type accelerator table.
void emitSectionContents(StringRef SecData, StringRef SecName) override
Emit contents of section SecName From Obj.
void finish()
Dump the file to the disk.
void emitPubNamesForUnit(const CompileUnit &Unit) override
Emit the .debug_pubnames contribution for Unit.
void translateLineTable(DataExtractor LineData, uint64_t Offset) override
Copy the debug_line over to the updated binary while unobfuscating the file names and directories.
void emitDwarfDebugLocListFragment(const CompileUnit &Unit, const DWARFLocationExpressionsVector &LinkedLocationExpression, PatchLocation Patch) override
Emit debug ranges(.debug_loc, .debug_loclists) fragment.
void emitCIE(StringRef CIEBytes) override
Emit a CIE.
void emitDIE(DIE &Die) override
Recursively emit the DIE tree rooted at Die.
AsmPrinter & getAsmPrinter() const
Definition: DWARFStreamer.h:59
void emitDwarfDebugLocListFooter(const CompileUnit &Unit, MCSymbol *EndLabel) override
Emit debug ranges(.debug_loc, .debug_loclists) footer.
void emitCompileUnitHeader(CompileUnit &Unit, unsigned DwarfVersion) override
Emit the compilation unit header for Unit in the debug_info section.
MCSymbol * emitDwarfDebugLocListHeader(const CompileUnit &Unit) override
Emit debug locations(.debug_loc, .debug_loclists) header.
void emitPubTypesForUnit(const CompileUnit &Unit) override
Emit the .debug_pubtypes contribution for Unit.
void emitAbbrevs(const std::vector< std::unique_ptr< DIEAbbrev > > &Abbrevs, unsigned DwarfVersion) override
Emit the abbreviation table Abbrevs to the debug_abbrev section.
void emitSwiftReflectionSection(llvm::binaryformat::Swift5ReflectionSectionKind ReflSectionKind, StringRef Buffer, uint32_t Alignment, uint32_t Size)
Emit the swift reflection section stored in Buffer.
MCSymbol * emitDwarfDebugRangeListHeader(const CompileUnit &Unit) override
Emit debug ranges(.debug_ranges, .debug_rnglists) header.
void emitSwiftAST(StringRef Buffer)
Emit the swift_ast section stored in Buffer.
bool init(Triple TheTriple, StringRef Swift5ReflectionSegmentName)
void switchToDebugInfoSection(unsigned DwarfVersion)
Set the current output section to debug_info and change the MC Dwarf version to DwarfVersion.
void emitLineTableForUnit(MCDwarfLineTableParams Params, StringRef PrologueBytes, unsigned MinInstLength, std::vector< DWARFDebugLine::Row > &Rows, unsigned AdddressSize) override
Emit the line table described in Rows into the debug_line section.
void emitDebugNames(AccelTable< DWARF5AccelTableStaticData > &Table) override
Emit DWARF debug names.
void emitFDE(uint32_t CIEOffset, uint32_t AddreSize, uint64_t Address, StringRef Bytes) override
Emit an FDE with data Bytes.
std::unique_ptr< MCObjectWriter > createObjectWriter(raw_pwrite_stream &OS) const
Create a new MCObjectWriter instance for use by the assembler backend to emit the final object file.
Context object for machine code objects.
Definition: MCContext.h:76
static void Encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Definition: MCDwarf.cpp:682
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
void setAlignment(Align Value)
Definition: MCSection.h:141
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:423
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
Definition: MCStreamer.cpp:134
void emitInt16(uint64_t Value)
Definition: MCStreamer.h:747
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...
Definition: MCStreamer.cpp:162
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
void emitInt32(uint64_t Value)
Definition: MCStreamer.h:748
unsigned emitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:172
void emitInt8(uint64_t Value)
Definition: MCStreamer.h:746
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
void finish(SMLoc EndLoc=SMLoc())
Finish emission of machine code.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A string table that doesn't need relocations.
std::vector< DwarfStringPoolEntryRef > getEntriesForEmission() const
Return the list of strings to be emitted.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
size_t size() const
Definition: SmallVector.h:91
void resize(size_type N)
Definition: SmallVector.h:642
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition: StringRef.h:671
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
Helper for making strong types.
Target - Wrapper for Target specific information.
MCCodeEmitter * createMCCodeEmitter(const MCInstrInfo &II, MCContext &Ctx) const
createMCCodeEmitter - Create a target specific code emitter.
MCObjectFileInfo * createMCObjectFileInfo(MCContext &Ctx, bool PIC, bool LargeCodeModel=false) const
Create a MCObjectFileInfo implementation for the specified target triple.
MCSubtargetInfo * createMCSubtargetInfo(StringRef TheTriple, StringRef CPU, StringRef Features) const
createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, bool IsVerboseAsm, bool UseDwarfDirectory, MCInstPrinter *InstPrint, std::unique_ptr< MCCodeEmitter > &&CE, std::unique_ptr< MCAsmBackend > &&TAB, bool ShowInst) const
MCAsmBackend * createMCAsmBackend(const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) const
createMCAsmBackend - Create a target specific assembly parser.
MCRegisterInfo * createMCRegInfo(StringRef TT) const
createMCRegInfo - Create a MCRegisterInfo implementation.
MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TheTriple, const MCTargetOptions &Options) const
createMCAsmInfo - Create a MCAsmInfo implementation for the specified target triple.
MCInstPrinter * createMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) const
MCStreamer * createMCObjectStreamer(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, const MCSubtargetInfo &STI, bool RelaxAll, bool IncrementalLinkerCompatible, bool DWARFMustBeAtTheEnd) const
Create a target specific MCStreamer.
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOpt::Level OL=CodeGenOpt::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
AsmPrinter * createAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer) const
createAsmPrinter - Create a target specific assembly printer pass.
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
const std::string & getTriple() const
Definition: Triple.h:417
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:672
StringRef str() const
Return a StringRef for the vector contents.
Definition: raw_ostream.h:697
Swift5ReflectionSectionKind
Definition: Swift.h:14
@ DW_MACRO_lo_user
Definition: Dwarf.h:475
@ DW_MACRO_hi_user
Definition: Dwarf.h:476
@ DW_MACINFO_vendor_ext
Definition: Dwarf.h:468
@ DW_ARANGES_VERSION
Section version number for .debug_aranges.
Definition: Dwarf.h:64
@ DW_PUBNAMES_VERSION
Section version number for .debug_pubnames.
Definition: Dwarf.h:63
MCTargetOptions InitMCTargetOptionsFromFlags()
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
std::vector< DWARFLocationExpression > DWARFLocationExpressionsVector
Represents a set of absolute location expressions.
void emitDWARF5AccelTable(AsmPrinter *Asm, AccelTable< DWARF5AccelTableData > &Contents, const DwarfDebug &DD, ArrayRef< std::unique_ptr< DwarfCompileUnit > > CUs)
Definition: AccelTable.cpp:545
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
Definition: Alignment.h:197
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition: LEB128.cpp:19
void emitAppleAccelTable(AsmPrinter *Asm, AccelTable< DataT > &Contents, StringRef Prefix, const MCSymbol *SecBegin)
Emit an Apple Accelerator Table consisting of entries in the specified AccelTable.
Definition: AccelTable.h:301
unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.
Definition: LEB128.cpp:29
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Standard .debug_line state machine structure.
Represents a single DWARF expression, whose value is location-dependent.
void set(uint64_t New) const
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.