Index: lld/trunk/COFF/Driver.h =================================================================== --- lld/trunk/COFF/Driver.h +++ lld/trunk/COFF/Driver.h @@ -74,6 +74,8 @@ void enqueueArchiveMember(const Archive::Child &C, StringRef SymName, StringRef ParentName); + MemoryBufferRef takeBuffer(std::unique_ptr MB); + private: std::unique_ptr Tar; // for /linkrepro @@ -109,7 +111,6 @@ void invokeMSVC(llvm::opt::InputArgList &Args); - MemoryBufferRef takeBuffer(std::unique_ptr MB); void addBuffer(std::unique_ptr MB, bool WholeArchive); void addArchiveBuffer(MemoryBufferRef MBRef, StringRef SymName, StringRef ParentName); Index: lld/trunk/COFF/PDB.cpp =================================================================== --- lld/trunk/COFF/PDB.cpp +++ lld/trunk/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 @@ static Expected> tryToLoadPDB(const GUID &GuidFromObj, StringRef TSPath) { + ErrorOr> MBOrErr = MemoryBuffer::getFile( + TSPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false); + if (!MBOrErr) + return errorCodeToError(MBOrErr.getError()); + std::unique_ptr 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 NS( Index: lld/trunk/test/COFF/linkrepro-pdb.test =================================================================== --- lld/trunk/test/COFF/linkrepro-pdb.test +++ lld/trunk/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 Index: lld/trunk/test/lit.cfg.py =================================================================== --- lld/trunk/test/lit.cfg.py +++ lld/trunk/test/lit.cfg.py @@ -82,3 +82,9 @@ 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: llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeSession.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeSession.h +++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeSession.h @@ -31,7 +31,7 @@ std::unique_ptr Allocator); ~NativeSession() override; - static Error createFromPdb(StringRef Path, + static Error createFromPdb(std::unique_ptr MB, std::unique_ptr &Session); static Error createFromExe(StringRef Path, std::unique_ptr &Session); Index: llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ llvm/trunk/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -68,15 +68,9 @@ NativeSession::~NativeSession() = default; -Error NativeSession::createFromPdb(StringRef Path, +Error NativeSession::createFromPdb(std::unique_ptr Buffer, std::unique_ptr &Session) { - ErrorOr> ErrorOrBuffer = - MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, - /*RequiresNullTerminator=*/false); - if (!ErrorOrBuffer) - return make_error(generic_error_code::invalid_path); - - std::unique_ptr Buffer = std::move(*ErrorOrBuffer); + StringRef Path = Buffer->getBufferIdentifier(); auto Stream = llvm::make_unique( std::move(Buffer), llvm::support::little); Index: llvm/trunk/lib/DebugInfo/PDB/PDB.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/PDB/PDB.cpp +++ llvm/trunk/lib/DebugInfo/PDB/PDB.cpp @@ -23,8 +23,15 @@ Error llvm::pdb::loadDataForPDB(PDB_ReaderType Type, StringRef Path, std::unique_ptr &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> ErrorOrBuffer = + MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1, + /*RequiresNullTerminator=*/false); + if (!ErrorOrBuffer) + return make_error(generic_error_code::invalid_path, Path); + + return NativeSession::createFromPdb(std::move(*ErrorOrBuffer), Session); + } #if LLVM_ENABLE_DIA_SDK return DIASession::createFromPdb(Path, Session);