summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/COFF/Driver.h3
-rw-r--r--lld/COFF/PDB.cpp12
-rw-r--r--lld/test/COFF/linkrepro-pdb.test9
-rw-r--r--lld/test/lit.cfg.py6
-rw-r--r--llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h2
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp10
-rw-r--r--llvm/lib/DebugInfo/PDB/PDB.cpp11
7 files changed, 39 insertions, 14 deletions
diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h
index ff21a4280dd..df54fc1e45e 100644
--- a/lld/COFF/Driver.h
+++ b/lld/COFF/Driver.h
@@ -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);
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index 7a6cd875f8d..921b933db90 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -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
index 00000000000..33aa0bc4a90
--- /dev/null
+++ b/lld/test/COFF/linkrepro-pdb.test
@@ -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
diff --git a/lld/test/lit.cfg.py b/lld/test/lit.cfg.py
index 2a4404461c4..0c6c6b5f1e9 100644
--- a/lld/test/lit.cfg.py
+++ b/lld/test/lit.cfg.py
@@ -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()
diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h b/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h
index 77067311550..c2344d5648e 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h
@@ -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);
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
index d7be2d576c2..7be4c762b02 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
@@ -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);
diff --git a/llvm/lib/DebugInfo/PDB/PDB.cpp b/llvm/lib/DebugInfo/PDB/PDB.cpp
index 501d4f5985b..c1b21c12036 100644
--- a/llvm/lib/DebugInfo/PDB/PDB.cpp
+++ b/llvm/lib/DebugInfo/PDB/PDB.cpp
@@ -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);
OpenPOWER on IntegriCloud