aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCDwarf.cpp
diff options
context:
space:
mode:
authorPaul Robinson <paul.robinson@sony.com>2018-03-27 22:40:34 +0000
committerPaul Robinson <paul.robinson@sony.com>2018-03-27 22:40:34 +0000
commit07480bd17760c76fa6d51c4dfc3337247beda6de (patch)
tree90b9e07b451e8189cd79834b2f7e8cc89e54114e /llvm/lib/MC/MCDwarf.cpp
parent2519ee70810c561ce40e5e4e57a9c083d30faf67 (diff)
downloadllvm-07480bd17760c76fa6d51c4dfc3337247beda6de.zip
llvm-07480bd17760c76fa6d51c4dfc3337247beda6de.tar.gz
llvm-07480bd17760c76fa6d51c4dfc3337247beda6de.tar.bz2
Reapply "[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. Fixes the bug found by asan. Also XFAIL the new test for Darwin, which is stuck on DWARF v2, and fix up other tests so they stop failing on Windows. Last but not least, don't break "clang -g" of an assembler file that has .file directives in it. Differential Revision: https://reviews.llvm.org/D44054 llvm-svn: 328676
Diffstat (limited to 'llvm/lib/MC/MCDwarf.cpp')
-rw-r--r--llvm/lib/MC/MCDwarf.cpp61
1 files changed, 34 insertions, 27 deletions
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 2da69fe..0e0ea96 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -349,6 +349,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
@@ -397,33 +425,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 *>