This is an archive of the discontinued LLVM Phabricator instance.

[LLD] Fix precompiled headers build break on Linux
ClosedPublic

Authored by aganea on Nov 5 2018, 2:19 PM.

Details

Summary

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:

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.

Diff Detail

Event Timeline

aganea created this revision.Nov 5 2018, 2:19 PM
aganea added inline comments.Nov 5 2018, 2:23 PM
COFF/SymbolTable.cpp
246 ↗(On Diff #172653)

@neerajksingh: Out of curiosity, could you please explain how _PchSym_ symbols are mangled? If I don't add this check, I get:

lld-link: error: <root>: undefined symbol: __@@_PchSym_@00@UhemUoowUgvhgUxluuUkivxlnkUkivxlnkOlyq@4B2008FD98C1DD4

I find this confusing for users, I've consequently removed pch symbols, in order to emit a better message a bit later on.

aganea updated this revision to Diff 172662.Nov 5 2018, 2:48 PM

Updated with better error message:

F:\svn\build> lld-link precomp-a.obj /OUT:a.exe
lld-link: warning: Cannot use debug info for 'precomp-a.obj'
>>> failed to load reference 'precomp.obj': The path to this file must be provided on the command-line.
rnk accepted this revision.Nov 5 2018, 3:14 PM

lgtm

lld/trunk/COFF/PDB.cpp
-10–1

Do we really need to make each object file path absolute before calling sys::path::filename? I would've expected we could just do StringRef CurrentFileName = sys::path::filename(F->getName());.

This revision is now accepted and ready to land.Nov 5 2018, 3:14 PM
aganea updated this revision to Diff 172763.Nov 6 2018, 6:58 AM
aganea marked an inline comment as done.

Thank you Reid! I've simplified the code as you suggested.

This revision was automatically updated to reflect the committed changes.