summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Robinson <paul.robinson@sony.com>2018-03-06 22:37:45 +0000
committerPaul Robinson <paul.robinson@sony.com>2018-03-06 22:37:45 +0000
commit4428e90efa31df7b288b170330dc7ec941ea72f8 (patch)
treef22c88ca283c4e5c7e19c2d1c52637d340b4612a
parentca38c762e46c22566f09e41712c2ea3ea2e1240a (diff)
downloadbcm5719-llvm-4428e90efa31df7b288b170330dc7ec941ea72f8.tar.gz
bcm5719-llvm-4428e90efa31df7b288b170330dc7ec941ea72f8.zip
Reapply "[DWARFv5] Emit file 0 to the line table."
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. llvm-svn: 326839
-rw-r--r--llvm/include/llvm/MC/MCContext.h9
-rw-r--r--llvm/include/llvm/MC/MCDwarf.h29
-rw-r--r--llvm/include/llvm/MC/MCStreamer.h6
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp11
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h8
-rw-r--r--llvm/lib/MC/MCAsmStreamer.cpp86
-rw-r--r--llvm/lib/MC/MCDwarf.cpp61
-rw-r--r--llvm/lib/MC/MCParser/AsmParser.cpp6
-rw-r--r--llvm/lib/MC/MCStreamer.cpp9
-rw-r--r--llvm/test/CodeGen/Generic/dwarf-md5.ll35
-rw-r--r--llvm/test/CodeGen/Generic/dwarf-source.ll39
-rw-r--r--llvm/test/DebugInfo/X86/dbg-file-name.ll2
-rw-r--r--llvm/test/DebugInfo/X86/inline-asm-locs.ll2
-rw-r--r--llvm/test/MC/ARM/dwarf-asm-multiple-sections.s4
-rw-r--r--llvm/test/MC/ELF/debug-file-options.s13
-rw-r--r--llvm/test/MC/ELF/debug-md5.s12
-rw-r--r--llvm/test/MC/ELF/debug-source.s12
-rw-r--r--llvm/test/MC/ELF/dwarf-file0.s19
-rw-r--r--llvm/tools/llvm-mc/llvm-mc.cpp12
20 files changed, 249 insertions, 128 deletions
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index c4abef1a9b4..c110ffd3a77 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -537,8 +537,13 @@ namespace llvm {
DwarfCompileUnitID = CUIndex;
}
- void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir) {
- getMCDwarfLineTable(CUID).setCompilationDir(CompilationDir);
+ /// Specifies the "root" file and directory of the compilation unit.
+ /// These are "file 0" and "directory 0" in DWARF v5.
+ void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir,
+ StringRef Filename, MD5::MD5Result *Checksum,
+ Optional<StringRef> Source) {
+ getMCDwarfLineTable(CUID).setRootFile(CompilationDir, Filename, Checksum,
+ Source);
}
/// Saves the information from the currently parsed dwarf .loc directive
diff --git a/llvm/include/llvm/MC/MCDwarf.h b/llvm/include/llvm/MC/MCDwarf.h
index c90a07608ed..995f9fe4c83 100644
--- a/llvm/include/llvm/MC/MCDwarf.h
+++ b/llvm/include/llvm/MC/MCDwarf.h
@@ -214,6 +214,7 @@ struct MCDwarfLineTableHeader {
SmallVector<MCDwarfFile, 3> MCDwarfFiles;
StringMap<unsigned> SourceIdMap;
StringRef CompilationDir;
+ MCDwarfFile RootFile;
bool HasMD5 = false;
bool HasSource = false;
@@ -241,8 +242,17 @@ class MCDwarfDwoLineTable {
MCDwarfLineTableHeader Header;
public:
- void setCompilationDir(StringRef CompilationDir) {
- Header.CompilationDir = CompilationDir;
+ void maybeSetRootFile(StringRef Directory, StringRef FileName,
+ MD5::MD5Result *Checksum, Optional<StringRef> Source) {
+ if (!Header.RootFile.Name.empty())
+ return;
+ Header.CompilationDir = Directory;
+ Header.RootFile.Name = FileName;
+ Header.RootFile.DirIndex = 0;
+ Header.RootFile.Checksum = Checksum;
+ Header.RootFile.Source = Source;
+ Header.HasMD5 = (Checksum != nullptr);
+ Header.HasSource = Source.hasValue();
}
unsigned getFile(StringRef Directory, StringRef FileName,
@@ -276,6 +286,17 @@ public:
FileNumber));
}
+ void setRootFile(StringRef Directory, StringRef FileName,
+ MD5::MD5Result *Checksum, Optional<StringRef> Source) {
+ Header.CompilationDir = Directory;
+ Header.RootFile.Name = FileName;
+ Header.RootFile.DirIndex = 0;
+ Header.RootFile.Checksum = Checksum;
+ Header.RootFile.Source = Source;
+ Header.HasMD5 = (Checksum != nullptr);
+ Header.HasSource = Source.hasValue();
+ }
+
MCSymbol *getLabel() const {
return Header.Label;
}
@@ -284,10 +305,6 @@ public:
Header.Label = Label;
}
- void setCompilationDir(StringRef CompilationDir) {
- Header.CompilationDir = CompilationDir;
- }
-
const SmallVectorImpl<std::string> &getMCDwarfDirs() const {
return Header.MCDwarfDirs;
}
diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
index 8f0230d2d37..a25df57651d 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -774,6 +774,12 @@ public:
MD5::MD5Result *Checksum = nullptr, Optional<StringRef> Source = None,
unsigned CUID = 0);
+ /// Specify the "root" file of the compilation, using the ".file 0" extension.
+ virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
+ MD5::MD5Result *Checksum,
+ Optional<StringRef> Source,
+ unsigned CUID = 0);
+
/// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler
/// directive.
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 2caf9c9ed27..3681556ca38 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -476,8 +476,9 @@ DwarfDebug::getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit) {
// explicitly describe the directory of all files, never relying on the
// compilation directory.
if (!Asm->OutStreamer->hasRawTextSupport() || SingleCU)
- Asm->OutStreamer->getContext().setMCLineTableCompilationDir(
- NewCU.getUniqueID(), CompilationDir);
+ Asm->OutStreamer->emitDwarfFile0Directive(
+ CompilationDir, FN, NewCU.getMD5AsBytes(DIUnit->getFile()),
+ DIUnit->getSource(), NewCU.getUniqueID());
StringRef Producer = DIUnit->getProducer();
StringRef Flags = DIUnit->getFlags();
@@ -2110,8 +2111,10 @@ void DwarfDebug::emitDebugStrDWO() {
MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {
if (!useSplitDwarf())
return nullptr;
- if (SingleCU)
- SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode()->getDirectory());
+ const DICompileUnit *DIUnit = CU.getCUNode();
+ SplitTypeUnitFileTable.maybeSetRootFile(
+ DIUnit->getDirectory(), DIUnit->getFilename(),
+ CU.getMD5AsBytes(DIUnit->getFile()), DIUnit->getSource());
return &SplitTypeUnitFileTable;
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 377e557f637..3df2894b43b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -284,7 +284,7 @@ void DwarfUnit::addSectionOffset(DIE &Die, dwarf::Attribute Attribute,
addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
}
-MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) {
+MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) const {
assert(File);
Optional<DIFile::ChecksumInfo<StringRef>> Checksum = File->getChecksum();
if (!Checksum || Checksum->Kind != DIFile::CSK_MD5)
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index 5de39637f52..9752a961183 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -306,6 +306,10 @@ public:
const MCSymbol *Label,
const MCSymbol *Sec);
+ /// If the \p File has an MD5 checksum, return it as an MD5Result
+ /// allocated in the MCContext.
+ MD5::MD5Result *getMD5AsBytes(const DIFile *File) const;
+
protected:
~DwarfUnit();
@@ -316,10 +320,6 @@ protected:
/// create a new ID and insert it in the line table.
virtual unsigned getOrCreateSourceID(const DIFile *File) = 0;
- /// If the \p File has an MD5 checksum, return it as an MD5Result
- /// allocated in the MCContext.
- MD5::MD5Result *getMD5AsBytes(const DIFile *File);
-
/// Look in the DwarfDebug map for the MDNode that corresponds to the
/// reference.
template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index f254cb50b60..0a006ecf66d 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -218,6 +218,10 @@ public:
MD5::MD5Result *Checksum = 0,
Optional<StringRef> Source = None,
unsigned CUID = 0) override;
+ void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
+ MD5::MD5Result *Checksum,
+ Optional<StringRef> Source,
+ unsigned CUID = 0) override;
void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa, unsigned Discriminator,
@@ -1076,21 +1080,10 @@ void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
EmitEOL();
}
-Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
- unsigned FileNo, StringRef Directory, StringRef Filename,
- MD5::MD5Result *Checksum, Optional<StringRef> Source, unsigned CUID) {
- assert(CUID == 0);
-
- MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
- unsigned NumFiles = Table.getMCDwarfFiles().size();
- Expected<unsigned> FileNoOrErr =
- Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo);
- if (!FileNoOrErr)
- return FileNoOrErr.takeError();
- FileNo = FileNoOrErr.get();
- if (NumFiles == Table.getMCDwarfFiles().size())
- return FileNo;
-
+void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
+ StringRef Filename, MD5::MD5Result *Checksum,
+ Optional<StringRef> Source, bool UseDwarfDirectory,
+ raw_svector_ostream &OS) {
SmallString<128> FullPathName;
if (!UseDwarfDirectory && !Directory.empty()) {
@@ -1104,31 +1097,68 @@ Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
}
}
- SmallString<128> Str;
- raw_svector_ostream OS1(Str);
- OS1 << "\t.file\t" << FileNo << ' ';
+ OS << "\t.file\t" << FileNo << ' ';
if (!Directory.empty()) {
- PrintQuotedString(Directory, OS1);
- OS1 << ' ';
+ PrintQuotedString(Directory, OS);
+ OS << ' ';
}
- PrintQuotedString(Filename, OS1);
+ PrintQuotedString(Filename, OS);
if (Checksum) {
- OS1 << " md5 ";
- PrintQuotedString(Checksum->digest(), OS1);
+ OS << " md5 ";
+ PrintQuotedString(Checksum->digest(), OS);
}
if (Source) {
- OS1 << " source ";
- PrintQuotedString(*Source, OS1);
+ OS << " source ";
+ PrintQuotedString(*Source, OS);
}
- if (MCTargetStreamer *TS = getTargetStreamer()) {
+}
+
+Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
+ unsigned FileNo, StringRef Directory, StringRef Filename,
+ MD5::MD5Result *Checksum, Optional<StringRef> Source, unsigned CUID) {
+ assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer");
+
+ MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
+ unsigned NumFiles = Table.getMCDwarfFiles().size();
+ Expected<unsigned> FileNoOrErr =
+ Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo);
+ if (!FileNoOrErr)
+ return FileNoOrErr.takeError();
+ FileNo = FileNoOrErr.get();
+ if (NumFiles == Table.getMCDwarfFiles().size())
+ return FileNo;
+
+ SmallString<128> Str;
+ raw_svector_ostream OS1(Str);
+ printDwarfFileDirective(FileNo, Directory, Filename, Checksum, Source,
+ UseDwarfDirectory, OS1);
+
+ if (MCTargetStreamer *TS = getTargetStreamer())
TS->emitDwarfFileDirective(OS1.str());
- } else {
+ else
EmitRawText(OS1.str());
- }
return FileNo;
}
+void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory,
+ StringRef Filename,
+ MD5::MD5Result *Checksum,
+ Optional<StringRef> Source,
+ unsigned CUID) {
+ assert(CUID == 0);
+
+ SmallString<128> Str;
+ raw_svector_ostream OS1(Str);
+ printDwarfFileDirective(0, Directory, Filename, Checksum, Source,
+ UseDwarfDirectory, OS1);
+
+ if (MCTargetStreamer *TS = getTargetStreamer())
+ TS->emitDwarfFileDirective(OS1.str());
+ else
+ EmitRawText(OS1.str());
+}
+
void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa,
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 685b46a606d..ee675acd530 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 *>
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 54a76732bbe..2df5251097c 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3258,8 +3258,8 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
FileNumber = getTok().getIntVal();
Lex();
- if (FileNumber < 1)
- return TokError("file number less than one");
+ if (FileNumber < 0)
+ return TokError("negative file number");
}
std::string Path = getTok().getString();
@@ -3338,6 +3338,8 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
// we turn off -g option, directly use the existing debug info instead.
if (getContext().getGenDwarfForAssembly())
getContext().setGenDwarfForAssembly(false);
+ else if (FileNumber == 0)
+ getStreamer().emitDwarfFile0Directive(Directory, Filename, CKMem, Source);
else {
Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(
FileNumber, Directory, Filename, CKMem, Source);
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index bf27a0abfda..eed061dcacd 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -199,6 +199,15 @@ MCStreamer::tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
Source, CUID);
}
+void MCStreamer::emitDwarfFile0Directive(StringRef Directory,
+ StringRef Filename,
+ MD5::MD5Result *Checksum,
+ Optional<StringRef> Source,
+ unsigned CUID) {
+ getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,
+ Source);
+}
+
void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa,
diff --git a/llvm/test/CodeGen/Generic/dwarf-md5.ll b/llvm/test/CodeGen/Generic/dwarf-md5.ll
index b9977200de1..09b901efaf7 100644
--- a/llvm/test/CodeGen/Generic/dwarf-md5.ll
+++ b/llvm/test/CodeGen/Generic/dwarf-md5.ll
@@ -8,28 +8,25 @@
; RUN: %llc_dwarf -dwarf-version 4 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM
; RUN: %llc_dwarf -dwarf-version 5 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM
; RUN: %llc_dwarf -dwarf-version 4 -filetype=obj -o %t4.o %s
-; RUN: llvm-dwarfdump -debug-line %t4.o | FileCheck %s --check-prefix=OBJ-4
+; RUN: llvm-dwarfdump -debug-line %t4.o | FileCheck %s --check-prefix=OBJ
; RUN: %llc_dwarf -dwarf-version 5 -filetype=obj -o %t5.o %s
-; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefix=OBJ-5
+; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefixes=OBJ,OBJ-5
-; FIXME: Need to convey the MD5 for the primary source file.
-; ASM: .file 1 ".{{/|\\\\}}t1.h" md5 "11111111111111111111111111111111"
-; ASM: .file 2 ".{{/|\\\\}}t2.h" md5 "22222222222222222222222222222222"
-
-; OBJ-4: file_names[ 1]:
-; OBJ-4-NEXT: name: "t1.h"
-; OBJ-4-NEXT: dir_index: 1
-; OBJ-4: file_names[ 2]:
-; OBJ-4-NEXT: name: "t2.h"
-; OBJ-4-NEXT: dir_index: 1
+; ASM: .file 0 "[[COMPDIR:.*]]{{[/\\]}}t.c" md5 "00000000000000000000000000000000"
+; ASM: .file 1 "[[COMPDIR]]{{[/\\]}}t1.h" md5 "11111111111111111111111111111111"
+; ASM: .file 2 "[[COMPDIR]]{{[/\\]}}t2.h" md5 "22222222222222222222222222222222"
; OBJ-5: file_names[ 0]:
-; OBJ-5-NEXT: name: "t1.h"
-; OBJ-5-NEXT: dir_index: 1
+; OBJ-5-NEXT: name: "t.c"
+; OBJ-5-NEXT: dir_index: 0
+; OBJ-5-NEXT: md5_checksum: 00000000000000000000000000000000
+; OBJ: file_names[ 1]:
+; OBJ-NEXT: name: "t1.h"
+; OBJ-NEXT: dir_index: 0
; OBJ-5-NEXT: md5_checksum: 11111111111111111111111111111111
-; OBJ-5: file_names[ 1]:
-; OBJ-5-NEXT: name: "t2.h"
-; OBJ-5-NEXT: dir_index: 1
+; OBJ: file_names[ 2]:
+; OBJ-NEXT: name: "t2.h"
+; OBJ-NEXT: dir_index: 0
; OBJ-5-NEXT: md5_checksum: 22222222222222222222222222222222
; ModuleID = 't.c'
@@ -50,9 +47,9 @@ source_filename = "t.c"
!5 = !{!0, !6}
!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
!7 = distinct !DIGlobalVariable(name: "t2", scope: !2, file: !8, line: 1, type: !9, isLocal: false, isDefinition: true)
-!8 = !DIFile(filename: "./t2.h", directory: "/home/probinson/projects/scratch", checksumkind: CSK_MD5, checksum: "22222222222222222222222222222222")
+!8 = !DIFile(filename: "t2.h", directory: "/home/probinson/projects/scratch", checksumkind: CSK_MD5, checksum: "22222222222222222222222222222222")
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!10 = !DIFile(filename: "./t1.h", directory: "/home/probinson/projects/scratch", checksumkind: CSK_MD5, checksum: "11111111111111111111111111111111")
+!10 = !DIFile(filename: "t1.h", directory: "/home/probinson/projects/scratch", checksumkind: CSK_MD5, checksum: "11111111111111111111111111111111")
!11 = !{i32 2, !"Dwarf Version", i32 4}
!12 = !{i32 2, !"Debug Info Version", i32 3}
!13 = !{i32 1, !"wchar_size", i32 4}
diff --git a/llvm/test/CodeGen/Generic/dwarf-source.ll b/llvm/test/CodeGen/Generic/dwarf-source.ll
index 9c34fc5285b..e59193d0d8a 100644
--- a/llvm/test/CodeGen/Generic/dwarf-source.ll
+++ b/llvm/test/CodeGen/Generic/dwarf-source.ll
@@ -8,30 +8,27 @@
; RUN: %llc_dwarf -dwarf-version 4 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM
; RUN: %llc_dwarf -dwarf-version 5 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM
; RUN: %llc_dwarf -dwarf-version 4 -filetype=obj -o %t4.o %s
-; RUN: llvm-dwarfdump -debug-line %t4.o | FileCheck %s --check-prefix=OBJ-4
+; RUN: llvm-dwarfdump -debug-line %t4.o | FileCheck %s --check-prefixes=OBJ,OBJ-4
; RUN: %llc_dwarf -dwarf-version 5 -filetype=obj -o %t5.o %s
-; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefix=OBJ-5
+; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefixes=OBJ,OBJ-5
-; FIXME: Need to convey the source for the primary source file.
-; ASM: .file 1 ".{{/|\\\\}}t1.h" source "11111111111111111111111111111111"
-; ASM: .file 2 ".{{/|\\\\}}t2.h" source "22222222222222222222222222222222"
-
-; OBJ-4: file_names[ 1]:
-; OBJ-4-NEXT: name: "t1.h"
-; OBJ-4-NEXT: dir_index: 1
-; OBJ-4-NOT: 11111111111111111111111111111111
-; OBJ-4: file_names[ 2]:
-; OBJ-4-NEXT: name: "t2.h"
-; OBJ-4-NEXT: dir_index: 1
-; OBJ-4-NOT: 22222222222222222222222222222222
+; ASM: .file 0 "[[COMPDIR:.*]]{{[/\\]}}t.c" source "00000000000000000000000000000000"
+; ASM: .file 1 "[[COMPDIR]]{{[/\\]}}t1.h" source "11111111111111111111111111111111"
+; ASM: .file 2 "[[COMPDIR]]{{[/\\]}}t2.h" source "22222222222222222222222222222222"
; OBJ-5: file_names[ 0]:
-; OBJ-5-NEXT: name: "t1.h"
-; OBJ-5-NEXT: dir_index: 1
+; OBJ-5-NEXT: name: "t.c"
+; OBJ-5-NEXT: dir_index: 0
+; OBJ-5-NEXT: source: "00000000000000000000000000000000"
+; OBJ: file_names[ 1]:
+; OBJ-NEXT: name: "t1.h"
+; OBJ-NEXT: dir_index: 0
+; OBJ-4-NOT: 11111111111111111111111111111111
; OBJ-5-NEXT: source: "11111111111111111111111111111111"
-; OBJ-5: file_names[ 1]:
-; OBJ-5-NEXT: name: "t2.h"
-; OBJ-5-NEXT: dir_index: 1
+; OBJ: file_names[ 2]:
+; OBJ-NEXT: name: "t2.h"
+; OBJ-NEXT: dir_index: 0
+; OBJ-4-NOT: 22222222222222222222222222222222
; OBJ-5-NEXT: source: "22222222222222222222222222222222"
; ModuleID = 't.c'
@@ -52,9 +49,9 @@ source_filename = "t.c"
!5 = !{!0, !6}
!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
!7 = distinct !DIGlobalVariable(name: "t2", scope: !2, file: !8, line: 1, type: !9, isLocal: false, isDefinition: true)
-!8 = !DIFile(filename: "./t2.h", directory: "/test", source: "22222222222222222222222222222222")
+!8 = !DIFile(filename: "t2.h", directory: "/test", source: "22222222222222222222222222222222")
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!10 = !DIFile(filename: "./t1.h", directory: "/test", source: "11111111111111111111111111111111")
+!10 = !DIFile(filename: "t1.h", directory: "/test", source: "11111111111111111111111111111111")
!11 = !{i32 2, !"Dwarf Version", i32 4}
!12 = !{i32 2, !"Debug Info Version", i32 3}
!13 = !{i32 1, !"wchar_size", i32 4}
diff --git a/llvm/test/DebugInfo/X86/dbg-file-name.ll b/llvm/test/DebugInfo/X86/dbg-file-name.ll
index 251952df191..633b9c069c5 100644
--- a/llvm/test/DebugInfo/X86/dbg-file-name.ll
+++ b/llvm/test/DebugInfo/X86/dbg-file-name.ll
@@ -2,7 +2,7 @@
; Verify that the file name is relative to the directory.
; rdar://problem/8884898
-; CHECK: file 1 "simple.c"
+; CHECK: file 1 "/Users/manav/one/two" "simple.c"
declare i32 @printf(i8*, ...) nounwind
diff --git a/llvm/test/DebugInfo/X86/inline-asm-locs.ll b/llvm/test/DebugInfo/X86/inline-asm-locs.ll
index 632aa0be623..5412c7f4133 100644
--- a/llvm/test/DebugInfo/X86/inline-asm-locs.ll
+++ b/llvm/test/DebugInfo/X86/inline-asm-locs.ll
@@ -22,7 +22,7 @@
; CHECK: .file 2 "B.asm"
; CHECK: .loc 1 111
; CHECK: .loc 2 222
-; CHECK: .file 3 "test.c"
+; CHECK: .file 3 "{{.*[/\\]}}test.c"
; CHECK: .loc 3 14 0
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s b/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s
index 4c099acccd5..cff8f000731 100644
--- a/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s
+++ b/llvm/test/MC/ARM/dwarf-asm-multiple-sections.s
@@ -54,9 +54,9 @@ b:
// DWARF-DL: .debug_line contents:
// DWARF-DL: version: [[DWVER]]
// DWARF-DL-5: address_size: 4
-// DWARF-DL-5: include_directories[ 0] = ""
+// DWARF-DL-5: include_directories[ 0] = "/tmp"
// DWARF-DL: file_names[ [[DWFILE]]]:
-// DWARF-DL: name: "<stdin>"
+// DWARF-DL: name: "{{(<stdin>|-)}}"
// DWARF-DL: 0x0000000000000000 17 0 1 0 0 is_stmt
// DWARF-DL-NEXT: 0x0000000000000004 17 0 1 0 0 is_stmt end_sequence
// DWARF-DL-NEXT: 0x0000000000000000 21 0 1 0 0 is_stmt
diff --git a/llvm/test/MC/ELF/debug-file-options.s b/llvm/test/MC/ELF/debug-file-options.s
index 3bcd131cc38..5c77a48ab72 100644
--- a/llvm/test/MC/ELF/debug-file-options.s
+++ b/llvm/test/MC/ELF/debug-file-options.s
@@ -11,25 +11,32 @@
# CHECK: debug_line[0x00000000]
# CHECK: version: 5
-# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = ""
+# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = "{{.+}}"
# CHECK: include_directories[ 1] = .debug_line_str[0x[[DIR1:[0-9a-f]+]]] = "dir1"
# 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: md5_checksum:
+# CHECK-NEXT: source: .debug_line_str[0x[[FILE0SRC:[0-9a-f]+]]] = ""
+# CHECK: file_names[ 1]:
# CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "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: file_names[ 1]:
+# CHECK: file_names[ 2]:
# CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar"
# CHECK-NEXT: dir_index: 2
# CHECK-NEXT: md5_checksum: 816225a0c90ca8948b70eb58be4d522f
# CHECK-NEXT: source: .debug_line_str[0x[[FILE2SRC:[0-9a-f]+]]] = "void bar() {}"
# CHECK: .debug_line_str contents:
-# CHECK-NEXT: 0x[[DIR0]]: ""
+# 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[[FILE2]]: "bar"
diff --git a/llvm/test/MC/ELF/debug-md5.s b/llvm/test/MC/ELF/debug-md5.s
index f8f3bc1a362..658e02e5917 100644
--- a/llvm/test/MC/ELF/debug-md5.s
+++ b/llvm/test/MC/ELF/debug-md5.s
@@ -1,4 +1,4 @@
-// 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
+// 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
.file 1 "dir1/foo" md5 "00112233445566778899aabbccddeeff"
.file 2 "dir2" "bar" md5 "ffeeddccbbaa99887766554433221100"
@@ -9,22 +9,26 @@
# CHECK: debug_line[0x00000000]
# CHECK: version: 5
-# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = ""
+# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = "/tmp"
# CHECK: include_directories[ 1] = .debug_line_str[0x[[DIR1:[0-9a-f]+]]] = "dir1"
# 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: file_names[ 1]:
# CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo"
# CHECK-NEXT: dir_index: 1
# CHECK-NEXT: md5_checksum: 00112233445566778899aabbccddeeff
-# CHECK: file_names[ 1]:
+# CHECK: file_names[ 2]:
# CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar"
# CHECK-NEXT: dir_index: 2
# CHECK-NEXT: md5_checksum: ffeeddccbbaa99887766554433221100
# CHECK: .debug_line_str contents:
-# CHECK-NEXT: 0x[[DIR0]]: ""
+# 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[[FILE2]]: "bar"
diff --git a/llvm/test/MC/ELF/debug-source.s b/llvm/test/MC/ELF/debug-source.s
index 0b919e15ddb..1cf39c7a9d2 100644
--- a/llvm/test/MC/ELF/debug-source.s
+++ b/llvm/test/MC/ELF/debug-source.s
@@ -9,23 +9,29 @@
# CHECK: debug_line[0x00000000]
# CHECK: version: 5
-# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = ""
+# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = "{{.+}}"
# CHECK: include_directories[ 1] = .debug_line_str[0x[[DIR1:[0-9a-f]+]]] = "dir1"
# 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: file_names[ 1]:
# CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo"
# CHECK-NEXT: dir_index: 1
# CHECK-NEXT: source: .debug_line_str[0x[[FILE1SRC:[0-9a-f]+]]] = "void foo() {}"
-# CHECK: file_names[ 1]:
+# CHECK: file_names[ 2]:
# CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar"
# CHECK-NEXT: dir_index: 2
# CHECK-NEXT: source: .debug_line_str[0x[[FILE2SRC:[0-9a-f]+]]] = "void bar()\n{\n}"
# CHECK: .debug_line_str contents:
-# CHECK-NEXT: 0x[[DIR0]]: ""
+# 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[[FILE2]]: "bar"
diff --git a/llvm/test/MC/ELF/dwarf-file0.s b/llvm/test/MC/ELF/dwarf-file0.s
new file mode 100644
index 00000000000..ae87df2a3f0
--- /dev/null
+++ b/llvm/test/MC/ELF/dwarf-file0.s
@@ -0,0 +1,19 @@
+# RUN: llvm-mc -dwarf-version 4 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK,CHECK-4
+# RUN: llvm-mc -dwarf-version 5 %s -filetype=obj -o - | llvm-dwarfdump -debug-line - | FileCheck %s --check-prefixes=CHECK,CHECK-5
+# Darwin is stuck on DWARF v2.
+# XFAIL: darwin
+ .file 0 "root.cpp"
+ .file 1 "header.h"
+ .file 2 "root.cpp"
+# CHECK-5: include_directories[ 0] = ""
+# CHECK-4-NOT: include_directories
+# CHECK-4-NOT: file_names[ 0]
+# CHECK-5: file_names[ 0]:
+# CHECK-5-NEXT: name: "root.cpp"
+# CHECK-5-NEXT: dir_index: 0
+# CHECK: file_names[ 1]:
+# CHECK-NEXT: name: "header.h"
+# CHECK-NEXT: dir_index: 0
+# CHECK: file_names[ 2]:
+# CHECK-NEXT: name: "root.cpp"
+# CHECK-NEXT: dir_index: 0
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index 933aecce696..5d9c060dc21 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -390,6 +390,18 @@ int main(int argc, char **argv) {
}
if (!MainFileName.empty())
Ctx.setMainFileName(MainFileName);
+ if (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;
+ MD5::MD5Result *Cksum =
+ (MD5::MD5Result *)Ctx.allocate(sizeof(MD5::MD5Result), 1);
+ Hash.update(Buffer->getBuffer());
+ Hash.final(*Cksum);
+ Ctx.setMCLineTableRootFile(
+ /*CUID=*/0, Ctx.getCompilationDir(),
+ !MainFileName.empty() ? MainFileName : InputFilename, Cksum, None);
+ }
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
OpenPOWER on IntegriCloud