[lld] r294279 - COFF: prevent nullptr dereference

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 6 20:28:03 PST 2017


Author: compnerd
Date: Mon Feb  6 22:28:02 2017
New Revision: 294279

URL: http://llvm.org/viewvc/llvm-project?rev=294279&view=rev
Log:
COFF: prevent nullptr dereference

If `/debugtypes` is used to omit the codeview information, we would not
have constructed the debug info codeview record which is used to tie the
PDB to the binary.  In such a case, rub out the GUID and Age fields.

Added:
    lld/trunk/test/COFF/pdb-none.test
Modified:
    lld/trunk/COFF/PDB.cpp
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=294279&r1=294278&r2=294279&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Mon Feb  6 22:28:02 2017
@@ -178,9 +178,12 @@ void coff::createPDB(StringRef Path, Sym
 
   // Add an Info stream.
   auto &InfoBuilder = Builder.getInfoBuilder();
-  InfoBuilder.setAge(DI->PDB70.Age);
-  InfoBuilder.setGuid(
-      *reinterpret_cast<const pdb::PDB_UniqueId *>(&DI->PDB70.Signature));
+  InfoBuilder.setAge(DI ? DI->PDB70.Age : 0);
+
+  pdb::PDB_UniqueId uuid{};
+  if (DI)
+    memcpy(&uuid, &DI->PDB70.Signature, sizeof(uuid));
+  InfoBuilder.setGuid(uuid);
   // Should be the current time, but set 0 for reproducibilty.
   InfoBuilder.setSignature(0);
   InfoBuilder.setVersion(pdb::PdbRaw_ImplVer::PdbImplVC70);

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=294279&r1=294278&r2=294279&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Mon Feb  6 22:28:02 2017
@@ -258,8 +258,12 @@ void Writer::run() {
   sortExceptionTable();
   writeBuildId();
 
-  if (!Config->PDBPath.empty())
-    createPDB(Config->PDBPath, Symtab, SectionTable, BuildId->DI);
+  if (!Config->PDBPath.empty()) {
+    const llvm::codeview::DebugInfo *DI = nullptr;
+    if (Config->DebugTypes & static_cast<unsigned>(coff::DebugType::CV))
+      DI = BuildId->DI;
+    createPDB(Config->PDBPath, Symtab, SectionTable, DI);
+  }
 
   writeMapFile(OutputSections);
 

Added: lld/trunk/test/COFF/pdb-none.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/pdb-none.test?rev=294279&view=auto
==============================================================================
--- lld/trunk/test/COFF/pdb-none.test (added)
+++ lld/trunk/test/COFF/pdb-none.test Mon Feb  6 22:28:02 2017
@@ -0,0 +1,13 @@
+# RUN: yaml2obj < %p/Inputs/pdb1.yaml > %t1.obj
+# RUN: yaml2obj < %p/Inputs/pdb2.yaml > %t2.obj
+# RUN: lld-link /debug /debugtype:pdata /pdb:%t.pdb /dll /out:%t.dll /entry:main /nodefaultlib \
+# RUN:   /debugpdb %t1.obj %t2.obj
+
+# RUN: llvm-pdbdump pdb2yaml -pdb-stream %t.pdb | FileCheck %s
+
+# CHECK:      PdbStream:
+# CHECK-NEXT:   Age:             0
+# CHECK-NEXT:   Guid:            '{00000000-0000-0000-0000-000000000000}'
+# CHECK-NEXT:   Signature:       0
+# CHECK-NEXT:   Version:         VC70
+




More information about the llvm-commits mailing list