[lld][COFF] Fix lld-link crash when several .obj files built with /Zi refer to a...
authorSylvain Audi <sylvain.audi@ubisoft.com>
Thu, 15 Dec 2022 15:56:47 +0000 (10:56 -0500)
committerSylvain Audi <sylvain.audi@ubisoft.com>
Wed, 21 Dec 2022 21:13:46 +0000 (16:13 -0500)
commit84038cf914f6a0060477ba35bafbff2fd0c49fe0
tree6e3da2512d6c06b192545d466d93ab835ae9e1a6
parentb5415f301586b74f729bee20fcfb34066413dbb5
[lld][COFF] Fix lld-link crash when several .obj files built with /Zi refer to a .pdb file that failed to load

This patch relaxes the constraints on the error message saved in PDBInputFile when failing to load a pdb file.

Storing an `Error` member infers that it must be accessed exactly once, which doesn't fit in several scenarios:
- If an invalid PDB file is provided as input file but never used, a loading error is created but never handled, causing an assert at shutdown.
- PDB file created using MSVC's `/Zi` option : The loading error message must be displayed once per obj file.

Also, the state of `PDBInputFile` was altered when reading (taking) the `Error` member, causing issues:
 - accessing it (taking the `Error`) makes the object look valid whereas it's not properly initialized
 - read vs write concurrency on a same `PDBInputFile` in the ghash parallel algorithm

The solution adopted here was to instead store an optional error string, and generate Error objects from it on demand.

Differential Revision: https://reviews.llvm.org/D140333
lld/COFF/DebugTypes.cpp
lld/COFF/InputFiles.cpp
lld/COFF/InputFiles.h
lld/test/COFF/Inputs/pdb-type-server-corrupted-a.yaml [new file with mode: 0644]
lld/test/COFF/Inputs/pdb-type-server-corrupted-b.yaml [new file with mode: 0644]
lld/test/COFF/invalid-input-pdb.ll [new file with mode: 0644]
lld/test/COFF/pdb-type-server-corrupted.test [new file with mode: 0644]