<div dir="ltr"><div>This commit breaks assembly file parsing:</div><div><br></div><div>$ cat q.c <br></div><div>void g() {}</div><div>$ clang -S q.c -g</div><div>$ clang -g -c q.s </div><div>q.s:9:2: error: file number already allocated</div><div>        .file   1 "/tmp/test" "q.c"</div><div>        ^</div><div><br></div><div>Please fix or revert.</div><div><br></div><div>Thank you!</div></div><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Mar 6, 2018 at 11:40 PM Paul Robinson via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: probinson<br>
Date: Tue Mar  6 14:37:45 2018<br>
New Revision: 326839<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=326839&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=326839&view=rev</a><br>
Log:<br>
Reapply "[DWARFv5] Emit file 0 to the line table."<br>
<br>
Fixes the bug found by asan. Also XFAIL the new test for Darwin,<br>
which is stuck on DWARF v2, and fix up other tests so they stop<br>
failing on Windows.<br>
<br>
Added:<br>
    llvm/trunk/test/MC/ELF/dwarf-file0.s<br>
Modified:<br>
    llvm/trunk/include/llvm/MC/MCContext.h<br>
    llvm/trunk/include/llvm/MC/MCDwarf.h<br>
    llvm/trunk/include/llvm/MC/MCStreamer.h<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h<br>
    llvm/trunk/lib/MC/MCAsmStreamer.cpp<br>
    llvm/trunk/lib/MC/MCDwarf.cpp<br>
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
    llvm/trunk/lib/MC/MCStreamer.cpp<br>
    llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll<br>
    llvm/trunk/test/CodeGen/Generic/dwarf-source.ll<br>
    llvm/trunk/test/DebugInfo/X86/dbg-file-name.ll<br>
    llvm/trunk/test/DebugInfo/X86/inline-asm-locs.ll<br>
    llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s<br>
    llvm/trunk/test/MC/ELF/debug-file-options.s<br>
    llvm/trunk/test/MC/ELF/debug-md5.s<br>
    llvm/trunk/test/MC/ELF/debug-source.s<br>
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCContext.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCContext.h Tue Mar  6 14:37:45 2018<br>
@@ -537,8 +537,13 @@ namespace llvm {<br>
       DwarfCompileUnitID = CUIndex;<br>
     }<br>
<br>
-    void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir) {<br>
-      getMCDwarfLineTable(CUID).setCompilationDir(CompilationDir);<br>
+    /// Specifies the "root" file and directory of the compilation unit.<br>
+    /// These are "file 0" and "directory 0" in DWARF v5.<br>
+    void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir,<br>
+                                StringRef Filename, MD5::MD5Result *Checksum,<br>
+                                Optional<StringRef> Source) {<br>
+      getMCDwarfLineTable(CUID).setRootFile(CompilationDir, Filename, Checksum,<br>
+                                            Source);<br>
     }<br>
<br>
     /// Saves the information from the currently parsed dwarf .loc directive<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCDwarf.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCDwarf.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCDwarf.h Tue Mar  6 14:37:45 2018<br>
@@ -214,6 +214,7 @@ struct MCDwarfLineTableHeader {<br>
   SmallVector<MCDwarfFile, 3> MCDwarfFiles;<br>
   StringMap<unsigned> SourceIdMap;<br>
   StringRef CompilationDir;<br>
+  MCDwarfFile RootFile;<br>
   bool HasMD5 = false;<br>
   bool HasSource = false;<br>
<br>
@@ -241,8 +242,17 @@ class MCDwarfDwoLineTable {<br>
   MCDwarfLineTableHeader Header;<br>
<br>
 public:<br>
-  void setCompilationDir(StringRef CompilationDir) {<br>
-    Header.CompilationDir = CompilationDir;<br>
+  void maybeSetRootFile(StringRef Directory, StringRef FileName,<br>
+                        MD5::MD5Result *Checksum, Optional<StringRef> Source) {<br>
+    if (!Header.RootFile.Name.empty())<br>
+      return;<br>
+    Header.CompilationDir = Directory;<br>
+    <a href="http://Header.RootFile.Name" rel="noreferrer" target="_blank">Header.RootFile.Name</a> = FileName;<br>
+    Header.RootFile.DirIndex = 0;<br>
+    Header.RootFile.Checksum = Checksum;<br>
+    Header.RootFile.Source = Source;<br>
+    Header.HasMD5 = (Checksum != nullptr);<br>
+    Header.HasSource = Source.hasValue();<br>
   }<br>
<br>
   unsigned getFile(StringRef Directory, StringRef FileName,<br>
@@ -276,6 +286,17 @@ public:<br>
                                FileNumber));<br>
   }<br>
<br>
+  void setRootFile(StringRef Directory, StringRef FileName,<br>
+                   MD5::MD5Result *Checksum, Optional<StringRef> Source) {<br>
+    Header.CompilationDir = Directory;<br>
+    <a href="http://Header.RootFile.Name" rel="noreferrer" target="_blank">Header.RootFile.Name</a> = FileName;<br>
+    Header.RootFile.DirIndex = 0;<br>
+    Header.RootFile.Checksum = Checksum;<br>
+    Header.RootFile.Source = Source;<br>
+    Header.HasMD5 = (Checksum != nullptr);<br>
+    Header.HasSource = Source.hasValue();<br>
+  }<br>
+<br>
   MCSymbol *getLabel() const {<br>
     return Header.Label;<br>
   }<br>
@@ -284,10 +305,6 @@ public:<br>
     Header.Label = Label;<br>
   }<br>
