blob: e8a37562d40de500ef56115ac41a20a6a79d7431 [file] [log] [blame]
Rui Ueyamae7378242015-12-04 23:11:05 +00001//===- PDB.cpp ------------------------------------------------------------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Rui Ueyama1d99ab32016-09-15 22:24:51 +000010#include "PDB.h"
Rui Ueyamae7378242015-12-04 23:11:05 +000011#include "Error.h"
Rui Ueyamab28c6d42016-09-16 04:32:33 +000012#include "llvm/DebugInfo/MSF/MSFBuilder.h"
Rui Ueyama7f382992016-09-15 18:55:18 +000013#include "llvm/DebugInfo/MSF/MSFCommon.h"
Rui Ueyamab28c6d42016-09-16 04:32:33 +000014#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
15#include "llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h"
16#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
17#include "llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h"
18#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
19#include "llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h"
20#include "llvm/DebugInfo/PDB/Raw/TpiStream.h"
21#include "llvm/DebugInfo/PDB/Raw/TpiStreamBuilder.h"
Rui Ueyama1763c0d2015-12-08 18:39:55 +000022#include "llvm/Support/Endian.h"
Rui Ueyamae7378242015-12-04 23:11:05 +000023#include "llvm/Support/FileOutputBuffer.h"
24#include <memory>
25
Rui Ueyama1d99ab32016-09-15 22:24:51 +000026using namespace lld;
Rui Ueyamae7378242015-12-04 23:11:05 +000027using namespace llvm;
Rui Ueyama1763c0d2015-12-08 18:39:55 +000028using namespace llvm::support;
29using namespace llvm::support::endian;
Rui Ueyamae7378242015-12-04 23:11:05 +000030
Rui Ueyamab28c6d42016-09-16 04:32:33 +000031static ExitOnError ExitOnErr;
32
Rui Ueyama1d99ab32016-09-15 22:24:51 +000033void coff::createPDB(StringRef Path) {
Rui Ueyamab28c6d42016-09-16 04:32:33 +000034 BumpPtrAllocator Alloc;
35 pdb::PDBFileBuilder Builder(Alloc);
Rui Ueyama12979542016-09-30 20:53:45 +000036 ExitOnErr(Builder.initialize(4096)); // 4096 is blocksize
Rui Ueyama7f382992016-09-15 18:55:18 +000037
Rui Ueyamab28c6d42016-09-16 04:32:33 +000038 ExitOnErr(Builder.getMsfBuilder().addStream(1, {4}));
39 ExitOnErr(Builder.getMsfBuilder().addStream(1, {5}));
40 ExitOnErr(Builder.getMsfBuilder().addStream(1, {6}));
Rui Ueyama7f382992016-09-15 18:55:18 +000041
Rui Ueyamabb542b32016-09-16 22:51:17 +000042 // Add an Info stream.
43 auto &InfoBuilder = Builder.getInfoBuilder();
44 InfoBuilder.setAge(1);
45
46 // Should be a random number, 0 for now.
47 InfoBuilder.setGuid({});
48
49 // Should be the current time, but set 0 for reproducibilty.
50 InfoBuilder.setSignature(0);
51
52 InfoBuilder.setVersion(pdb::PdbRaw_ImplVer::PdbImplVC70);
Rui Ueyama7f382992016-09-15 18:55:18 +000053
Rui Ueyamab28c6d42016-09-16 04:32:33 +000054 // Add an empty TPI stream.
55 auto &TpiBuilder = Builder.getTpiBuilder();
56 TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
Rui Ueyama1763c0d2015-12-08 18:39:55 +000057
Rui Ueyama3e9d6bb2016-09-26 23:53:55 +000058 // Write to a file.
Rui Ueyama5c82eea2016-09-30 20:39:04 +000059 ExitOnErr(Builder.commit(Path));
Rui Ueyamae7378242015-12-04 23:11:05 +000060}