This is an archive of the discontinued LLVM Phabricator instance.

Fix some differences between LLD and MSVC generated PDBs
ClosedPublic

Authored by zturner on Jul 6 2017, 2:16 PM.

Details

Summary
A couple of things were different about our generated PDBs.

1) We were outputting the wrong Version on the PDB Stream.
   The version we were setting was newer than what MSVC is setting.
   It's not clear what the implications are, but we change LLD
   to use PdbImplVC70, as MSVC does.
2) For the optional debug stream indices in the DBI Stream, we
   were outputting 0 to mean "the stream is not present".  MSVC
   outputs uint16_t(-1), which is the "correct" way to specify
   that a stream is not present.  So we fix that as well.
3) We were setting the PDB Stream signature to 0.  This is supposed
   to be the result of calling time(nullptr).  Although this leads
   to non-deterministic builds, a better way to solve that is by
   having a command line option explicitly for generating a
   reproducible build, and have the default behavior of lld-link
   match the default behavior of link.

To test this, I'm making use of the new and improved `pdb diff`
sub command.  To make it suitable for writing tests against, I had
to modify the diff subcommand slightly to print less verbose output.
Previously it would always print | <column> | <value1> | <value2> |
which is quite verbose, and the values are fragile.  All we really
want to know is "did we produce the same value as link?"  So I added
command line options to print a single character representing the
result status (different, identical, equivalent), and another to
hide the value display.  Note that just inspecting the diff output
used to write the test, you can see some things that are obviously
wrong.  That is just reflective of the fact that this is the state
of affairs today, not that we're asserting that this is "correct".
We can use this as a starting point to discover differences, fix
them, and update the test.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner created this revision.Jul 6 2017, 2:16 PM
rnk added inline comments.Jul 7 2017, 9:47 AM
lld/COFF/PDB.cpp
344 ↗(On Diff #105531)

Generally speaking we want our tool output to be deterministic. Clang has a /Brepro flag that controls the emission of timestamps in file headers. Can you add a FIXME here to add a flag for this?

lld/test/COFF/pdb-diff.test
10 ↗(On Diff #105531)

Are you worried about the fragility of these CHECKs? FileCheck ignores whitespace differences, so it might not be so bad, but I'm a little concerned.

rnk added inline comments.Jul 7 2017, 9:52 AM
lld/COFF/PDB.cpp
344 ↗(On Diff #105531)

Actually, ignore this. We already need to absolute-ize paths, so our output isn't really deterministic.

lld/test/COFF/pdb-diff.test
177 ↗(On Diff #105531)

This isn't going to match on other people's systems.

(BTW, ignore in case you already noticed them, but I also have D35092 and D35039 if you don't mind taking a look at those as well)

lld/COFF/PDB.cpp
344 ↗(On Diff #105531)

There are other places where we parts of LLD where we will need to by default produce non-reproducible builds as well (for example, the guid in a PDB needs to be unique). Probably one or two other examples that escape me at the moment. But yea, we should add a flag for this and use the flag in tests.

lld/test/COFF/pdb-diff.test
10 ↗(On Diff #105531)

Doesn't it only ignore leading and trailing whitespace differences? We could add a "no table" mode that just outputs <Field>: <Result> but I think that can come later, right now it's just good to have minimal test coverage documenting the places we differ.

177 ↗(On Diff #105531)

Yea my bad. I already fixed this to {{.*Inputs/pdb-diff.obj}} locally.

This revision was automatically updated to reflect the committed changes.