<br>
-  void setCompilationDir(StringRef CompilationDir) {<br>
-    Header.CompilationDir = CompilationDir;<br>
-  }<br>
-<br>
   const SmallVectorImpl<std::string> &getMCDwarfDirs() const {<br>
     return Header.MCDwarfDirs;<br>
   }<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCStreamer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Tue Mar  6 14:37:45 2018<br>
@@ -774,6 +774,12 @@ public:<br>
       MD5::MD5Result *Checksum = nullptr, Optional<StringRef> Source = None,<br>
       unsigned CUID = 0);<br>
<br>
+  /// Specify the "root" file of the compilation, using the ".file 0" extension.<br>
+  virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,<br>
+                                       MD5::MD5Result *Checksum,<br>
+                                       Optional<StringRef> Source,<br>
+                                       unsigned CUID = 0);<br>
+<br>
   /// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler<br>
   /// directive.<br>
   virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Mar  6 14:37:45 2018<br>
@@ -476,8 +476,9 @@ DwarfDebug::getOrCreateDwarfCompileUnit(<br>
   // explicitly describe the directory of all files, never relying on the<br>
   // compilation directory.<br>
   if (!Asm->OutStreamer->hasRawTextSupport() || SingleCU)<br>
-    Asm->OutStreamer->getContext().setMCLineTableCompilationDir(<br>
-        NewCU.getUniqueID(), CompilationDir);<br>
+    Asm->OutStreamer->emitDwarfFile0Directive(<br>
+        CompilationDir, FN, NewCU.getMD5AsBytes(DIUnit->getFile()),<br>
+        DIUnit->getSource(), NewCU.getUniqueID());<br>
<br>
   StringRef Producer = DIUnit->getProducer();<br>
   StringRef Flags = DIUnit->getFlags();<br>
@@ -2110,8 +2111,10 @@ void DwarfDebug::emitDebugStrDWO() {<br>
 MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {<br>
   if (!useSplitDwarf())<br>
     return nullptr;<br>
-  if (SingleCU)<br>
-    SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode()->getDirectory());<br>
+  const DICompileUnit *DIUnit = CU.getCUNode();<br>
+  SplitTypeUnitFileTable.maybeSetRootFile(<br>
+      DIUnit->getDirectory(), DIUnit->getFilename(),<br>
+      CU.getMD5AsBytes(DIUnit->getFile()), DIUnit->getSource());<br>
   return &SplitTypeUnitFileTable;<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Tue Mar  6 14:37:45 2018<br>
@@ -284,7 +284,7 @@ void DwarfUnit::addSectionOffset(DIE &Di<br>
     addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);<br>
 }<br>
<br>
-MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) {<br>
+MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) const {<br>
   assert(File);<br>
   Optional<DIFile::ChecksumInfo<StringRef>> Checksum = File->getChecksum();<br>
   if (!Checksum || Checksum->Kind != DIFile::CSK_MD5)<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h Tue Mar  6 14:37:45 2018<br>
@@ -306,6 +306,10 @@ public:<br>
                                       const MCSymbol *Label,<br>
                                       const MCSymbol *Sec);<br>
<br>
+  /// If the \p File has an MD5 checksum, return it as an MD5Result<br>
+  /// allocated in the MCContext.<br>
+  MD5::MD5Result *getMD5AsBytes(const DIFile *File) const;<br>
+<br>
 protected:<br>
   ~DwarfUnit();<br>
<br>
@@ -316,10 +320,6 @@ protected:<br>
   /// create a new ID and insert it in the line table.<br>
   virtual unsigned getOrCreateSourceID(const DIFile *File) = 0;<br>
<br>
-  /// If the \p File has an MD5 checksum, return it as an MD5Result<br>
-  /// allocated in the MCContext.<br>
-  MD5::MD5Result *getMD5AsBytes(const DIFile *File);<br>
-<br>
   /// Look in the DwarfDebug map for the MDNode that corresponds to the<br>
   /// reference.<br>
   template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {<br>
<br>
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Tue Mar  6 14:37:45 2018<br>
@@ -218,6 +218,10 @@ public:<br>
                                                MD5::MD5Result *Checksum = 0,<br>
                                                Optional<StringRef> Source = None,<br>
                                                unsigned CUID = 0) override;<br>
+  void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,<br>
+                               MD5::MD5Result *Checksum,<br>
+                               Optional<StringRef> Source,<br>
+                               unsigned CUID = 0) override;<br>
   void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,<br>
                              unsigned Column, unsigned Flags,<br>
                              unsigned Isa, unsigned Discriminator,<br>
@@ -1076,21 +1080,10 @@ void MCAsmStreamer::EmitFileDirective(St<br>
   EmitEOL();<br>
 }<br>
