Fix some differences between lld and MSVC generated PDBs.
authorZachary Turner <zturner@google.com>
Fri, 7 Jul 2017 18:45:56 +0000 (18:45 +0000)
committerZachary Turner <zturner@google.com>
Fri, 7 Jul 2017 18:45:56 +0000 (18:45 +0000)
commitc1e93e5fa46772c959a9f5d74dfeb95d3cde4ce3
treee6a1e16d55e10052f109ee10270b4952c722dad8
parentf3b4b2d89d06ededb515703f86ca4ab8744c154d
Fix some differences between lld and MSVC generated PDBs.

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.

Differential Revision: https://reviews.llvm.org/D35086

llvm-svn: 307422
16 files changed:
lld/COFF/PDB.cpp
lld/test/COFF/Inputs/pdb-diff-cl.pdb [new file with mode: 0644]
lld/test/COFF/Inputs/pdb-diff.cpp [new file with mode: 0644]
lld/test/COFF/Inputs/pdb-diff.obj [new file with mode: 0644]
lld/test/COFF/pdb-diff.test [new file with mode: 0644]
lld/test/COFF/pdb-source-lines.test
lld/test/COFF/pdb.test
llvm/include/llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h
llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp
llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp
llvm/tools/llvm-pdbutil/Diff.cpp
llvm/tools/llvm-pdbutil/DiffPrinter.cpp
llvm/tools/llvm-pdbutil/DiffPrinter.h
llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
llvm/tools/llvm-pdbutil/llvm-pdbutil.h