Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 1 | //===- 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 Ueyama | 1d99ab3 | 2016-09-15 22:24:51 +0000 | [diff] [blame] | 10 | #include "PDB.h" |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 11 | #include "Error.h" |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/MSF/MSFBuilder.h" |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/MSF/MSFCommon.h" |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 14 | #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 Ueyama | 1763c0d | 2015-12-08 18:39:55 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Endian.h" |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 23 | #include "llvm/Support/FileOutputBuffer.h" |
| 24 | #include <memory> |
| 25 | |
Rui Ueyama | 1d99ab3 | 2016-09-15 22:24:51 +0000 | [diff] [blame] | 26 | using namespace lld; |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 27 | using namespace llvm; |
Rui Ueyama | 1763c0d | 2015-12-08 18:39:55 +0000 | [diff] [blame] | 28 | using namespace llvm::support; |
| 29 | using namespace llvm::support::endian; |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 30 | |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 31 | static ExitOnError ExitOnErr; |
| 32 | |
Rui Ueyama | 1d99ab3 | 2016-09-15 22:24:51 +0000 | [diff] [blame] | 33 | void coff::createPDB(StringRef Path) { |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 34 | BumpPtrAllocator Alloc; |
| 35 | pdb::PDBFileBuilder Builder(Alloc); |
Rui Ueyama | 1297954 | 2016-09-30 20:53:45 +0000 | [diff] [blame] | 36 | ExitOnErr(Builder.initialize(4096)); // 4096 is blocksize |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 37 | |
Rui Ueyama | 8d3fb5d | 2016-10-05 22:08:58 +0000 | [diff] [blame^] | 38 | // Create streams in MSF for predefined streams, namely |
| 39 | // PDB, TPI, DBI and IPI. |
| 40 | for (int I = 0; I < (int)pdb::kSpecialStreamCount; ++I) |
| 41 | ExitOnErr(Builder.getMsfBuilder().addStream(0)); |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 42 | |
Rui Ueyama | bb542b3 | 2016-09-16 22:51:17 +0000 | [diff] [blame] | 43 | // Add an Info stream. |
| 44 | auto &InfoBuilder = Builder.getInfoBuilder(); |
| 45 | InfoBuilder.setAge(1); |
| 46 | |
| 47 | // Should be a random number, 0 for now. |
| 48 | InfoBuilder.setGuid({}); |
| 49 | |
| 50 | // Should be the current time, but set 0 for reproducibilty. |
| 51 | InfoBuilder.setSignature(0); |
| 52 | |
| 53 | InfoBuilder.setVersion(pdb::PdbRaw_ImplVer::PdbImplVC70); |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 54 | |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 55 | // Add an empty TPI stream. |
| 56 | auto &TpiBuilder = Builder.getTpiBuilder(); |
| 57 | TpiBuilder.setVersionHeader(pdb::PdbTpiV80); |
Rui Ueyama | 1763c0d | 2015-12-08 18:39:55 +0000 | [diff] [blame] | 58 | |
Rui Ueyama | d381c98 | 2016-10-05 21:37:25 +0000 | [diff] [blame] | 59 | // Add an empty IPI stream. |
| 60 | auto &IpiBuilder = Builder.getIpiBuilder(); |
| 61 | IpiBuilder.setVersionHeader(pdb::PdbTpiV80); |
| 62 | |
Rui Ueyama | 3e9d6bb | 2016-09-26 23:53:55 +0000 | [diff] [blame] | 63 | // Write to a file. |
Rui Ueyama | 5c82eea | 2016-09-30 20:39:04 +0000 | [diff] [blame] | 64 | ExitOnErr(Builder.commit(Path)); |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 65 | } |