summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h1
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp1
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp1
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp20
-rw-r--r--llvm/lib/MC/MCContext.cpp5
-rw-r--r--llvm/lib/MC/MCDwarf.cpp11
6 files changed, 33 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
index d9addb52376..683d3245e56 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
@@ -101,6 +101,7 @@ class DwarfCompileUnit final : public DwarfUnit {
}
public:
+ unsigned getDwarfVersion() const { return DD->getDwarfVersion(); }
DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A,
DwarfDebug *DW, DwarfFile *DWU);
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 0e0a5b24864..226014cf0bb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -319,6 +319,7 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
: DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()),
InfoHolder(A, "info_string", DIEValueAllocator),
SkeletonHolder(A, "skel_string", DIEValueAllocator),
+ SplitTypeUnitFileTable(A->getDwarfVersion()),
IsDarwin(A->TM.getTargetTriple().isOSDarwin()) {
const Triple &TT = Asm->TM.getTargetTriple();
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 6e547469c24..5d8e236a6b3 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -397,7 +397,6 @@ void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, const DIFile *File) {
return;
unsigned FileID = getOrCreateSourceID(File);
- assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
}
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 53420187773..6ad06a8553e 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1017,14 +1017,28 @@ bool DWARFDebugLine::LineTable::lookupAddressRangeImpl(
}
bool DWARFDebugLine::LineTable::hasFileAtIndex(uint64_t FileIndex) const {
- return FileIndex != 0 && FileIndex <= Prologue.FileNames.size();
+ uint16_t DwarfVersion = Prologue.getVersion();
+ assert(DwarfVersion != 0 && "LineTable has no dwarf version information");
+ if (DwarfVersion >= 5)
+ return FileIndex < Prologue.FileNames.size();
+ else
+ return FileIndex != 0 && FileIndex <= Prologue.FileNames.size();
+}
+const llvm::DWARFDebugLine::FileNameEntry &
+DWARFDebugLine::LineTable::getFileNameEntry(uint64_t Index) const {
+ uint16_t DwarfVersion = Prologue.getVersion();
+ assert(DwarfVersion != 0 && "LineTable has no dwarf version information");
+ if (DwarfVersion >= 5)
+ return Prologue.FileNames[Index];
+ else
+ return Prologue.FileNames[Index - 1];
}
Optional<StringRef> DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,
FileLineInfoKind Kind) const {
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
return None;
- const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
+ const FileNameEntry &Entry = getFileNameEntry(FileIndex);
if (Optional<const char *> source = Entry.Source.getAsCString())
return StringRef(*source);
return None;
@@ -1044,7 +1058,7 @@ bool DWARFDebugLine::LineTable::getFileNameByIndex(uint64_t FileIndex,
std::string &Result) const {
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
return false;
- const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
+ const FileNameEntry &Entry = getFileNameEntry(FileIndex);
StringRef FileName = Entry.Name.getAsCString().getValue();
if (Kind != FileLineInfoKind::AbsoluteFilePath ||
isPathAbsoluteOnWindowsOrPosix(FileName)) {
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 49fad131a2c..348436f4bd0 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -603,7 +603,8 @@ Expected<unsigned> MCContext::getDwarfFile(StringRef Directory,
MD5::MD5Result *Checksum,
Optional<StringRef> Source,
unsigned CUID) {
- MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
+ MCDwarfLineTable &Table =
+ MCDwarfLineTablesCUMap.emplace(CUID, DwarfVersion).first->second;
return Table.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
}
@@ -612,7 +613,7 @@ Expected<unsigned> MCContext::getDwarfFile(StringRef Directory,
bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
if (FileNumber == 0)
- return getDwarfVersion() >= 5 && LineTable.hasRootFile();
+ return getDwarfVersion() >= 5;
if (FileNumber >= LineTable.getMCDwarfFiles().size())
return false;
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 83b6b4f1aa3..73b4d4bcd19 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -542,6 +542,15 @@ Expected<unsigned> MCDwarfLineTable::tryGetFile(StringRef &Directory,
return Header.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
}
+bool isRootFile(const MCDwarfFile &RootFile, StringRef &Directory,
+ StringRef &FileName, MD5::MD5Result *Checksum) {
+ if (RootFile.Name.empty() || RootFile.Name != FileName.data())
+ return false;
+ if (!RootFile.Checksum)
+ return !Checksum;
+ return *RootFile.Checksum == *Checksum;
+}
+
Expected<unsigned>
MCDwarfLineTableHeader::tryGetFile(StringRef &Directory,
StringRef &FileName,
@@ -561,6 +570,8 @@ MCDwarfLineTableHeader::tryGetFile(StringRef &Directory,
trackMD5Usage(Checksum);
HasSource = (Source != None);
}
+ if (isRootFile(RootFile, Directory, FileName, Checksum) && DwarfVersion >= 5)
+ return 0;
if (FileNumber == 0) {
// File numbers start with 1 and/or after any file numbers
// allocated by inline-assembler .file directives.
OpenPOWER on IntegriCloud