[llvm] r334512 - [DWARFv5] llvm-mc -dwarf-version does not imply -g.

Paul Robinson via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 12 09:09:03 PDT 2018


Author: probinson
Date: Tue Jun 12 09:09:03 2018
New Revision: 334512

URL: http://llvm.org/viewvc/llvm-project?rev=334512&view=rev
Log:
[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

Modified:
    llvm/trunk/include/llvm/MC/MCDwarf.h
    llvm/trunk/lib/MC/MCDwarf.cpp
    llvm/trunk/test/MC/ELF/debug-file-options.s
    llvm/trunk/test/MC/ELF/debug-md5.s
    llvm/trunk/test/MC/ELF/debug-source.s
    llvm/trunk/test/MC/ELF/dwarf-file0.s
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp

Modified: llvm/trunk/include/llvm/MC/MCDwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=334512&r1=334511&r2=334512&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCDwarf.h (original)
+++ llvm/trunk/include/llvm/MC/MCDwarf.h Tue Jun 12 09:09:03 2018
@@ -234,8 +234,8 @@ struct MCDwarfLineTableHeader {
 
 private:
   void emitV2FileDirTables(MCStreamer *MCOS) const;
-  void emitV5FileDirTables(MCStreamer *MCOS,
-                           Optional<MCDwarfLineStr> &LineStr) const;
+  void emitV5FileDirTables(MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr,
+                           StringRef CtxCompilationDir) const;
 };
 
 class MCDwarfDwoLineTable {

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=334512&r1=334511&r2=334512&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Tue Jun 12 09:09:03 2018
@@ -378,7 +378,8 @@ static void emitOneV5FileEntry(MCStreame
 }
 
 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::emitV5FileD
   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::emitV5FileD
                                       : 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
   // 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);
 

Modified: llvm/trunk/test/MC/ELF/debug-file-options.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-file-options.s?rev=334512&r1=334511&r2=334512&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/debug-file-options.s (original)
+++ llvm/trunk/test/MC/ELF/debug-file-options.s Tue Jun 12 09:09:03 2018
@@ -16,15 +16,15 @@
 # CHECK: include_directories[ 2] = .debug_line_str[0x[[DIR2:[0-9a-f]+]]] = "dir2"
 # CHECK-NOT: include_directories
 # CHECK: file_names[ 0]:
-# CHECK-NEXT: name: .debug_line_str[0x[[FILE0:[0-9a-f]+]]] = "{{.+}}"
-# CHECK-NEXT: dir_index: 0
+# CHECK-NEXT: name: .debug_line_str[0x[[FILE0:[0-9a-f]+]]] = "foo"
+# CHECK-NEXT: dir_index: 1
 # CHECK-NEXT: md5_checksum:
-# CHECK-NEXT: source: .debug_line_str[0x[[FILE0SRC:[0-9a-f]+]]] = ""
+# CHECK-NEXT: source: .debug_line_str[0x[[FILE0SRC:[0-9a-f]+]]] = "void foo() {}"
 # CHECK: file_names[ 1]:
-# CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo"
+# CHECK-NEXT: name: .debug_line_str[0x[[FILE0]]] = "foo"
 # CHECK-NEXT: dir_index: 1
 # CHECK-NEXT: md5_checksum: ee87e05688663173cd6043a3a15bba6e
-# CHECK-NEXT: source: .debug_line_str[0x[[FILE1SRC:[0-9a-f]+]]] = "void foo() {}"
+# CHECK-NEXT: source: .debug_line_str[0x[[FILE0SRC]]] = "void foo() {}"
 # CHECK: file_names[ 2]:
 # CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar"
 # CHECK-NEXT: dir_index: 2
@@ -35,9 +35,7 @@
 # CHECK-NEXT: 0x[[DIR0]]: "{{.+}}"
 # CHECK-NEXT: 0x[[DIR1]]: "dir1"
 # CHECK-NEXT: 0x[[DIR2]]: "dir2"
-# CHECK-NEXT: 0x[[FILE0]]: "{{.+}}"
-# CHECK-NEXT: 0x[[FILE0SRC]]: ""
-# CHECK-NEXT: 0x[[FILE1]]: "foo"
-# CHECK-NEXT: 0x[[FILE1SRC]]: "void foo() {}"
+# CHECK-NEXT: 0x[[FILE0]]: "foo"
+# CHECK-NEXT: 0x[[FILE0SRC]]: "void foo() {}"
 # CHECK-NEXT: 0x[[FILE2]]: "bar"
 # CHECK-NEXT: 0x[[FILE2SRC]]: "void bar() {}"

Modified: llvm/trunk/test/MC/ELF/debug-md5.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-md5.s?rev=334512&r1=334511&r2=334512&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/debug-md5.s (original)
+++ llvm/trunk/test/MC/ELF/debug-md5.s Tue Jun 12 09:09:03 2018
@@ -14,10 +14,10 @@
 # CHECK: include_directories[ 2] = .debug_line_str[0x[[DIR2:[0-9a-f]+]]] = "dir2"
 # CHECK-NOT: include_directories
 # CHECK: file_names[ 0]:
-# CHECK-NEXT: name: .debug_line_str[0x[[FILE0:[0-9a-f]+]]] = "{{.+}}"
-# CHECK-NEXT: dir_index: 0
+# CHECK-NEXT: name: .debug_line_str[0x[[FILE0:[0-9a-f]+]]] = "foo"
+# CHECK-NEXT: dir_index: 1
 # CHECK: file_names[ 1]:
-# CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo"
+# CHECK-NEXT: name: .debug_line_str[0x[[FILE0]]] = "foo"
 # CHECK-NEXT: dir_index: 1
 # CHECK-NEXT: md5_checksum: 00112233445566778899aabbccddeeff
 # CHECK: file_names[ 2]:
@@ -29,6 +29,5 @@
 # CHECK-NEXT: 0x[[DIR0]]: "/tmp"
 # CHECK-NEXT: 0x[[DIR1]]: "dir1"
 # CHECK-NEXT: 0x[[DIR2]]: "dir2"
-# CHECK-NEXT: 0x[[FILE0]]: "{{.+}}"
-# CHECK-NEXT: 0x[[FILE1]]: "foo"
+# CHECK-NEXT: 0x[[FILE0]]: "foo"
 # CHECK-NEXT: 0x[[FILE2]]: "bar"

Modified: llvm/trunk/test/MC/ELF/debug-source.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-source.s?rev=334512&r1=334511&r2=334512&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/debug-source.s (original)
+++ llvm/trunk/test/MC/ELF/debug-source.s Tue Jun 12 09:09:03 2018
@@ -14,13 +14,13 @@
 # CHECK: include_directories[ 2] = .debug_line_str[0x[[DIR2:[0-9a-f]+]]] = "dir2"
 # CHECK-NOT: include_directories
 # CHECK: file_names[ 0]:
-# CHECK-NEXT: name: .debug_line_str[0x[[FILE0:[0-9a-f]+]]] = "{{.+}}"
-# CHECK-NEXT: dir_index: 0
-# CHECK-NEXT: source: .debug_line_str[0x[[FILE0SRC:[0-9a-f]+]]] = ""
+# CHECK-NEXT: name: .debug_line_str[0x[[FILE0:[0-9a-f]+]]] = "foo"
+# CHECK-NEXT: dir_index: 1
+# CHECK-NEXT: source: .debug_line_str[0x[[FILE0SRC:[0-9a-f]+]]] = "void foo() {}"
 # CHECK: file_names[ 1]:
-# CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo"
+# CHECK-NEXT: name: .debug_line_str[0x[[FILE0]]] = "foo"
 # CHECK-NEXT: dir_index: 1
-# CHECK-NEXT: source: .debug_line_str[0x[[FILE1SRC:[0-9a-f]+]]] = "void foo() {}"
+# CHECK-NEXT: source: .debug_line_str[0x[[FILE0SRC]]] = "void foo() {}"
 # CHECK: file_names[ 2]:
 # CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar"
 # CHECK-NEXT: dir_index: 2
@@ -30,9 +30,7 @@
 # CHECK-NEXT: 0x[[DIR0]]: "{{.+}}"
 # CHECK-NEXT: 0x[[DIR1]]: "dir1"
 # CHECK-NEXT: 0x[[DIR2]]: "dir2"
-# CHECK-NEXT: 0x[[FILE0]]: "{{.+}}"
-# CHECK-NEXT: 0x[[FILE0SRC]]: ""
-# CHECK-NEXT: 0x[[FILE1]]: "foo"
-# CHECK-NEXT: 0x[[FILE1SRC]]: "void foo() {}"
+# CHECK-NEXT: 0x[[FILE0]]: "foo"
+# CHECK-NEXT: 0x[[FILE0SRC]]: "void foo() {}"
 # CHECK-NEXT: 0x[[FILE2]]: "bar"
 # CHECK-NEXT: 0x[[FILE2SRC]]: "void bar()\n{\n}"

Modified: llvm/trunk/test/MC/ELF/dwarf-file0.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/dwarf-file0.s?rev=334512&r1=334511&r2=334512&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/dwarf-file0.s (original)
+++ llvm/trunk/test/MC/ELF/dwarf-file0.s Tue Jun 12 09:09:03 2018
@@ -6,7 +6,7 @@
         .file 0 "root.cpp"
         .file 1 "header.h"
         .file 2 "root.cpp"
-# CHECK-5:     include_directories[ 0] = ""
+# CHECK-5:     include_directories[ 0] = "{{.+}}"
 # CHECK-4-NOT: include_directories
 # CHECK-4-NOT: file_names[ 0]
 # CHECK-5:     file_names[ 0]:

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=334512&r1=334511&r2=334512&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Tue Jun 12 09:09:03 2018
@@ -389,7 +389,7 @@ int main(int argc, char **argv) {
   }
   if (!MainFileName.empty())
     Ctx.setMainFileName(MainFileName);
-  if (DwarfVersion >= 5) {
+  if (GenDwarfForAssembly && DwarfVersion >= 5) {
     // DWARF v5 needs the root file as well as the compilation directory.
     // If we find a '.file 0' directive that will supersede these values.
     MD5 Hash;




More information about the llvm-commits mailing list