COFF: Add type server pdb files to linkrepro tar file.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 20 Oct 2017 19:48:26 +0000 (19:48 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 20 Oct 2017 19:48:26 +0000 (19:48 +0000)
Differential Revision: https://reviews.llvm.org/D38977

llvm-svn: 316233

lld/COFF/Driver.h
lld/COFF/PDB.cpp
lld/test/COFF/linkrepro-pdb.test [new file with mode: 0644]
lld/test/lit.cfg.py
llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h
llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
llvm/lib/DebugInfo/PDB/PDB.cpp

index ff21a42..df54fc1 100644 (file)
@@ -74,6 +74,8 @@ public:
   void enqueueArchiveMember(const Archive::Child &C, StringRef SymName,
                             StringRef ParentName);
 
+  MemoryBufferRef takeBuffer(std::unique_ptr<MemoryBuffer> MB);
+
 private:
   std::unique_ptr<llvm::TarWriter> Tar; // for /linkrepro
 
@@ -109,7 +111,6 @@ private:
 
   void invokeMSVC(llvm::opt::InputArgList &Args);
 
-  MemoryBufferRef takeBuffer(std::unique_ptr<MemoryBuffer> MB);
   void addBuffer(std::unique_ptr<MemoryBuffer> MB, bool WholeArchive);
   void addArchiveBuffer(MemoryBufferRef MBRef, StringRef SymName,
                         StringRef ParentName);
index 7a6cd87..921b933 100644 (file)
@@ -10,6 +10,7 @@
 #include "PDB.h"
 #include "Chunks.h"
 #include "Config.h"
+#include "Driver.h"
 #include "Error.h"
 #include "SymbolTable.h"
 #include "Symbols.h"
@@ -218,9 +219,16 @@ const CVIndexMap &PDBLinker::mergeDebugT(ObjFile *File,
 
 static Expected<std::unique_ptr<pdb::NativeSession>>
 tryToLoadPDB(const GUID &GuidFromObj, StringRef TSPath) {
+  ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getFile(
+      TSPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false);
+  if (!MBOrErr)
+    return errorCodeToError(MBOrErr.getError());
+
   std::unique_ptr<pdb::IPDBSession> ThisSession;
-  if (auto EC =
-          pdb::loadDataForPDB(pdb::PDB_ReaderType::Native, TSPath, ThisSession))
+  if (auto EC = pdb::NativeSession::createFromPdb(
+          MemoryBuffer::getMemBuffer(Driver->takeBuffer(std::move(*MBOrErr)),
+                                     /*RequiresNullTerminator=*/false),
+          ThisSession))
     return std::move(EC);
 
   std::unique_ptr<pdb::NativeSession> NS(
diff --git a/lld/test/COFF/linkrepro-pdb.test b/lld/test/COFF/linkrepro-pdb.test
new file mode 100644 (file)
index 0000000..33aa0bc
--- /dev/null
@@ -0,0 +1,9 @@
+REQUIRES: x86, gnutar
+
+RUN: rm -rf %t && mkdir -p %t && cd %t
+RUN: yaml2obj %S/Inputs/pdb-type-server-simple-a.yaml -o a.obj
+RUN: yaml2obj %S/Inputs/pdb-type-server-simple-b.yaml -o b.obj
+RUN: llvm-pdbutil yaml2pdb %S/Inputs/pdb-type-server-simple-ts.yaml -pdb ts.pdb
+RUN: lld-link a.obj b.obj -entry:main -debug -out:t.exe -pdb:t.pdb -nodefaultlib -linkrepro:.
+RUN: tar xOf repro.tar repro/%:t/ts.pdb > repro-ts.pdb
+RUN: diff ts.pdb repro-ts.pdb
index 2a44044..0c6c6b5 100644 (file)
@@ -82,3 +82,9 @@ if (lit.util.which('cvtres', config.environment['PATH'])) or \
 
 if (config.llvm_libxml2_enabled == '1'):
     config.available_features.add('libxml2')
+
+tar_version = subprocess.Popen(
+    ['tar', '--version'], stdout=subprocess.PIPE, env={'LANG': 'C'})
+if 'GNU tar' in tar_version.stdout.read().decode():
+    config.available_features.add('gnutar')
+tar_version.wait()
index 7706731..c2344d5 100644 (file)
@@ -31,7 +31,7 @@ public:
                 std::unique_ptr<BumpPtrAllocator> Allocator);
   ~NativeSession() override;
 
-  static Error createFromPdb(StringRef Path,
+  static Error createFromPdb(std::unique_ptr<MemoryBuffer> MB,
                              std::unique_ptr<IPDBSession> &Session);
   static Error createFromExe(StringRef Path,
                              std::unique_ptr<IPDBSession> &Session);
index d7be2d5..7be4c76 100644 (file)
@@ -68,15 +68,9 @@ NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile,
 
 NativeSession::~NativeSession() = default;
 
-Error NativeSession::createFromPdb(StringRef Path,
+Error NativeSession::createFromPdb(std::unique_ptr<MemoryBuffer> Buffer,
                                    std::unique_ptr<IPDBSession> &Session) {
-  ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
-      MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
-                                   /*RequiresNullTerminator=*/false);
-  if (!ErrorOrBuffer)
-    return make_error<GenericError>(generic_error_code::invalid_path);
-
-  std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
+  StringRef Path = Buffer->getBufferIdentifier();
   auto Stream = llvm::make_unique<MemoryBufferByteStream>(
       std::move(Buffer), llvm::support::little);
 
index 501d4f5..c1b21c1 100644 (file)
@@ -23,8 +23,15 @@ using namespace llvm::pdb;
 Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path,
                                 std::unique_ptr<IPDBSession> &Session) {
   // Create the correct concrete instance type based on the value of Type.
-  if (Type == PDB_ReaderType::Native)
-    return NativeSession::createFromPdb(Path, Session);
+  if (Type == PDB_ReaderType::Native) {
+    ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
+        MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
+                                     /*RequiresNullTerminator=*/false);
+    if (!ErrorOrBuffer)
+      return make_error<GenericError>(generic_error_code::invalid_path, Path);
+
+    return NativeSession::createFromPdb(std::move(*ErrorOrBuffer), Session);
+  }
 
 #if LLVM_ENABLE_DIA_SDK
   return DIASession::createFromPdb(Path, Session);