Skip to content

Commit

Permalink
COFF: Add type server pdb files to linkrepro tar file.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D38977

llvm-svn: 316233
  • Loading branch information
pcc committed Oct 20, 2017
1 parent 48db80c commit 75257bc
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
3 changes: 2 additions & 1 deletion lld/COFF/Driver.h
Expand Up @@ -74,6 +74,8 @@ class LinkerDriver {
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

Expand Down Expand Up @@ -109,7 +111,6 @@ class LinkerDriver {

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);
Expand Down
12 changes: 10 additions & 2 deletions lld/COFF/PDB.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions 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
6 changes: 6 additions & 0 deletions lld/test/lit.cfg.py
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion llvm/include/llvm/DebugInfo/PDB/Native/NativeSession.h
Expand Up @@ -31,7 +31,7 @@ class NativeSession : public IPDBSession {
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);
Expand Down
10 changes: 2 additions & 8 deletions llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
Expand Up @@ -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);

Expand Down
11 changes: 9 additions & 2 deletions llvm/lib/DebugInfo/PDB/PDB.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 75257bc

Please sign in to comment.