diff options
author | Paul Robinson <paul.robinson@sony.com> | 2018-03-06 01:59:56 +0000 |
---|---|---|
committer | Paul Robinson <paul.robinson@sony.com> | 2018-03-06 01:59:56 +0000 |
commit | d5069ba3da031774ad6b751f0f72c65e7dda9b04 (patch) | |
tree | efa6dae9e93355da9e17edf2ba279c6ae71bdbf9 /llvm/lib/MC/MCDwarf.cpp | |
parent | b8b9af2ad46ff1ed901956c155c48c15cb585fa9 (diff) | |
download | llvm-d5069ba3da031774ad6b751f0f72c65e7dda9b04.zip llvm-d5069ba3da031774ad6b751f0f72c65e7dda9b04.tar.gz llvm-d5069ba3da031774ad6b751f0f72c65e7dda9b04.tar.bz2 |
[DWARFv5] Emit file 0 to the line table.
DWARF v5 specifies that the root file (also given in the DW_AT_name
attribute of the compilation unit DIE) should be emitted explicitly to
the line table's list of files. This makes the line table more
independent of the .debug_info section.
Differential Revision: https://reviews.llvm.org/D44054
llvm-svn: 326758
Diffstat (limited to 'llvm/lib/MC/MCDwarf.cpp')
-rw-r--r-- | llvm/lib/MC/MCDwarf.cpp | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp index 685b46a..ee675ac 100644 --- a/llvm/lib/MC/MCDwarf.cpp +++ b/llvm/lib/MC/MCDwarf.cpp @@ -346,6 +346,34 @@ void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const { MCOS->EmitIntValue(0, 1); // Terminate the file list. } +static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile, + bool HasMD5, bool HasSource, + Optional<MCDwarfLineStr> &LineStr) { + assert(!DwarfFile.Name.empty()); + if (LineStr) + LineStr->emitRef(MCOS, DwarfFile.Name); + else { + MCOS->EmitBytes(DwarfFile.Name); // FileName and... + MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator. + } + MCOS->EmitULEB128IntValue(DwarfFile.DirIndex); // Directory number. + if (HasMD5) { + MD5::MD5Result *Cksum = DwarfFile.Checksum; + MCOS->EmitBinaryData( + StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()), + Cksum->Bytes.size())); + } + if (HasSource) { + if (LineStr) + LineStr->emitRef(MCOS, DwarfFile.Source.getValueOr(StringRef())); + else { + MCOS->EmitBytes( + DwarfFile.Source.getValueOr(StringRef())); // Source and... + MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator. + } + } +} + void MCDwarfLineTableHeader::emitV5FileDirTables( MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const { // The directory format, which is just a list of the directory paths. In a @@ -394,33 +422,12 @@ void MCDwarfLineTableHeader::emitV5FileDirTables( MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp : dwarf::DW_FORM_string); } - // Then the list of file names. These start at 1. - MCOS->EmitULEB128IntValue(MCDwarfFiles.size() - 1); - for (unsigned i = 1; i < MCDwarfFiles.size(); ++i) { - assert(!MCDwarfFiles[i].Name.empty()); - if (LineStr) - LineStr->emitRef(MCOS, MCDwarfFiles[i].Name); - else { - MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName and... - MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator. - } - MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex); // Directory number. - if (HasMD5) { - MD5::MD5Result *Cksum = MCDwarfFiles[i].Checksum; - MCOS->EmitBinaryData( - StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()), - Cksum->Bytes.size())); - } - if (HasSource) { - if (LineStr) - LineStr->emitRef(MCOS, MCDwarfFiles[i].Source.getValueOr(StringRef())); - else { - MCOS->EmitBytes( - MCDwarfFiles[i].Source.getValueOr(StringRef())); // Source and... - MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator. - } - } - } + // Then the counted list of files. The root file is file #0, then emit the + // files as provide by .file directives. + MCOS->EmitULEB128IntValue(MCDwarfFiles.size()); + emitOneV5FileEntry(MCOS, RootFile, HasMD5, HasSource, LineStr); + for (unsigned i = 1; i < MCDwarfFiles.size(); ++i) + emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasMD5, HasSource, LineStr); } std::pair<MCSymbol *, MCSymbol *> |