This is not quite ready for real review. I still need to collect performance data of this, and of the more naive approach that just hashes in a second pass after writing the file.
So feel free to ignore for now, but I figured I'd upload what I have. It's probably done enough that I can use it for benchmarking.
Actual patch description:
Previously, lld-link would use a random byte sequence as the PDB GUID. Instead, use a hash of the PDB file contents.
To compute it, introduce HashingFileBufferByteStream that computes a running hash of the bytes it writes.
Since we already use xxhash, add its streaming parts to llvm//Support/xxhash. xxhash gives only 8 bytes of content hash, so put a fixed string in the other 8 bytes available in the PDB GUID.
To not disturb llvm-pdbutil pdb2yaml, make the hash generation an opt-in feature on InfoStreamBuilder and let ldb/COFF/PDB.cpp always set it.
Since writing the PDB computes this ID which also goes in the exe, the PDB writing code now must be called before writeBuildId(). writeBuildId() for that reason is no longer included in the "Code Layout" timer.
Since the PDB GUID is now a function of the PDB contents, the PDB Age is always set to 1. There was a long comment above loadExistingBuildId (now gone) about how not changing the GUID and only incrementing the age was important, but according to the discussion in PR35914 that comment was incorrect.