20 #include "llvm/Config/config.h" 52 bool UseRelocs =
false;
73 if (MinInsnLength == 1)
75 if (AddrDelta % MinInsnLength != 0) {
79 return AddrDelta / MinInsnLength;
109 .addLineEntry(LineEntry, Section);
136 static inline const MCExpr *
152 unsigned FileNum = 1;
153 unsigned LastLine = 1;
157 unsigned Discriminator = 0;
162 int64_t LineDelta =
static_cast<int64_t
>(LineEntry.getLine()) - LastLine;
164 if (FileNum != LineEntry.getFileNum()) {
165 FileNum = LineEntry.getFileNum();
169 if (Column != LineEntry.getColumn()) {
170 Column = LineEntry.getColumn();
174 if (Discriminator != LineEntry.getDiscriminator() &&
176 Discriminator = LineEntry.getDiscriminator();
183 if (Isa != LineEntry.getIsa()) {
184 Isa = LineEntry.getIsa();
189 Flags = LineEntry.getFlags();
197 MCOS->
EmitIntValue(dwarf::DW_LNS_set_epilogue_begin, 1);
199 MCSymbol *Label = LineEntry.getLabel();
209 LastLine = LineEntry.getLine();
240 if (LineTables.empty())
252 for (
const auto &CUIDTablePair : LineTables) {
253 CUIDTablePair.second.EmitCU(MCOS, Params, LineStr);
262 if (!HasSplitLineTable)
266 MCOS.
EmitLabel(Header.Emit(&MCOS, Params,
None, NoLineStr).second);
269 std::pair<MCSymbol *, MCSymbol *>
272 static const char StandardOpcodeLengths[] = {
296 assert(!isa<MCSymbolRefExpr>(Expr));
318 LineStrings.
write((uint8_t *)Data.
data());
332 void MCDwarfLineTableHeader::emitV2FileDirTables(
MCStreamer *MCOS)
const {
334 for (
auto &Dir : MCDwarfDirs) {
341 for (
unsigned i = 1; i < MCDwarfFiles.size(); i++) {
353 bool EmitMD5,
bool HasSource,
367 Cksum.
Bytes.size()));
380 void MCDwarfLineTableHeader::emitV5FileDirTables(
388 : dwarf::DW_FORM_string);
396 LineStr->
emitRef(MCOS, CompDir);
397 for (
const auto &Dir : MCDwarfDirs)
403 for (
const auto &Dir : MCDwarfDirs) {
412 uint64_t Entries = 2;
420 : dwarf::DW_FORM_string);
430 : dwarf::DW_FORM_string);
439 assert((!RootFile.Name.empty() || MCDwarfFiles.size() >= 1) &&
440 "No root file and no .file directives");
442 HasAllMD5, HasSource, LineStr);
443 for (
unsigned i = 1; i < MCDwarfFiles.size(); ++i)
447 std::pair<MCSymbol *, MCSymbol *>
474 unsigned PreHeaderLengthBytes = 4 + 2;
477 if (LineTableVersion >= 5) {
480 PreHeaderLengthBytes += 2;
490 (PreHeaderLengthBytes + 4)),
498 if (LineTableVersion >= 4)
506 for (
char Length : StandardOpcodeLengths)
511 if (LineTableVersion >= 5)
512 emitV5FileDirTables(MCOS, LineStr);
514 emitV2FileDirTables(MCOS);
520 return std::make_pair(LineStartSym, LineEndSym);
526 MCSymbol *LineEndSym = Header.Emit(MCOS, Params, LineStr).second;
529 for (
const auto &LineSec : MCLineSections.getMCLineEntries())
542 unsigned FileNumber) {
543 return Header.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
549 if (RootFile.
Name.empty() || RootFile.
Name != FileName.
data())
551 return RootFile.
Checksum == Checksum;
560 unsigned FileNumber) {
561 if (Directory == CompilationDir)
563 if (FileName.
empty()) {
564 FileName =
"<stdin>";
570 if (MCDwarfFiles.empty()) {
572 HasSource = (Source !=
None);
574 if (
isRootFile(RootFile, Directory, FileName, Checksum) && DwarfVersion >= 5)
576 if (FileNumber == 0) {
579 FileNumber = MCDwarfFiles.empty() ? 1 : MCDwarfFiles.size();
581 auto IterBool = SourceIdMap.
insert(
584 if (!IterBool.second)
585 return IterBool.first->second;
588 if (FileNumber >= MCDwarfFiles.size())
589 MCDwarfFiles.resize(FileNumber + 1);
595 if (!File.
Name.empty())
596 return make_error<StringError>(
"file number already allocated",
600 if (HasSource != (Source !=
None))
601 return make_error<StringError>(
"inconsistent use of embedded source",
604 if (Directory.
empty()) {
607 if (!tFileName.
empty()) {
609 if (!Directory.
empty())
610 FileName = tFileName;
617 if (Directory.
empty()) {
621 DirIndex =
llvm::find(MCDwarfDirs, Directory) - MCDwarfDirs.begin();
622 if (DirIndex >= MCDwarfDirs.size())
623 MCDwarfDirs.push_back(Directory);
631 File.
Name = FileName;
645 int64_t LineDelta, uint64_t AddrDelta) {
661 int64_t LineDelta, uint64_t AddrDelta,
663 uint64_t Temp, Opcode;
664 bool NeedCopy =
false;
667 uint64_t MaxSpecialAddrDelta =
SpecialAddr(Params, 255);
676 if (AddrDelta == MaxSpecialAddrDelta)
677 OS <<
char(dwarf::DW_LNS_const_add_pc);
678 else if (AddrDelta) {
679 OS << char(dwarf::DW_LNS_advance_pc);
682 OS << char(dwarf::DW_LNS_extended_op);
684 OS << char(dwarf::DW_LNE_end_sequence);
695 OS <<
char(dwarf::DW_LNS_advance_line);
704 if (LineDelta == 0 && AddrDelta == 0) {
705 OS <<
char(dwarf::DW_LNS_copy);
713 if (AddrDelta < 256 + MaxSpecialAddrDelta) {
722 Opcode = Temp + (AddrDelta - MaxSpecialAddrDelta) * Params.
DWARF2LineRange;
724 OS <<
char(dwarf::DW_LNS_const_add_pc);
731 OS <<
char(dwarf::DW_LNS_advance_pc);
735 OS << char(dwarf::DW_LNS_copy);
737 assert(Temp <= 255 &&
"Buggy special opcode encoding.");
744 int64_t LineDelta, uint64_t AddrDelta,
748 OS <<
char(dwarf::DW_LNS_advance_line);
758 if (AddrDelta > 60000) {
762 OS <<
char(dwarf::DW_LNS_extended_op);
764 OS << char(dwarf::DW_LNE_set_address);
771 OS <<
char(dwarf::DW_LNS_fixed_advance_pc);
781 OS <<
char(dwarf::DW_LNS_extended_op);
783 OS << char(dwarf::DW_LNE_end_sequence);
785 OS <<
char(dwarf::DW_LNS_copy);
808 ? dwarf::DW_FORM_sec_offset
809 : dwarf::DW_FORM_data4);
813 ? dwarf::DW_FORM_sec_offset
814 : dwarf::DW_FORM_data4);
816 EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
817 EmitAbbrev(MCOS, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr);
819 EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
821 EmitAbbrev(MCOS, dwarf::DW_AT_comp_dir, dwarf::DW_FORM_string);
823 if (!DwarfDebugFlags.
empty())
824 EmitAbbrev(MCOS, dwarf::DW_AT_APPLE_flags, dwarf::DW_FORM_string);
825 EmitAbbrev(MCOS, dwarf::DW_AT_producer, dwarf::DW_FORM_string);
826 EmitAbbrev(MCOS, dwarf::DW_AT_language, dwarf::DW_FORM_data2);
833 EmitAbbrev(MCOS, dwarf::DW_AT_name, dwarf::DW_FORM_string);
834 EmitAbbrev(MCOS, dwarf::DW_AT_decl_file, dwarf::DW_FORM_data4);
835 EmitAbbrev(MCOS, dwarf::DW_AT_decl_line, dwarf::DW_FORM_data4);
836 EmitAbbrev(MCOS, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr);
837 EmitAbbrev(MCOS, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag);
855 const MCSymbol *InfoSectionSymbol) {
864 int Length = 4 + 2 + 4 + 1 + 1;
870 int Pad = 2 * AddrSize - (Length & (2 * AddrSize - 1));
871 if (Pad == 2 * AddrSize)
877 Length += 2 * AddrSize * Sections.size();
879 Length += 2 * AddrSize;
888 if (InfoSectionSymbol)
898 for(
int i = 0; i < Pad; i++)
904 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
905 MCSymbol *EndSymbol = Sec->getEndSymbol(context);
906 assert(StartSymbol &&
"StartSymbol must not be NULL");
907 assert(EndSymbol &&
"EndSymbol must not be NULL");
912 *StartSymbol, *EndSymbol, 0);
926 const MCSymbol *AbbrevSectionSymbol,
928 const MCSymbol *RangesSectionSymbol) {
959 if (AbbrevSectionSymbol ==
nullptr)
974 if (LineSectionSymbol)
980 if (RangesSectionSymbol) {
993 const auto TextSection = Sections.begin();
994 assert(TextSection != Sections.end() &&
"No text section found");
996 MCSymbol *StartSymbol = (*TextSection)->getBeginSymbol();
997 MCSymbol *EndSymbol = (*TextSection)->getEndSymbol(context);
998 assert(StartSymbol &&
"StartSymbol must not be NULL");
999 assert(EndSymbol &&
"EndSymbol must not be NULL");
1015 if (MCDwarfDirs.
size() > 0) {
1024 MCDwarfFiles.
empty()
1038 if (!DwarfDebugFlags.
empty()){
1045 if (!DwarfDebugProducer.
empty())
1058 const std::vector<MCGenDwarfLabelEntry> &Entries =
1060 for (
const auto &
Entry : Entries) {
1109 const MCSymbol *StartSymbol = Sec->getBeginSymbol();
1110 MCSymbol *EndSymbol = Sec->getEndSymbol(context);
1111 assert(StartSymbol &&
"StartSymbol must not be NULL");
1112 assert(EndSymbol &&
"EndSymbol must not be NULL");
1118 MCOS->
EmitValue(SectionStartAddr, AddrSize);
1122 *StartSymbol, *EndSymbol, 0);
1141 bool CreateDwarfSectionSymbols =
1143 MCSymbol *LineSectionSymbol =
nullptr;
1144 if (CreateDwarfSectionSymbols)
1146 MCSymbol *AbbrevSectionSymbol =
nullptr;
1147 MCSymbol *InfoSectionSymbol =
nullptr;
1148 MCSymbol *RangesSectionSymbol =
nullptr;
1160 const bool UseRangesSection =
1163 CreateDwarfSectionSymbols |= UseRangesSection;
1166 if (CreateDwarfSectionSymbols) {
1171 if (CreateDwarfSectionSymbols) {
1175 if (UseRangesSection) {
1177 if (CreateDwarfSectionSymbols) {
1183 assert((RangesSectionSymbol !=
nullptr) || !UseRangesSection);
1190 if (UseRangesSection)
1198 RangesSectionSymbol);
1255 unsigned symbolEncoding) {
1257 unsigned format = symbolEncoding & 0x0f;
1276 unsigned symbolEncoding,
bool isEH) {
1290 unsigned symbolEncoding) {
1302 class FrameEmitterImpl {
1304 int InitialCFAOffset = 0;
1310 : IsEH(IsEH), Streamer(Streamer) {}
1317 bool LastInSection,
const MCSymbol &SectionStart);
1331 auto *
MRI = Streamer.getContext().getRegisterInfo();
1338 Reg1 =
MRI->getDwarfRegNumFromDwarfEHRegNum(Reg1);
1339 Reg2 =
MRI->getDwarfRegNumFromDwarfEHRegNum(Reg2);
1341 Streamer.EmitIntValue(dwarf::DW_CFA_register, 1);
1342 Streamer.EmitULEB128IntValue(Reg1);
1343 Streamer.EmitULEB128IntValue(Reg2);
1347 Streamer.EmitIntValue(dwarf::DW_CFA_GNU_window_save, 1);
1351 Streamer.EmitIntValue(dwarf::DW_CFA_AARCH64_negate_ra_state, 1);
1356 Streamer.EmitIntValue(dwarf::DW_CFA_undefined, 1);
1357 Streamer.EmitULEB128IntValue(Reg);
1362 const bool IsRelative =
1365 Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_offset, 1);
1372 Streamer.EmitULEB128IntValue(CFAOffset);
1379 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1380 Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa, 1);
1381 Streamer.EmitULEB128IntValue(Reg);
1383 Streamer.EmitULEB128IntValue(CFAOffset);
1390 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1391 Streamer.EmitIntValue(dwarf::DW_CFA_def_cfa_register, 1);
1392 Streamer.EmitULEB128IntValue(Reg);
1398 const bool IsRelative =
1403 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1407 Offset -= CFAOffset;
1408 Offset = Offset / dataAlignmentFactor;
1411 Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended_sf, 1);
1412 Streamer.EmitULEB128IntValue(Reg);
1413 Streamer.EmitSLEB128IntValue(Offset);
1414 }
else if (Reg < 64) {
1415 Streamer.EmitIntValue(dwarf::DW_CFA_offset + Reg, 1);
1416 Streamer.EmitULEB128IntValue(Offset);
1418 Streamer.EmitIntValue(dwarf::DW_CFA_offset_extended, 1);
1419 Streamer.EmitULEB128IntValue(Reg);
1420 Streamer.EmitULEB128IntValue(Offset);
1425 Streamer.EmitIntValue(dwarf::DW_CFA_remember_state, 1);
1428 Streamer.EmitIntValue(dwarf::DW_CFA_restore_state, 1);
1432 Streamer.EmitIntValue(dwarf::DW_CFA_same_value, 1);
1433 Streamer.EmitULEB128IntValue(Reg);
1439 Reg =
MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
1441 Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
1443 Streamer.EmitIntValue(dwarf::DW_CFA_restore_extended, 1);
1444 Streamer.EmitULEB128IntValue(Reg);
1449 Streamer.EmitIntValue(dwarf::DW_CFA_GNU_args_size, 1);
1450 Streamer.EmitULEB128IntValue(Instr.
getOffset());
1466 if (Label && !Label->
isDefined())
continue;
1469 if (BaseLabel && Label) {
1471 if (ThisSym != BaseLabel) {
1472 Streamer.EmitDwarfAdvanceFrameAddr(BaseLabel, ThisSym);
1473 BaseLabel = ThisSym;
1477 EmitCFIInstruction(Instr);
1509 if (!Encoding)
return;
1513 if (!DwarfEHFrameOnly && Frame.
Lsda)
1514 Encoding |= 0x40000000;
1519 Streamer.EmitSymbolValue(Frame.
Begin, Size);
1528 Streamer.EmitIntValue(Encoding, Size);
1533 Streamer.EmitSymbolValue(Frame.
Personality, Size);
1535 Streamer.EmitIntValue(0, Size);
1539 if (!DwarfEHFrameOnly && Frame.
Lsda)
1540 Streamer.EmitSymbolValue(Frame.
Lsda, Size);
1542 Streamer.EmitIntValue(0, Size);
1548 switch (DwarfVersion) {
1561 MCContext &context = Streamer.getContext();
1566 Streamer.EmitLabel(sectionStart);
1576 unsigned CIE_ID = IsEH ? 0 : -1;
1577 Streamer.EmitIntValue(CIE_ID, 4);
1581 Streamer.EmitIntValue(CIEVersion, 1);
1585 Augmentation +=
"z";
1587 Augmentation +=
"P";
1589 Augmentation +=
"L";
1590 Augmentation +=
"R";
1592 Augmentation +=
"S";
1594 Augmentation +=
"B";
1595 Streamer.EmitBytes(Augmentation);
1597 Streamer.EmitIntValue(0, 1);
1599 if (CIEVersion >= 4) {
1604 Streamer.EmitIntValue(0, 1);
1614 unsigned RAReg = Frame.
RAReg;
1615 if (RAReg == static_cast<unsigned>(INT_MAX))
1618 if (CIEVersion == 1) {
1620 "DWARF 2 encodes return_address_register in one byte");
1621 Streamer.EmitIntValue(RAReg, 1);
1623 Streamer.EmitULEB128IntValue(RAReg);
1627 unsigned augmentationLength = 0;
1631 augmentationLength += 1;
1633 augmentationLength +=
1637 augmentationLength += 1;
1639 augmentationLength += 1;
1641 Streamer.EmitULEB128IntValue(augmentationLength);
1662 const std::vector<MCCFIInstruction> &Instructions =
1664 EmitCFIInstructions(Instructions,
nullptr);
1667 InitialCFAOffset = CFAOffset;
1670 Streamer.EmitValueToAlignment(IsEH ? 4 : MAI->getCodePointerSize());
1672 Streamer.EmitLabel(sectionEnd);
1673 return *sectionStart;
1676 void FrameEmitterImpl::EmitFDE(
const MCSymbol &cieStart,
1680 MCContext &context = Streamer.getContext();
1685 CFAOffset = InitialCFAOffset;
1691 Streamer.EmitLabel(fdeStart);
1704 Streamer.EmitSymbolValue(&cieStart, 4,
1709 unsigned PCEncoding =
1721 unsigned augmentationLength = 0;
1726 Streamer.EmitULEB128IntValue(augmentationLength);
1741 Streamer.EmitValueToAlignment(Align);
1743 Streamer.EmitLabel(fdeEnd);
1749 static const CIEKey getEmptyKey() {
1750 return CIEKey(
nullptr, 0, -1,
false,
false, static_cast<unsigned>(INT_MAX),
1754 static const CIEKey getTombstoneKey() {
1755 return CIEKey(
nullptr, -1, 0,
false,
false, static_cast<unsigned>(INT_MAX),
1759 CIEKey(
const MCSymbol *Personality,
unsigned PersonalityEncoding,
1760 unsigned LSDAEncoding,
bool IsSignalFrame,
bool IsSimple,
1761 unsigned RAReg,
bool IsBKeyFrame)
1762 : Personality(Personality), PersonalityEncoding(PersonalityEncoding),
1763 LsdaEncoding(LSDAEncoding), IsSignalFrame(IsSignalFrame),
1764 IsSimple(IsSimple), RAReg(RAReg), IsBKeyFrame(IsBKeyFrame) {}
1776 return Personality->
getName();
1780 return std::make_tuple(PersonalityName(), PersonalityEncoding, LsdaEncoding,
1781 IsSignalFrame, IsSimple, RAReg) <
1782 std::make_tuple(Other.PersonalityName(), Other.PersonalityEncoding,
1783 Other.LsdaEncoding, Other.IsSignalFrame,
1784 Other.IsSimple, Other.RAReg);
1788 unsigned PersonalityEncoding;
1789 unsigned LsdaEncoding;
1806 Key.Personality, Key.PersonalityEncoding, Key.LsdaEncoding,
1807 Key.IsSignalFrame, Key.IsSimple, Key.RAReg, Key.IsBKeyFrame));
1810 static bool isEqual(
const CIEKey &LHS,
const CIEKey &RHS) {
1811 return LHS.Personality == RHS.Personality &&
1812 LHS.PersonalityEncoding == RHS.PersonalityEncoding &&
1813 LHS.LsdaEncoding == RHS.LsdaEncoding &&
1814 LHS.IsSignalFrame == RHS.IsSignalFrame &&
1815 LHS.IsSimple == RHS.IsSimple && LHS.RAReg == RHS.RAReg &&
1816 LHS.IsBKeyFrame == RHS.IsBKeyFrame;
1829 FrameEmitterImpl Emitter(IsEH, Streamer);
1835 bool SectionEmitted =
false;
1838 if (!SectionEmitted) {
1841 SectionEmitted =
true;
1843 NeedsEHFrameSection |=
1846 Emitter.EmitCompactUnwind(Frame);
1850 if (!NeedsEHFrameSection)
return;
1862 const MCSymbol *DummyDebugKey =
nullptr;
1868 std::vector<MCDwarfFrameInfo> FrameArrayX(FrameArray.
begin(), FrameArray.
end());
1871 return CIEKey(X) < CIEKey(Y);
1873 for (
auto I = FrameArrayX.begin(),
E = FrameArrayX.end();
I !=
E;) {
1883 const MCSymbol *&CIEStart = IsEH ? CIEStarts[
Key] : DummyDebugKey;
1885 CIEStart = &Emitter.EmitCIE(Frame);
1887 Emitter.EmitFDE(*CIEStart, Frame,
I ==
E, *SectionStart);
1892 uint64_t AddrDelta) {
1906 bool WithFixups =
false;
1912 if (AddrDelta == 0) {
1917 }
else if (
isUIntN(6, AddrDelta)) {
1918 uint8_t Opcode = dwarf::DW_CFA_advance_loc | AddrDelta;
1920 *Offset = OS.
tell();
1922 OS << uint8_t(dwarf::DW_CFA_advance_loc);
1926 OS << uint8_t(dwarf::DW_CFA_advance_loc1);
1928 *Offset = OS.
tell();
1932 OS << uint8_t(AddrDelta);
1934 OS << uint8_t(dwarf::DW_CFA_advance_loc2);
1936 *Offset = OS.
tell();
1940 support::endian::write<uint16_t>(OS, AddrDelta,
E);
1943 OS << uint8_t(dwarf::DW_CFA_advance_loc4);
1945 *Offset = OS.
tell();
1949 support::endian::write<uint32_t>(OS, AddrDelta,
E);
static const MCExpr * forceExpAbs(MCStreamer &OS, const MCExpr *Expr)
const MCAsmInfo * getAsmInfo() const
void addMCGenDwarfLabelEntry(const MCGenDwarfLabelEntry &E)
constexpr bool isUInt< 32 >(uint64_t x)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static int getDataAlignmentFactor(MCStreamer &streamer)
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
static CIEKey getTombstoneKey()
#define DWARF2_FLAG_PROLOGUE_END
static void Make(MCObjectStreamer *MCOS, MCSection *Section)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Optional< StringRef > Source
The source code of the file.
This class represents lattice values for constants.
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
MCSection * getDwarfLineSection() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static bool FixedEncode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS, uint32_t *Offset, uint32_t *Size)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas using fixed length operands...
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles(unsigned CUID=0)
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
bool needsDwarfSectionOffsetDirective() const
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
MCSection * getDwarfLineStrSection() const
A raw_ostream that writes to an SmallVector or SmallString.
MCSection * getDwarfARangesSection() const
MCDwarfLineStr(MCContext &Ctx)
Construct an instance that can emit .debug_line_str (for use in a normal v5 line table).
uint16_t getDwarfVersion() const
static void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
bool getSupportsCompactUnwindWithoutEHFrame() const
static void EmitGenDwarfInfo(MCStreamer *MCOS, const MCSymbol *AbbrevSectionSymbol, const MCSymbol *LineSectionSymbol, const MCSymbol *RangesSectionSymbol)
StringRef getDwarfDebugFlags()
std::vector< MCDwarfLineEntry > MCDwarfLineEntryCollection
static void Encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize)
std::vector< MCCFIInstruction > Instructions
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
const std::vector< MCGenDwarfLabelEntry > & getMCGenDwarfLabelEntries() const
MCContext & getContext() const
#define DWARF2_FLAG_IS_STMT
StringRef getDwarfDebugProducer()
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth...
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them...
Base class for the full range of assembler expressions which are needed for parsing.
uint8_t DWARF2LineRange
Range of line offsets in a special line info. opcode.
Tagged union holding either a T or a Error.
unsigned getCompactUnwindDwarfEHFrameOnly() const
static void emitFDESymbol(MCObjectStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding, bool isEH)
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
MCSection * getDwarfFrameSection() const
const SmallVectorImpl< std::string > & getMCDwarfDirs(unsigned CUID=0)
bool hasAggressiveSymbolFolding() const
bool getOmitDwarfIfHaveCompactUnwind() const
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
StringRef str() const
Explicit conversion to StringRef.
Context object for machine code objects.
int getDwarfRegNum(MCRegister RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
static void EmitGenDwarfAbbrev(MCStreamer *MCOS)
void write(raw_ostream &OS) const
Utility for building string tables with deduplicated suffixes.
Optional< MD5::MD5Result > Checksum
The MD5 checksum, if there is one.
unsigned getDwarfCompileUnitID()
size_t add(CachedHashStringRef S)
Add a string to the builder.
const std::map< unsigned, MCDwarfLineTable > & getMCDwarfLineTables() const
Streaming object file generation interface.
bool doesDwarfUseRelocationsAcrossSections() const
Instances of this class represent the information from a dwarf .loc directive.
ArrayRef< MCDwarfFrameInfo > getDwarfFrameInfos() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
MCSection * getCompactUnwindSection() const
LLVM_NODISCARD size_t size() const
size - Get the string size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
virtual void EmitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
unsigned getGenDwarfFileNumber()
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...
MCSymbol * getLabel() const
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
MCSection * getDwarfAbbrevSection() const
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
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 unsigned getSizeForEncoding(MCStreamer &streamer, unsigned symbolEncoding)
Streaming machine code generation interface.
static unsigned getCIEVersion(bool IsEH, unsigned DwarfVersion)
static void EmitAbbrev(MCStreamer *MCOS, uint64_t Name, uint64_t Form)
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
uint8_t DWARF2LineOpcodeBase
First special line opcode - leave room for the standard opcodes.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
constexpr bool isUInt< 8 >(uint64_t x)
unsigned const MachineRegisterInfo * MRI
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
unsigned getRegister2() const
void finalizeInOrder()
Finalize the string table without reording it.
#define DWARF2_FLAG_EPILOGUE_BEGIN
Instrumentation for Order File
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
static void emitAbsValue(MCStreamer &OS, const MCExpr *Value, unsigned Size)
unsigned getFDEEncoding() const
static void EmitDwarfLineTable(MCObjectStreamer *MCOS, MCSection *Section, const MCLineSection::MCDwarfLineEntryCollection &LineEntries)
static void EmitGenDwarfAranges(MCStreamer *MCOS, const MCSymbol *InfoSectionSymbol)
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
OpType getOperation() const
const MCObjectFileInfo * getObjectFileInfo() const
#define DWARF2_FLAG_BASIC_BLOCK
const MCDwarfFile & getRootFile() const
bool doDwarfFDESymbolsUseAbsDiff() const
const MCDwarfLoc & getCurrentDwarfLoc()
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
unsigned PersonalityEncoding
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile, bool EmitMD5, bool HasSource, Optional< MCDwarfLineStr > &LineStr)
StringRef getValues() const
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
int8_t DWARF2LineBase
Minimum line offset in a special line info.
StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
void generateCompactUnwindEncodings(MCAsmBackend *MAB)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
StringRef getCompilationDir() const
Get the compilation directory for DW_AT_comp_dir The compilation directory should be set with setComp...
unsigned getRegister() const
const SetVector< MCSection * > & getGenDwarfSectionSyms()
const std::vector< MCCFIInstruction > & getInitialFrameState() const
void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params, MCSection *Section) const
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
static unsigned getHashValue(const CIEKey &Key)
void EmitCU(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params, Optional< MCDwarfLineStr > &LineStr) const
static bool isRootFile(const MCDwarfFile &RootFile, StringRef &Directory, StringRef &FileName, Optional< MD5::MD5Result > Checksum)
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
unsigned getMinInstAlignment() const
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
static bool isEqual(const CIEKey &LHS, const CIEKey &RHS)
MCSymbol * getBeginSymbol()
StringRef str()
Return a StringRef for the vector contents.
MCSection * getDwarfInfoSection() const
void EmitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
uint32_t CompactUnwindEncoding
static void EmitGenDwarfRanges(MCStreamer *MCOS)
This file contains constants used for implementing Dwarf debug support.
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
MCSection * getCurrentSectionOnly() const
static CIEKey getEmptyKey()
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static void Emit(MCStreamer *MCOS)
iterator insert(iterator I, T &&Elt)
#define DWARF2_LINE_DEFAULT_IS_STMT
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
bool isStackGrowthDirectionUp() const
True if target stack grow up.
static uint64_t ScaleAddrDelta(MCContext &Context, uint64_t AddrDelta)
Instances of this class represent the line information for the dwarf line table entries.
static void Emit(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params)
static const MCExpr * MakeStartMinusEndExpr(const MCStreamer &MCOS, const MCSymbol &Start, const MCSymbol &End, int IntVal)
pointer data()
Return a pointer to the vector's buffer, even if empty().
static void EmitPersonality(MCStreamer &streamer, const MCSymbol &symbol, unsigned symbolEncoding)
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
static void Make(MCSymbol *Symbol, MCStreamer *MCOS, SourceMgr &SrcMgr, SMLoc &Loc)
LLVM_NODISCARD bool empty() const
const MCSymbol * Personality
static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, raw_ostream &OS, uint32_t *Offset=nullptr, uint32_t *Size=nullptr)
static const MCExpr * makeStartPlusIntExpr(MCContext &Ctx, const MCSymbol &Start, int IntVal)
unsigned getCalleeSaveStackSlotSize() const
Get the callee-saved register stack slot size in bytes.
bool isLittleEndian() const
True if the target is little endian.
Manage the .debug_line_str section contents, if we use it.
constexpr bool isUInt< 16 >(uint64_t x)
void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
MCSymbol * endSection(MCSection *Section)
StringRef getName() const
getName - Get the symbol name.
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void emitRef(MCStreamer *MCOS, StringRef Path)
Emit a reference to the string.
std::array< uint8_t, 16 > Bytes
bool operator<(int64_t V1, const APSInt &V2)
void stable_sort(R &&Range)
const MCRegisterInfo * getRegisterInfo() const
LLVM Value Representation.
Generic interface to target specific assembler backends.
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
uint64_t tell() const
tell - Return the current offset with the file.
static void emitEncodingByte(MCObjectStreamer &Streamer, unsigned Encoding)
This class implements an extremely fast bulk output stream that can only output to a stream...
void emitSection(MCStreamer *MCOS)
Emit the .debug_line_str section if appropriate.
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
StringRef - Represent a constant reference to a string, i.e.
Instances of this class represent the name of the dwarf .file directive and its associated dwarf file...
MCSection * getDwarfRangesSection() const
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, Optional< MD5::MD5Result > Checksum, Optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
Represents a location in source code.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
MCRegister getRARegister() const
This method should return the register where the return address can be found.
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...