[PATCH] D36758: [LLD COFF / PDB] Incrementally update the BuildId when writing a PDB.

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 11:04:55 PDT 2017


zturner created this revision.
Herald added a subscriber: aprantl.

Previously, our algorithm to compute a build id involved hashing the executable and storing that as the GUID in the CV Debug Record chunk, and setting the age to 1.

This breaks down in one very obvious case: a user adds some newlines to a file, rebuilds, but changes nothing else.  This causes new line information and new file checksums to get written to the PDB, meaning that the debug info is different, but the generated code would be the same, so we would write the same build over again with an age of 1.

Anyone using a symbol cache would have a problem now, because the debugger would open the executable, look at the age and guid, find a matching PDB in the symbol cache and then load it.  It would never copy the new PDB to the symbol cache.

There are various other scenarios where this can arise as well, but this one is both the easiest to describe and is what people will run into the most often.

PE files are ultimately matched against PDBs using 3 pieces of information:

1. A 128-bit GUID.  When an executable is being written for the first time, a new GUID is generated, otherwise the existing GUID is re-used.
2. When an executable is being written for the first time, the Age is set to 1, otherwise the age is incremented.
3. Every time an executable is written, the time stamp field is updated.

Then, the debugger goes through these steps when looking for a PDB:

1. Is there a PDB with a matching GUID?  If not, there's no debug info, otherwise go to step 2.
2. Does the PDB have a matching age?  If not, warn the user that the debug info might be stale, otherwise go to step 3.
3. Does the PDB have a matching timestamp?  If not, warn the user that the debug info might be stale, otherwise we're good to go.

This patch implements the first two of these fields.  We're still not writing a timestamp, but this is at least better than before.  Unfortunately, this hurts reproducibility, but if we want PDBs to work correctly, we don't have much of a choice but to do this.  We can still get reproducibility through additional flags, or via a tool that runs as a post-processing step to strip out un-reproducible pieces.


https://reviews.llvm.org/D36758

Files:
  lld/COFF/PDB.cpp
  lld/COFF/PDB.h
  lld/COFF/Writer.cpp
  lld/test/COFF/pdb-diff.test
  lld/test/COFF/pdb-none.test
  lld/test/COFF/pdb-source-lines.test
  lld/test/COFF/pdb.test
  lld/test/COFF/rsds.test

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36758.111208.patch
Type: text/x-patch
Size: 17723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170815/3b62b1ce/attachment.bin>


More information about the llvm-commits mailing list