Author: hans Date: Tue Feb 13 06:01:21 2018 New Revision: 325005 URL: http://llvm.org/viewvc/llvm-project?rev=325005&view=rev Log: Merging r323893 and r323895:
------------------------------------------------------------------------ r323893 | colden | 2018-01-31 18:48:04 +0100 (Wed, 31 Jan 2018) | 11 lines [LLD][PDB] Implement FIXME: Warn on missing TypeServer PDB rather than error Summary: Instead of fatal-ing out when missing a type server PDB, insead warn and cache the miss. Reviewers: rnk, zturner Reviewed By: rnk Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D42188 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r323895 | colden | 2018-01-31 19:16:13 +0100 (Wed, 31 Jan 2018) | 1 line [PDB] Fix test failures due to expected warning not matching actual warning text ------------------------------------------------------------------------ Modified: lld/branches/release_60/ (props changed) lld/branches/release_60/COFF/PDB.cpp lld/branches/release_60/test/COFF/pdb-type-server-missing.yaml Propchange: lld/branches/release_60/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Feb 13 06:01:21 2018 @@ -1 +1 @@ -/lld/trunk:321983,321986,322041,322259,322264,322359,322421,322801,323155,323221,323243,323288,323395-323396,323399,323440,323449,323456,323625,324043,324467-324468 +/lld/trunk:321983,321986,322041,322259,322264,322359,322421,322801,323155,323221,323243,323288,323395-323396,323399,323440,323449,323456,323625,323893,323895,324043,324467-324468 Modified: lld/branches/release_60/COFF/PDB.cpp URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/COFF/PDB.cpp?rev=325005&r1=325004&r2=325005&view=diff ============================================================================== --- lld/branches/release_60/COFF/PDB.cpp (original) +++ lld/branches/release_60/COFF/PDB.cpp Tue Feb 13 06:01:21 2018 @@ -96,10 +96,11 @@ public: /// If the object does not use a type server PDB (compiled with /Z7), we merge /// all the type and item records from the .debug$S stream and fill in the /// caller-provided ObjectIndexMap. - const CVIndexMap &mergeDebugT(ObjFile *File, CVIndexMap &ObjectIndexMap); + Expected<const CVIndexMap&> mergeDebugT(ObjFile *File, + CVIndexMap &ObjectIndexMap); - const CVIndexMap &maybeMergeTypeServerPDB(ObjFile *File, - TypeServer2Record &TS); + Expected<const CVIndexMap&> maybeMergeTypeServerPDB(ObjFile *File, + TypeServer2Record &TS); /// Add the section map and section contributions to the PDB. void addSections(ArrayRef<OutputSection *> OutputSections, @@ -140,6 +141,10 @@ private: /// Type index mappings of type server PDBs that we've loaded so far. std::map<GUID, CVIndexMap> TypeServerIndexMappings; + + /// List of TypeServer PDBs which cannot be loaded. + /// Cached to prevent repeated load attempts. + std::set<GUID> MissingTypeServerPDBs; }; } @@ -230,8 +235,8 @@ maybeReadTypeServerRecord(CVTypeArray &T return std::move(TS); } -const CVIndexMap &PDBLinker::mergeDebugT(ObjFile *File, - CVIndexMap &ObjectIndexMap) { +Expected<const CVIndexMap&> PDBLinker::mergeDebugT(ObjFile *File, + CVIndexMap &ObjectIndexMap) { ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T"); if (Data.empty()) return ObjectIndexMap; @@ -304,11 +309,19 @@ tryToLoadPDB(const GUID &GuidFromObj, St return std::move(NS); } -const CVIndexMap &PDBLinker::maybeMergeTypeServerPDB(ObjFile *File, - TypeServer2Record &TS) { - // First, check if we already loaded a PDB with this GUID. Return the type +Expected<const CVIndexMap&> PDBLinker::maybeMergeTypeServerPDB(ObjFile *File, + TypeServer2Record &TS) { + const GUID& TSId = TS.getGuid(); + StringRef TSPath = TS.getName(); + + // First, check if the PDB has previously failed to load. + if (MissingTypeServerPDBs.count(TSId)) + return make_error<pdb::GenericError>( + pdb::generic_error_code::type_server_not_found, TSPath); + + // Second, check if we already loaded a PDB with this GUID. Return the type // index mapping if we have it. - auto Insertion = TypeServerIndexMappings.insert({TS.getGuid(), CVIndexMap()}); + auto Insertion = TypeServerIndexMappings.insert({TSId, CVIndexMap()}); CVIndexMap &IndexMap = Insertion.first->second; if (!Insertion.second) return IndexMap; @@ -319,18 +332,21 @@ const CVIndexMap &PDBLinker::maybeMergeT // Check for a PDB at: // 1. The given file path // 2. Next to the object file or archive file - auto ExpectedSession = tryToLoadPDB(TS.getGuid(), TS.getName()); + auto ExpectedSession = tryToLoadPDB(TSId, TSPath); if (!ExpectedSession) { consumeError(ExpectedSession.takeError()); StringRef LocalPath = !File->ParentName.empty() ? File->ParentName : File->getName(); SmallString<128> Path = sys::path::parent_path(LocalPath); sys::path::append( - Path, sys::path::filename(TS.getName(), sys::path::Style::windows)); - ExpectedSession = tryToLoadPDB(TS.getGuid(), Path); + Path, sys::path::filename(TSPath, sys::path::Style::windows)); + ExpectedSession = tryToLoadPDB(TSId, Path); + } + if (auto E = ExpectedSession.takeError()) { + TypeServerIndexMappings.erase(TSId); + MissingTypeServerPDBs.emplace(TSId); + return std::move(E); } - if (auto E = ExpectedSession.takeError()) - fatal("Type server PDB was not found: " + toString(std::move(E))); auto ExpectedTpi = (*ExpectedSession)->getPDBFile().getPDBTpiStream(); if (auto E = ExpectedTpi.takeError()) @@ -707,7 +723,16 @@ void PDBLinker::addObjFile(ObjFile *File // the PDB first, so that we can get the map from object file type and item // indices to PDB type and item indices. CVIndexMap ObjectIndexMap; - const CVIndexMap &IndexMap = mergeDebugT(File, ObjectIndexMap); + auto IndexMapResult = mergeDebugT(File, ObjectIndexMap); + + // If the .debug$T sections fail to merge, assume there is no debug info. + if (!IndexMapResult) { + warn("Type server PDB for " + Name + " is invalid, ignoring debug info. " + + toString(IndexMapResult.takeError())); + return; + } + + const CVIndexMap &IndexMap = *IndexMapResult; // Now do all live .debug$S sections. for (SectionChunk *DebugChunk : File->getDebugChunks()) { Modified: lld/branches/release_60/test/COFF/pdb-type-server-missing.yaml URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/test/COFF/pdb-type-server-missing.yaml?rev=325005&r1=325004&r2=325005&view=diff ============================================================================== --- lld/branches/release_60/test/COFF/pdb-type-server-missing.yaml (original) +++ lld/branches/release_60/test/COFF/pdb-type-server-missing.yaml Tue Feb 13 06:01:21 2018 @@ -1,13 +1,10 @@ # This is an object compiled with /Zi (see the LF_TYPESERVER2 record) without an # adjacent type server PDB. Test that LLD fails gracefully on it. -# FIXME: Ideally we'd do what MSVC does, which is to warn and drop all debug -# info in the object with the missing PDB. - # RUN: yaml2obj %s -o %t.obj -# RUN: not lld-link %t.obj -out:%t.exe -debug -pdb:%t.pdb -nodefaultlib -entry:main 2>&1 | FileCheck %s +# RUN: lld-link %t.obj -out:%t.exe -debug -pdb:%t.pdb -nodefaultlib -entry:main 2>&1 | FileCheck %s -# CHECK: error: Type server PDB was not found +# CHECK: warning: Type server PDB for {{.*}}.obj is invalid, ignoring debug info. --- !COFF header: _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits