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