[PATCH] D54122: [LLD] Fix precompiled headers build break on Linux

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 5 14:19:59 PST 2018


aganea created this revision.
aganea added reviewers: rnk, zturner, neerajksingh.
Herald added subscribers: llvm-commits, JDevlieghere, aprantl.

Currently, precompiled headers OBJs are only produced on Windows with `cl.exe` so any embedded paths are Windows-specific. Obviously manipulating these paths on Linux won't work.

Additionally, Microsoft `link.exe` requires a precompiled headers OBJ to be provided on the command-line (even if `precomp.obj` is there at the proper location, as specified internally by `precomp-a.obj`).
This fails:

  link.exe precomp-a.obj /OUT:a.exe

This works:

  link.exe precomp-a.obj precomp.obj /OUT:a.exe

I've consequently only kept the filename-based search. I'm not sure searching with the full embedded path makes sense.

----

The build break is here <http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/25790/steps/check-lld%20ubsan/logs/stdio>:

  FAIL: lld :: COFF/precomp-link.test (171 of 1917)
  ******************** TEST 'lld :: COFF/precomp-link.test' FAILED ********************
  Script:
  --
  : 'RUN: at line 1';   /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/lld-link /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/Inputs/precomp-a.obj /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/Inputs/precomp-b.obj /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/Inputs/precomp.obj /nodefaultlib /entry:main /debug /pdb:/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/tools/lld/test/COFF/Output/precomp-link.test.tmp.pdb /out:/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/tools/lld/test/COFF/Output/precomp-link.test.tmp.exe /opt:ref /opt:icf
  : 'RUN: at line 2';   /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/llvm-pdbutil dump -types /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/tools/lld/test/COFF/Output/precomp-link.test.tmp.pdb | /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/FileCheck /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/precomp-link.test
  : 'RUN: at line 4';   /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/lld-link /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/Inputs/precomp.obj /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/Inputs/precomp-a.obj /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/Inputs/precomp-b.obj /nodefaultlib /entry:main /debug /pdb:/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/tools/lld/test/COFF/Output/precomp-link.test.tmp.pdb /out:/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/tools/lld/test/COFF/Output/precomp-link.test.tmp.exe /opt:ref /opt:icf
  : 'RUN: at line 5';   /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/llvm-pdbutil dump -types /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/tools/lld/test/COFF/Output/precomp-link.test.tmp.pdb | /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/FileCheck /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/precomp-link.test
  : 'RUN: at line 7';   /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/lld-link /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/Inputs/precomp-a.obj /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/Inputs/precomp-invalid.obj /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/Inputs/precomp.obj /nodefaultlib /entry:main /debug /pdb:/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/tools/lld/test/COFF/Output/precomp-link.test.tmp.pdb /out:/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/tools/lld/test/COFF/Output/precomp-link.test.tmp.exe /opt:ref /opt:icf 2>&1 | /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/FileCheck /b/sanitizer-x86_64-linux-fast/build/llvm/tools/lld/test/COFF/precomp-link.test -check-prefix FAILURE
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  lld-link: warning: Cannot use debug info for 'precomp-a.obj'
  >>> failed to load reference 'f:\svn\lld\test\coff\precomp\precomp.obj': No such file or directory
  
  lld-link: error: codeview::mergeTypeAndIdRecords failed: The CodeView record is corrupted.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D54122

Files:
  COFF/PDB.cpp
  COFF/SymbolTable.cpp
  test/COFF/precomp-link.test


Index: test/COFF/precomp-link.test
===================================================================
--- test/COFF/precomp-link.test
+++ test/COFF/precomp-link.test
@@ -1,16 +1,19 @@
-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
 
 RUN: lld-link %S/Inputs/precomp.obj %S/Inputs/precomp-a.obj %S/Inputs/precomp-b.obj /nodefaultlib /entry:main /debug /pdb:%t.pdb /out:%t.exe /opt:ref /opt:icf
 RUN: llvm-pdbutil dump -types %t.pdb | FileCheck %s
 
 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
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: 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<std::pair<ObjFile *, std::string>>
-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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54122.172653.patch
Type: text/x-patch
Size: 3844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181105/2ff1037f/attachment.bin>


More information about the llvm-commits mailing list