[llvm] r326453 - [PDB] Defer writing the build id until the rest of the PDB is written.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 1 10:00:29 PST 2018
Author: zturner
Date: Thu Mar 1 10:00:29 2018
New Revision: 326453
URL: http://llvm.org/viewvc/llvm-project?rev=326453&view=rev
Log:
[PDB] Defer writing the build id until the rest of the PDB is written.
For now this is NFC, but this small refactor opens the door to
letting us embed a hash of the PDB in the build id field of the
PDB.
Differential Revision: https://reviews.llvm.org/D43913
Modified:
llvm/trunk/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h
llvm/trunk/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h?rev=326453&r1=326452&r2=326453&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h Thu Mar 1 10:00:29 2018
@@ -40,6 +40,10 @@ public:
void setGuid(codeview::GUID G);
void addFeature(PdbRaw_FeatureSig Sig);
+ uint32_t getAge() const { return Age; }
+ codeview::GUID getGuid() const { return Guid; }
+ Optional<uint32_t> getSignature() const { return Signature; }
+
uint32_t finalize();
Error finalizeMsfLayout();
@@ -52,8 +56,8 @@ private:
std::vector<PdbRaw_FeatureSig> Features;
PdbRaw_ImplVer Ver;
- uint32_t Sig;
uint32_t Age;
+ Optional<uint32_t> Signature;
codeview::GUID Guid;
NamedStreamMap &NamedStreams;
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp?rev=326453&r1=326452&r2=326453&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp Thu Mar 1 10:00:29 2018
@@ -25,15 +25,17 @@ using namespace llvm::pdb;
InfoStreamBuilder::InfoStreamBuilder(msf::MSFBuilder &Msf,
NamedStreamMap &NamedStreams)
- : Msf(Msf), Ver(PdbRaw_ImplVer::PdbImplVC70), Sig(-1), Age(0),
- NamedStreams(NamedStreams) {}
+ : Msf(Msf), Ver(PdbRaw_ImplVer::PdbImplVC70), Age(0),
+ NamedStreams(NamedStreams) {
+ ::memset(&Guid, 0, sizeof(Guid));
+}
void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; }
-void InfoStreamBuilder::setSignature(uint32_t S) { Sig = S; }
-
void InfoStreamBuilder::setAge(uint32_t A) { Age = A; }
+void InfoStreamBuilder::setSignature(uint32_t S) { Signature = S; }
+
void InfoStreamBuilder::setGuid(GUID G) { Guid = G; }
void InfoStreamBuilder::addFeature(PdbRaw_FeatureSig Sig) {
@@ -56,10 +58,10 @@ Error InfoStreamBuilder::commit(const ms
BinaryStreamWriter Writer(*InfoS);
InfoStreamHeader H;
- H.Age = Age;
- H.Signature = Sig;
+ // Leave the build id fields 0 so they can be set as the last step before
+ // committing the file to disk.
+ ::memset(&H, 0, sizeof(H));
H.Version = Ver;
- H.Guid = Guid;
if (auto EC = Writer.writeObject(H))
return EC;
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp?rev=326453&r1=326452&r2=326453&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp Thu Mar 1 10:00:29 2018
@@ -178,6 +178,8 @@ Error PDBFileBuilder::commit(StringRef F
auto OutFileOrError = FileOutputBuffer::create(Filename, Filesize);
if (auto E = OutFileOrError.takeError())
return E;
+ FileOutputBuffer *FOB = OutFileOrError->get();
+
FileBufferByteStream Buffer(std::move(*OutFileOrError),
llvm::support::little);
BinaryStreamWriter Writer(Buffer);
@@ -242,5 +244,20 @@ Error PDBFileBuilder::commit(StringRef F
return EC;
}
+ auto InfoStreamBlocks = Layout.StreamMap[StreamPDB];
+ assert(!InfoStreamBlocks.empty());
+ uint64_t InfoStreamFileOffset =
+ blockToOffset(InfoStreamBlocks.front(), Layout.SB->BlockSize);
+ InfoStreamHeader *H = reinterpret_cast<InfoStreamHeader *>(
+ FOB->getBufferStart() + InfoStreamFileOffset);
+
+ // Set the build id at the very end, after every other byte of the PDB
+ // has been written.
+ // FIXME: Use a hash of the PDB rather than time(nullptr) for the signature.
+ H->Age = Info->getAge();
+ H->Guid = Info->getGuid();
+ Optional<uint32_t> Sig = Info->getSignature();
+ H->Signature = Sig.hasValue() ? *Sig : time(nullptr);
+
return Buffer.commit();
}
More information about the llvm-commits
mailing list