[PATCH] D28182: COFF: tie the execute and the PDB together

Saleem Abdulrasool via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 30 12:12:19 PST 2016


compnerd created this revision.
compnerd added a reviewer: ruiu.
compnerd added a subscriber: llvm-commits.
compnerd set the repository for this revision to rL LLVM.
compnerd added a project: lld.

The PDB GUID, Age, and version are tied together by the RSDS record in
the binary.  Pass along the BuildId information into the createPDB to
allow us to tie the binary and the PDB together.


Repository:
  rL LLVM

https://reviews.llvm.org/D28182

Files:
  COFF/PDB.cpp
  COFF/PDB.h
  COFF/Writer.cpp
  test/COFF/pdb.test


Index: test/COFF/pdb.test
===================================================================
--- test/COFF/pdb.test
+++ test/COFF/pdb.test
@@ -28,8 +28,12 @@
 # CHECK-NEXT:   - Stream:          [ 8 ]
 # CHECK-NEXT:   - Stream:          [ 4 ]
 # CHECK-NEXT: PdbStream:
+# Ensure that the Guid matches the RSDS record:
+#   PDBSignature: 0x53445352
+#   PDBGUID (38 9A CC F2 14 A4 7F A2 6C F0 08 04 47 CF 5C 48)
+#   PDBAge: 1
 # CHECK-NEXT:   Age:             1
-# CHECK-NEXT:   Guid:            '{00000000-0000-0000-0000-000000000000}'
+# CHECK-NEXT:   Guid:            '{389ACCF2-14A4-7FA2-6CF0-080447CF5C48}'
 # CHECK-NEXT:   Signature:       0
 # CHECK-NEXT:   Version:         VC70
 # CHECK-NEXT:   NamedStreams:
Index: COFF/Writer.cpp
===================================================================
--- COFF/Writer.cpp
+++ COFF/Writer.cpp
@@ -304,7 +304,7 @@
   writeBuildId();

   if (!Config->PDBPath.empty())
-    createPDB(Config->PDBPath, Symtab, SectionTable);
+    createPDB(Config->PDBPath, Symtab, SectionTable, BuildId->DI);

   if (auto EC = Buffer->commit())
     fatal(EC, "failed to write the output file");
Index: COFF/PDB.h
===================================================================
--- COFF/PDB.h
+++ COFF/PDB.h
@@ -13,12 +13,19 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"

+namespace llvm {
+namespace codeview {
+union DebugInfo;
+}
+}
+
 namespace lld {
 namespace coff {
 class SymbolTable;

 void createPDB(llvm::StringRef Path, SymbolTable *Symtab,
-               llvm::ArrayRef<uint8_t> SectionTable);
+               llvm::ArrayRef<uint8_t> SectionTable,
+               const llvm::codeview::DebugInfo *DI);
 }
 }

Index: COFF/PDB.cpp
===================================================================
--- COFF/PDB.cpp
+++ COFF/PDB.cpp
@@ -13,6 +13,7 @@
 #include "Error.h"
 #include "SymbolTable.h"
 #include "Symbols.h"
+#include "llvm/DebugInfo/CodeView/CVDebugRecord.h"
 #include "llvm/DebugInfo/CodeView/SymbolDumper.h"
 #include "llvm/DebugInfo/CodeView/TypeDumper.h"
 #include "llvm/DebugInfo/MSF/ByteStream.h"
@@ -131,7 +132,8 @@

 // Creates a PDB file.
 void coff::createPDB(StringRef Path, SymbolTable *Symtab,
-                     ArrayRef<uint8_t> SectionTable) {
+                     ArrayRef<uint8_t> SectionTable,
+                     const llvm::codeview::DebugInfo *DI) {
   if (Config->DumpPdb)
     dumpCodeView(Symtab);

@@ -146,11 +148,11 @@

   // Add an Info stream.
   auto &InfoBuilder = Builder.getInfoBuilder();
-  InfoBuilder.setAge(1);
-
-  // Should be a random number, 0 for now.
-  InfoBuilder.setGuid({});
-
+  assert(DI->Signature.CVSignature == OMF::Signature::PDB70 &&
+         "only PDB 7.0 is supported");
+  InfoBuilder.setAge(DI->PDB70.Age);
+  InfoBuilder.setGuid(
+      *reinterpret_cast<const pdb::PDB_UniqueId *>(&DI->PDB70.Signature));
   // Should be the current time, but set 0 for reproducibilty.
   InfoBuilder.setSignature(0);
   InfoBuilder.setVersion(pdb::PdbRaw_ImplVer::PdbImplVC70);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28182.82740.patch
Type: text/x-patch
Size: 3015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161230/467bfab5/attachment.bin>


More information about the llvm-commits mailing list