LLVM 24.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"
19#include "llvm/MC/MCSection.h"
20#include "llvm/MC/MCStreamer.h"
25#include "llvm/Support/LEB128.h"
28
29using namespace llvm;
30using namespace dwarf_linker;
31using namespace dwarf_linker::classic;
32
34 const Triple &TheTriple, DWARFLinkerBase::OutputFileType FileType,
36 std::unique_ptr<DwarfStreamer> Streamer =
37 std::make_unique<DwarfStreamer>(FileType, OutFile, Warning);
38 if (Error Err = Streamer->init(TheTriple, "__DWARF"))
39 return std::move(Err);
40
41 return std::move(Streamer);
42}
43
45 StringRef Swift5ReflectionSegmentName) {
46 std::string ErrorStr;
47 std::string TripleName;
48
49 // Get the target.
50 const Target *TheTarget =
51 TargetRegistry::lookupTarget(TripleName, TheTriple, ErrorStr);
52 if (!TheTarget)
53 return createStringError(std::errc::invalid_argument, ErrorStr.c_str());
54
55 TripleName = TheTriple.getTriple();
56
57 // Create all the MC Objects.
58 MRI.reset(TheTarget->createMCRegInfo(TheTriple));
59 if (!MRI)
60 return createStringError(std::errc::invalid_argument,
61 "no register info for target %s",
62 TripleName.c_str());
63
65 MCOptions.AsmVerbose = true;
66 MCOptions.MCUseDwarfDirectory = MCTargetOptions::EnableDwarfDirectory;
67 MAI.reset(TheTarget->createMCAsmInfo(*MRI, TheTriple, MCOptions));
68 if (!MAI)
69 return createStringError(std::errc::invalid_argument,
70 "no asm info for target %s", TripleName.c_str());
71
72 MSTI.reset(TheTarget->createMCSubtargetInfo(TheTriple, "", ""));
73 if (!MSTI)
74 return createStringError(std::errc::invalid_argument,
75 "no subtarget info for target %s",
76 TripleName.c_str());
77
78 MC.reset(new MCContext(TheTriple, *MAI, *MRI, *MSTI, nullptr, true,
79 Swift5ReflectionSegmentName));
80 MOFI.reset(TheTarget->createMCObjectFileInfo(*MC, /*PIC=*/false, false));
81 MC->setObjectFileInfo(MOFI.get());
82
83 MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions);
84 if (!MAB)
85 return createStringError(std::errc::invalid_argument,
86 "no asm backend for target %s",
87 TripleName.c_str());
88
89 MII.reset(TheTarget->createMCInstrInfo());
90 if (!MII)
91 return createStringError(std::errc::invalid_argument,
92 "no instr info info for target %s",
93 TripleName.c_str());
94
95 MCE = TheTarget->createMCCodeEmitter(*MII, *MC);
96 if (!MCE)
97 return createStringError(std::errc::invalid_argument,
98 "no code emitter for target %s",
99 TripleName.c_str());
100
101 switch (OutFileType) {
103 std::unique_ptr<MCInstPrinter> MIP(TheTarget->createMCInstPrinter(
104 TheTriple, MAI->getAssemblerDialect(), *MAI, *MII, *MRI));
105 MS = TheTarget->createAsmStreamer(
106 *MC, std::make_unique<formatted_raw_ostream>(OutFile), std::move(MIP),
107 std::unique_ptr<MCCodeEmitter>(MCE),
108 std::unique_ptr<MCAsmBackend>(MAB));
109 break;
110 }
112 MS = TheTarget->createMCObjectStreamer(
113 TheTriple, *MC, std::unique_ptr<MCAsmBackend>(MAB),
114 MAB->createObjectWriter(OutFile), std::unique_ptr<MCCodeEmitter>(MCE),
115 *MSTI);
116 break;
117 }
118 }
119
120 if (!MS)
121 return createStringError(std::errc::invalid_argument,
122 "no object streamer for target %s",
123 TripleName.c_str());
124
125 // Finally create the AsmPrinter we'll use to emit the DIEs.
126 TM.reset(TheTarget->createTargetMachine(TheTriple, "", "", TargetOptions(),
127 std::nullopt));
128 if (!TM)
129 return createStringError(std::errc::invalid_argument,
130 "no target machine for target %s",
131 TripleName.c_str());
132
133 Asm.reset(TheTarget->createAsmPrinter(*TM, std::unique_ptr<MCStreamer>(MS)));
134 if (!Asm)
135 return createStringError(std::errc::invalid_argument,
136 "no asm printer for target %s",
137 TripleName.c_str());
138 Asm->setDwarfUsesRelocationsAcrossSections(false);
139
140 RangesSectionSize = 0;
141 RngListsSectionSize = 0;
142 LocSectionSize = 0;
143 LocListsSectionSize = 0;
144 LineSectionSize = 0;
145 FrameSectionSize = 0;
146 DebugInfoSectionSize = 0;
147 MacInfoSectionSize = 0;
148 MacroSectionSize = 0;
149
150 return Error::success();
151}
152
153void DwarfStreamer::finish() { MS->finish(); }
154
155void DwarfStreamer::switchToDebugInfoSection(unsigned DwarfVersion) {
156 MS->switchSection(MOFI->getDwarfInfoSection());
157 MC->setDwarfVersion(DwarfVersion);
158}
159
160/// Emit the compilation unit header for \p Unit in the debug_info section.
161///
162/// A Dwarf 4 section header is encoded as:
163/// uint32_t Unit length (omitting this field)
164/// uint16_t Version
165/// uint32_t Abbreviation table offset
166/// uint8_t Address size
167/// Leading to a total of 11 bytes.
168///
169/// A Dwarf 5 section header is encoded as:
170/// uint32_t Unit length (omitting this field)
171/// uint16_t Version
172/// uint8_t Unit type
173/// uint8_t Address size
174/// uint32_t Abbreviation table offset
175/// Leading to a total of 12 bytes.
177 unsigned DwarfVersion) {
178 switchToDebugInfoSection(DwarfVersion);
179
180 /// The start of the unit within its section.
181 Unit.setLabelBegin(Asm->createTempSymbol("cu_begin"));
182 Asm->OutStreamer->emitLabel(Unit.getLabelBegin());
183
184 // Emit size of content not including length itself. The size has already
185 // been computed in CompileUnit::computeOffsets(). Subtract 4 to that size to
186 // account for the length field.
187 Asm->emitInt32(Unit.getNextUnitOffset() - Unit.getStartOffset() - 4);
188 Asm->emitInt16(DwarfVersion);
189
190 if (DwarfVersion >= 5) {
191 dwarf::Tag RootTag = Unit.getOutputUnitDIE()->getTag();
192 Asm->emitInt8(RootTag == dwarf::DW_TAG_partial_unit ? dwarf::DW_UT_partial
193 : dwarf::DW_UT_compile);
194 Asm->emitInt8(Unit.getOrigUnit().getAddressByteSize());
195 // We share one abbreviations table across all units so it's always at the
196 // start of the section.
197 Asm->emitInt32(0);
198 DebugInfoSectionSize += 12;
199 } else {
200 // We share one abbreviations table across all units so it's always at the
201 // start of the section.
202 Asm->emitInt32(0);
203 Asm->emitInt8(Unit.getOrigUnit().getAddressByteSize());
204 DebugInfoSectionSize += 11;
205 }
206
207 // Remember this CU.
208 EmittedUnits.push_back({Unit.getUniqueID(), Unit.getLabelBegin()});
209}
210
211/// Emit the \p Abbrevs array as the shared abbreviation table
212/// for the linked Dwarf file.
214 const std::vector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
215 unsigned DwarfVersion) {
216 MS->switchSection(MOFI->getDwarfAbbrevSection());
217 MC->setDwarfVersion(DwarfVersion);
218 Asm->emitDwarfAbbrevs(Abbrevs);
219}
220
221/// Recursively emit the DIE tree rooted at \p Die.
223 MS->switchSection(MOFI->getDwarfInfoSection());
224 Asm->emitDwarfDIE(Die);
225 DebugInfoSectionSize += Die.getSize();
226}
227
228/// Emit contents of section SecName From Obj.
230 DebugSectionKind SecKind) {
231 if (SecData.empty())
232 return;
233
234 if (MCSection *Section = getMCSection(SecKind)) {
235 MS->switchSection(Section);
236
237 MS->emitBytes(SecData);
238 }
239}
240
241MCSection *DwarfStreamer::getMCSection(DebugSectionKind SecKind) {
242 switch (SecKind) {
244 return MC->getObjectFileInfo()->getDwarfInfoSection();
246 return MC->getObjectFileInfo()->getDwarfLineSection();
248 return MC->getObjectFileInfo()->getDwarfFrameSection();
250 return MC->getObjectFileInfo()->getDwarfRangesSection();
252 return MC->getObjectFileInfo()->getDwarfRnglistsSection();
254 return MC->getObjectFileInfo()->getDwarfLocSection();
256 return MC->getObjectFileInfo()->getDwarfLoclistsSection();
258 return MC->getObjectFileInfo()->getDwarfARangesSection();
260 return MC->getObjectFileInfo()->getDwarfAbbrevSection();
262 return MC->getObjectFileInfo()->getDwarfMacinfoSection();
264 return MC->getObjectFileInfo()->getDwarfMacroSection();
266 return MC->getObjectFileInfo()->getDwarfAddrSection();
268 return MC->getObjectFileInfo()->getDwarfStrSection();
270 return MC->getObjectFileInfo()->getDwarfLineStrSection();
272 return MC->getObjectFileInfo()->getDwarfStrOffSection();
274 return MC->getObjectFileInfo()->getDwarfPubNamesSection();
276 return MC->getObjectFileInfo()->getDwarfPubTypesSection();
278 return MC->getObjectFileInfo()->getDwarfDebugNamesSection();
280 return MC->getObjectFileInfo()->getDwarfAccelNamesSection();
282 return MC->getObjectFileInfo()->getDwarfAccelNamespaceSection();
284 return MC->getObjectFileInfo()->getDwarfAccelObjCSection();
286 return MC->getObjectFileInfo()->getDwarfAccelTypesSection();
288 llvm_unreachable("Unknown DebugSectionKind value");
289 break;
290 }
291
292 return nullptr;
293}
294
295/// Emit the debug_str section stored in \p Pool.
297 Asm->OutStreamer->switchSection(MOFI->getDwarfStrSection());
298 std::vector<DwarfStringPoolEntryRef> Entries = Pool.getEntriesForEmission();
299 for (auto Entry : Entries) {
300 // Emit the string itself.
301 Asm->OutStreamer->emitBytes(Entry.getString());
302 // Emit a null terminator.
303 Asm->emitInt8(0);
304 }
305}
306
307/// Emit the debug string offset table described by \p StringOffsets into the
308/// .debug_str_offsets table.
310 const SmallVector<uint64_t> &StringOffsets, uint16_t TargetDWARFVersion) {
311
312 if (TargetDWARFVersion < 5 || StringOffsets.empty())
313 return;
314
315 Asm->OutStreamer->switchSection(MOFI->getDwarfStrOffSection());
316
317 MCSymbol *BeginLabel = Asm->createTempSymbol("Bdebugstroff");
318 MCSymbol *EndLabel = Asm->createTempSymbol("Edebugstroff");
319
320 // Length.
321 Asm->emitLabelDifference(EndLabel, BeginLabel, sizeof(uint32_t));
322 Asm->OutStreamer->emitLabel(BeginLabel);
323 StrOffsetSectionSize += sizeof(uint32_t);
324
325 // Version.
326 MS->emitInt16(5);
327 StrOffsetSectionSize += sizeof(uint16_t);
328
329 // Padding.
330 MS->emitInt16(0);
331 StrOffsetSectionSize += sizeof(uint16_t);
332
333 for (auto Off : StringOffsets) {
334 Asm->OutStreamer->emitInt32(Off);
335 StrOffsetSectionSize += sizeof(uint32_t);
336 }
337 Asm->OutStreamer->emitLabel(EndLabel);
338}
339
340/// Emit the debug_line_str section stored in \p Pool.
342 Asm->OutStreamer->switchSection(MOFI->getDwarfLineStrSection());
343 std::vector<DwarfStringPoolEntryRef> Entries = Pool.getEntriesForEmission();
344 for (auto Entry : Entries) {
345 // Emit the string itself.
346 Asm->OutStreamer->emitBytes(Entry.getString());
347 // Emit a null terminator.
348 Asm->emitInt8(0);
349 }
350}
351
353 if (EmittedUnits.empty())
354 return;
355
356 // Build up data structures needed to emit this section.
357 std::vector<std::variant<MCSymbol *, uint64_t>> CompUnits;
358 DenseMap<unsigned, unsigned> UniqueIdToCuMap;
359 unsigned Id = 0;
360 for (auto &CU : EmittedUnits) {
361 CompUnits.push_back(CU.LabelBegin);
362 // We might be omitting CUs, so we need to remap them.
363 UniqueIdToCuMap[CU.ID] = Id++;
364 }
365
366 Asm->OutStreamer->switchSection(MOFI->getDwarfDebugNamesSection());
367 dwarf::Form Form = DIEInteger::BestForm(/*IsSigned*/ false,
368 (uint64_t)UniqueIdToCuMap.size() - 1);
369 /// llvm-dwarfutil doesn't support type units + .debug_names right now.
370 // FIXME: add support for type units + .debug_names. For now the behavior is
371 // unsuported.
373 Asm.get(), Table, CompUnits,
374 [&](const DWARF5AccelTableData &Entry)
375 -> std::optional<DWARF5AccelTable::UnitIndexAndEncoding> {
376 if (UniqueIdToCuMap.size() > 1)
377 return {{UniqueIdToCuMap[Entry.getUnitID()],
378 {dwarf::DW_IDX_compile_unit, Form}}};
379 return std::nullopt;
380 });
381}
382
385 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelNamespaceSection());
386 auto *SectionBegin = Asm->createTempSymbol("namespac_begin");
387 Asm->OutStreamer->emitLabel(SectionBegin);
388 emitAppleAccelTable(Asm.get(), Table, "namespac", SectionBegin);
389}
390
393 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelNamesSection());
394 auto *SectionBegin = Asm->createTempSymbol("names_begin");
395 Asm->OutStreamer->emitLabel(SectionBegin);
396 emitAppleAccelTable(Asm.get(), Table, "names", SectionBegin);
397}
398
401 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelObjCSection());
402 auto *SectionBegin = Asm->createTempSymbol("objc_begin");
403 Asm->OutStreamer->emitLabel(SectionBegin);
404 emitAppleAccelTable(Asm.get(), Table, "objc", SectionBegin);
405}
406
409 Asm->OutStreamer->switchSection(MOFI->getDwarfAccelTypesSection());
410 auto *SectionBegin = Asm->createTempSymbol("types_begin");
411 Asm->OutStreamer->emitLabel(SectionBegin);
412 emitAppleAccelTable(Asm.get(), Table, "types", SectionBegin);
413}
414
415/// Emit the swift_ast section stored in \p Buffers.
417 MCSection *SwiftASTSection = MOFI->getDwarfSwiftASTSection();
418 SwiftASTSection->setAlignment(Align(32));
419 MS->switchSection(SwiftASTSection);
420 MS->emitBytes(Buffer);
421}
422
425 StringRef Buffer, uint32_t Alignment, uint32_t Size) {
426 MCSection *ReflectionSection =
427 MOFI->getSwift5ReflectionSection(ReflSectionKind);
428 if (ReflectionSection == nullptr)
429 return;
430 ReflectionSection->setAlignment(Align(Alignment));
431 MS->switchSection(ReflectionSection);
432 MS->emitBytes(Buffer);
433}
434
436 const CompileUnit &Unit, const AddressRanges &LinkedRanges) {
437 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
438
439 // Make .debug_aranges to be current section.
440 MS->switchSection(MC->getObjectFileInfo()->getDwarfARangesSection());
441
442 // Emit Header.
443 MCSymbol *BeginLabel = Asm->createTempSymbol("Barange");
444 MCSymbol *EndLabel = Asm->createTempSymbol("Earange");
445
446 unsigned HeaderSize =
447 sizeof(int32_t) + // Size of contents (w/o this field
448 sizeof(int16_t) + // DWARF ARange version number
449 sizeof(int32_t) + // Offset of CU in the .debug_info section
450 sizeof(int8_t) + // Pointer Size (in bytes)
451 sizeof(int8_t); // Segment Size (in bytes)
452
453 unsigned TupleSize = AddressSize * 2;
454 unsigned Padding = offsetToAlignment(HeaderSize, Align(TupleSize));
455
456 Asm->emitLabelDifference(EndLabel, BeginLabel, 4); // Arange length
457 Asm->OutStreamer->emitLabel(BeginLabel);
458 Asm->emitInt16(dwarf::DW_ARANGES_VERSION); // Version number
459 Asm->emitInt32(Unit.getStartOffset()); // Corresponding unit's offset
460 Asm->emitInt8(AddressSize); // Address size
461 Asm->emitInt8(0); // Segment size
462
463 Asm->OutStreamer->emitFill(Padding, 0x0);
464
465 // Emit linked ranges.
466 for (const AddressRange &Range : LinkedRanges) {
467 MS->emitIntValue(Range.start(), AddressSize);
468 MS->emitIntValue(Range.end() - Range.start(), AddressSize);
469 }
470
471 // Emit terminator.
472 Asm->OutStreamer->emitIntValue(0, AddressSize);
473 Asm->OutStreamer->emitIntValue(0, AddressSize);
474 Asm->OutStreamer->emitLabel(EndLabel);
475}
476
477Error DwarfStreamer::emitDwarfDebugRangesTableFragment(
478 const CompileUnit &Unit, const AddressRanges &LinkedRanges,
479 PatchLocation Patch) {
480 Expected<uint64_t> Offset = clampSecOffset(
481 RangesSectionSize, Unit.getOrigUnit().getFormParams(), ".debug_ranges");
482 if (!Offset)
483 return Offset.takeError();
484 Patch.set(*Offset);
485
486 // Make .debug_ranges to be current section.
487 MS->switchSection(MC->getObjectFileInfo()->getDwarfRangesSection());
488 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
489
490 // Emit ranges.
491 uint64_t BaseAddress = 0;
492 if (std::optional<uint64_t> LowPC = Unit.getLowPc())
493 BaseAddress = *LowPC;
494
495 for (const AddressRange &Range : LinkedRanges) {
496 MS->emitIntValue(Range.start() - BaseAddress, AddressSize);
497 MS->emitIntValue(Range.end() - BaseAddress, AddressSize);
498
499 RangesSectionSize += AddressSize;
500 RangesSectionSize += AddressSize;
501 }
502
503 // Add the terminator entry.
504 MS->emitIntValue(0, AddressSize);
505 MS->emitIntValue(0, AddressSize);
506
507 RangesSectionSize += AddressSize;
508 RangesSectionSize += AddressSize;
509 return Error::success();
510}
511
512MCSymbol *
514 if (Unit.getOrigUnit().getVersion() < 5)
515 return nullptr;
516
517 // Make .debug_rnglists to be current section.
518 MS->switchSection(MC->getObjectFileInfo()->getDwarfRnglistsSection());
519
520 MCSymbol *BeginLabel = Asm->createTempSymbol("Brnglists");
521 MCSymbol *EndLabel = Asm->createTempSymbol("Ernglists");
522 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
523
524 // Length
525 Asm->emitLabelDifference(EndLabel, BeginLabel, sizeof(uint32_t));
526 Asm->OutStreamer->emitLabel(BeginLabel);
527 RngListsSectionSize += sizeof(uint32_t);
528
529 // Version.
530 MS->emitInt16(5);
531 RngListsSectionSize += sizeof(uint16_t);
532
533 // Address size.
534 MS->emitInt8(AddressSize);
535 RngListsSectionSize++;
536
537 // Seg_size
538 MS->emitInt8(0);
539 RngListsSectionSize++;
540
541 // Offset entry count
542 MS->emitInt32(0);
543 RngListsSectionSize += sizeof(uint32_t);
544
545 return EndLabel;
546}
547
549 const CompileUnit &Unit, const AddressRanges &LinkedRanges,
550 PatchLocation Patch, DebugDieValuePool &AddrPool) {
551 if (Unit.getOrigUnit().getVersion() < 5) {
552 return emitDwarfDebugRangesTableFragment(Unit, LinkedRanges, Patch);
553 }
554
555 return emitDwarfDebugRngListsTableFragment(Unit, LinkedRanges, Patch,
556 AddrPool);
557}
558
560 MCSymbol *EndLabel) {
561 if (Unit.getOrigUnit().getVersion() < 5)
562 return;
563
564 // Make .debug_rnglists to be current section.
565 MS->switchSection(MC->getObjectFileInfo()->getDwarfRnglistsSection());
566
567 if (EndLabel != nullptr)
568 Asm->OutStreamer->emitLabel(EndLabel);
569}
570
571Error DwarfStreamer::emitDwarfDebugRngListsTableFragment(
572 const CompileUnit &Unit, const AddressRanges &LinkedRanges,
573 PatchLocation Patch, DebugDieValuePool &AddrPool) {
575 clampSecOffset(RngListsSectionSize, Unit.getOrigUnit().getFormParams(),
576 ".debug_rnglists");
577 if (!Offset)
578 return Offset.takeError();
579 Patch.set(*Offset);
580
581 // Make .debug_rnglists to be current section.
582 MS->switchSection(MC->getObjectFileInfo()->getDwarfRnglistsSection());
583 std::optional<uint64_t> BaseAddress;
584
585 for (const AddressRange &Range : LinkedRanges) {
586
587 if (!BaseAddress) {
588 BaseAddress = Range.start();
589
590 // Emit base address.
591 MS->emitInt8(dwarf::DW_RLE_base_addressx);
592 RngListsSectionSize += 1;
593 RngListsSectionSize +=
594 MS->emitULEB128IntValue(AddrPool.getValueIndex(*BaseAddress));
595 }
596
597 // Emit type of entry.
598 MS->emitInt8(dwarf::DW_RLE_offset_pair);
599 RngListsSectionSize += 1;
600
601 // Emit start offset relative to base address.
602 RngListsSectionSize +=
603 MS->emitULEB128IntValue(Range.start() - *BaseAddress);
604
605 // Emit end offset relative to base address.
606 RngListsSectionSize += MS->emitULEB128IntValue(Range.end() - *BaseAddress);
607 }
608
609 // Emit the terminator entry.
610 MS->emitInt8(dwarf::DW_RLE_end_of_list);
611 RngListsSectionSize += 1;
612 return Error::success();
613}
614
615/// Emit debug locations(.debug_loc, .debug_loclists) header.
617 if (Unit.getOrigUnit().getVersion() < 5)
618 return nullptr;
619
620 // Make .debug_loclists the current section.
621 MS->switchSection(MC->getObjectFileInfo()->getDwarfLoclistsSection());
622
623 MCSymbol *BeginLabel = Asm->createTempSymbol("Bloclists");
624 MCSymbol *EndLabel = Asm->createTempSymbol("Eloclists");
625 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
626
627 // Length
628 Asm->emitLabelDifference(EndLabel, BeginLabel, sizeof(uint32_t));
629 Asm->OutStreamer->emitLabel(BeginLabel);
630 LocListsSectionSize += sizeof(uint32_t);
631
632 // Version.
633 MS->emitInt16(5);
634 LocListsSectionSize += sizeof(uint16_t);
635
636 // Address size.
637 MS->emitInt8(AddressSize);
638 LocListsSectionSize++;
639
640 // Seg_size
641 MS->emitInt8(0);
642 LocListsSectionSize++;
643
644 // Offset entry count
645 MS->emitInt32(0);
646 LocListsSectionSize += sizeof(uint32_t);
647
648 return EndLabel;
649}
650
651/// Emit debug locations(.debug_loc, .debug_loclists) fragment.
653 const CompileUnit &Unit,
654 const DWARFLocationExpressionsVector &LinkedLocationExpression,
655 PatchLocation Patch, DebugDieValuePool &AddrPool) {
656 if (Unit.getOrigUnit().getVersion() < 5) {
657 return emitDwarfDebugLocTableFragment(Unit, LinkedLocationExpression,
658 Patch);
659 }
660
661 return emitDwarfDebugLocListsTableFragment(Unit, LinkedLocationExpression,
662 Patch, AddrPool);
663}
664
665/// Emit debug locations(.debug_loc, .debug_loclists) footer.
667 MCSymbol *EndLabel) {
668 if (Unit.getOrigUnit().getVersion() < 5)
669 return;
670
671 // Make .debug_loclists the current section.
672 MS->switchSection(MC->getObjectFileInfo()->getDwarfLoclistsSection());
673
674 if (EndLabel != nullptr)
675 Asm->OutStreamer->emitLabel(EndLabel);
676}
677
678/// Emit piece of .debug_loc for \p LinkedLocationExpression.
679Error DwarfStreamer::emitDwarfDebugLocTableFragment(
680 const CompileUnit &Unit,
681 const DWARFLocationExpressionsVector &LinkedLocationExpression,
682 PatchLocation Patch) {
683 Expected<uint64_t> Offset = clampSecOffset(
684 LocSectionSize, Unit.getOrigUnit().getFormParams(), ".debug_loc");
685 if (!Offset)
686 return Offset.takeError();
687 Patch.set(*Offset);
688
689 // Make .debug_loc to be current section.
690 MS->switchSection(MC->getObjectFileInfo()->getDwarfLocSection());
691 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
692
693 // Emit ranges.
694 uint64_t BaseAddress = 0;
695 if (std::optional<uint64_t> LowPC = Unit.getLowPc())
696 BaseAddress = *LowPC;
697
698 for (const DWARFLocationExpression &LocExpression :
699 LinkedLocationExpression) {
700 if (LocExpression.Range) {
701 MS->emitIntValue(LocExpression.Range->LowPC - BaseAddress, AddressSize);
702 MS->emitIntValue(LocExpression.Range->HighPC - BaseAddress, AddressSize);
703
704 LocSectionSize += AddressSize;
705 LocSectionSize += AddressSize;
706 }
707
708 Asm->OutStreamer->emitIntValue(LocExpression.Expr.size(), 2);
709 Asm->OutStreamer->emitBytes(StringRef(
710 (const char *)LocExpression.Expr.data(), LocExpression.Expr.size()));
711 LocSectionSize += LocExpression.Expr.size() + 2;
712 }
713
714 // Add the terminator entry.
715 MS->emitIntValue(0, AddressSize);
716 MS->emitIntValue(0, AddressSize);
717
718 LocSectionSize += AddressSize;
719 LocSectionSize += AddressSize;
720 return Error::success();
721}
722
723/// Emit .debug_addr header.
725
726 // Make .debug_addr the current section.
727 MS->switchSection(MC->getObjectFileInfo()->getDwarfAddrSection());
728
729 MCSymbol *BeginLabel = Asm->createTempSymbol("Bdebugaddr");
730 MCSymbol *EndLabel = Asm->createTempSymbol("Edebugaddr");
731 unsigned AddrSize = Unit.getOrigUnit().getAddressByteSize();
732
733 // Emit length.
734 Asm->emitLabelDifference(EndLabel, BeginLabel, sizeof(uint32_t));
735 Asm->OutStreamer->emitLabel(BeginLabel);
736 AddrSectionSize += sizeof(uint32_t);
737
738 // Emit version.
739 Asm->emitInt16(5);
740 AddrSectionSize += 2;
741
742 // Emit address size.
743 Asm->emitInt8(AddrSize);
744 AddrSectionSize += 1;
745
746 // Emit segment size.
747 Asm->emitInt8(0);
748 AddrSectionSize += 1;
749
750 return EndLabel;
751}
752
753/// Emit the .debug_addr addresses stored in \p Addrs.
755 uint8_t AddrSize) {
756 Asm->OutStreamer->switchSection(MOFI->getDwarfAddrSection());
757 for (auto Addr : Addrs) {
758 Asm->OutStreamer->emitIntValue(Addr, AddrSize);
759 AddrSectionSize += AddrSize;
760 }
761}
762
763/// Emit .debug_addr footer.
765 MCSymbol *EndLabel) {
766
767 // Make .debug_addr the current section.
768 MS->switchSection(MC->getObjectFileInfo()->getDwarfAddrSection());
769
770 if (EndLabel != nullptr)
771 Asm->OutStreamer->emitLabel(EndLabel);
772}
773
774/// Emit piece of .debug_loclists for \p LinkedLocationExpression.
775Error DwarfStreamer::emitDwarfDebugLocListsTableFragment(
776 const CompileUnit &Unit,
777 const DWARFLocationExpressionsVector &LinkedLocationExpression,
778 PatchLocation Patch, DebugDieValuePool &AddrPool) {
780 clampSecOffset(LocListsSectionSize, Unit.getOrigUnit().getFormParams(),
781 ".debug_loclists");
782 if (!Offset)
783 return Offset.takeError();
784 Patch.set(*Offset);
785
786 // Make .debug_loclists the current section.
787 MS->switchSection(MC->getObjectFileInfo()->getDwarfLoclistsSection());
788 std::optional<uint64_t> BaseAddress;
789
790 for (const DWARFLocationExpression &LocExpression :
791 LinkedLocationExpression) {
792 if (LocExpression.Range) {
793
794 if (!BaseAddress) {
795
796 BaseAddress = LocExpression.Range->LowPC;
797
798 // Emit base address.
799 MS->emitInt8(dwarf::DW_LLE_base_addressx);
800 LocListsSectionSize += 1;
801 LocListsSectionSize +=
802 MS->emitULEB128IntValue(AddrPool.getValueIndex(*BaseAddress));
803 }
804
805 // Emit type of entry.
806 MS->emitInt8(dwarf::DW_LLE_offset_pair);
807 LocListsSectionSize += 1;
808
809 // Emit start offset relative to base address.
810 LocListsSectionSize +=
811 MS->emitULEB128IntValue(LocExpression.Range->LowPC - *BaseAddress);
812
813 // Emit end offset relative to base address.
814 LocListsSectionSize +=
815 MS->emitULEB128IntValue(LocExpression.Range->HighPC - *BaseAddress);
816 } else {
817 // Emit type of entry.
818 MS->emitInt8(dwarf::DW_LLE_default_location);
819 LocListsSectionSize += 1;
820 }
821
822 LocListsSectionSize += MS->emitULEB128IntValue(LocExpression.Expr.size());
823 Asm->OutStreamer->emitBytes(StringRef(
824 (const char *)LocExpression.Expr.data(), LocExpression.Expr.size()));
825 LocListsSectionSize += LocExpression.Expr.size();
826 }
827
828 // Emit the terminator entry.
829 MS->emitInt8(dwarf::DW_LLE_end_of_list);
830 LocListsSectionSize += 1;
831 return Error::success();
832}
833
835 const DWARFDebugLine::LineTable &LineTable, const CompileUnit &Unit,
836 OffsetsStringPool &DebugStrPool, OffsetsStringPool &DebugLineStrPool,
837 std::vector<uint64_t> *RowOffsets) {
838 // Switch to the section where the table will be emitted into.
839 MS->switchSection(MC->getObjectFileInfo()->getDwarfLineSection());
840
841 MCSymbol *LineStartSym = MC->createTempSymbol();
842 MCSymbol *LineEndSym = MC->createTempSymbol();
843
844 // unit_length.
846 MS->emitInt32(dwarf::DW_LENGTH_DWARF64);
847 LineSectionSize += 4;
848 }
849 emitLabelDifference(LineEndSym, LineStartSym,
850 LineTable.Prologue.FormParams.Format, LineSectionSize);
851 Asm->OutStreamer->emitLabel(LineStartSym);
852
853 // Emit prologue.
854 emitLineTablePrologue(LineTable.Prologue, DebugStrPool, DebugLineStrPool);
855
856 // Emit rows.
857 emitLineTableRows(LineTable, LineEndSym,
858 Unit.getOrigUnit().getAddressByteSize(), RowOffsets);
859}
860
861void DwarfStreamer::emitLineTablePrologue(const DWARFDebugLine::Prologue &P,
862 OffsetsStringPool &DebugStrPool,
863 OffsetsStringPool &DebugLineStrPool) {
864 MCSymbol *PrologueStartSym = MC->createTempSymbol();
865 MCSymbol *PrologueEndSym = MC->createTempSymbol();
866
867 // version (uhalf).
868 MS->emitInt16(P.getVersion());
869 LineSectionSize += 2;
870 if (P.getVersion() == 5) {
871 // address_size (ubyte).
872 MS->emitInt8(P.getAddressSize());
873 LineSectionSize += 1;
874
875 // segment_selector_size (ubyte).
876 MS->emitInt8(P.SegSelectorSize);
877 LineSectionSize += 1;
878 }
879
880 // header_length.
881 emitLabelDifference(PrologueEndSym, PrologueStartSym, P.FormParams.Format,
882 LineSectionSize);
883
884 Asm->OutStreamer->emitLabel(PrologueStartSym);
885 emitLineTableProloguePayload(P, DebugStrPool, DebugLineStrPool);
886 Asm->OutStreamer->emitLabel(PrologueEndSym);
887}
888
889void DwarfStreamer::emitLineTablePrologueV2IncludeAndFileTable(
890 const DWARFDebugLine::Prologue &P, OffsetsStringPool &DebugStrPool,
891 OffsetsStringPool &DebugLineStrPool) {
892 // include_directories (sequence of path names).
893 for (const DWARFFormValue &Include : P.IncludeDirectories)
894 emitLineTableString(P, Include, DebugStrPool, DebugLineStrPool);
895 // The last entry is followed by a single null byte.
896 MS->emitInt8(0);
897 LineSectionSize += 1;
898
899 // file_names (sequence of file entries).
900 for (const DWARFDebugLine::FileNameEntry &File : P.FileNames) {
901 // A null-terminated string containing the full or relative path name of a
902 // source file.
903 emitLineTableString(P, File.Name, DebugStrPool, DebugLineStrPool);
904 // An unsigned LEB128 number representing the directory index of a directory
905 // in the include_directories section.
906 LineSectionSize += MS->emitULEB128IntValue(File.DirIdx);
907 // An unsigned LEB128 number representing the (implementation-defined) time
908 // of last modification for the file, or 0 if not available.
909 LineSectionSize += MS->emitULEB128IntValue(File.ModTime);
910 // An unsigned LEB128 number representing the length in bytes of the file,
911 // or 0 if not available.
912 LineSectionSize += MS->emitULEB128IntValue(File.Length);
913 }
914 // The last entry is followed by a single null byte.
915 MS->emitInt8(0);
916 LineSectionSize += 1;
917}
918
919void DwarfStreamer::emitLineTablePrologueV5IncludeAndFileTable(
920 const DWARFDebugLine::Prologue &P, OffsetsStringPool &DebugStrPool,
921 OffsetsStringPool &DebugLineStrPool) {
922 if (P.IncludeDirectories.empty()) {
923 // directory_entry_format_count(ubyte).
924 MS->emitInt8(0);
925 LineSectionSize += 1;
926 } else {
927 // directory_entry_format_count(ubyte).
928 MS->emitInt8(1);
929 LineSectionSize += 1;
930
931 // directory_entry_format (sequence of ULEB128 pairs).
932 LineSectionSize += MS->emitULEB128IntValue(dwarf::DW_LNCT_path);
933 LineSectionSize +=
934 MS->emitULEB128IntValue(P.IncludeDirectories[0].getForm());
935 }
936
937 // directories_count (ULEB128).
938 LineSectionSize += MS->emitULEB128IntValue(P.IncludeDirectories.size());
939 // directories (sequence of directory names).
940 for (auto Include : P.IncludeDirectories)
941 emitLineTableString(P, Include, DebugStrPool, DebugLineStrPool);
942
943 bool HasChecksums = P.ContentTypes.HasMD5;
944 bool HasInlineSources = P.ContentTypes.HasSource;
945
946 if (P.FileNames.empty()) {
947 // file_name_entry_format_count (ubyte).
948 MS->emitInt8(0);
949 LineSectionSize += 1;
950 } else {
951 // file_name_entry_format_count (ubyte).
952 MS->emitInt8(2 + (HasChecksums ? 1 : 0) + (HasInlineSources ? 1 : 0));
953 LineSectionSize += 1;
954
955 // file_name_entry_format (sequence of ULEB128 pairs).
956 auto StrForm = P.FileNames[0].Name.getForm();
957 LineSectionSize += MS->emitULEB128IntValue(dwarf::DW_LNCT_path);
958 LineSectionSize += MS->emitULEB128IntValue(StrForm);
959
960 LineSectionSize += MS->emitULEB128IntValue(dwarf::DW_LNCT_directory_index);
961 LineSectionSize += MS->emitULEB128IntValue(dwarf::DW_FORM_udata);
962
963 if (HasChecksums) {
964 LineSectionSize += MS->emitULEB128IntValue(dwarf::DW_LNCT_MD5);
965 LineSectionSize += MS->emitULEB128IntValue(dwarf::DW_FORM_data16);
966 }
967
968 if (HasInlineSources) {
969 LineSectionSize += MS->emitULEB128IntValue(dwarf::DW_LNCT_LLVM_source);
970 LineSectionSize += MS->emitULEB128IntValue(StrForm);
971 }
972 }
973
974 // file_names_count (ULEB128).
975 LineSectionSize += MS->emitULEB128IntValue(P.FileNames.size());
976
977 // file_names (sequence of file name entries).
978 for (auto File : P.FileNames) {
979 emitLineTableString(P, File.Name, DebugStrPool, DebugLineStrPool);
980 LineSectionSize += MS->emitULEB128IntValue(File.DirIdx);
981 if (HasChecksums) {
982 MS->emitBinaryData(
983 StringRef(reinterpret_cast<const char *>(File.Checksum.data()),
984 File.Checksum.size()));
985 LineSectionSize += File.Checksum.size();
986 }
987 if (HasInlineSources)
988 emitLineTableString(P, File.Source, DebugStrPool, DebugLineStrPool);
989 }
990}
991
992void DwarfStreamer::emitLineTableString(const DWARFDebugLine::Prologue &P,
993 const DWARFFormValue &String,
994 OffsetsStringPool &DebugStrPool,
995 OffsetsStringPool &DebugLineStrPool) {
996 std::optional<const char *> StringVal = dwarf::toString(String);
997 if (!StringVal) {
998 warn("Cann't read string from line table.");
999 return;
1000 }
1001
1002 switch (String.getForm()) {
1003 case dwarf::DW_FORM_string: {
1004 StringRef Str = *StringVal;
1005 Asm->OutStreamer->emitBytes(Str.data());
1006 Asm->emitInt8(0);
1007 LineSectionSize += Str.size() + 1;
1008 } break;
1009 case dwarf::DW_FORM_strp:
1010 case dwarf::DW_FORM_line_strp: {
1011 DwarfStringPoolEntryRef StringRef =
1012 String.getForm() == dwarf::DW_FORM_strp
1013 ? DebugStrPool.getEntry(*StringVal)
1014 : DebugLineStrPool.getEntry(*StringVal);
1015
1016 emitIntOffset(StringRef.getOffset(), P.FormParams.Format, LineSectionSize);
1017 } break;
1018 default:
1019 warn("Unsupported string form inside line table.");
1020 break;
1021 };
1022}
1023
1024void DwarfStreamer::emitLineTableProloguePayload(
1025 const DWARFDebugLine::Prologue &P, OffsetsStringPool &DebugStrPool,
1026 OffsetsStringPool &DebugLineStrPool) {
1027 // minimum_instruction_length (ubyte).
1028 MS->emitInt8(P.MinInstLength);
1029 LineSectionSize += 1;
1030 if (P.FormParams.Version >= 4) {
1031 // maximum_operations_per_instruction (ubyte).
1032 MS->emitInt8(P.MaxOpsPerInst);
1033 LineSectionSize += 1;
1034 }
1035 // default_is_stmt (ubyte).
1036 MS->emitInt8(P.DefaultIsStmt);
1037 LineSectionSize += 1;
1038 // line_base (sbyte).
1039 MS->emitInt8(P.LineBase);
1040 LineSectionSize += 1;
1041 // line_range (ubyte).
1042 MS->emitInt8(P.LineRange);
1043 LineSectionSize += 1;
1044 // opcode_base (ubyte).
1045 MS->emitInt8(P.OpcodeBase);
1046 LineSectionSize += 1;
1047
1048 // standard_opcode_lengths (array of ubyte).
1049 for (auto Length : P.StandardOpcodeLengths) {
1050 MS->emitInt8(Length);
1051 LineSectionSize += 1;
1052 }
1053
1054 if (P.FormParams.Version < 5)
1055 emitLineTablePrologueV2IncludeAndFileTable(P, DebugStrPool,
1056 DebugLineStrPool);
1057 else
1058 emitLineTablePrologueV5IncludeAndFileTable(P, DebugStrPool,
1059 DebugLineStrPool);
1060}
1061
1062void DwarfStreamer::emitLineTableRows(
1063 const DWARFDebugLine::LineTable &LineTable, MCSymbol *LineEndSym,
1064 unsigned AddressByteSize, std::vector<uint64_t> *RowOffsets) {
1065
1066 MCDwarfLineTableParams Params;
1067 Params.DWARF2LineOpcodeBase = LineTable.Prologue.OpcodeBase;
1068 Params.DWARF2LineBase = LineTable.Prologue.LineBase;
1069 Params.DWARF2LineRange = LineTable.Prologue.LineRange;
1070
1071 SmallString<128> EncodingBuffer;
1072
1073 if (LineTable.Rows.empty()) {
1074 // We only have the dummy entry, dsymutil emits an entry with a 0
1075 // address in that case.
1076 MCDwarfLineAddr::encode(*MC, Params, std::numeric_limits<int64_t>::max(), 0,
1077 EncodingBuffer);
1078 MS->emitBytes(EncodingBuffer);
1079 LineSectionSize += EncodingBuffer.size();
1080 MS->emitLabel(LineEndSym);
1081 return;
1082 }
1083
1084 // Line table state machine fields
1085 unsigned FileNum = 1;
1086 unsigned LastLine = 1;
1087 unsigned Column = 0;
1088 unsigned Discriminator = 0;
1089 unsigned IsStatement = 1;
1090 unsigned Isa = 0;
1091 uint64_t Address = -1ULL;
1092
1093 unsigned RowsSinceLastSequence = 0;
1094
1095 for (const DWARFDebugLine::Row &Row : LineTable.Rows) {
1096 // If we're tracking row offsets, record the current section size as the
1097 // offset of this row.
1098 if (RowOffsets)
1099 RowOffsets->push_back(LineSectionSize);
1100
1101 int64_t AddressDelta;
1102 if (Address == -1ULL) {
1103 MS->emitIntValue(dwarf::DW_LNS_extended_op, 1);
1104 MS->emitULEB128IntValue(AddressByteSize + 1);
1105 MS->emitIntValue(dwarf::DW_LNE_set_address, 1);
1106 MS->emitIntValue(Row.Address.Address, AddressByteSize);
1107 LineSectionSize +=
1108 2 + AddressByteSize + getULEB128Size(AddressByteSize + 1);
1109 AddressDelta = 0;
1110 } else {
1111 AddressDelta =
1112 (Row.Address.Address - Address) / LineTable.Prologue.MinInstLength;
1113 }
1114
1115 // FIXME: code copied and transformed from MCDwarf.cpp::EmitDwarfLineTable.
1116 // We should find a way to share this code, but the current compatibility
1117 // requirement with classic dsymutil makes it hard. Revisit that once this
1118 // requirement is dropped.
1119
1120 if (FileNum != Row.File) {
1121 FileNum = Row.File;
1122 MS->emitIntValue(dwarf::DW_LNS_set_file, 1);
1123 MS->emitULEB128IntValue(FileNum);
1124 LineSectionSize += 1 + getULEB128Size(FileNum);
1125 }
1126 if (Column != Row.Column) {
1127 Column = Row.Column;
1128 MS->emitIntValue(dwarf::DW_LNS_set_column, 1);
1129 MS->emitULEB128IntValue(Column);
1130 LineSectionSize += 1 + getULEB128Size(Column);
1131 }
1132 if (Discriminator != Row.Discriminator &&
1133 MS->getContext().getDwarfVersion() >= 4) {
1134 Discriminator = Row.Discriminator;
1135 unsigned Size = getULEB128Size(Discriminator);
1136 MS->emitIntValue(dwarf::DW_LNS_extended_op, 1);
1137 MS->emitULEB128IntValue(Size + 1);
1138 MS->emitIntValue(dwarf::DW_LNE_set_discriminator, 1);
1139 MS->emitULEB128IntValue(Discriminator);
1140 LineSectionSize += /* extended op */ 1 + getULEB128Size(Size + 1) +
1141 /* discriminator */ 1 + Size;
1142 }
1143 Discriminator = 0;
1144
1145 if (Isa != Row.Isa) {
1146 Isa = Row.Isa;
1147 MS->emitIntValue(dwarf::DW_LNS_set_isa, 1);
1148 MS->emitULEB128IntValue(Isa);
1149 LineSectionSize += 1 + getULEB128Size(Isa);
1150 }
1151 if (IsStatement != Row.IsStmt) {
1152 IsStatement = Row.IsStmt;
1153 MS->emitIntValue(dwarf::DW_LNS_negate_stmt, 1);
1154 LineSectionSize += 1;
1155 }
1156 if (Row.BasicBlock) {
1157 MS->emitIntValue(dwarf::DW_LNS_set_basic_block, 1);
1158 LineSectionSize += 1;
1159 }
1160
1161 if (Row.PrologueEnd) {
1162 MS->emitIntValue(dwarf::DW_LNS_set_prologue_end, 1);
1163 LineSectionSize += 1;
1164 }
1165
1166 if (Row.EpilogueBegin) {
1167 MS->emitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1);
1168 LineSectionSize += 1;
1169 }
1170
1171 int64_t LineDelta = int64_t(Row.Line) - LastLine;
1172 if (!Row.EndSequence) {
1173 MCDwarfLineAddr::encode(*MC, Params, LineDelta, AddressDelta,
1174 EncodingBuffer);
1175 MS->emitBytes(EncodingBuffer);
1176 LineSectionSize += EncodingBuffer.size();
1177 EncodingBuffer.resize(0);
1178 Address = Row.Address.Address;
1179 LastLine = Row.Line;
1180 RowsSinceLastSequence++;
1181 } else {
1182 if (LineDelta) {
1183 MS->emitIntValue(dwarf::DW_LNS_advance_line, 1);
1184 MS->emitSLEB128IntValue(LineDelta);
1185 LineSectionSize += 1 + getSLEB128Size(LineDelta);
1186 }
1187 if (AddressDelta) {
1188 MS->emitIntValue(dwarf::DW_LNS_advance_pc, 1);
1189 MS->emitULEB128IntValue(AddressDelta);
1190 LineSectionSize += 1 + getULEB128Size(AddressDelta);
1191 }
1192 MCDwarfLineAddr::encode(*MC, Params, std::numeric_limits<int64_t>::max(),
1193 0, EncodingBuffer);
1194 MS->emitBytes(EncodingBuffer);
1195 LineSectionSize += EncodingBuffer.size();
1196 EncodingBuffer.resize(0);
1197 Address = -1ULL;
1198 LastLine = FileNum = IsStatement = 1;
1199 RowsSinceLastSequence = Column = Discriminator = Isa = 0;
1200 }
1201 }
1202
1203 if (RowsSinceLastSequence) {
1204 MCDwarfLineAddr::encode(*MC, Params, std::numeric_limits<int64_t>::max(), 0,
1205 EncodingBuffer);
1206 MS->emitBytes(EncodingBuffer);
1207 LineSectionSize += EncodingBuffer.size();
1208 EncodingBuffer.resize(0);
1209 }
1210
1211 MS->emitLabel(LineEndSym);
1212}
1213
1214void DwarfStreamer::emitIntOffset(uint64_t Offset, dwarf::DwarfFormat Format,
1215 uint64_t &SectionSize) {
1217 MS->emitIntValue(Offset, Size);
1218 SectionSize += Size;
1219}
1220
1221void DwarfStreamer::emitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo,
1223 uint64_t &SectionSize) {
1225 Asm->emitLabelDifference(Hi, Lo, Size);
1226 SectionSize += Size;
1227}
1228
1229/// Emit the pubnames or pubtypes section contribution for \p
1230/// Unit into \p Sec. The data is provided in \p Names.
1231void DwarfStreamer::emitPubSectionForUnit(
1232 MCSection *Sec, StringRef SecName, const CompileUnit &Unit,
1233 const std::vector<CompileUnit::AccelInfo> &Names) {
1234 if (Names.empty())
1235 return;
1236
1237 // Start the dwarf pubnames section.
1238 Asm->OutStreamer->switchSection(Sec);
1239 MCSymbol *BeginLabel = Asm->createTempSymbol("pub" + SecName + "_begin");
1240 MCSymbol *EndLabel = Asm->createTempSymbol("pub" + SecName + "_end");
1241
1242 bool HeaderEmitted = false;
1243 // Emit the pubnames for this compilation unit.
1244 for (const auto &Name : Names) {
1245 if (Name.SkipPubSection)
1246 continue;
1247
1248 if (!HeaderEmitted) {
1249 // Emit the header.
1250 Asm->emitLabelDifference(EndLabel, BeginLabel, 4); // Length
1251 Asm->OutStreamer->emitLabel(BeginLabel);
1252 Asm->emitInt16(dwarf::DW_PUBNAMES_VERSION); // Version
1253 Asm->emitInt32(Unit.getStartOffset()); // Unit offset
1254 Asm->emitInt32(Unit.getNextUnitOffset() - Unit.getStartOffset()); // Size
1255 HeaderEmitted = true;
1256 }
1257 Asm->emitInt32(Name.Die->getOffset());
1258
1259 // Emit the string itself.
1260 Asm->OutStreamer->emitBytes(Name.Name.getString());
1261 // Emit a null terminator.
1262 Asm->emitInt8(0);
1263 }
1264
1265 if (!HeaderEmitted)
1266 return;
1267 Asm->emitInt32(0); // End marker.
1268 Asm->OutStreamer->emitLabel(EndLabel);
1269}
1270
1271/// Emit .debug_pubnames for \p Unit.
1273 emitPubSectionForUnit(MC->getObjectFileInfo()->getDwarfPubNamesSection(),
1274 "names", Unit, Unit.getPubnames());
1275}
1276
1277/// Emit .debug_pubtypes for \p Unit.
1279 emitPubSectionForUnit(MC->getObjectFileInfo()->getDwarfPubTypesSection(),
1280 "types", Unit, Unit.getPubtypes());
1281}
1282
1283/// Emit a CIE into the debug_frame section.
1285 MS->switchSection(MC->getObjectFileInfo()->getDwarfFrameSection());
1286
1287 MS->emitBytes(CIEBytes);
1288 FrameSectionSize += CIEBytes.size();
1289}
1290
1291/// Emit a FDE into the debug_frame section. \p FDEBytes
1292/// contains the FDE data without the length, CIE offset and address
1293/// which will be replaced with the parameter values.
1295 uint64_t Address, StringRef FDEBytes) {
1296 MS->switchSection(MC->getObjectFileInfo()->getDwarfFrameSection());
1297
1298 MS->emitIntValue(FDEBytes.size() + 4 + AddrSize, 4);
1299 MS->emitIntValue(CIEOffset, 4);
1300 MS->emitIntValue(Address, AddrSize);
1301 MS->emitBytes(FDEBytes);
1302 FrameSectionSize += FDEBytes.size() + 8 + AddrSize;
1303}
1304
1306 const Offset2UnitMap &UnitMacroMap,
1308 assert(Context != nullptr && "Empty DWARF context");
1309
1310 // Check for .debug_macinfo table.
1311 if (const DWARFDebugMacro *Table = Context->getDebugMacinfo()) {
1312 MS->switchSection(MC->getObjectFileInfo()->getDwarfMacinfoSection());
1313 emitMacroTableImpl(Table, UnitMacroMap, StringPool, MacInfoSectionSize);
1314 }
1315
1316 // Check for .debug_macro table.
1317 if (const DWARFDebugMacro *Table = Context->getDebugMacro()) {
1318 MS->switchSection(MC->getObjectFileInfo()->getDwarfMacroSection());
1319 emitMacroTableImpl(Table, UnitMacroMap, StringPool, MacroSectionSize);
1320 }
1321}
1322
1323void DwarfStreamer::emitMacroTableImpl(const DWARFDebugMacro *MacroTable,
1324 const Offset2UnitMap &UnitMacroMap,
1326 uint64_t &OutOffset) {
1327 bool DefAttributeIsReported = false;
1328 bool UndefAttributeIsReported = false;
1329 bool ImportAttributeIsReported = false;
1330 for (const DWARFDebugMacro::MacroList &List : MacroTable->MacroLists) {
1331 Offset2UnitMap::const_iterator UnitIt = UnitMacroMap.find(List.Offset);
1332 if (UnitIt == UnitMacroMap.end()) {
1333 warn(formatv(
1334 "couldn`t find compile unit for the macro table with offset = {0:x}",
1335 List.Offset));
1336 continue;
1337 }
1338
1339 // Skip macro table if the unit was not cloned.
1340 DIE *OutputUnitDIE = UnitIt->second->getOutputUnitDIE();
1341 if (OutputUnitDIE == nullptr)
1342 continue;
1343
1344 // Update macro attribute of cloned compile unit with the proper offset to
1345 // the macro table.
1346 bool hasDWARFv5Header = false;
1347 for (auto &V : OutputUnitDIE->values()) {
1348 if (V.getAttribute() == dwarf::DW_AT_macro_info) {
1349 V = DIEValue(V.getAttribute(), V.getForm(), DIEInteger(OutOffset));
1350 break;
1351 } else if (V.getAttribute() == dwarf::DW_AT_macros) {
1352 hasDWARFv5Header = true;
1353 V = DIEValue(V.getAttribute(), V.getForm(), DIEInteger(OutOffset));
1354 break;
1355 }
1356 }
1357
1358 // Write DWARFv5 header.
1359 if (hasDWARFv5Header) {
1360 // Write header version.
1361 MS->emitIntValue(List.Header.Version, sizeof(List.Header.Version));
1362 OutOffset += sizeof(List.Header.Version);
1363
1364 uint8_t Flags = List.Header.Flags;
1365
1366 // Check for OPCODE_OPERANDS_TABLE.
1367 if (Flags &
1368 DWARFDebugMacro::HeaderFlagMask::MACRO_OPCODE_OPERANDS_TABLE) {
1369 Flags &= ~DWARFDebugMacro::HeaderFlagMask::MACRO_OPCODE_OPERANDS_TABLE;
1370 warn("opcode_operands_table is not supported yet.");
1371 }
1372
1373 // Check for DEBUG_LINE_OFFSET.
1374 std::optional<uint64_t> StmtListOffset;
1375 if (Flags & DWARFDebugMacro::HeaderFlagMask::MACRO_DEBUG_LINE_OFFSET) {
1376 // Get offset to the line table from the cloned compile unit.
1377 for (auto &V : OutputUnitDIE->values()) {
1378 if (V.getAttribute() == dwarf::DW_AT_stmt_list) {
1379 StmtListOffset = V.getDIEInteger().getValue();
1380 break;
1381 }
1382 }
1383
1384 if (!StmtListOffset) {
1385 Flags &= ~DWARFDebugMacro::HeaderFlagMask::MACRO_DEBUG_LINE_OFFSET;
1386 warn("couldn`t find line table for macro table.");
1387 }
1388 }
1389
1390 // Write flags.
1391 MS->emitIntValue(Flags, sizeof(Flags));
1392 OutOffset += sizeof(Flags);
1393
1394 // Write offset to line table.
1395 if (StmtListOffset) {
1396 MS->emitIntValue(*StmtListOffset, List.Header.getOffsetByteSize());
1397 OutOffset += List.Header.getOffsetByteSize();
1398 }
1399 }
1400
1401 // Write macro entries.
1402 for (const DWARFDebugMacro::Entry &MacroEntry : List.Macros) {
1403 if (MacroEntry.Type == 0) {
1404 OutOffset += MS->emitULEB128IntValue(MacroEntry.Type);
1405 continue;
1406 }
1407
1408 uint8_t MacroType = MacroEntry.Type;
1409 switch (MacroType) {
1410 default: {
1411 bool HasVendorSpecificExtension =
1412 (!hasDWARFv5Header && MacroType == dwarf::DW_MACINFO_vendor_ext) ||
1413 (hasDWARFv5Header && (MacroType >= dwarf::DW_MACRO_lo_user &&
1414 MacroType <= dwarf::DW_MACRO_hi_user));
1415
1416 if (HasVendorSpecificExtension) {
1417 // Write macinfo type.
1418 MS->emitIntValue(MacroType, 1);
1419 OutOffset++;
1420
1421 // Write vendor extension constant.
1422 OutOffset += MS->emitULEB128IntValue(MacroEntry.ExtConstant);
1423
1424 // Write vendor extension string.
1425 StringRef String = MacroEntry.ExtStr;
1426 MS->emitBytes(String);
1427 MS->emitIntValue(0, 1);
1428 OutOffset += String.size() + 1;
1429 } else
1430 warn("unknown macro type. skip.");
1431 } break;
1432 // debug_macro and debug_macinfo share some common encodings.
1433 // DW_MACRO_define == DW_MACINFO_define
1434 // DW_MACRO_undef == DW_MACINFO_undef
1435 // DW_MACRO_start_file == DW_MACINFO_start_file
1436 // DW_MACRO_end_file == DW_MACINFO_end_file
1437 // For readibility/uniformity we are using DW_MACRO_*.
1438 case dwarf::DW_MACRO_define:
1439 case dwarf::DW_MACRO_undef: {
1440 // Write macinfo type.
1441 MS->emitIntValue(MacroType, 1);
1442 OutOffset++;
1443
1444 // Write source line.
1445 OutOffset += MS->emitULEB128IntValue(MacroEntry.Line);
1446
1447 // Write macro string.
1448 StringRef String = MacroEntry.MacroStr;
1449 MS->emitBytes(String);
1450 MS->emitIntValue(0, 1);
1451 OutOffset += String.size() + 1;
1452 } break;
1453 case dwarf::DW_MACRO_define_strp:
1454 case dwarf::DW_MACRO_undef_strp:
1455 case dwarf::DW_MACRO_define_strx:
1456 case dwarf::DW_MACRO_undef_strx: {
1457 assert(UnitIt->second->getOrigUnit().getVersion() >= 5);
1458
1459 // DW_MACRO_*_strx forms are not supported currently.
1460 // Convert to *_strp.
1461 switch (MacroType) {
1462 case dwarf::DW_MACRO_define_strx: {
1463 MacroType = dwarf::DW_MACRO_define_strp;
1464 if (!DefAttributeIsReported) {
1465 warn("DW_MACRO_define_strx unsupported yet. Convert to "
1466 "DW_MACRO_define_strp.");
1467 DefAttributeIsReported = true;
1468 }
1469 } break;
1470 case dwarf::DW_MACRO_undef_strx: {
1471 MacroType = dwarf::DW_MACRO_undef_strp;
1472 if (!UndefAttributeIsReported) {
1473 warn("DW_MACRO_undef_strx unsupported yet. Convert to "
1474 "DW_MACRO_undef_strp.");
1475 UndefAttributeIsReported = true;
1476 }
1477 } break;
1478 default:
1479 // Nothing to do.
1480 break;
1481 }
1482
1483 // Write macinfo type.
1484 MS->emitIntValue(MacroType, 1);
1485 OutOffset++;
1486
1487 // Write source line.
1488 OutOffset += MS->emitULEB128IntValue(MacroEntry.Line);
1489
1490 // Write macro string.
1491 DwarfStringPoolEntryRef EntryRef =
1492 StringPool.getEntry(MacroEntry.MacroStr);
1493 MS->emitIntValue(EntryRef.getOffset(), List.Header.getOffsetByteSize());
1494 OutOffset += List.Header.getOffsetByteSize();
1495 break;
1496 }
1497 case dwarf::DW_MACRO_start_file: {
1498 // Write macinfo type.
1499 MS->emitIntValue(MacroType, 1);
1500 OutOffset++;
1501 // Write source line.
1502 OutOffset += MS->emitULEB128IntValue(MacroEntry.Line);
1503 // Write source file id.
1504 OutOffset += MS->emitULEB128IntValue(MacroEntry.File);
1505 } break;
1506 case dwarf::DW_MACRO_end_file: {
1507 // Write macinfo type.
1508 MS->emitIntValue(MacroType, 1);
1509 OutOffset++;
1510 } break;
1511 case dwarf::DW_MACRO_import:
1512 case dwarf::DW_MACRO_import_sup: {
1513 if (!ImportAttributeIsReported) {
1514 warn("DW_MACRO_import and DW_MACRO_import_sup are unsupported yet. "
1515 "remove.");
1516 ImportAttributeIsReported = true;
1517 }
1518 } break;
1519 }
1520 }
1521 }
1522}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define P(N)
std::unique_ptr< MCStreamer > && Streamer
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
Definition AccelTable.h:203
A class that represents an address range.
The AddressRanges class helps normalize address range collections.
An integer value DIE.
Definition DIE.h:169
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
Definition DIE.h:176
value_range values()
Definition DIE.h:823
A structured debug information entry.
Definition DIE.h:835
unsigned getSize() const
Definition DIE.h:875
The Data class implementation for DWARF v5 accelerator table.
Definition AccelTable.h:286
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:767
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition DenseMap.h:680
iterator end()
Definition DenseMap.h:687
unsigned size() const
Definition DenseMap.h:718
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
Context object for machine code objects.
Definition MCContext.h:83
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:744
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:580
void setAlignment(Align Value)
Definition MCSection.h:665
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.
void emitInt16(uint64_t Value)
Definition MCStreamer.h:768
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 switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
void emitInt8(uint64_t Value)
Definition MCStreamer.h:767
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
A string table that doesn't need relocations.
LLVM_ABI DwarfStringPoolEntryRef getEntry(StringRef S)
LLVM_ABI std::vector< DwarfStringPoolEntryRef > getEntriesForEmission() const
Return the list of strings to be emitted.
void resize(size_type N)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
Target - Wrapper for Target specific information.
TargetMachine * createTargetMachine(const Triple &TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
MCRegisterInfo * createMCRegInfo(const Triple &TT) const
Create a MCRegisterInfo implementation.
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.
MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TheTriple, const MCTargetOptions &Options) const
Create a MCAsmInfo implementation for the specified target triple.
MCAsmBackend * createMCAsmBackend(const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) const
createMCAsmBackend - Create a target specific assembly parser.
LLVM_ABI MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< MCInstPrinter > IP, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB) const
LLVM_ABI 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) const
Create a target specific MCStreamer.
MCInstPrinter * createMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) const
MCSubtargetInfo * createMCSubtargetInfo(const Triple &TheTriple, StringRef CPU, StringRef Features) const
createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
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:48
const std::string & getTriple() const
Definition Triple.h:582
std::function< void( const Twine &Warning, StringRef Context, const DWARFDie *DIE)> MessageHandlerTy
Stores all information relating to a compile unit, be it in its original instance in the object file ...
Error emitDwarfDebugLocListFragment(const CompileUnit &Unit, const DWARFLocationExpressionsVector &LinkedLocationExpression, PatchLocation Patch, DebugDieValuePool &AddrPool) override
Emit debug ranges(.debug_loc, .debug_loclists) fragment.
void emitDwarfDebugAddrsFooter(const CompileUnit &Unit, MCSymbol *EndLabel) override
Emit .debug_addr footer.
void emitDwarfDebugArangesTable(const CompileUnit &Unit, const AddressRanges &LinkedRanges) override
Emit .debug_aranges entries for Unit.
void emitLineTableForUnit(const DWARFDebugLine::LineTable &LineTable, const CompileUnit &Unit, OffsetsStringPool &DebugStrPool, OffsetsStringPool &DebugLineStrPool, std::vector< uint64_t > *RowOffsets=nullptr) override
Emit .debug_line table entry for specified LineTable The optional parameter RowOffsets,...
void emitAppleTypes(AccelTable< AppleAccelTableStaticTypeData > &Table) override
Emit Apple type accelerator table.
void emitDIE(DIE &Die) override
Recursively emit the DIE tree rooted at Die.
void emitStrings(const NonRelocatableStringpool &Pool) override
Emit the string table described by Pool into .debug_str table.
static Expected< std::unique_ptr< DwarfStreamer > > createStreamer(const Triple &TheTriple, DWARFLinkerBase::OutputFileType FileType, raw_pwrite_stream &OutFile, DWARFLinkerBase::MessageHandlerTy Warning)
void emitDebugNames(DWARF5AccelTable &Table) override
Emit DWARF debug names.
void emitDwarfDebugLocListFooter(const CompileUnit &Unit, MCSymbol *EndLabel) override
Emit debug ranges(.debug_loc, .debug_loclists) footer.
MCSymbol * emitDwarfDebugAddrsHeader(const CompileUnit &Unit) override
Emit .debug_addr header.
void emitStringOffsets(const SmallVector< uint64_t > &StringOffset, uint16_t TargetDWARFVersion) override
Emit the debug string offset table described by StringOffsets into the .debug_str_offsets table.
void emitLineStrings(const NonRelocatableStringpool &Pool) override
Emit the string table described by Pool into .debug_line_str table.
Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName)
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 emitCIE(StringRef CIEBytes) override
Emit a CIE.
void emitSectionContents(StringRef SecData, DebugSectionKind SecKind) override
Emit contents of section SecName From Obj.
void emitAppleNames(AccelTable< AppleAccelTableStaticOffsetData > &Table) override
Emit Apple names accelerator table.
void finish() override
Dump the file to the disk.
void emitAbbrevs(const std::vector< std::unique_ptr< DIEAbbrev > > &Abbrevs, unsigned DwarfVersion) override
Emit the abbreviation table Abbrevs to the debug_abbrev section.
MCSymbol * emitDwarfDebugLocListHeader(const CompileUnit &Unit) override
Emit debug locations(.debug_loc, .debug_loclists) header.
void emitFDE(uint32_t CIEOffset, uint32_t AddreSize, uint64_t Address, StringRef Bytes) override
Emit an FDE with data Bytes.
void emitPubNamesForUnit(const CompileUnit &Unit) override
Emit the .debug_pubnames contribution for Unit.
void emitPubTypesForUnit(const CompileUnit &Unit) override
Emit the .debug_pubtypes contribution for Unit.
void emitDwarfDebugAddrs(const SmallVector< uint64_t > &Addrs, uint8_t AddrSize) override
Emit the addresses described by Addrs into .debug_addr table.
void emitAppleObjc(AccelTable< AppleAccelTableStaticOffsetData > &Table) override
Emit Apple Objective-C accelerator table.
void emitAppleNamespaces(AccelTable< AppleAccelTableStaticOffsetData > &Table) override
Emit Apple namespaces accelerator table.
void emitMacroTables(DWARFContext *Context, const Offset2UnitMap &UnitMacroMap, OffsetsStringPool &StringPool) override
Emit all available macro tables(DWARFv4 and DWARFv5).
void switchToDebugInfoSection(unsigned DwarfVersion)
Set the current output section to debug_info and change the MC Dwarf version to DwarfVersion.
void emitCompileUnitHeader(CompileUnit &Unit, unsigned DwarfVersion) override
Emit the compilation unit header for Unit in the debug_info section.
void emitSwiftAST(StringRef Buffer)
Emit the swift_ast section stored in Buffer.
Error emitDwarfDebugRangeListFragment(const CompileUnit &Unit, const AddressRanges &LinkedRanges, PatchLocation Patch, DebugDieValuePool &AddrPool) override
Emit debug ranges(.debug_ranges, .debug_rnglists) fragment.
void emitDwarfDebugRangeListFooter(const CompileUnit &Unit, MCSymbol *EndLabel) override
Emit debug ranges(.debug_ranges, .debug_rnglists) footer.
An abstract base class for streams implementations that also support a pwrite operation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ SectionSize
Definition COFF.h:61
Swift5ReflectionSectionKind
Definition Swift.h:14
IndexedValuesMap< uint64_t > DebugDieValuePool
Definition DWARFLinker.h:38
DenseMap< uint64_t, CompileUnit * > Offset2UnitMap
Definition DWARFLinker.h:37
DebugSectionKind
List of tracked debug tables.
@ DW_MACRO_lo_user
Definition Dwarf.h:926
@ DW_MACRO_hi_user
Definition Dwarf.h:927
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition Dwarf.h:93
@ DWARF64
Definition Dwarf.h:93
@ DW_MACINFO_vendor_ext
Definition Dwarf.h:919
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
Definition Dwarf.h:1203
@ DW_ARANGES_VERSION
Section version number for .debug_aranges.
Definition Dwarf.h:66
@ DW_PUBNAMES_VERSION
Section version number for .debug_pubnames.
Definition Dwarf.h:65
@ DW_LENGTH_DWARF64
Indicator of 64-bit DWARF format.
Definition Dwarf.h:57
LLVM_ABI MCTargetOptions InitMCTargetOptionsFromFlags()
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
@ Length
Definition DWP.cpp:577
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
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:191
LLVM_ABI 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:445
LLVM_ABI void emitDWARF5AccelTable(AsmPrinter *Asm, DWARF5AccelTable &Contents, const DwarfDebug &DD, ArrayRef< std::unique_ptr< DwarfCompileUnit > > CUs)
StrongType< NonRelocatableStringpool, OffsetsTag > OffsetsStringPool
LLVM_ABI unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.
Definition LEB128.cpp:29
std::vector< DWARFLocationExpression > DWARFLocationExpressionsVector
Represents a set of absolute location expressions.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
uint8_t MinInstLength
The size in bytes of the smallest target machine instruction.
int8_t LineBase
This parameter affects the meaning of the special opcodes. See below.
uint8_t LineRange
This parameter affects the meaning of the special opcodes. See below.
uint8_t OpcodeBase
The number assigned to the first special opcode.
dwarf::FormParams FormParams
Version, address size (starting in v5), and DWARF32/64 format; these parameters affect interpretation...
Represents a single DWARF expression, whose value is location-dependent.
uint8_t DWARF2LineOpcodeBase
First special line opcode - leave room for the standard opcodes.
Definition MCDwarf.h:270
uint8_t DWARF2LineRange
Range of line offsets in a special line info. opcode.
Definition MCDwarf.h:275
int8_t DWARF2LineBase
Minimum line offset in a special line info.
Definition MCDwarf.h:273
static LLVM_ABI const Target * lookupTarget(const Triple &TheTriple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
DwarfFormat Format
Definition Dwarf.h:1219