diff options
author | Paul Robinson <paul.robinson@sony.com> | 2018-06-12 16:09:03 +0000 |
---|---|---|
committer | Paul Robinson <paul.robinson@sony.com> | 2018-06-12 16:09:03 +0000 |
commit | f69316c6179aa9b96e4fe04ec109c64e1995786c (patch) | |
tree | 7f06277b25f77252027e771789a3cee3e0ba8509 /llvm/lib | |
parent | ede97c95488a40c1e6cdbe99a3653afb88a60892 (diff) | |
download | bcm5719-llvm-f69316c6179aa9b96e4fe04ec109c64e1995786c.tar.gz bcm5719-llvm-f69316c6179aa9b96e4fe04ec109c64e1995786c.zip |
[DWARFv5] llvm-mc -dwarf-version does not imply -g.
Don't provide the assembler source as the "root file" unless the user
asked to have debug info for the assembler source (with -g).
If the source doesn't provide an explicit ".file 0" then (a) use the
compilation directory as directory #0, and (b) use the file #1 info
for file #0 also.
Differential Revision: https://reviews.llvm.org/D48055
llvm-svn: 334512
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/MCDwarf.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp index 57823e419f7..9dbe211cd8e 100644 --- a/llvm/lib/MC/MCDwarf.cpp +++ b/llvm/lib/MC/MCDwarf.cpp @@ -378,7 +378,8 @@ static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile, } void MCDwarfLineTableHeader::emitV5FileDirTables( - MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const { + MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr, + StringRef CtxCompilationDir) const { // The directory format, which is just a list of the directory paths. In a // non-split object, these are references to .debug_line_str; in a split // object, they are inline strings. @@ -387,14 +388,17 @@ void MCDwarfLineTableHeader::emitV5FileDirTables( MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp : dwarf::DW_FORM_string); MCOS->EmitULEB128IntValue(MCDwarfDirs.size() + 1); + // Try not to emit an empty compilation directory. + const StringRef &CompDir = + CompilationDir.empty() ? CtxCompilationDir : CompilationDir; if (LineStr) { // Record path strings, emit references here. - LineStr->emitRef(MCOS, CompilationDir); + LineStr->emitRef(MCOS, CompDir); for (auto &Dir : MCDwarfDirs) LineStr->emitRef(MCOS, Dir); } else { - // The list of directory paths. CompilationDir comes first. - MCOS->EmitBytes(CompilationDir); + // The list of directory paths. Compilation directory comes first. + MCOS->EmitBytes(CompDir); MCOS->EmitBytes(StringRef("\0", 1)); for (auto &Dir : MCDwarfDirs) { MCOS->EmitBytes(Dir); // The DirectoryName, and... @@ -426,9 +430,12 @@ void MCDwarfLineTableHeader::emitV5FileDirTables( : dwarf::DW_FORM_string); } // Then the counted list of files. The root file is file #0, then emit the - // files as provide by .file directives. + // files as provide by .file directives. To accommodate assembler source + // written for DWARF v4 but trying to emit v5, if we didn't see a root file + // explicitly, replicate file #1. MCOS->EmitULEB128IntValue(MCDwarfFiles.size()); - emitOneV5FileEntry(MCOS, RootFile, HasMD5, HasSource, LineStr); + emitOneV5FileEntry(MCOS, RootFile.Name.empty() ? MCDwarfFiles[1] : RootFile, + HasMD5, HasSource, LineStr); for (unsigned i = 1; i < MCDwarfFiles.size(); ++i) emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasMD5, HasSource, LineStr); } @@ -501,7 +508,7 @@ MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, // Put out the directory and file tables. The formats vary depending on // the version. if (LineTableVersion >= 5) - emitV5FileDirTables(MCOS, LineStr); + emitV5FileDirTables(MCOS, LineStr, context.getCompilationDir()); else emitV2FileDirTables(MCOS); |