Index: COFF/PDB.cpp =================================================================== --- COFF/PDB.cpp +++ COFF/PDB.cpp @@ -670,24 +670,18 @@ #endif } -// Find an OBJ provided on the command line, either by name or full path +// Find by name an OBJ provided on the command line static Optional> -findObjByName(StringRef NameOrPath) { +findObjByName(StringRef FileNameOnly) { SmallString<128> CurrentPath; - StringRef FileNameOnly = sys::path::filename(NameOrPath); - for (ObjFile *F : ObjFile::Instances) { CurrentPath = F->getName(); sys::fs::make_absolute(CurrentPath); - // First compare with the full path name - if (equals_path(CurrentPath, NameOrPath)) - return std::make_pair(F, CurrentPath.str().str()); - StringRef CurrentFileName = sys::path::filename(CurrentPath); - // Otherwise compare based solely on the file name (link.exe behavior) + // Compare based solely on the file name (link.exe behavior) if (equals_path(CurrentFileName, FileNameOnly)) return std::make_pair(F, CurrentPath.str().str()); } @@ -715,13 +709,11 @@ CVIndexMap &IndexMap = R.first; - SmallString<128> PrecompPath = Precomp.getPrecompFilePath(); - sys::fs::make_absolute(PrecompPath); - // Cross-compile warning: given that Clang doesn't generate LF_PRECOMP // records, we assume the OBJ comes from a Windows build of cl.exe. Thusly, // the paths embedded in the OBJs are in the Windows format. - sys::path::native(PrecompPath, sys::path::Style::windows); + SmallString<128> PrecompPath = sys::path::filename( + Precomp.getPrecompFilePath(), sys::path::Style::windows); // link.exe requires that a precompiled headers object must always be provided // on the command-line, even if that's not necessary. Index: COFF/SymbolTable.cpp =================================================================== --- COFF/SymbolTable.cpp +++ COFF/SymbolTable.cpp @@ -241,6 +241,11 @@ } } + // We don't want to report Microsoft precompiled headers missing OBJs. + // A proper message will be emitted instead in PDBLinker::aquirePrecompObj + if (Name.contains("_PchSym_")) + continue; + if (Config->MinGW && handleMinGWAutomaticImport(Sym, Name)) continue; Index: test/COFF/precomp-link.test =================================================================== --- test/COFF/precomp-link.test +++ test/COFF/precomp-link.test @@ -1,5 +1,3 @@ -REQUIRES: system-windows - RUN: lld-link %S/Inputs/precomp-a.obj %S/Inputs/precomp-b.obj %S/Inputs/precomp.obj /nodefaultlib /entry:main /debug /pdb:%t.pdb /out:%t.exe /opt:ref /opt:icf RUN: llvm-pdbutil dump -types %t.pdb | FileCheck %s @@ -8,9 +6,14 @@ RUN: lld-link %S/Inputs/precomp-a.obj %S/Inputs/precomp-invalid.obj %S/Inputs/precomp.obj /nodefaultlib /entry:main /debug /pdb:%t.pdb /out:%t.exe /opt:ref /opt:icf 2>&1 | FileCheck %s -check-prefix FAILURE +RUN: not lld-link %S/Inputs/precomp-a.obj %S/Inputs/precomp-b.obj /nodefaultlib /entry:main /debug /pdb:%t.pdb /out:%t.exe /opt:ref /opt:icf 2>&1 | FileCheck %s -check-prefix FAILURE-MISSING-PRECOMPOBJ + FAILURE: warning: Cannot use debug info for 'precomp-invalid.obj' FAILURE-NEXT: failed to load reference '{{.*}}precomp.obj': The signature does not match; the file(s) might be out of date. +FAILURE-MISSING-PRECOMPOBJ: warning: Cannot use debug info for 'precomp-a.obj' +FAILURE-MISSING-PRECOMPOBJ-NEXT: failed to load reference '{{.*}}precomp.obj': {{N|n}}o such file or directory + CHECK: Types (TPI Stream) CHECK-NOT: LF_PRECOMP CHECK-NOT: LF_ENDPRECOMP