Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -363,13 +363,13 @@ Checksum.clear(); if (!CGM.getCodeGenOpts().EmitCodeView) - return llvm::DIFile::CSK_None; + return llvm::DIFile::ChecksumKind::CSK_None; SourceManager &SM = CGM.getContext().getSourceManager(); bool Invalid; llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid); if (Invalid) - return llvm::DIFile::CSK_None; + return llvm::DIFile::ChecksumKind::CSK_None; llvm::MD5 Hash; llvm::MD5::MD5Result Result; @@ -378,7 +378,7 @@ Hash.final(Result); Hash.stringifyResult(Result, Checksum); - return llvm::DIFile::CSK_MD5; + return llvm::DIFile::ChecksumKind::CSK_MD5; } llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { @@ -469,7 +469,7 @@ void CGDebugInfo::CreateCompileUnit() { SmallString<32> Checksum; - llvm::DIFile::ChecksumKind CSKind = llvm::DIFile::CSK_None; + llvm::DIFile::ChecksumKind CSKind = llvm::DIFile::ChecksumKind::CSK_None; // Should we be asking the SourceManager for the main file name, instead of // accepting it as an argument? This just causes the main file name to Index: llvm/include/llvm/IR/DIBuilder.h =================================================================== --- llvm/include/llvm/IR/DIBuilder.h +++ llvm/include/llvm/IR/DIBuilder.h @@ -127,7 +127,7 @@ /// \param CSKind Checksum kind (e.g. CSK_None, CSK_MD5, CSK_SHA1, etc.). /// \param Checksum Checksum data. DIFile *createFile(StringRef Filename, StringRef Directory, - DIFile::ChecksumKind CSKind = DIFile::CSK_None, + DIFile::ChecksumKind CSKind = DIFile::ChecksumKind::CSK_None, StringRef Checksum = StringRef()); /// Create debugging information entry for a macro. Index: llvm/include/llvm/IR/DebugInfoMetadata.h =================================================================== --- llvm/include/llvm/IR/DebugInfoMetadata.h +++ llvm/include/llvm/IR/DebugInfoMetadata.h @@ -473,7 +473,7 @@ friend class MDNode; public: - enum ChecksumKind { + enum class ChecksumKind : uint8_t { CSK_None, CSK_MD5, CSK_SHA1, @@ -507,11 +507,11 @@ public: DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory, - ChecksumKind CSK = CSK_None, + ChecksumKind CSK = ChecksumKind::CSK_None, StringRef CS = StringRef()), (Filename, Directory, CSK, CS)) DEFINE_MDNODE_GET(DIFile, (MDString *Filename, MDString *Directory, - ChecksumKind CSK = CSK_None, + ChecksumKind CSK = ChecksumKind::CSK_None, MDString *CS = nullptr), (Filename, Directory, CSK, CS)) Index: llvm/include/llvm/MC/MCCodeView.h =================================================================== --- llvm/include/llvm/MC/MCCodeView.h +++ llvm/include/llvm/MC/MCCodeView.h @@ -161,8 +161,7 @@ ~CodeViewContext(); bool isValidFileNumber(unsigned FileNumber) const; - bool addFile(unsigned FileNumber, StringRef Filename); - ArrayRef getFilenames() { return Filenames; } + bool addFile(unsigned FileNumber, StringRef Filename, StringRef Checksum, uint8_t ChecksumKind); /// Records the function id of a normal function. Returns false if the /// function id has already been used, and true otherwise. @@ -273,6 +272,8 @@ /// Emits the file checksum substream. void emitFileChecksums(MCObjectStreamer &OS); + void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo); + private: /// The current CodeView line information from the last .cv_loc directive. MCCVLoc CurrentCVLoc = MCCVLoc(0, 0, 0, 0, false, true); @@ -280,6 +281,7 @@ /// Map from string to string table offset. StringMap StringTable; + //std::map StringTable; /// The fragment that ultimately holds our strings. MCDataFragment *StrTabFragment = nullptr; @@ -288,13 +290,19 @@ MCDataFragment *getStringTableFragment(); /// Add something to the string table. - StringRef addToStringTable(StringRef S); + std::pair addToStringTable(StringRef S); /// Get a string table offset. unsigned getStringTableOffset(StringRef S); /// An array of absolute paths. Eventually this may include the file checksum. - SmallVector Filenames; + /// Array of string table offset, checksum table offset pairs. + SmallVector, 4> Files; + + // Map from filename to checksum. + // StringMap> Checksums; + // Map from string table offset to checksum + std::map> Checksums; /// The offset of the first and last .cv_loc directive for a given function /// id. @@ -305,6 +313,10 @@ /// All known functions and inlined call sites, indexed by function id. std::vector Functions; + + void assignChecksumOffsets(); + + bool ChecksumOffsetsAssigned = false; }; } // end namespace llvm Index: llvm/include/llvm/MC/MCObjectStreamer.h =================================================================== --- llvm/include/llvm/MC/MCObjectStreamer.h +++ llvm/include/llvm/MC/MCObjectStreamer.h @@ -140,6 +140,7 @@ StringRef FixedSizePortion) override; void EmitCVStringTableDirective() override; void EmitCVFileChecksumsDirective() override; + void EmitCVFileChecksumOffsetDirective(unsigned FileNo) override; void EmitDTPRel32Value(const MCExpr *Value) override; void EmitDTPRel64Value(const MCExpr *Value) override; void EmitTPRel32Value(const MCExpr *Value) override; Index: llvm/include/llvm/MC/MCStreamer.h =================================================================== --- llvm/include/llvm/MC/MCStreamer.h +++ llvm/include/llvm/MC/MCStreamer.h @@ -732,7 +732,7 @@ /// \brief Associate a filename with a specified logical file number. This /// implements the '.cv_file 4 "foo.c"' assembler directive. Returns true on /// success. - virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename); + virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename, StringRef Checksum, unsigned ChecksumKind); /// \brief Introduces a function id for use with .cv_loc. virtual bool EmitCVFuncIdDirective(unsigned FunctionId); @@ -774,6 +774,8 @@ /// \brief This implements the CodeView '.cv_filechecksums' assembler directive. virtual void EmitCVFileChecksumsDirective() {} + virtual void EmitCVFileChecksumOffsetDirective(unsigned FileNo) {} + /// Emit the absolute difference between two symbols. /// /// \pre Offset of \c Hi is greater than the offset \c Lo. Index: llvm/lib/AsmParser/LLParser.cpp =================================================================== --- llvm/lib/AsmParser/LLParser.cpp +++ llvm/lib/AsmParser/LLParser.cpp @@ -3525,7 +3525,7 @@ }; struct ChecksumKindField : public MDFieldImpl { - ChecksumKindField() : ImplTy(DIFile::CSK_None) {} + ChecksumKindField() : ImplTy(DIFile::ChecksumKind::CSK_None) {} ChecksumKindField(DIFile::ChecksumKind CSKind) : ImplTy(CSKind) {} }; Index: llvm/lib/Bitcode/Reader/MetadataLoader.cpp =================================================================== --- llvm/lib/Bitcode/Reader/MetadataLoader.cpp +++ llvm/lib/Bitcode/Reader/MetadataLoader.cpp @@ -1347,7 +1347,7 @@ GET_OR_DISTINCT( DIFile, (Context, getMDString(Record[1]), getMDString(Record[2]), - Record.size() == 3 ? DIFile::CSK_None + Record.size() == 3 ? DIFile::ChecksumKind::CSK_None : static_cast(Record[3]), Record.size() == 3 ? nullptr : getMDString(Record[4]))), NextMetadataNo); Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1483,7 +1483,7 @@ Record.push_back(N->isDistinct()); Record.push_back(VE.getMetadataOrNullID(N->getRawFilename())); Record.push_back(VE.getMetadataOrNullID(N->getRawDirectory())); - Record.push_back(N->getChecksumKind()); + Record.push_back(static_cast(N->getChecksumKind())); Record.push_back(VE.getMetadataOrNullID(N->getRawChecksum())); Stream.EmitRecord(bitc::METADATA_FILE, Record, Abbrev); Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -159,7 +159,9 @@ if (Insertion.second) { // We have to compute the full filepath and emit a .cv_file directive. StringRef FullPath = getFullFilepath(F); - bool Success = OS.EmitCVFileDirective(NextId, FullPath); + StringRef Checksum = F->getChecksum(); + DIFile::ChecksumKind ChecksumKind = F->getChecksumKind(); + bool Success = OS.EmitCVFileDirective(NextId, FullPath, Checksum, static_cast(ChecksumKind)); (void)Success; assert(Success && ".cv_file directive failed"); } @@ -694,13 +696,14 @@ OS.AddComment("Inlined function " + SP->getName() + " starts at " + SP->getFilename() + Twine(':') + Twine(SP->getLine())); OS.AddBlankLine(); - // The filechecksum table uses 8 byte entries for now, and file ids start at + // The filechecksum table uses 8 bytes entries for now, and file ids start at // 1. - unsigned FileOffset = (FileId - 1) * 8; + unsigned FileOffset = (FileId - 1) * 12; OS.AddComment("Type index of inlined function"); OS.EmitIntValue(InlineeIdx.getIndex(), 4); OS.AddComment("Offset into filechecksum table"); - OS.EmitIntValue(FileOffset, 4); + //OS.EmitIntValue(FileOffset, 4); + OS.EmitCVFileChecksumOffsetDirective(FileId); OS.AddComment("Starting line number"); OS.EmitIntValue(SP->getLine(), 4); } Index: llvm/lib/DebugInfo/CodeView/DebugChecksumsSubsection.cpp =================================================================== --- llvm/lib/DebugInfo/CodeView/DebugChecksumsSubsection.cpp +++ llvm/lib/DebugInfo/CodeView/DebugChecksumsSubsection.cpp @@ -50,9 +50,9 @@ } Error DebugChecksumsSubsectionRef::initialize(BinaryStreamReader Reader) { + //errs() << "checksum bytes remaining " << Reader.bytesRemaining() << "\n"; if (auto EC = Reader.readArray(Checksums, Reader.bytesRemaining())) return EC; - return Error::success(); } Index: llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp =================================================================== --- llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp +++ llvm/lib/DebugInfo/CodeView/DebugStringTableSubsection.cpp @@ -29,16 +29,19 @@ } Error DebugStringTableSubsectionRef::initialize(BinaryStreamReader &Reader) { + errs() << "String table bytes remaining " << Reader.bytesRemaining() << "\n"; return Reader.readStreamRef(Stream); } Expected DebugStringTableSubsectionRef::getString(uint32_t Offset) const { + //errs() << "DebugStringTableSubsectionRef getString\n"; BinaryStreamReader Reader(Stream); Reader.setOffset(Offset); StringRef Result; if (auto EC = Reader.readCString(Result)) return std::move(EC); + //errs() << "leaving getString\n"; return Result; } Index: llvm/lib/IR/AsmWriter.cpp =================================================================== --- llvm/lib/IR/AsmWriter.cpp +++ llvm/lib/IR/AsmWriter.cpp @@ -1493,7 +1493,7 @@ } void MDFieldPrinter::printChecksumKind(const DIFile *N) { - if (N->getChecksumKind() == DIFile::CSK_None) + if (N->getChecksumKind() == DIFile::ChecksumKind::CSK_None) // Skip CSK_None checksum kind. return; Out << FS << "checksumkind: " << N->getChecksumKindAsString(); Index: llvm/lib/IR/DebugInfoMetadata.cpp =================================================================== --- llvm/lib/IR/DebugInfoMetadata.cpp +++ llvm/lib/IR/DebugInfoMetadata.cpp @@ -354,7 +354,7 @@ DEFINE_GETIMPL_STORE(DISubroutineType, (Flags, CC), Ops); } -static const char *ChecksumKindName[DIFile::CSK_Last + 1] = { +static const char *ChecksumKindName[static_cast(DIFile::ChecksumKind::CSK_Last) + 1] = { "CSK_None", "CSK_MD5", "CSK_SHA1" @@ -362,14 +362,14 @@ DIFile::ChecksumKind DIFile::getChecksumKind(StringRef CSKindStr) { return StringSwitch(CSKindStr) - .Case("CSK_MD5", DIFile::CSK_MD5) - .Case("CSK_SHA1", DIFile::CSK_SHA1) - .Default(DIFile::CSK_None); + .Case("CSK_MD5", DIFile::ChecksumKind::CSK_MD5) + .Case("CSK_SHA1", DIFile::ChecksumKind::CSK_SHA1) + .Default(DIFile::ChecksumKind::CSK_None); } StringRef DIFile::getChecksumKindAsString() const { - assert(CSKind <= DIFile::CSK_Last && "Invalid checksum kind"); - return ChecksumKindName[CSKind]; + assert(CSKind <= DIFile::ChecksumKind::CSK_Last && "Invalid checksum kind"); + return ChecksumKindName[static_cast(CSKind)]; } DIFile *DIFile::getImpl(LLVMContext &Context, MDString *Filename, Index: llvm/lib/IR/Verifier.cpp =================================================================== --- llvm/lib/IR/Verifier.cpp +++ llvm/lib/IR/Verifier.cpp @@ -960,7 +960,7 @@ void Verifier::visitDIFile(const DIFile &N) { AssertDI(N.getTag() == dwarf::DW_TAG_file_type, "invalid tag", &N); - AssertDI((N.getChecksumKind() != DIFile::CSK_None || + AssertDI((N.getChecksumKind() != DIFile::ChecksumKind::CSK_None || N.getChecksum().empty()), "invalid checksum kind", &N); } Index: llvm/lib/MC/MCAsmStreamer.cpp =================================================================== --- llvm/lib/MC/MCAsmStreamer.cpp +++ llvm/lib/MC/MCAsmStreamer.cpp @@ -225,7 +225,7 @@ StringRef FileName) override; MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override; - bool EmitCVFileDirective(unsigned FileNo, StringRef Filename) override; + bool EmitCVFileDirective(unsigned FileNo, StringRef Filename, StringRef Checksum, unsigned ChecksumKind) override; bool EmitCVFuncIdDirective(unsigned FuncId) override; bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc, unsigned IAFile, unsigned IALine, @@ -1120,13 +1120,22 @@ return MCStreamer::getDwarfLineTableSymbol(0); } -bool MCAsmStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename) { - if (!getContext().getCVContext().addFile(FileNo, Filename)) +bool MCAsmStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename, StringRef Checksum, unsigned ChecksumKind) { + if (!getContext().getCVContext().addFile(FileNo, Filename, Checksum, ChecksumKind)) return false; OS << "\t.cv_file\t" << FileNo << ' '; - PrintQuotedString(Filename, OS); + + if (!ChecksumKind) { + EmitEOL(); + return true; + } + + OS << ' '; + PrintQuotedString(Checksum, OS); + OS << ' ' << ChecksumKind; + EmitEOL(); return true; } Index: llvm/lib/MC/MCCodeView.cpp =================================================================== --- llvm/lib/MC/MCCodeView.cpp +++ llvm/lib/MC/MCCodeView.cpp @@ -39,29 +39,35 @@ /// for it. bool CodeViewContext::isValidFileNumber(unsigned FileNumber) const { unsigned Idx = FileNumber - 1; - if (Idx < Filenames.size()) - return !Filenames[Idx].empty(); + if (Idx < Files.size()) + return !Files[Idx].empty(); return false; } -bool CodeViewContext::addFile(unsigned FileNumber, StringRef Filename) { +bool CodeViewContext::addFile(unsigned FileNumber, StringRef Filename, StringRef Checksum, uint8_t ChecksumKind) { assert(FileNumber > 0); - Filename = addToStringTable(Filename); + auto FilenameOffset = addToStringTable(Filename); + Filename = FilenameOffset.first; unsigned Idx = FileNumber - 1; - if (Idx >= Filenames.size()) - Filenames.resize(Idx + 1); + if (Idx >= Files.size()) + Files.resize(Idx + 1); if (Filename.empty()) Filename = ""; - if (!Filenames[Idx].empty()) + if (!Files[Idx].empty()) return false; // FIXME: We should store the string table offset of the filename, rather than // the filename itself for efficiency. - Filename = addToStringTable(Filename); + FilenameOffset = addToStringTable(Filename); + Filename = FilenameOffset.first; + unsigned Offset = FilenameOffset.second; + + Files[Idx] = std::make_pair(Offset, nullptr); + + Checksums.insert(std::make_pair(Offset, std::make_pair(Checksum,ChecksumKind))); - Filenames[Idx] = Filename; return true; } @@ -118,17 +124,18 @@ return StrTabFragment; } -StringRef CodeViewContext::addToStringTable(StringRef S) { +std::pair CodeViewContext::addToStringTable(StringRef S) { SmallVectorImpl &Contents = getStringTableFragment()->getContents(); auto Insertion = StringTable.insert(std::make_pair(S, unsigned(Contents.size()))); // Return the string from the table, since it is stable. - S = Insertion.first->first(); + auto Ret = *(Insertion.first); + S = Ret.first; if (Insertion.second) { // The string map key is always null terminated. Contents.append(S.begin(), S.end() + 1); } - return S; + return Ret; } unsigned CodeViewContext::getStringTableOffset(StringRef S) { @@ -140,6 +147,29 @@ return I->second; } +void CodeViewContext::assignChecksumOffsets(MCObjectStreamer &OS) { + if (ChecksumOffsetsAssigned) + return; + + ChecksumOffsetsAssigned = true; + + unsigned CurrentOffset = 0; + + MCContext &Ctx = OS.getContext(); + + for (auto File : Files) { + //File.second = CurrentOffset; + Ctx.setSymbolValue(OS, File.second->getName(), CurrentOffset); + CurrentOffset += 2; + auto Checksum = Checksums[File.first]; + if (!Checksum.second) { + CurrentOffset += 2; + continue; + } + CurrentOffset += Checksum.first.size(); + } +} + void CodeViewContext::emitStringTable(MCObjectStreamer &OS) { MCContext &Ctx = OS.getContext(); MCSymbol *StringBegin = Ctx.createTempSymbol("strtab_begin", false), @@ -165,9 +195,11 @@ void CodeViewContext::emitFileChecksums(MCObjectStreamer &OS) { // Do nothing if there are no file checksums. Microsoft's linker rejects empty // CodeView substreams. - if (Filenames.empty()) + if (Files.empty()) return; + assignChecksumOffsets(OS); + MCContext &Ctx = OS.getContext(); MCSymbol *FileBegin = Ctx.createTempSymbol("filechecksums_begin", false), *FileEnd = Ctx.createTempSymbol("filechecksums_end", false); @@ -179,16 +211,42 @@ // Emit an array of FileChecksum entries. We index into this table using the // user-provided file number. Each entry is currently 8 bytes, as we don't // emit checksums. - for (StringRef Filename : Filenames) { - OS.EmitIntValue(getStringTableOffset(Filename), 4); - // Zero the next two fields and align back to 4 bytes. This indicates that - // no checksum is present. - OS.EmitIntValue(0, 4); + for (auto File : Files) { + OS.EmitIntValue(File.first, 4); + + std::pair Checksum = Checksums[File.first]; + if (!Checksum.second) { + // There is no checksum. + OS.EmitIntValue(0, 4); + continue; + } + OS.EmitIntValue(static_cast(Checksum.first.size()), 1); //checksum size + // OS.EmitIntValue(6, 1); + // OS.EmitIntValue(3, 1); + // OS.EmitIntValue(3147, 6); + OS.EmitIntValue(Checksum.second, 1); //checksum type + OS.EmitBytes(Checksum.first); //actual checksum + OS.EmitValueToAlignment(4); //align } OS.EmitLabel(FileEnd); } +void CodeViewContext::emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo) { + if (ChecksumOffsetsAssigned) { + OS.EmitSymbolValue(Files[FileNo].second, 1); + return; + } + + Files[FileNo].second = OS.getContext().createTempSymbol(); + const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Files[FileNo].second, Ctx); + + MCDataFragment *DF = OS.getOrCreateDataFragment(); + flushPendingLabels(DF, DF->getContents().size()); + + DF->getFixups().push_back(MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_1)); +} + void CodeViewContext::emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, @@ -211,6 +269,8 @@ OS.EmitIntValue(HaveColumns ? int(LF_HaveColumns) : 0, 2); OS.emitAbsoluteSymbolDiff(FuncEnd, FuncBegin, 4); + //assignChecksumOffsets(); + for (auto I = Locs.begin(), E = Locs.end(); I != E;) { // Emit a file segment for the run of locations that share a file id. unsigned CurFileNum = I->getFileNum(); @@ -219,9 +279,11 @@ return Loc.getFileNum() != CurFileNum; }); unsigned EntryCount = FileSegEnd - I; - OS.AddComment("Segment for file '" + Twine(Filenames[CurFileNum - 1]) + + OS.AddComment("Segment for file '" + Twine(getStringTableFragment()->getContents()[Files[CurFileNum - 1].first]) + "' begins"); - OS.EmitIntValue(8 * (CurFileNum - 1), 4); + //OS.EmitIntValue(Files[CurFileNum].second, 4); + OS.EmitCVFileChecksumOffsetDirective(CurFileNum); + //OS.EmitIntValue(12 * (CurFileNum - 1), 4); // assumes 8 bytes checksum OS.EmitIntValue(EntryCount, 4); uint32_t SegmentSize = 12; SegmentSize += 8 * EntryCount; @@ -357,6 +419,9 @@ SmallVectorImpl &Buffer = Frag.getContents(); Buffer.clear(); // Clear old contents if we went through relaxation. + + //assignChecksumOffsets(); + for (const MCCVLineEntry &Loc : Locs) { // Exit early if our line table would produce an oversized InlineSiteSym // record. Account for the ChangeCodeLength annotation emitted after the @@ -403,7 +468,8 @@ if (CurSourceLoc.File != LastSourceLoc.File) { // File ids are 1 based, and each file checksum table entry is 8 bytes // long. See emitFileChecksums above. - unsigned FileOffset = 8 * (CurSourceLoc.File - 1); + //unsigned FileOffset = 12 * (CurSourceLoc.File - 1); + unsigned FileOffset = Files[CurSourceLoc.File].second ? Files[CurSourceLoc.File].second->getVariableValue()->getValue() : 8; compressAnnotation(BinaryAnnotationsOpCode::ChangeFile, Buffer); compressAnnotation(FileOffset, Buffer); } Index: llvm/lib/MC/MCObjectStreamer.cpp =================================================================== --- llvm/lib/MC/MCObjectStreamer.cpp +++ llvm/lib/MC/MCObjectStreamer.cpp @@ -426,6 +426,10 @@ getContext().getCVContext().emitFileChecksums(*this); } +void MCObjectStreamer::EmitCVFileChecksumOffsetDirective(unsigned FileNo) { + getContext().getCVContext().emitFileChecksumOffset(*this, FileNo); +} + void MCObjectStreamer::EmitBytes(StringRef Data) { MCCVLineEntry::Make(this); Index: llvm/lib/MC/MCParser/AsmParser.cpp =================================================================== --- llvm/lib/MC/MCParser/AsmParser.cpp +++ llvm/lib/MC/MCParser/AsmParser.cpp @@ -3452,25 +3452,33 @@ } /// parseDirectiveCVFile -/// ::= .cv_file number filename +/// ::= .cv_file number filename [Checksum] [ChecksumKind] bool AsmParser::parseDirectiveCVFile() { SMLoc FileNumberLoc = getTok().getLoc(); int64_t FileNumber; std::string Filename; + std::string Checksum; + int64_t ChecksumKind = 0; if (parseIntToken(FileNumber, "expected file number in '.cv_file' directive") || check(FileNumber < 1, FileNumberLoc, "file number less than one") || check(getTok().isNot(AsmToken::String), - "unexpected token in '.cv_file' directive") || - // Usually directory and filename are together, otherwise just - // directory. Allow the strings to have escaped octal character sequence. - parseEscapedString(Filename) || - parseToken(AsmToken::EndOfStatement, - "unexpected token in '.cv_file' directive")) + "a") || + parseEscapedString(Filename)) return true; + if (!parseOptionalToken(AsmToken::EndOfStatement)) { + if(check(getTok().isNot(AsmToken::String), + "b") || + parseEscapedString(Checksum) || + parseIntToken(ChecksumKind, "expected checksum kind in '.cv_file' directive") || + parseToken(AsmToken::EndOfStatement, + "c")) + return true; + } + - if (!getStreamer().EmitCVFileDirective(FileNumber, Filename)) + if (!getStreamer().EmitCVFileDirective(FileNumber, Filename, Checksum, static_cast(ChecksumKind))) return Error(FileNumberLoc, "file number already allocated"); return false; Index: llvm/lib/MC/MCStreamer.cpp =================================================================== --- llvm/lib/MC/MCStreamer.cpp +++ llvm/lib/MC/MCStreamer.cpp @@ -224,8 +224,8 @@ report_fatal_error("No open frame"); } -bool MCStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename) { - return getContext().getCVContext().addFile(FileNo, Filename); +bool MCStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename, StringRef Checksum, unsigned ChecksumKind) { + return getContext().getCVContext().addFile(FileNo, Filename, Checksum, ChecksumKind); } bool MCStreamer::EmitCVFuncIdDirective(unsigned FunctionId) { Index: llvm/test/DebugInfo/COFF/multifile.ll =================================================================== --- llvm/test/DebugInfo/COFF/multifile.ll +++ llvm/test/DebugInfo/COFF/multifile.ll @@ -185,11 +185,11 @@ !llvm.ident = !{!11} !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.5 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) -!1 = !DIFile(filename: "", directory: "D:\5C") +!1 = !DIFile(filename: "", directory: "D:\5C", checksumkind: CSK_MD5, checksum:"70b51f534d80639d033ae92c6a856af6") !2 = !{} !4 = distinct !DISubprogram(name: "f", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 3, file: !5, scope: !6, type: !7, variables: !2) -!5 = !DIFile(filename: "input.c", directory: "D:\5C") -!6 = !DIFile(filename: "input.c", directory: "D:C") +!5 = !DIFile(filename: "input.c", directory: "D:\5C", checksumkind: CSK_MD5, checksum:"70b51f534d80639d033ae92c6a856af6") +!6 = !DIFile(filename: "input.c", directory: "D:C", checksumkind: CSK_MD5, checksum:"70b51f534d80639d033ae92c6a856af6") !7 = !DISubroutineType(types: !8) !8 = !{null} !9 = !{i32 2, !"CodeView", i32 1} @@ -197,9 +197,9 @@ !11 = !{!"clang version 3.5 "} !12 = !DILocation(line: 1, scope: !13) !13 = !DILexicalBlockFile(discriminator: 0, file: !14, scope: !4) -!14 = !DIFile(filename: "one.c", directory: "D:\5C") +!14 = !DIFile(filename: "oneblahblahblah.c", directory: "D:\5C", checksumkind: CSK_MD5, checksum:"70b51f534d80639d033ae92c6a856af6") !15 = !DILocation(line: 2, scope: !16) !16 = !DILexicalBlockFile(discriminator: 0, file: !17, scope: !4) -!17 = !DIFile(filename: "two.c", directory: "D:\5C") +!17 = !DIFile(filename: "twoblahblahblah.c", directory: "D:\5C", checksumkind: CSK_MD5, checksum:"70b51f534d80639d033ae92c6a856af6") !18 = !DILocation(line: 7, scope: !13) !19 = !DILocation(line: 8, scope: !13) Index: llvm/tools/llvm-readobj/COFFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/COFFDumper.cpp +++ llvm/tools/llvm-readobj/COFFDumper.cpp @@ -924,7 +924,9 @@ error(CVFileChecksumTable.initialize(ST)); break; case DebugSubsectionKind::StringTable: + errs() << "initializing string table\n"; error(CVStringTable.initialize(ST)); + errs() << "initialized string table\n"; break; default: break; @@ -1083,7 +1085,9 @@ for (const auto &Entry : LineInfo) { ListScope S(W, "FilenameSegment"); + //errs() << "about to pring filename with offset " << Entry.NameIndex << "\n"; printFileNameForOffset("Filename", Entry.NameIndex); + //errs() << "printed filename\n"; uint32_t ColumnIndex = 0; for (const auto &Line : Entry.LineNumbers) { if (Line.Offset >= LineInfo.header()->CodeSize) { @@ -1187,6 +1191,7 @@ if (Iter == CVFileChecksumTable.end()) error(object_error::parse_failed); + errs() << "File offset: " << FileOffset << "\n"; return error(CVStringTable.getString(Iter->FileNameOffset)); } Index: llvm/unittests/IR/MetadataTest.cpp =================================================================== --- llvm/unittests/IR/MetadataTest.cpp +++ llvm/unittests/IR/MetadataTest.cpp @@ -1370,7 +1370,7 @@ TEST_F(DIFileTest, get) { StringRef Filename = "file"; StringRef Directory = "dir"; - DIFile::ChecksumKind CSKind = DIFile::CSK_MD5; + DIFile::ChecksumKind CSKind = DIFile::ChecksumKind::CSK_MD5; StringRef Checksum = "000102030405060708090a0b0c0d0e0f"; auto *N = DIFile::get(Context, Filename, Directory, CSKind, Checksum); @@ -1383,7 +1383,7 @@ EXPECT_NE(N, DIFile::get(Context, "other", Directory, CSKind, Checksum)); EXPECT_NE(N, DIFile::get(Context, Filename, "other", CSKind, Checksum)); - EXPECT_NE(N, DIFile::get(Context, Filename, Directory, DIFile::CSK_SHA1, Checksum)); + EXPECT_NE(N, DIFile::get(Context, Filename, Directory, DIFile::ChecksumKind::CSK_SHA1, Checksum)); EXPECT_NE(N, DIFile::get(Context, Filename, Directory)); TempDIFile Temp = N->clone();