From: Peter Collingbourne Date: Fri, 20 Oct 2017 19:48:26 +0000 (+0000) Subject: COFF: Add type server pdb files to linkrepro tar file. X-Git-Tag: llvmorg-6.0.0-rc1~5256 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=75257bc2ec080af735932cb25eca9574307c195c;p=platform%2Fupstream%2Fllvm.git COFF: Add type server pdb files to linkrepro tar file. Differential Revision: https://reviews.llvm.org/D38977 llvm-svn: 316233 --- diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h index ff21a42..df54fc1 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 MB); + private: std::unique_ptr Tar; // for /linkrepro @@ -109,7 +111,6 @@ private: 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); diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp index 7a6cd87..921b933 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> 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( diff --git a/lld/test/COFF/linkrepro-pdb.test b/lld/test/COFF/linkrepro-pdb.test new file mode 100644 index 0000000..33aa0bc --- /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 2a44044..0c6c6b5 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 7706731..c2344d5 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 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); diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp index d7be2d5..7be4c76 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, 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); diff --git a/llvm/lib/DebugInfo/PDB/PDB.cpp b/llvm/lib/DebugInfo/PDB/PDB.cpp index 501d4f5..c1b21c1 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 &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);