<br>
-Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(<br>
-    unsigned FileNo, StringRef Directory, StringRef Filename,<br>
-    MD5::MD5Result *Checksum, Optional<StringRef> Source, unsigned CUID) {<br>
-  assert(CUID == 0);<br>
-<br>
-  MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);<br>
-  unsigned NumFiles = Table.getMCDwarfFiles().size();<br>
-  Expected<unsigned> FileNoOrErr =<br>
-      Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo);<br>
-  if (!FileNoOrErr)<br>
-    return FileNoOrErr.takeError();<br>
-  FileNo = FileNoOrErr.get();<br>
-  if (NumFiles == Table.getMCDwarfFiles().size())<br>
-    return FileNo;<br>
-<br>
+void printDwarfFileDirective(unsigned FileNo, StringRef Directory,<br>
+                             StringRef Filename, MD5::MD5Result *Checksum,<br>
+                             Optional<StringRef> Source, bool UseDwarfDirectory,<br>
+                             raw_svector_ostream &OS) {<br>
   SmallString<128> FullPathName;<br>
<br>
   if (!UseDwarfDirectory && !Directory.empty()) {<br>
@@ -1104,31 +1097,68 @@ Expected<unsigned> MCAsmStreamer::tryEmi<br>
     }<br>
   }<br>
<br>
-  SmallString<128> Str;<br>
-  raw_svector_ostream OS1(Str);<br>
-  OS1 << "\t.file\t" << FileNo << ' ';<br>
+  OS << "\t.file\t" << FileNo << ' ';<br>
   if (!Directory.empty()) {<br>
-    PrintQuotedString(Directory, OS1);<br>
-    OS1 << ' ';<br>
+    PrintQuotedString(Directory, OS);<br>
+    OS << ' ';<br>
   }<br>
-  PrintQuotedString(Filename, OS1);<br>
+  PrintQuotedString(Filename, OS);<br>
   if (Checksum) {<br>
-    OS1 << " md5 ";<br>
-    PrintQuotedString(Checksum->digest(), OS1);<br>
+    OS << " md5 ";<br>
+    PrintQuotedString(Checksum->digest(), OS);<br>
   }<br>
   if (Source) {<br>
-    OS1 << " source ";<br>
-    PrintQuotedString(*Source, OS1);<br>
+    OS << " source ";<br>
+    PrintQuotedString(*Source, OS);<br>
   }<br>
-  if (MCTargetStreamer *TS = getTargetStreamer()) {<br>
+}<br>
+<br>
+Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(<br>
+    unsigned FileNo, StringRef Directory, StringRef Filename,<br>
+    MD5::MD5Result *Checksum, Optional<StringRef> Source, unsigned CUID) {<br>
+  assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer");<br>
+<br>
+  MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);<br>
+  unsigned NumFiles = Table.getMCDwarfFiles().size();<br>
+  Expected<unsigned> FileNoOrErr =<br>
+      Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo);<br>
+  if (!FileNoOrErr)<br>
+    return FileNoOrErr.takeError();<br>
+  FileNo = FileNoOrErr.get();<br>
+  if (NumFiles == Table.getMCDwarfFiles().size())<br>
+    return FileNo;<br>
+<br>
+  SmallString<128> Str;<br>
+  raw_svector_ostream OS1(Str);<br>
+  printDwarfFileDirective(FileNo, Directory, Filename, Checksum, Source,<br>
+                          UseDwarfDirectory, OS1);<br>
+<br>
+  if (MCTargetStreamer *TS = getTargetStreamer())<br>
     TS->emitDwarfFileDirective(OS1.str());<br>
-  } else {<br>
+  else<br>
     EmitRawText(OS1.str());<br>
-  }<br>
<br>
   return FileNo;<br>
 }<br>
<br>
+void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory,<br>
+                                            StringRef Filename,<br>
+                                            MD5::MD5Result *Checksum,<br>
+                                            Optional<StringRef> Source,<br>
+                                            unsigned CUID) {<br>
+  assert(CUID == 0);<br>
+<br>
+  SmallString<128> Str;<br>
+  raw_svector_ostream OS1(Str);<br>
+  printDwarfFileDirective(0, Directory, Filename, Checksum, Source,<br>
+                          UseDwarfDirectory, OS1);<br>
+<br>
+  if (MCTargetStreamer *TS = getTargetStreamer())<br>
+    TS->emitDwarfFileDirective(OS1.str());<br>
+  else<br>
+    EmitRawText(OS1.str());<br>
+}<br>
+<br>
 void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,<br>
                                           unsigned Column, unsigned Flags,<br>
                                           unsigned Isa,<br>
<br>
Modified: llvm/trunk/lib/MC/MCDwarf.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCDwarf.cpp Tue Mar  6 14:37:45 2018<br>
@@ -346,6 +346,34 @@ void MCDwarfLineTableHeader::emitV2FileD<br>
   MCOS->EmitIntValue(0, 1); // Terminate the file list.<br>
 }<br>
<br>
+static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,<br>
+                               bool HasMD5, bool HasSource,<br>
+                               Optional<MCDwarfLineStr> &LineStr) {<br>
+  assert(!DwarfFile.Name.empty());<br>
+  if (LineStr)<br>
+    LineStr->emitRef(MCOS, DwarfFile.Name);<br>
+  else {<br>
+    MCOS->EmitBytes(DwarfFile.Name);     // FileName and...<br>
+    MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.<br>
+  }<br>
+  MCOS->EmitULEB128IntValue(DwarfFile.DirIndex); // Directory number.<br>
+  if (HasMD5) {<br>
+    MD5::MD5Result *Cksum = DwarfFile.Checksum;<br>
+    MCOS->EmitBinaryData(<br>
+        StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()),<br>
+                  Cksum->Bytes.size()));<br>
+  }<br>
+  if (HasSource) {<br>
+    if (LineStr)<br>
+      LineStr->emitRef(MCOS, DwarfFile.Source.getValueOr(StringRef()));<br>
+    else {<br>
+      MCOS->EmitBytes(<br>
+          DwarfFile.Source.getValueOr(StringRef())); // Source and...<br>
+      MCOS->EmitBytes(StringRef("\0", 1));           // its null terminator.<br>
+    }<br>
+  }<br>
+}<br>
+<br>
 void MCDwarfLineTableHeader::emitV5FileDirTables(<br>
     MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const {<br>
   // The directory format, which is just a list of the directory paths.  In a<br>
@@ -394,33 +422,12 @@ void MCDwarfLineTableHeader::emitV5FileD<br>
     MCOS->EmitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp<br>
                                       : dwarf::DW_FORM_string);<br>
   }<br>
