17#include "llvm/Config/config.h"
66 unsigned MinInsnLength = Context.getAsmInfo().getMinInstAlignment();
67 if (MinInsnLength == 1)
69 if (AddrDelta % MinInsnLength != 0) {
73 return AddrDelta / MinInsnLength;
77 UseRelocs = Ctx.getAsmInfo().doesDwarfUseRelocationsAcrossSections();
80 Ctx.getObjectFileInfo()->getDwarfLineStrSection();
81 assert(DwarfLineStrSection &&
"DwarfLineStrSection must not be NULL");
142 auto I = MCLineDivisions.find(Sec);
143 if (
I == MCLineDivisions.end())
146 auto &Entries =
I->second;
164 Entries.push_back(EndEntry);
179 return A.Subsection <
B.Subsection;
186 LineEntries = Sorted;
189 unsigned FileNum, LastLine, Column, Flags, Isa, Discriminator;
205 for (
auto It = LineEntries.
begin(); It != LineEntries.
end(); ++It) {
206 auto LineEntry = *It;
207 MCSymbol *CurrLabel = LineEntry.getLabel();
210 if (LineEntry.LineStreamLabel) {
212 auto *Label = CurrLabel;
213 auto NextIt = It + 1;
218 if (!Label && NextIt != LineEntries.
end()) {
219 Label = NextIt->getLabel();
225 MCOS->
emitLabel(LineEntry.LineStreamLabel, LineEntry.StreamLabelDefLoc);
229 if (LineEntry.IsEndEntry) {
236 int64_t LineDelta =
static_cast<int64_t
>(LineEntry.getLine()) - LastLine;
238 if (FileNum != LineEntry.getFileNum()) {
239 FileNum = LineEntry.getFileNum();
240 MCOS->
emitInt8(dwarf::DW_LNS_set_file);
243 if (Column != LineEntry.getColumn()) {
244 Column = LineEntry.getColumn();
245 MCOS->
emitInt8(dwarf::DW_LNS_set_column);
248 if (Discriminator != LineEntry.getDiscriminator() &&
250 Discriminator = LineEntry.getDiscriminator();
252 MCOS->
emitInt8(dwarf::DW_LNS_extended_op);
254 MCOS->
emitInt8(dwarf::DW_LNE_set_discriminator);
257 if (Isa != LineEntry.getIsa()) {
258 Isa = LineEntry.getIsa();
259 MCOS->
emitInt8(dwarf::DW_LNS_set_isa);
263 Flags = LineEntry.getFlags();
264 MCOS->
emitInt8(dwarf::DW_LNS_negate_stmt);
267 MCOS->
emitInt8(dwarf::DW_LNS_set_basic_block);
269 MCOS->
emitInt8(dwarf::DW_LNS_set_prologue_end);
271 MCOS->
emitInt8(dwarf::DW_LNS_set_epilogue_begin);
280 LastLine = LineEntry.getLine();
281 PrevLabel = CurrLabel;
282 IsAtStartSeq =
false;
300 auto *LineSym = ctx.createTempSymbol();
302 const MCDwarfLoc &DwarfLoc = ctx.getCurrentDwarfLoc();
322 if (LineTables.empty())
326 std::optional<MCDwarfLineStr> LineStr;
328 LineStr.emplace(context);
334 for (
const auto &CUIDTablePair : LineTables) {
335 CUIDTablePair.second.emitCU(MCOS, Params, LineStr);
339 LineStr->emitSection(MCOS);
344 if (!HasSplitLineTable)
346 std::optional<MCDwarfLineStr> NoLineStr(std::nullopt);
348 MCOS.
emitLabel(Header.Emit(&MCOS, Params, {}, NoLineStr).second);
351std::pair<MCSymbol *, MCSymbol *>
353 std::optional<MCDwarfLineStr> &LineStr)
const {
354 static const char StandardOpcodeLengths[] = {
368 assert(std::size(StandardOpcodeLengths) >=
370 return Emit(MCOS, Params,
378 if (!Context.getAsmInfo().doesSetDirectiveSuppressReloc())
382 MCSymbol *ABS = Context.createTempSymbol();
402 if (!LineStrings.isFinalized())
403 LineStrings.finalizeInOrder();
405 Data.resize(LineStrings.getSize());
411 return LineStrings.add(Path);
424void MCDwarfLineTableHeader::emitV2FileDirTables(
MCStreamer *MCOS)
const {
445 bool EmitMD5,
bool HasAnySource,
446 std::optional<MCDwarfLineStr> &LineStr) {
458 StringRef(
reinterpret_cast<const char *
>(Cksum.data()), Cksum.size()));
469 LineStr->emitRef(MCOS, Source);
477void MCDwarfLineTableHeader::emitV5FileDirTables(
478 MCStreamer *MCOS, std::optional<MCDwarfLineStr> &LineStr)
const {
485 : dwarf::DW_FORM_string);
488 SmallString<256> Dir;
495 CompDir = LineStr->getSaver().save(CompDir);
499 LineStr->emitRef(MCOS, CompDir);
501 LineStr->emitRef(MCOS, Dir);
523 : dwarf::DW_FORM_string);
533 : dwarf::DW_FORM_string);
543 "No root file and no .file directives");
550std::pair<MCSymbol *, MCSymbol *>
553 std::optional<MCDwarfLineStr> &LineStr)
const {
573 if (LineTableVersion >= 5) {
593 if (LineTableVersion >= 4)
601 for (
char Length : StandardOpcodeLengths)
606 if (LineTableVersion >= 5)
607 emitV5FileDirTables(MCOS, LineStr);
609 emitV2FileDirTables(MCOS);
615 return std::make_pair(LineStartSym, LineEndSym);
619 std::optional<MCDwarfLineStr> &LineStr)
const {
620 MCSymbol *LineEndSym = Header.Emit(MCOS, Params, LineStr).second;
623 for (
const auto &LineSec : MCLineSections.getMCLineEntries())
624 emitOne(MCOS, LineSec.first, LineSec.second);
633 std::optional<MD5::MD5Result> Checksum,
634 std::optional<StringRef> Source,
635 uint16_t DwarfVersion,
unsigned FileNumber) {
636 return Header.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
642 std::optional<MD5::MD5Result> Checksum) {
645 return RootFile.
Checksum == Checksum;
650 std::optional<MD5::MD5Result> Checksum,
651 std::optional<StringRef> Source,
652 uint16_t DwarfVersion,
unsigned FileNumber) {
655 if (FileName.
empty()) {
656 FileName =
"<stdin>";
666 if (FileNumber == 0) {
667 if (DwarfVersion >= 5 &&
677 if (!IterBool.second)
678 return IterBool.first->second;
688 if (!File.Name.empty())
692 if (Directory.
empty()) {
695 if (!tFileName.
empty()) {
697 if (!Directory.
empty())
698 FileName = tFileName;
705 if (Directory.
empty()) {
719 File.Name = std::string(FileName);
720 File.DirIndex = DirIndex;
721 File.Checksum = Checksum;
723 File.Source = Source;
724 if (Source.has_value())
733 int64_t LineDelta, uint64_t AddrDelta) {
748 int64_t LineDelta, uint64_t AddrDelta,
750 uint64_t Temp, Opcode;
751 bool NeedCopy =
false;
754 uint64_t MaxSpecialAddrDelta =
SpecialAddr(Params, 255);
763 if (AddrDelta == MaxSpecialAddrDelta)
764 Out.push_back(dwarf::DW_LNS_const_add_pc);
765 else if (AddrDelta) {
766 Out.push_back(dwarf::DW_LNS_advance_pc);
769 Out.push_back(dwarf::DW_LNS_extended_op);
771 Out.push_back(dwarf::DW_LNE_end_sequence);
782 Out.push_back(dwarf::DW_LNS_advance_line);
791 if (LineDelta == 0 && AddrDelta == 0) {
792 Out.push_back(dwarf::DW_LNS_copy);
800 if (AddrDelta < 256 + MaxSpecialAddrDelta) {
804 Out.push_back(Opcode);
809 Opcode = Temp + (AddrDelta - MaxSpecialAddrDelta) * Params.
DWARF2LineRange;
811 Out.push_back(dwarf::DW_LNS_const_add_pc);
812 Out.push_back(Opcode);
818 Out.push_back(dwarf::DW_LNS_advance_pc);
822 Out.push_back(dwarf::DW_LNS_copy);
824 assert(Temp <= 255 &&
"Buggy special opcode encoding.");
847 ? dwarf::DW_FORM_sec_offset
849 : dwarf::DW_FORM_data4);
850 EmitAbbrev(MCOS, dwarf::DW_AT_stmt_list, SecOffsetForm);
853 EmitAbbrev(MCOS, dwarf::DW_AT_ranges, SecOffsetForm);
855 EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
856 EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr);
858 EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
860 EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
862 if (!DwarfDebugFlags.
empty())
863 EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string);
864 EmitAbbrev(MCOS, dwarf::DW_AT_producer, dwarf::DW_FORM_string);
867 EmitAbbrev(MCOS, dwarf::DW_AT_language_name, dwarf::DW_FORM_data2);
869 EmitAbbrev(MCOS, dwarf::DW_AT_language, dwarf::DW_FORM_data2);
877 EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
878 EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4);
879 EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4);
880 EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
892 const MCSymbol *InfoSectionSymbol) {
899 unsigned UnitLengthBytes =
905 int Length = UnitLengthBytes + 2 + OffsetSize + 1 + 1;
911 int Pad = 2 * AddrSize - (
Length & (2 * AddrSize - 1));
912 if (Pad == 2 * AddrSize)
918 Length += 2 * AddrSize * Sections.size();
933 if (InfoSectionSymbol)
942 for(
int i = 0; i < Pad; i++)
948 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
949 MCSymbol *EndSymbol = Sec->getEndSymbol(context);
950 assert(StartSymbol &&
"StartSymbol must not be NULL");
951 assert(EndSymbol &&
"EndSymbol must not be NULL");
969 const MCSymbol *AbbrevSectionSymbol,
984 unsigned UnitLengthBytes =
1006 MCOS->
emitInt8(dwarf::DW_UT_compile);
1011 if (AbbrevSectionSymbol)
1026 if (LineSectionSymbol)
1043 const auto TextSection = Sections.begin();
1044 assert(TextSection != Sections.end() &&
"No text section found");
1046 MCSymbol *StartSymbol = (*TextSection)->getBeginSymbol();
1047 MCSymbol *EndSymbol = (*TextSection)->getEndSymbol(context);
1048 assert(StartSymbol &&
"StartSymbol must not be NULL");
1049 assert(EndSymbol &&
"EndSymbol must not be NULL");
1063 if (MCDwarfDirs.
size() > 0) {
1072 MCDwarfFiles.
empty()
1086 if (!DwarfDebugFlags.
empty()){
1093 if (!DwarfDebugProducer.
empty())
1101 MCOS->
emitInt16(dwarf::DW_LNAME_Assembly);
1106 MCOS->
emitInt16(dwarf::DW_LANG_Mips_Assembler);
1112 const std::vector<MCGenDwarfLabelEntry> &Entries =
1114 for (
const auto &Entry : Entries) {
1159 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
1160 const MCSymbol *EndSymbol = Sec->getEndSymbol(context);
1161 const MCExpr *SectionStartAddr =
1163 const MCExpr *SectionSize =
1165 MCOS->
emitInt8(dwarf::DW_RLE_start_length);
1166 MCOS->
emitValue(SectionStartAddr, AddrSize);
1169 MCOS->
emitInt8(dwarf::DW_RLE_end_of_list);
1176 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
1177 const MCSymbol *EndSymbol = Sec->getEndSymbol(context);
1180 const MCExpr *SectionStartAddr =
1183 MCOS->
emitValue(SectionStartAddr, AddrSize);
1186 const MCExpr *SectionSize =
1197 return RangesSymbol;
1209 bool CreateDwarfSectionSymbols =
1211 MCSymbol *LineSectionSymbol =
nullptr;
1212 if (CreateDwarfSectionSymbols)
1214 MCSymbol *AbbrevSectionSymbol =
nullptr;
1215 MCSymbol *InfoSectionSymbol =
nullptr;
1228 const bool UseRangesSection =
1231 CreateDwarfSectionSymbols |= UseRangesSection;
1234 if (CreateDwarfSectionSymbols) {
1239 if (CreateDwarfSectionSymbols) {
1249 if (UseRangesSection) {
1258 EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol, RangesSymbol);
1270 if (Symbol->isTemporary())
1281 if (Name.starts_with(
"_"))
1282 Name = Name.
substr(1, Name.size()-1);
1289 unsigned CurBuffer =
SrcMgr.FindBufferContainingLoc(
Loc);
1290 unsigned LineNumber =
SrcMgr.FindLineNumber(
Loc, CurBuffer);
1305 auto ReplaceReg = [=](
unsigned &Reg) {
1311 ReplaceReg(
F.Register);
1312 ReplaceReg(
F.Register2);
1316 ReplaceReg(
F.Register);
1321 ReplaceReg(
F.Register);
1326 ReplaceReg(
F.Register);
1327 ReplaceReg(
F.MaskRegister);
1330 ReplaceReg(
F.Register);
1331 ReplaceReg(
F.SpillRegister);
1332 ReplaceReg(
F.MaskRegister);
1337 std::visit(Visitor, ExtraFields);
1351 unsigned symbolEncoding) {
1353 unsigned format = symbolEncoding & 0x0f;
1372 unsigned symbolEncoding,
bool isEH) {
1385 unsigned symbolEncoding) {
1396class FrameEmitterImpl {
1397 int64_t CFAOffset = 0;
1398 int64_t InitialCFAOffset = 0;
1404 FrameEmitterImpl(
bool IsEH, MCObjectStreamer &
Streamer)
1408 void EmitCompactUnwind(
const MCDwarfFrameInfo &frame);
1410 const MCSymbol &EmitCIE(
const MCDwarfFrameInfo &
F);
1411 void EmitFDE(
const MCSymbol &cieStart,
const MCDwarfFrameInfo &frame,
1412 bool LastInSection,
const MCSymbol &SectionStart);
1414 MCSymbol *BaseLabel);
1415 void emitCFIInstruction(
const MCCFIInstruction &Instr);
1426 if (DwarfReg < 32) {
1427 OS <<
uint8_t(dwarf::DW_OP_reg0 + DwarfReg);
1429 OS <<
uint8_t(dwarf::DW_OP_regx);
1436 auto *
MRI =
Streamer.getContext().getRegisterInfo();
1438 switch (
Instr.getOperation()) {
1440 unsigned Reg1 =
Instr.getRegister();
1441 unsigned Reg2 =
Instr.getRegister2();
1443 Reg1 =
MRI->getDwarfRegNumFromDwarfEHRegNum(Reg1);
1444 Reg2 =
MRI->getDwarfRegNumFromDwarfEHRegNum(Reg2);
1446 Streamer.emitInt8(dwarf::DW_CFA_register);
1447 Streamer.emitULEB128IntValue(Reg1);
1448 Streamer.emitULEB128IntValue(Reg2);
1452 Streamer.emitInt8(dwarf::DW_CFA_GNU_window_save);
1456 Streamer.emitInt8(dwarf::DW_CFA_AARCH64_negate_ra_state);
1460 Streamer.emitInt8(dwarf::DW_CFA_AARCH64_negate_ra_state_with_pc);
1464 Streamer.emitInt8(dwarf::DW_CFA_AARCH64_set_ra_state);
1475 Streamer.emitSLEB128Value(Factored);
1482 unsigned Reg =
Instr.getRegister();
1483 Streamer.emitInt8(dwarf::DW_CFA_undefined);
1489 const bool IsRelative =
1492 Streamer.emitInt8(dwarf::DW_CFA_def_cfa_offset);
1495 CFAOffset +=
Instr.getOffset();
1497 CFAOffset =
Instr.getOffset();
1499 Streamer.emitULEB128IntValue(CFAOffset);
1504 unsigned Reg =
Instr.getRegister();
1506 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(
Reg);
1507 Streamer.emitInt8(dwarf::DW_CFA_def_cfa);
1509 CFAOffset =
Instr.getOffset();
1510 Streamer.emitULEB128IntValue(CFAOffset);
1515 unsigned Reg =
Instr.getRegister();
1517 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(
Reg);
1518 Streamer.emitInt8(dwarf::DW_CFA_def_cfa_register);
1525 unsigned Reg =
Instr.getRegister();
1527 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(
Reg);
1528 Streamer.emitIntValue(dwarf::DW_CFA_LLVM_def_aspace_cfa, 1);
1530 CFAOffset =
Instr.getOffset();
1531 Streamer.emitULEB128IntValue(CFAOffset);
1538 const bool IsRelative =
1541 unsigned Reg =
Instr.getRegister();
1543 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(
Reg);
1551 Streamer.emitInt8(dwarf::DW_CFA_offset_extended_sf);
1554 }
else if (
Reg < 64) {
1558 Streamer.emitInt8(dwarf::DW_CFA_offset_extended);
1565 Streamer.emitInt8(dwarf::DW_CFA_remember_state);
1566 SavedCFAOffsets.push_back(CFAOffset);
1569 Streamer.emitInt8(dwarf::DW_CFA_restore_state);
1570 CFAOffset = SavedCFAOffsets.pop_back_val();
1573 unsigned Reg =
Instr.getRegister();
1574 Streamer.emitInt8(dwarf::DW_CFA_same_value);
1579 unsigned Reg =
Instr.getRegister();
1581 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(
Reg);
1585 Streamer.emitInt8(dwarf::DW_CFA_restore_extended);
1591 Streamer.emitInt8(dwarf::DW_CFA_GNU_args_size);
1603 unsigned Reg =
Instr.getRegister();
1605 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(
Reg);
1611 Streamer.emitInt8(dwarf::DW_CFA_val_offset_sf);
1615 Streamer.emitInt8(dwarf::DW_CFA_val_offset);
1637 const auto &Fields =
1643 if (Fields.Reg1SizeInBits % 8 == 0) {
1644 OSBlock << uint8_t(dwarf::DW_OP_piece);
1647 OSBlock << uint8_t(dwarf::DW_OP_bit_piece);
1652 if (Fields.Reg2SizeInBits % 8 == 0) {
1653 OSBlock << uint8_t(dwarf::DW_OP_piece);
1656 OSBlock << uint8_t(dwarf::DW_OP_bit_piece);
1661 Streamer.emitInt8(dwarf::DW_CFA_expression);
1662 Streamer.emitULEB128IntValue(Fields.Register);
1692 const auto &Fields =
1699 if (VRs.size() == 1 && VRs[0].SizeInBits % 8 == 0) {
1701 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1702 << uint8_t(dwarf::DW_OP_LLVM_offset_uconst);
1706 for (
const auto &VR : VRs) {
1711 OSBlock << uint8_t(dwarf::DW_OP_bit_piece);
1717 Streamer.emitInt8(dwarf::DW_CFA_expression);
1718 Streamer.emitULEB128IntValue(Fields.Register);
1735 const auto &Fields =
1741 OSBlock << uint8_t(dwarf::DW_OP_swap);
1742 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1743 << uint8_t(dwarf::DW_OP_LLVM_offset_uconst);
1745 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1746 << uint8_t(dwarf::DW_OP_LLVM_call_frame_entry_reg);
1748 OSBlock << uint8_t(dwarf::DW_OP_deref_size);
1749 OSBlock << uint8_t(Fields.MaskRegisterSizeInBits / 8);
1750 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1751 << uint8_t(dwarf::DW_OP_LLVM_select_bit_piece);
1755 Streamer.emitInt8(dwarf::DW_CFA_expression);
1756 Streamer.emitULEB128IntValue(Fields.Register);
1780 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1781 << uint8_t(dwarf::DW_OP_LLVM_call_frame_entry_reg);
1783 OSBlock << uint8_t(dwarf::DW_OP_deref_size)
1784 << uint8_t(Fields.MaskRegisterSizeInBits / 8);
1785 OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
1786 << uint8_t(dwarf::DW_OP_LLVM_select_bit_piece);
1790 Streamer.emitInt8(dwarf::DW_CFA_expression);
1791 Streamer.emitULEB128IntValue(Fields.Register);
1807 if (Label && !
Label->isDefined())
continue;
1810 if (BaseLabel && Label) {
1812 if (ThisSym != BaseLabel) {
1813 Streamer.emitDwarfAdvanceFrameAddr(BaseLabel, ThisSym,
Instr.getLoc());
1814 BaseLabel = ThisSym;
1818 emitCFIInstruction(Instr);
1850 if (!Encoding)
return;
1854 if (!DwarfEHFrameOnly && Frame.
Lsda)
1855 Encoding |= 0x40000000;
1880 if (!DwarfEHFrameOnly && Frame.
Lsda)
1889 switch (DwarfVersion) {
1923 *sectionEnd, UnitLengthBytes);
1929 Streamer.emitIntValue(CIE_ID, OffsetSize);
1937 Augmentation +=
"z";
1939 Augmentation +=
"P";
1941 Augmentation +=
"L";
1942 Augmentation +=
"R";
1944 Augmentation +=
"S";
1946 Augmentation +=
"B";
1948 Augmentation +=
"G";
1950 Augmentation +=
"N";
1955 if (CIEVersion >= 4) {
1971 if (
RAReg ==
static_cast<unsigned>(INT_MAX))
1972 RAReg =
MRI->getDwarfRegNum(
MRI->getRARegister(), IsEH);
1974 if (CIEVersion == 1) {
1976 "DWARF 2 encodes return_address_register in one byte");
1983 unsigned augmentationLength = 0;
1987 augmentationLength += 1;
1989 augmentationLength +=
1993 augmentationLength += 1;
1995 augmentationLength += 1;
1997 Streamer.emitULEB128IntValue(augmentationLength);
2020 emitCFIInstructions(Instructions,
nullptr);
2023 InitialCFAOffset = CFAOffset;
2029 return *sectionStart;
2032void FrameEmitterImpl::EmitFDE(
const MCSymbol &cieStart,
2041 CFAOffset = InitialCFAOffset;
2042 SavedCFAOffsets.clear();
2068 Streamer.emitDwarfSectionOffset(&cieStart, 0, OffsetSize);
2072 unsigned PCEncoding =
2084 unsigned augmentationLength = 0;
2089 Streamer.emitULEB128IntValue(augmentationLength);
2114 explicit CIEKey(
const MCDwarfFrameInfo &Frame,
bool IsEH)
2115 : Personality(Frame.Personality),
2116 PersonalityEncoding(Frame.PersonalityEncoding),
2117 LsdaEncoding(Frame.LsdaEncoding), IsSignalFrame(Frame.IsSignalFrame),
2118 IsSimple(Frame.IsSimple),
RAReg(Frame.
RAReg),
2119 IsBKeyFrame(Frame.IsBKeyFrame),
2120 IsMTETaggedFrame(Frame.IsMTETaggedFrame),
2121 IsNonHintPAuthFrame(Frame.IsNonHintPAuthFrame), IsEH(IsEH) {}
2123 StringRef PersonalityName()
const {
2126 return Personality->getName();
2132 return std::make_tuple(
RAReg, IsSimple) <
2133 std::make_tuple(
Other.RAReg,
Other.IsSimple);
2135 return std::make_tuple(PersonalityName(), PersonalityEncoding, LsdaEncoding,
2136 IsSignalFrame, IsSimple,
RAReg, IsBKeyFrame,
2137 IsMTETaggedFrame, IsNonHintPAuthFrame) <
2138 std::make_tuple(
Other.PersonalityName(),
Other.PersonalityEncoding,
2141 Other.IsMTETaggedFrame,
Other.IsNonHintPAuthFrame);
2149 return Personality ==
Other.Personality &&
2150 PersonalityEncoding ==
Other.PersonalityEncoding &&
2151 LsdaEncoding ==
Other.LsdaEncoding &&
2152 IsSignalFrame ==
Other.IsSignalFrame && IsSimple ==
Other.IsSimple &&
2154 IsMTETaggedFrame ==
Other.IsMTETaggedFrame &&
2155 IsNonHintPAuthFrame ==
Other.IsNonHintPAuthFrame;
2159 const MCSymbol *Personality =
nullptr;
2160 unsigned PersonalityEncoding = 0;
2161 unsigned LsdaEncoding = -1;
2162 bool IsSignalFrame =
false;
2163 bool IsSimple =
false;
2164 unsigned RAReg = UINT_MAX;
2165 bool IsBKeyFrame =
false;
2166 bool IsMTETaggedFrame =
false;
2167 bool IsNonHintPAuthFrame =
false;
2176 const MCAsmInfo &AsmInfo = Context.getAsmInfo();
2183 Streamer.generateCompactUnwindEncodings();
2184 bool SectionEmitted =
false;
2187 if (!SectionEmitted) {
2190 SectionEmitted =
true;
2192 NeedsEHFrameSection |=
2195 Emitter.EmitCompactUnwind(Frame);
2203 if (!NeedsEHFrameSection && IsEH)
return;
2210 MCSymbol *SectionStart = Context.createTempSymbol();
2222 return CIEKey(*
X, IsEH) < CIEKey(*
Y, IsEH);
2225 const MCSymbol *LastCIEStart =
nullptr;
2226 for (
auto I = Frames.
begin(), E = Frames.
end();
I != E;) {
2239 CIEKey
Key(Frame, IsEH);
2240 if (!LastCIEStart ||
Key != LastKey) {
2242 LastCIEStart = &
Emitter.EmitCIE(Frame);
2245 Emitter.EmitFDE(*LastCIEStart, Frame,
I == E, *SectionStart);
2262 uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
2263 Out.push_back(Opcode);
2265 Out.push_back(dwarf::DW_CFA_advance_loc1);
2266 Out.push_back(AddrDelta);
2268 Out.push_back(dwarf::DW_CFA_advance_loc2);
2272 Out.push_back(dwarf::DW_CFA_advance_loc4);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
dxil container DXContainer Global Emitter
This file contains constants used for implementing Dwarf debug support.
static void emitFDESymbol(MCObjectStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding, bool isEH)
static uint64_t SpecialAddr(MCDwarfLineTableParams Params, uint64_t op)
Given a special op, return the address skip amount (in units of DWARF2_LINE_MIN_INSN_LENGTH).
static void EmitGenDwarfAranges(MCStreamer *MCOS, const MCSymbol *InfoSectionSymbol)
static bool isRootFile(const MCDwarfFile &RootFile, StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum)
static uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta)
static const MCExpr * forceExpAbs(MCStreamer &OS, const MCExpr *Expr)
static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size)
static void encodeDwarfRegisterLocation(int DwarfReg, raw_ostream &OS)
static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile, bool EmitMD5, bool HasAnySource, std::optional< MCDwarfLineStr > &LineStr)
static const MCExpr * makeEndMinusStartExpr(MCContext &Ctx, const MCSymbol &Start, const MCSymbol &End, int IntVal)
static unsigned getCIEVersion(bool IsEH, unsigned DwarfVersion)
static void EmitGenDwarfInfo(MCStreamer *MCOS, const MCSymbol *AbbrevSectionSymbol, const MCSymbol *LineSectionSymbol, const MCSymbol *RangesSymbol)
static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form)
static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding)
static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding)
static int getDataAlignmentFactor(MCStreamer &streamer)
static MCSymbol * emitGenDwarfRanges(MCStreamer *MCOS)
static void EmitGenDwarfAbbrev(MCStreamer *MCOS)
static unsigned getSizeForEncoding(MCStreamer &streamer, unsigned symbolEncoding)
#define DWARF2_FLAG_IS_STMT
#define DWARF2_FLAG_BASIC_BLOCK
#define DWARF2_LINE_DEFAULT_IS_STMT
#define DWARF2_FLAG_PROLOGUE_END
#define DWARF2_FLAG_EPILOGUE_BEGIN
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr MCPhysReg RAReg
MachineRegisterInfo & MRI
This file defines the SmallString class.
This file defines the SmallVector class.
std::unique_ptr< MCStreamer > && Streamer
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Tagged union holding either a T or a Error.
This class is intended to be used as a base class for asm properties and features specific to the tar...
unsigned getMinInstAlignment() const
const std::vector< MCCFIInstruction > & getInitialFrameState() const
bool doesDwarfUseRelocationsAcrossSections() const
const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
bool isStackGrowthDirectionUp() const
True if target stack grow up.
unsigned getCalleeSaveStackSlotSize() const
Get the callee-saved register stack slot size in bytes.
bool doDwarfFDESymbolsUseAbsDiff() const
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
static const MCBinaryExpr * createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
LLVM_ABI void replaceRegister(unsigned FromReg, unsigned ToReg)
Replaces in place all references to FromReg with ToReg.
@ OpLLVMVectorRegisterMask
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
const MCObjectFileInfo * getObjectFileInfo() const
LLVM_ABI void remapDebugPath(SmallVectorImpl< char > &Path)
Remap one path in-place as per the debug prefix map.
const SetVector< MCSection * > & getGenDwarfSectionSyms()
const SmallVectorImpl< std::string > & getMCDwarfDirs(unsigned CUID=0)
StringRef getDwarfDebugProducer()
StringRef getDwarfDebugFlags()
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
unsigned getDwarfCompileUnitID()
const MCRegisterInfo * getRegisterInfo() const
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles(unsigned CUID=0)
const std::map< unsigned, MCDwarfLineTable > & getMCDwarfLineTables() const
unsigned getGenDwarfFileNumber()
uint16_t getDwarfVersion() const
LLVM_ABI void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them.
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E)
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
const MCDwarfLoc & getCurrentDwarfLoc()
dwarf::DwarfFormat getDwarfFormat() const
const MCAsmInfo & getAsmInfo() const
const std::vector< MCGenDwarfLabelEntry > & getMCGenDwarfLabelEntries() const
LLVM_ABI void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params, MCSection *Section) const
static LLVM_ABI void emit(MCObjectStreamer &streamer, bool isEH)
static LLVM_ABI void encodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
static LLVM_ABI void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
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.
Instances of this class represent the line information for the dwarf line table entries.
void setEndLabel(MCSymbol *EndLabel)
MCDwarfLineEntry(MCSymbol *label, const MCDwarfLoc loc, MCSymbol *lineStreamLabel=nullptr, SMLoc streamLabelDefLoc={})
MCSymbol * LineStreamLabel
static LLVM_ABI void make(MCStreamer *MCOS, MCSection *Section)
LLVM_ABI void emitSection(MCStreamer *MCOS)
Emit the .debug_line_str section if appropriate.
LLVM_ABI MCDwarfLineStr(MCContext &Ctx)
Construct an instance that can emit .debug_line_str (for use in a normal v5 line table).
LLVM_ABI SmallString< 0 > getFinalizedData()
Returns finalized section.
LLVM_ABI void emitRef(MCStreamer *MCOS, StringRef Path)
Emit a reference to the string.
LLVM_ABI size_t addString(StringRef Path)
Adds path Path to the line string.
LLVM_ABI void endCurrentSeqAndEmitLineStreamLabel(MCStreamer *MCOS, SMLoc DefLoc, StringRef Name)
MCDwarfFile & getRootFile()
const MCLineSection & getMCLineSections() const
static LLVM_ABI void emit(MCStreamer *MCOS, MCDwarfLineTableParams Params)
static LLVM_ABI void emitOne(MCStreamer *MCOS, MCSection *Section, const MCLineSection::MCDwarfLineEntryCollection &LineEntries)
LLVM_ABI Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
LLVM_ABI void emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params, std::optional< MCDwarfLineStr > &LineStr) const
Instances of this class represent the information from a dwarf .loc directive.
Base class for the full range of assembler expressions which are needed for parsing.
static LLVM_ABI void Emit(MCStreamer *MCOS)
MCGenDwarfLabelEntry(StringRef name, unsigned fileNumber, unsigned lineNumber, MCSymbol *label)
static LLVM_ABI void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
LLVM_ABI void addEndEntry(MCSymbol *EndLabel)
void addLineEntry(const MCDwarfLineEntry &LineEntry, MCSection *Sec)
std::vector< MCDwarfLineEntry > MCDwarfLineEntryCollection
MCSection * getDwarfRangesSection() const
bool getSupportsCompactUnwindWithoutEHFrame() const
MCSection * getDwarfLineStrSection() const
unsigned getCompactUnwindDwarfEHFrameOnly() const
MCSection * getDwarfRnglistsSection() const
MCSection * getDwarfLineSection() const
MCSection * getDwarfInfoSection() const
MCSection * getDwarfFrameSection() const
unsigned getFDEEncoding() const
MCSection * getDwarfAbbrevSection() const
bool getOmitDwarfIfHaveCompactUnwind() const
MCSection * getDwarfARangesSection() const
MCSection * getCompactUnwindSection() const
Streaming object file generation interface.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Instances of this class represent a uniqued identifier for a section in the current translation unit.
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void emitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
virtual void emitDwarfUnitLength(uint64_t Length, const Twine &Comment)
Emit a unit length field.
void emitSymbolValue(const MCSymbol *Sym, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
MCContext & getContext() const
virtual void AddComment(const Twine &T, bool EOL=true)
Add a textual comment.
void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
virtual void emitDwarfLineStartLabel(MCSymbol *StartSym)
Emit the debug line start label.
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
virtual void emitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize)
If targets does not support representing debug line section by .loc/.file directives in assembly outp...
void emitInt16(uint64_t Value)
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
virtual void emitULEB128Value(const MCExpr *Value)
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
void emitInt32(uint64_t Value)
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
MCSection * getCurrentSectionOnly() const
virtual void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel, MCSymbol *EndLabel=nullptr)
Emit the debug line end entry.
void emitInt8(uint64_t Value)
void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
void emitDwarfSectionOffset(const MCSymbol *Sym, uint64_t Offset, unsigned Size)
Emit the offset of Sym + Offset from the start of its DWARF section as a section-relative relocation.
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Wrapper class representing virtual and physical registers.
Represents a location in source code.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr bool empty() const
Check if the string is empty.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const uint32_t DW_CIE_ID
Special ID values that distinguish a CIE from a FDE in DWARF CFI.
uint8_t getUnitLengthFieldByteSize(DwarfFormat Format)
Get the byte size of the unit length field depending on the DWARF format.
const uint64_t DW64_CIE_ID
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
@ DW_LENGTH_DWARF64
Indicator of 64-bit DWARF format.
LLVM_ABI MCSymbol * emitListsTableHeaderStart(MCStreamer &S)
NodeAddr< InstrNode * > Instr
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
LLVM_ABI StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
void stable_sort(R &&Range)
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
bool operator!=(uint64_t V1, const APInt &V2)
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
LLVM_ABI SourceMgr SrcMgr
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
ArrayRef(const T &OneElt) -> ArrayRef< T >
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
void appendLEB128(SmallVectorImpl< U > &Buffer, T Value)
constexpr decltype(auto) makeVisitor(CallableTs &&...Callables)
Returns an opaquely-typed Callable object whose operator() overload set is the sum of the operator() ...
@ End
Run the machine verifier once, at the end of the pipeline.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Held in ExtraFields when OpLLVMSetRAState.
Held in ExtraFields when OpLLVMRegisterPair.
Held in ExtraFields when OpLLVMVectorOffset.
Held in ExtraFields when OpLLVMVectorRegisterMask.
Held in ExtraFields when OpLLVMVectorRegisters.
std::vector< VectorRegisterWithLane > VectorRegisters
Instances of this class represent the name of the dwarf .file directive and its associated dwarf file...
std::optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
const MCSymbol * Personality
unsigned PersonalityEncoding
uint64_t CompactUnwindEncoding
std::vector< MCCFIInstruction > Instructions
uint8_t DWARF2LineOpcodeBase
First special line opcode - leave room for the standard opcodes.
uint8_t DWARF2LineRange
Range of line offsets in a special line info. opcode.
int8_t DWARF2LineBase
Minimum line offset in a special line info.