diff --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp --- a/lld/COFF/DebugTypes.cpp +++ b/lld/COFF/DebugTypes.cpp @@ -54,7 +54,8 @@ auto expectedInfo = file.getPDBInfoStream(); if (!expectedInfo) return; - auto it = mappings.emplace(expectedInfo->getGuid(), this); + Guid = expectedInfo->getGuid(); + auto it = mappings.emplace(Guid, this); assert(it.second); (void)it; } @@ -71,6 +72,9 @@ // TpiSource for IPI stream. TypeServerIpiSource *ipiSrc = nullptr; + // The PDB signature GUID. + codeview::GUID Guid; + static std::map mappings; }; @@ -429,6 +433,15 @@ return createFileError(tsPath, std::move(*pdb->loadErr)); tsSrc = (TypeServerSource *)pdb->debugTypesObj; + + // Just because a file with a matching name was found and it was an actual + // PDB file doesn't mean it matches. For it to match the InfoStream's GUID + // must match the GUID specified in the TypeServer2 record. + if (tsSrc->Guid != tsId) { + return createFileError(tsPath, + make_error( + pdb::pdb_error_code::signature_out_of_date)); + } } return tsSrc; } @@ -443,14 +456,6 @@ if (!expectedInfo) return expectedInfo.takeError(); - // Just because a file with a matching name was found and it was an actual - // PDB file doesn't mean it matches. For it to match the InfoStream's GUID - // must match the GUID specified in the TypeServer2 record. - if (expectedInfo->getGuid() != typeServerDependency.getGuid()) - return createFileError( - typeServerDependency.getName(), - make_error(pdb::pdb_error_code::signature_out_of_date)); - // Reuse the type index map of the type server. tpiMap = (*tsSrc)->tpiMap; ipiMap = (*tsSrc)->ipiMap; @@ -810,11 +815,13 @@ // server. Errors should have been reported earlier. Symbols from this object // will be ignored. Expected maybeTsSrc = getTypeServerSource(); + if (!maybeTsSrc) { typeMergingError = joinErrors(std::move(typeMergingError), maybeTsSrc.takeError()); return; } + TypeServerSource *tsSrc = *maybeTsSrc; tpiMap = tsSrc->tpiMap; ipiMap = tsSrc->ipiMap; diff --git a/lld/test/COFF/pdb-type-server-invalid-signature.yaml b/lld/test/COFF/pdb-type-server-invalid-signature.yaml --- a/lld/test/COFF/pdb-type-server-invalid-signature.yaml +++ b/lld/test/COFF/pdb-type-server-invalid-signature.yaml @@ -3,6 +3,7 @@ # RUN: cd %S/Inputs # RUN: yaml2obj %s -o %t.obj # RUN: 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:ghash -pdb:%t.pdb -nodefaultlib -entry:main 2>&1 | FileCheck %s # RUN: cd %S # CHECK: warning: Cannot use debug info for '{{.*}}.obj'