-  // Then the list of file names. These start at 1.<br>
-  MCOS->EmitULEB128IntValue(MCDwarfFiles.size() - 1);<br>
-  for (unsigned i = 1; i < MCDwarfFiles.size(); ++i) {<br>
-    assert(!MCDwarfFiles[i].Name.empty());<br>
-    if (LineStr)<br>
-      LineStr->emitRef(MCOS, MCDwarfFiles[i].Name);<br>
-    else {<br>
-      MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName and...<br>
-      MCOS->EmitBytes(StringRef("\0", 1));   // its null terminator.<br>
-    }<br>
-    MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex); // Directory number.<br>
-    if (HasMD5) {<br>
-      MD5::MD5Result *Cksum = MCDwarfFiles[i].Checksum;<br>
-      MCOS->EmitBinaryData(<br>
-          StringRef(reinterpret_cast<const char *>(Cksum->Bytes.data()),<br>
-                    Cksum->Bytes.size()));<br>
-    }<br>
-    if (HasSource) {<br>
-      if (LineStr)<br>
-        LineStr->emitRef(MCOS, MCDwarfFiles[i].Source.getValueOr(StringRef()));<br>
-      else {<br>
-        MCOS->EmitBytes(<br>
-            MCDwarfFiles[i].Source.getValueOr(StringRef())); // Source and...<br>
-        MCOS->EmitBytes(StringRef("\0", 1)); // its null terminator.<br>
-      }<br>
-    }<br>
-  }<br>
+  // Then the counted list of files. The root file is file #0, then emit the<br>
+  // files as provide by .file directives.<br>
+  MCOS->EmitULEB128IntValue(MCDwarfFiles.size());<br>
+  emitOneV5FileEntry(MCOS, RootFile, HasMD5, HasSource, LineStr);<br>
+  for (unsigned i = 1; i < MCDwarfFiles.size(); ++i)<br>
+    emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasMD5, HasSource, LineStr);<br>
 }<br>
<br>
 std::pair<MCSymbol *, MCSymbol *><br>
<br>
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Mar  6 14:37:45 2018<br>
@@ -3258,8 +3258,8 @@ bool AsmParser::parseDirectiveFile(SMLoc<br>
     FileNumber = getTok().getIntVal();<br>
     Lex();<br>
<br>
-    if (FileNumber < 1)<br>
-      return TokError("file number less than one");<br>
+    if (FileNumber < 0)<br>
+      return TokError("negative file number");<br>
   }<br>
<br>
   std::string Path = getTok().getString();<br>
@@ -3338,6 +3338,8 @@ bool AsmParser::parseDirectiveFile(SMLoc<br>
     // we turn off -g option, directly use the existing debug info instead.<br>
     if (getContext().getGenDwarfForAssembly())<br>
       getContext().setGenDwarfForAssembly(false);<br>
+    else if (FileNumber == 0)<br>
+      getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);<br>
     else {<br>
       Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(<br>
           FileNumber, Directory, Filename, CKMem, Source);<br>
<br>
Modified: llvm/trunk/lib/MC/MCStreamer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCStreamer.cpp Tue Mar  6 14:37:45 2018<br>
@@ -199,6 +199,15 @@ MCStreamer::tryEmitDwarfFileDirective(un<br>
                                    Source, CUID);<br>
 }<br>
<br>
+void MCStreamer::emitDwarfFile0Directive(StringRef Directory,<br>
+                                         StringRef Filename,<br>
+                                         MD5::MD5Result *Checksum,<br>
+                                         Optional<StringRef> Source,<br>
+                                         unsigned CUID) {<br>
+  getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,<br>
+                                      Source);<br>
+}<br>
+<br>
 void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,<br>
                                        unsigned Column, unsigned Flags,<br>
                                        unsigned Isa,<br>
<br>
Modified: llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll (original)<br>
+++ llvm/trunk/test/CodeGen/Generic/dwarf-md5.ll Tue Mar  6 14:37:45 2018<br>
@@ -8,28 +8,25 @@<br>
 ; RUN: %llc_dwarf -dwarf-version 4 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM<br>
 ; RUN: %llc_dwarf -dwarf-version 5 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM<br>
 ; RUN: %llc_dwarf -dwarf-version 4 -filetype=obj -o %t4.o %s<br>
-; RUN: llvm-dwarfdump -debug-line %t4.o | FileCheck %s --check-prefix=OBJ-4<br>
+; RUN: llvm-dwarfdump -debug-line %t4.o | FileCheck %s --check-prefix=OBJ<br>
 ; RUN: %llc_dwarf -dwarf-version 5 -filetype=obj -o %t5.o %s<br>
-; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefix=OBJ-5<br>
+; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefixes=OBJ,OBJ-5<br>
<br>
-; FIXME: Need to convey the MD5 for the primary source file.<br>
-; ASM: .file 1 ".{{/|\\\\}}t1.h" md5 "11111111111111111111111111111111"<br>
-; ASM: .file 2 ".{{/|\\\\}}t2.h" md5 "22222222222222222222222222222222"<br>
-<br>
-; OBJ-4: file_names[ 1]:<br>
-; OBJ-4-NEXT: name: "t1.h"<br>
-; OBJ-4-NEXT: dir_index: 1<br>
-; OBJ-4: file_names[ 2]:<br>
-; OBJ-4-NEXT: name: "t2.h"<br>
-; OBJ-4-NEXT: dir_index: 1<br>
+; ASM: .file 0 "[[COMPDIR:.*]]{{[/\\]}}t.c" md5 "00000000000000000000000000000000"<br>
+; ASM: .file 1 "[[COMPDIR]]{{[/\\]}}t1.h" md5 "11111111111111111111111111111111"<br>
+; ASM: .file 2 "[[COMPDIR]]{{[/\\]}}t2.h" md5 "22222222222222222222222222222222"<br>
<br>
 ; OBJ-5: file_names[ 0]:<br>
-; OBJ-5-NEXT: name: "t1.h"<br>
-; OBJ-5-NEXT: dir_index: 1<br>
+; OBJ-5-NEXT: name: "t.c"<br>
+; OBJ-5-NEXT: dir_index: 0<br>
+; OBJ-5-NEXT: md5_checksum: 00000000000000000000000000000000<br>
+; OBJ: file_names[ 1]:<br>
+; OBJ-NEXT: name: "t1.h"<br>
+; OBJ-NEXT: dir_index: 0<br>
 ; OBJ-5-NEXT: md5_checksum: 11111111111111111111111111111111<br>
-; OBJ-5: file_names[ 1]:<br>
-; OBJ-5-NEXT: name: "t2.h"<br>
-; OBJ-5-NEXT: dir_index: 1<br>
+; OBJ: file_names[ 2]:<br>
+; OBJ-NEXT: name: "t2.h"<br>
+; OBJ-NEXT: dir_index: 0<br>
 ; OBJ-5-NEXT: md5_checksum: 22222222222222222222222222222222<br>
<br>
 ; ModuleID = 't.c'<br>
@@ -50,9 +47,9 @@ source_filename = "t.c"<br>
 !5 = !{!0, !6}<br>
 !6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())<br>
 !7 = distinct !DIGlobalVariable(name: "t2", scope: !2, file: !8, line: 1, type: !9, isLocal: false, isDefinition: true)<br>
-!8 = !DIFile(filename: "./t2.h", directory: "/home/probinson/projects/scratch", checksumkind: CSK_MD5, checksum: "22222222222222222222222222222222")<br>
+!8 = !DIFile(filename: "t2.h", directory: "/home/probinson/projects/scratch", checksumkind: CSK_MD5, checksum: "22222222222222222222222222222222")<br>
 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
-!10 = !DIFile(filename: "./t1.h", directory: "/home/probinson/projects/scratch", checksumkind: CSK_MD5, checksum: "11111111111111111111111111111111")<br>
+!10 = !DIFile(filename: "t1.h", directory: "/home/probinson/projects/scratch", checksumkind: CSK_MD5, checksum: "11111111111111111111111111111111")<br>
 !11 = !{i32 2, !"Dwarf Version", i32 4}<br>
 !12 = !{i32 2, !"Debug Info Version", i32 3}<br>
 !13 = !{i32 1, !"wchar_size", i32 4}<br>
<br>
Modified: llvm/trunk/test/CodeGen/Generic/dwarf-source.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/dwarf-source.ll?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/dwarf-source.ll?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/Generic/dwarf-source.ll (original)<br>
+++ llvm/trunk/test/CodeGen/Generic/dwarf-source.ll Tue Mar  6 14:37:45 2018<br>
@@ -8,30 +8,27 @@<br>
 ; RUN: %llc_dwarf -dwarf-version 4 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM<br>
 ; RUN: %llc_dwarf -dwarf-version 5 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM<br>
 ; RUN: %llc_dwarf -dwarf-version 4 -filetype=obj -o %t4.o %s<br>
-; RUN: llvm-dwarfdump -debug-line %t4.o | FileCheck %s --check-prefix=OBJ-4<br>
+; RUN: llvm-dwarfdump -debug-line %t4.o | FileCheck %s --check-prefixes=OBJ,OBJ-4<br>
 ; RUN: %llc_dwarf -dwarf-version 5 -filetype=obj -o %t5.o %s<br>
-; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefix=OBJ-5<br>
+; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefixes=OBJ,OBJ-5<br>
<br>
-; FIXME: Need to convey the source for the primary source file.<br>
-; ASM: .file 1 ".{{/|\\\\}}t1.h" source "11111111111111111111111111111111"<br>
-; ASM: .file 2 ".{{/|\\\\}}t2.h" source "22222222222222222222222222222222"<br>
-<br>
-; OBJ-4: file_names[ 1]:<br>
-; OBJ-4-NEXT: name: "t1.h"<br>
-; OBJ-4-NEXT: dir_index: 1<br>
-; OBJ-4-NOT: 11111111111111111111111111111111<br>
-; OBJ-4: file_names[ 2]:<br>
-; OBJ-4-NEXT: name: "t2.h"<br>
-; OBJ-4-NEXT: dir_index: 1<br>
-; OBJ-4-NOT: 22222222222222222222222222222222<br>
+; ASM: .file 0 "[[COMPDIR:.*]]{{[/\\]}}t.c" source "00000000000000000000000000000000"<br>
+; ASM: .file 1 "[[COMPDIR]]{{[/\\]}}t1.h" source "11111111111111111111111111111111"<br>
+; ASM: .file 2 "[[COMPDIR]]{{[/\\]}}t2.h" source "22222222222222222222222222222222"<br>
<br>
 ; OBJ-5: file_names[ 0]:<br>
-; OBJ-5-NEXT: name: "t1.h"<br>
-; OBJ-5-NEXT: dir_index: 1<br>
+; OBJ-5-NEXT: name: "t.c"<br>
+; OBJ-5-NEXT: dir_index: 0<br>
+; OBJ-5-NEXT: source: "00000000000000000000000000000000"<br>
+; OBJ: file_names[ 1]:<br>
+; OBJ-NEXT: name: "t1.h"<br>
+; OBJ-NEXT: dir_index: 0<br>
+; OBJ-4-NOT: 11111111111111111111111111111111<br>
 ; OBJ-5-NEXT: source: "11111111111111111111111111111111"<br>
-; OBJ-5: file_names[ 1]:<br>
-; OBJ-5-NEXT: name: "t2.h"<br>
-; OBJ-5-NEXT: dir_index: 1<br>
+; OBJ: file_names[ 2]:<br>
+; OBJ-NEXT: name: "t2.h"<br>
+; OBJ-NEXT: dir_index: 0<br>
+; OBJ-4-NOT: 22222222222222222222222222222222<br>
 ; OBJ-5-NEXT: source: "22222222222222222222222222222222"<br>
<br>
 ; ModuleID = 't.c'<br>
@@ -52,9 +49,9 @@ source_filename = "t.c"<br>
 !5 = !{!0, !6}<br>
 !6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())<br>
 !7 = distinct !DIGlobalVariable(name: "t2", scope: !2, file: !8, line: 1, type: !9, isLocal: false, isDefinition: true)<br>
-!8 = !DIFile(filename: "./t2.h", directory: "/test", source: "22222222222222222222222222222222")<br>
+!8 = !DIFile(filename: "t2.h", directory: "/test", source: "22222222222222222222222222222222")<br>
 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
-!10 = !DIFile(filename: "./t1.h", directory: "/test", source: "11111111111111111111111111111111")<br>
+!10 = !DIFile(filename: "t1.h", directory: "/test", source: "11111111111111111111111111111111")<br>
 !11 = !{i32 2, !"Dwarf Version", i32 4}<br>
 !12 = !{i32 2, !"Debug Info Version", i32 3}<br>
 !13 = !{i32 1, !"wchar_size", i32 4}<br>
<br>
Modified: llvm/trunk/test/DebugInfo/X86/dbg-file-name.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dbg-file-name.ll?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dbg-file-name.ll?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/X86/dbg-file-name.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/X86/dbg-file-name.ll Tue Mar  6 14:37:45 2018<br>
@@ -2,7 +2,7 @@<br>
<br>
 ; Verify that the file name is relative to the directory.<br>
 ; rdar://problem/8884898<br>
-; CHECK: file  1 "simple.c"<br>
+; CHECK: file  1 "/Users/manav/one/two" "simple.c"<br>
<br>
 declare i32 @printf(i8*, ...) nounwind<br>
<br>
<br>
Modified: llvm/trunk/test/DebugInfo/X86/inline-asm-locs.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/inline-asm-locs.ll?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/inline-asm-locs.ll?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/X86/inline-asm-locs.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/X86/inline-asm-locs.ll Tue Mar  6 14:37:45 2018<br>
@@ -22,7 +22,7 @@<br>
 ; CHECK: .file 2 "B.asm"<br>
 ; CHECK: .loc  1 111<br>
 ; CHECK: .loc  2 222<br>
-; CHECK: .file 3 "test.c"<br>
+; CHECK: .file 3 "{{.*[/\\]}}test.c"<br>
 ; CHECK: .loc  3 14 0<br>
<br>
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
<br>
Modified: llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s (original)<br>
+++ llvm/trunk/test/MC/ARM/dwarf-asm-multiple-sections.s Tue Mar  6 14:37:45 2018<br>
@@ -54,9 +54,9 @@ b:<br>
 // DWARF-DL: .debug_line contents:<br>
 // DWARF-DL: version: [[DWVER]]<br>
 // DWARF-DL-5:    address_size: 4<br>
-// DWARF-DL-5:    include_directories[  0] = ""<br>
+// DWARF-DL-5:    include_directories[  0] = "/tmp"<br>
 // DWARF-DL:      file_names[  [[DWFILE]]]:<br>
-// DWARF-DL:      name: "<stdin>"<br>
+// DWARF-DL:      name: "{{(<stdin>|-)}}"<br>
 // DWARF-DL:      0x0000000000000000     17      0      1   0   0  is_stmt<br>
 // DWARF-DL-NEXT: 0x0000000000000004     17      0      1   0   0  is_stmt end_sequence<br>
 // DWARF-DL-NEXT: 0x0000000000000000     21      0      1   0   0  is_stmt<br>
<br>
Modified: llvm/trunk/test/MC/ELF/debug-file-options.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-file-options.s?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-file-options.s?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ELF/debug-file-options.s (original)<br>
+++ llvm/trunk/test/MC/ELF/debug-file-options.s Tue Mar  6 14:37:45 2018<br>
@@ -11,25 +11,32 @@<br>
<br>
 # CHECK: debug_line[0x00000000]<br>
 # CHECK: version: 5<br>
-# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = ""<br>
+# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = "{{.+}}"<br>
 # CHECK: include_directories[ 1] = .debug_line_str[0x[[DIR1:[0-9a-f]+]]] = "dir1"<br>
 # CHECK: include_directories[ 2] = .debug_line_str[0x[[DIR2:[0-9a-f]+]]] = "dir2"<br>
 # CHECK-NOT: include_directories<br>
 # CHECK: file_names[ 0]:<br>
+# CHECK-NEXT: name: .debug_line_str[0x[[FILE0:[0-9a-f]+]]] = "{{.+}}"<br>
+# CHECK-NEXT: dir_index: 0<br>
+# CHECK-NEXT: md5_checksum:<br>
+# CHECK-NEXT: source: .debug_line_str[0x[[FILE0SRC:[0-9a-f]+]]] = ""<br>
+# CHECK: file_names[ 1]:<br>
 # CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo"<br>
 # CHECK-NEXT: dir_index: 1<br>
 # CHECK-NEXT: md5_checksum: ee87e05688663173cd6043a3a15bba6e<br>
 # CHECK-NEXT: source: .debug_line_str[0x[[FILE1SRC:[0-9a-f]+]]] = "void foo() {}"<br>
-# CHECK: file_names[ 1]:<br>
+# CHECK: file_names[ 2]:<br>
 # CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar"<br>
 # CHECK-NEXT: dir_index: 2<br>
 # CHECK-NEXT: md5_checksum: 816225a0c90ca8948b70eb58be4d522f<br>
 # CHECK-NEXT: source: .debug_line_str[0x[[FILE2SRC:[0-9a-f]+]]] = "void bar() {}"<br>
<br>
 # CHECK: .debug_line_str contents:<br>
-# CHECK-NEXT: 0x[[DIR0]]: ""<br>
+# CHECK-NEXT: 0x[[DIR0]]: "{{.+}}"<br>
 # CHECK-NEXT: 0x[[DIR1]]: "dir1"<br>
 # CHECK-NEXT: 0x[[DIR2]]: "dir2"<br>
+# CHECK-NEXT: 0x[[FILE0]]: "{{.+}}"<br>
+# CHECK-NEXT: 0x[[FILE0SRC]]: ""<br>
 # CHECK-NEXT: 0x[[FILE1]]: "foo"<br>
 # CHECK-NEXT: 0x[[FILE1SRC]]: "void foo() {}"<br>
 # CHECK-NEXT: 0x[[FILE2]]: "bar"<br>
<br>
Modified: llvm/trunk/test/MC/ELF/debug-md5.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-md5.s?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-md5.s?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ELF/debug-md5.s (original)<br>
+++ llvm/trunk/test/MC/ELF/debug-md5.s Tue Mar  6 14:37:45 2018<br>
@@ -1,4 +1,4 @@<br>
-// RUN: llvm-mc -triple x86_64-unknown-unknown -dwarf-version 5 -filetype=obj %s -o - | llvm-dwarfdump --debug-line --debug-line-str -v - | FileCheck %s<br>
+// RUN: llvm-mc -triple x86_64-unknown-unknown -dwarf-version 5 -fdebug-compilation-dir=/tmp -filetype=obj %s -o - | llvm-dwarfdump --debug-line --debug-line-str -v - | FileCheck %s<br>
<br>
         .file 1 "dir1/foo"   md5 "00112233445566778899aabbccddeeff"<br>
         .file 2 "dir2" "bar" md5 "ffeeddccbbaa99887766554433221100"<br>
@@ -9,22 +9,26 @@<br>
<br>
 # CHECK: debug_line[0x00000000]<br>
 # CHECK: version: 5<br>
-# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = ""<br>
+# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = "/tmp"<br>
 # CHECK: include_directories[ 1] = .debug_line_str[0x[[DIR1:[0-9a-f]+]]] = "dir1"<br>
 # CHECK: include_directories[ 2] = .debug_line_str[0x[[DIR2:[0-9a-f]+]]] = "dir2"<br>
 # CHECK-NOT: include_directories<br>
 # CHECK: file_names[ 0]:<br>
+# CHECK-NEXT: name: .debug_line_str[0x[[FILE0:[0-9a-f]+]]] = "{{.+}}"<br>
+# CHECK-NEXT: dir_index: 0<br>
+# CHECK: file_names[ 1]:<br>
 # CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo"<br>
 # CHECK-NEXT: dir_index: 1<br>
 # CHECK-NEXT: md5_checksum: 00112233445566778899aabbccddeeff<br>
-# CHECK: file_names[ 1]:<br>
+# CHECK: file_names[ 2]:<br>
 # CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar"<br>
 # CHECK-NEXT: dir_index: 2<br>
 # CHECK-NEXT: md5_checksum: ffeeddccbbaa99887766554433221100<br>
<br>
 # CHECK: .debug_line_str contents:<br>
-# CHECK-NEXT: 0x[[DIR0]]: ""<br>
+# CHECK-NEXT: 0x[[DIR0]]: "/tmp"<br>
 # CHECK-NEXT: 0x[[DIR1]]: "dir1"<br>
 # CHECK-NEXT: 0x[[DIR2]]: "dir2"<br>
