This is an archive of the discontinued LLVM Phabricator instance.

[lld][COFF] Fix lld-link crash when several .obj files built with /Zi refer to a .pdb file that failed to load
ClosedPublic

Authored by saudi on Dec 19 2022, 11:56 AM.

Details

Summary

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:

  • making it 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.

Diff Detail

Event Timeline

saudi created this revision.Dec 19 2022, 11:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 11:56 AM
saudi requested review of this revision.Dec 19 2022, 11:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 11:56 AM
saudi updated this revision to Diff 484333.Dec 20 2022, 11:17 AM

Fixed clang-format

aganea added inline comments.Dec 20 2022, 3:38 PM
lld/COFF/InputFiles.cpp
899

I wouldn't add those two accessor functions, and would keep loadErrorStr public. The intent is already clear enough by accessing std::optional and you seem to only use getLoadError once. What about moving the make_error.. line to the call site and compose it with createFileError?

saudi updated this revision to Diff 484558.Dec 21 2022, 6:24 AM

Followed @aganea's suggestion, it's indeed clearer, thanks!

aganea accepted this revision.Dec 21 2022, 12:05 PM

Thanks for making the changes! LGTM.

This revision is now accepted and ready to land.Dec 21 2022, 12:05 PM
thieta accepted this revision.Dec 21 2022, 12:45 PM

Oh sorry for the late reply. I think removing the getter makes sense as well - it worked better when we had the earlier revision that copied string out of the Error etc.

Anyway LGTM and this hopefully fixes the crash we got reported internally.