+# CHECK-NEXT: 0x[[FILE0]]: "{{.+}}"<br>
 # CHECK-NEXT: 0x[[FILE1]]: "foo"<br>
 # CHECK-NEXT: 0x[[FILE2]]: "bar"<br>
<br>
Modified: llvm/trunk/test/MC/ELF/debug-source.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-source.s?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/debug-source.s?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ELF/debug-source.s (original)<br>
+++ llvm/trunk/test/MC/ELF/debug-source.s Tue Mar  6 14:37:45 2018<br>
@@ -9,23 +9,29 @@<br>
<br>
 # CHECK: debug_line[0x00000000]<br>
 # CHECK: version: 5<br>
-# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = ""<br>
+# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = "{{.+}}"<br>
 # CHECK: include_directories[ 1] = .debug_line_str[0x[[DIR1:[0-9a-f]+]]] = "dir1"<br>
 # CHECK: include_directories[ 2] = .debug_line_str[0x[[DIR2:[0-9a-f]+]]] = "dir2"<br>
 # CHECK-NOT: include_directories<br>
 # CHECK: file_names[ 0]:<br>
+# CHECK-NEXT: name: .debug_line_str[0x[[FILE0:[0-9a-f]+]]] = "{{.+}}"<br>
+# CHECK-NEXT: dir_index: 0<br>
+# CHECK-NEXT: source: .debug_line_str[0x[[FILE0SRC:[0-9a-f]+]]] = ""<br>
+# CHECK: file_names[ 1]:<br>
 # CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo"<br>
 # CHECK-NEXT: dir_index: 1<br>
 # CHECK-NEXT: source: .debug_line_str[0x[[FILE1SRC:[0-9a-f]+]]] = "void foo() {}"<br>
-# CHECK: file_names[ 1]:<br>
+# CHECK: file_names[ 2]:<br>
 # CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar"<br>
 # CHECK-NEXT: dir_index: 2<br>
 # CHECK-NEXT: source: .debug_line_str[0x[[FILE2SRC:[0-9a-f]+]]] = "void bar()\n{\n}"<br>
<br>
 # CHECK: .debug_line_str contents:<br>
-# CHECK-NEXT: 0x[[DIR0]]: ""<br>
+# CHECK-NEXT: 0x[[DIR0]]: "{{.+}}"<br>
 # CHECK-NEXT: 0x[[DIR1]]: "dir1"<br>
 # CHECK-NEXT: 0x[[DIR2]]: "dir2"<br>
+# CHECK-NEXT: 0x[[FILE0]]: "{{.+}}"<br>
+# CHECK-NEXT: 0x[[FILE0SRC]]: ""<br>
 # CHECK-NEXT: 0x[[FILE1]]: "foo"<br>
 # CHECK-NEXT: 0x[[FILE1SRC]]: "void foo() {}"<br>
 # CHECK-NEXT: 0x[[FILE2]]: "bar"<br>
<br>
Added: llvm/trunk/test/MC/ELF/dwarf-file0.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/dwarf-file0.s?rev=326839&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/dwarf-file0.s?rev=326839&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/ELF/dwarf-file0.s (added)<br>
+++ llvm/trunk/test/MC/ELF/dwarf-file0.s Tue Mar  6 14:37:45 2018<br>
@@ -0,0 +1,19 @@<br>
+# RUN: llvm-mc -dwarf-version 4 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK,CHECK-4<br>
+# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK,CHECK-5<br>
+# Darwin is stuck on DWARF v2.<br>
+# XFAIL: darwin<br>
+        .file 0 "root.cpp"<br>
+        .file 1 "header.h"<br>
+        .file 2 "root.cpp"<br>
+# CHECK-5:     include_directories[ 0] = ""<br>
+# CHECK-4-NOT: include_directories<br>
+# CHECK-4-NOT: file_names[ 0]<br>
+# CHECK-5:     file_names[ 0]:<br>
+# CHECK-5-NEXT: name: "root.cpp"<br>
+# CHECK-5-NEXT: dir_index: 0<br>
+# CHECK:       file_names[ 1]:<br>
+# CHECK-NEXT:  name: "header.h"<br>
+# CHECK-NEXT:  dir_index: 0<br>
+# CHECK:       file_names[ 2]:<br>
+# CHECK-NEXT:  name: "root.cpp"<br>
+# CHECK-NEXT:  dir_index: 0<br>
<br>
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=326839&r1=326838&r2=326839&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=326839&r1=326838&r2=326839&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)<br>
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Tue Mar  6 14:37:45 2018<br>
@@ -390,6 +390,18 @@ int main(int argc, char **argv) {<br>
   }<br>
   if (!MainFileName.empty())<br>
     Ctx.setMainFileName(MainFileName);<br>
+  if (DwarfVersion >= 5) {<br>
+    // DWARF v5 needs the root file as well as the compilation directory.<br>
+    // If we find a '.file 0' directive that will supersede these values.<br>
+    MD5 Hash;<br>
+    MD5::MD5Result *Cksum =<br>
+        (MD5::MD5Result *)Ctx.allocate(sizeof(MD5::MD5Result), 1);<br>
+    Hash.update(Buffer->getBuffer());<br>
+    Hash.final(*Cksum);<br>
+    Ctx.setMCLineTableRootFile(<br>
+        /*CUID=*/0, Ctx.getCompilationDir(),<br>
+        !MainFileName.empty() ? MainFileName : InputFilename, Cksum, None);<br>
+  }<br>
<br>
   // Package up features to be passed to target/subtarget<br>
   std::string FeaturesStr;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>