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 | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 11 | #include "Chunks.h" |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 12 | #include "Config.h" |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 13 | #include "Error.h" |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 14 | #include "SymbolTable.h" |
| 15 | #include "Symbols.h" |
Saleem Abdulrasool | df8a13b | 2017-01-04 17:56:54 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/CodeView/CVDebugRecord.h" |
Zachary Turner | 526f4f2 | 2017-05-19 19:26:58 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h" |
| 18 | #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" |
Rui Ueyama | 24625fd | 2016-11-22 23:51:34 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/CodeView/SymbolDumper.h" |
Zachary Turner | 629cb7d | 2017-01-11 23:24:22 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/CodeView/TypeDatabase.h" |
| 21 | #include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h" |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/CodeView/TypeStreamMerger.h" |
| 23 | #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h" |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 24 | #include "llvm/DebugInfo/MSF/MSFBuilder.h" |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 25 | #include "llvm/DebugInfo/MSF/MSFCommon.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 26 | #include "llvm/DebugInfo/PDB/Native/DbiStream.h" |
| 27 | #include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h" |
| 28 | #include "llvm/DebugInfo/PDB/Native/InfoStream.h" |
| 29 | #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h" |
| 30 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
| 31 | #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h" |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame^] | 32 | #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h" |
Rafael Espindola | a0f30da | 2017-05-02 20:19:42 +0000 | [diff] [blame] | 33 | #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h" |
Zachary Turner | 7b327d0 | 2017-02-16 23:35:45 +0000 | [diff] [blame] | 34 | #include "llvm/DebugInfo/PDB/Native/PDBTypeServerHandler.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 35 | #include "llvm/DebugInfo/PDB/Native/TpiStream.h" |
| 36 | #include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h" |
Rui Ueyama | 20df4ec | 2016-10-31 21:09:21 +0000 | [diff] [blame] | 37 | #include "llvm/Object/COFF.h" |
Zachary Turner | d9dc282 | 2017-03-02 20:52:51 +0000 | [diff] [blame] | 38 | #include "llvm/Support/BinaryByteStream.h" |
Rui Ueyama | 1763c0d | 2015-12-08 18:39:55 +0000 | [diff] [blame] | 39 | #include "llvm/Support/Endian.h" |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 40 | #include "llvm/Support/FileOutputBuffer.h" |
Zachary Turner | 7b327d0 | 2017-02-16 23:35:45 +0000 | [diff] [blame] | 41 | #include "llvm/Support/Path.h" |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 42 | #include "llvm/Support/ScopedPrinter.h" |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 43 | #include <memory> |
| 44 | |
Rui Ueyama | 1d99ab3 | 2016-09-15 22:24:51 +0000 | [diff] [blame] | 45 | using namespace lld; |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 46 | using namespace lld::coff; |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 47 | using namespace llvm; |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 48 | using namespace llvm::codeview; |
Rui Ueyama | 1763c0d | 2015-12-08 18:39:55 +0000 | [diff] [blame] | 49 | using namespace llvm::support; |
| 50 | using namespace llvm::support::endian; |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 51 | |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 52 | using llvm::object::coff_section; |
| 53 | |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 54 | static ExitOnError ExitOnErr; |
| 55 | |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 56 | // Returns a list of all SectionChunks. |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame^] | 57 | static void addSectionContribs(SymbolTable *Symtab, pdb::DbiStreamBuilder &DbiBuilder) { |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 58 | for (Chunk *C : Symtab->getChunks()) |
| 59 | if (auto *SC = dyn_cast<SectionChunk>(C)) |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame^] | 60 | DbiBuilder.addSectionContrib(SC->File->ModuleDBI, SC->Header); |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 63 | static SectionChunk *findByName(std::vector<SectionChunk *> &Sections, |
| 64 | StringRef Name) { |
| 65 | for (SectionChunk *C : Sections) |
| 66 | if (C->getSectionName() == Name) |
| 67 | return C; |
| 68 | return nullptr; |
| 69 | } |
| 70 | |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 71 | static ArrayRef<uint8_t> getDebugSection(ObjectFile *File, StringRef SecName) { |
| 72 | SectionChunk *Sec = findByName(File->getDebugChunks(), SecName); |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 73 | if (!Sec) |
Rui Ueyama | 26186c7 | 2016-12-09 04:46:54 +0000 | [diff] [blame] | 74 | return {}; |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 75 | |
| 76 | // First 4 bytes are section magic. |
| 77 | ArrayRef<uint8_t> Data = Sec->getContents(); |
| 78 | if (Data.size() < 4) |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 79 | fatal(SecName + " too short"); |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 80 | if (read32le(Data.data()) != COFF::DEBUG_SECTION_MAGIC) |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 81 | fatal(SecName + " has an invalid magic"); |
Rui Ueyama | 26186c7 | 2016-12-09 04:46:54 +0000 | [diff] [blame] | 82 | return Data.slice(4); |
| 83 | } |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 84 | |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 85 | static void addTypeInfo(pdb::TpiStreamBuilder &TpiBuilder, |
Reid Kleckner | 13fc411 | 2017-04-04 00:56:34 +0000 | [diff] [blame] | 86 | codeview::TypeTableBuilder &TypeTable) { |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 87 | // Start the TPI or IPI stream header. |
| 88 | TpiBuilder.setVersionHeader(pdb::PdbTpiV80); |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 89 | |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 90 | // Flatten the in memory type table. |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 91 | TypeTable.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Rec) { |
Reid Kleckner | 13fc411 | 2017-04-04 00:56:34 +0000 | [diff] [blame] | 92 | // FIXME: Hash types. |
| 93 | TpiBuilder.addTypeRecord(Rec, None); |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 94 | }); |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame^] | 97 | // Add all object files to the PDB. Merge .debug$T sections into IpiData and |
| 98 | // TpiData. |
| 99 | static void addObjectsToPDB(SymbolTable *Symtab, pdb::PDBFileBuilder &Builder, |
| 100 | codeview::TypeTableBuilder &TypeTable, |
| 101 | codeview::TypeTableBuilder &IDTable) { |
Zachary Turner | 2897e03 | 2017-05-25 21:16:03 +0000 | [diff] [blame] | 102 | // Follow type servers. If the same type server is encountered more than |
| 103 | // once for this instance of `PDBTypeServerHandler` (for example if many |
| 104 | // object files reference the same TypeServer), the types from the |
| 105 | // TypeServer will only be visited once. |
| 106 | pdb::PDBTypeServerHandler Handler; |
| 107 | |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 108 | // Visit all .debug$T sections to add them to Builder. |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 109 | for (ObjectFile *File : Symtab->ObjectFiles) { |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame^] | 110 | // Add a module descriptor for every object file. We need to put an absolute |
| 111 | // path to the object into the PDB. If this is a plain object, we make its |
| 112 | // path absolute. If it's an object in an archive, we make the archive path |
| 113 | // absolute. |
| 114 | bool InArchive = !File->ParentName.empty(); |
| 115 | SmallString<128> Path = InArchive ? File->ParentName : File->getName(); |
| 116 | sys::fs::make_absolute(Path); |
| 117 | StringRef Name = InArchive ? File->getName() : StringRef(Path); |
| 118 | File->ModuleDBI = &ExitOnErr(Builder.getDbiBuilder().addModuleInfo(Name)); |
| 119 | File->ModuleDBI->setObjFileName(Path); |
| 120 | |
| 121 | // FIXME: Walk the .debug$S sections and add them. Do things like recording |
| 122 | // source files. |
| 123 | |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 124 | ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T"); |
| 125 | if (Data.empty()) |
| 126 | continue; |
| 127 | |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 128 | BinaryByteStream Stream(Data, support::little); |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 129 | codeview::CVTypeArray Types; |
Zachary Turner | 120faca | 2017-02-27 22:11:43 +0000 | [diff] [blame] | 130 | BinaryStreamReader Reader(Stream); |
Zachary Turner | b32ec02 | 2017-05-18 23:04:08 +0000 | [diff] [blame] | 131 | SmallVector<TypeIndex, 128> SourceToDest; |
Zachary Turner | 7b327d0 | 2017-02-16 23:35:45 +0000 | [diff] [blame] | 132 | Handler.addSearchPath(llvm::sys::path::parent_path(File->getName())); |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 133 | if (auto EC = Reader.readArray(Types, Reader.getLength())) |
| 134 | fatal(EC, "Reader::readArray failed"); |
Zachary Turner | d4136e9 | 2017-05-22 21:07:43 +0000 | [diff] [blame] | 135 | if (auto Err = codeview::mergeTypeAndIdRecords( |
Zachary Turner | bb64231 | 2017-05-24 00:26:27 +0000 | [diff] [blame] | 136 | IDTable, TypeTable, SourceToDest, &Handler, Types)) |
Rui Ueyama | a9b2961 | 2017-02-02 00:47:10 +0000 | [diff] [blame] | 137 | fatal(Err, "codeview::mergeTypeStreams failed"); |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 140 | // Construct TPI stream contents. |
Reid Kleckner | 13fc411 | 2017-04-04 00:56:34 +0000 | [diff] [blame] | 141 | addTypeInfo(Builder.getTpiBuilder(), TypeTable); |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 142 | |
| 143 | // Construct IPI stream contents. |
Reid Kleckner | 13fc411 | 2017-04-04 00:56:34 +0000 | [diff] [blame] | 144 | addTypeInfo(Builder.getIpiBuilder(), IDTable); |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Rui Ueyama | 26186c7 | 2016-12-09 04:46:54 +0000 | [diff] [blame] | 147 | static void dumpDebugT(ScopedPrinter &W, ObjectFile *File) { |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 148 | ListScope LS(W, "DebugT"); |
| 149 | ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T"); |
Rui Ueyama | 26186c7 | 2016-12-09 04:46:54 +0000 | [diff] [blame] | 150 | if (Data.empty()) |
| 151 | return; |
| 152 | |
Zachary Turner | 526f4f2 | 2017-05-19 19:26:58 +0000 | [diff] [blame] | 153 | LazyRandomTypeCollection Types(Data, 100); |
| 154 | TypeDumpVisitor TDV(Types, &W, false); |
Zachary Turner | 7b327d0 | 2017-02-16 23:35:45 +0000 | [diff] [blame] | 155 | // Use a default implementation that does not follow type servers and instead |
| 156 | // just dumps the contents of the TypeServer2 record. |
Zachary Turner | 526f4f2 | 2017-05-19 19:26:58 +0000 | [diff] [blame] | 157 | if (auto EC = codeview::visitTypeStream(Types, TDV)) |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 158 | fatal(EC, "CVTypeDumper::dump failed"); |
| 159 | } |
| 160 | |
| 161 | static void dumpDebugS(ScopedPrinter &W, ObjectFile *File) { |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 162 | ListScope LS(W, "DebugS"); |
| 163 | ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$S"); |
| 164 | if (Data.empty()) |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 165 | return; |
| 166 | |
Zachary Turner | 695ed56 | 2017-02-28 00:04:07 +0000 | [diff] [blame] | 167 | BinaryByteStream Stream(Data, llvm::support::little); |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 168 | CVSymbolArray Symbols; |
Zachary Turner | 120faca | 2017-02-27 22:11:43 +0000 | [diff] [blame] | 169 | BinaryStreamReader Reader(Stream); |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 170 | if (auto EC = Reader.readArray(Symbols, Reader.getLength())) |
| 171 | fatal(EC, "StreamReader.readArray<CVSymbolArray> failed"); |
| 172 | |
Zachary Turner | 5634ccf | 2017-05-05 22:06:06 +0000 | [diff] [blame] | 173 | TypeDatabase TDB(0); |
Zachary Turner | ebd3ae8 | 2017-06-01 21:52:41 +0000 | [diff] [blame] | 174 | CVSymbolDumper SymbolDumper(W, TDB, CodeViewContainer::ObjectFile, nullptr, |
| 175 | false); |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 176 | if (auto EC = SymbolDumper.dump(Symbols)) |
| 177 | fatal(EC, "CVSymbolDumper::dump failed"); |
| 178 | } |
| 179 | |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 180 | // Dump CodeView debug info. This is for debugging. |
| 181 | static void dumpCodeView(SymbolTable *Symtab) { |
| 182 | ScopedPrinter W(outs()); |
| 183 | |
| 184 | for (ObjectFile *File : Symtab->ObjectFiles) { |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 185 | dumpDebugT(W, File); |
| 186 | dumpDebugS(W, File); |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 190 | // Creates a PDB file. |
| 191 | void coff::createPDB(StringRef Path, SymbolTable *Symtab, |
Saleem Abdulrasool | df8a13b | 2017-01-04 17:56:54 +0000 | [diff] [blame] | 192 | ArrayRef<uint8_t> SectionTable, |
| 193 | const llvm::codeview::DebugInfo *DI) { |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 194 | if (Config->DumpPdb) |
| 195 | dumpCodeView(Symtab); |
| 196 | |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 197 | BumpPtrAllocator Alloc; |
| 198 | pdb::PDBFileBuilder Builder(Alloc); |
Rui Ueyama | 1297954 | 2016-09-30 20:53:45 +0000 | [diff] [blame] | 199 | ExitOnErr(Builder.initialize(4096)); // 4096 is blocksize |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 200 | |
Rui Ueyama | 8d3fb5d | 2016-10-05 22:08:58 +0000 | [diff] [blame] | 201 | // Create streams in MSF for predefined streams, namely |
| 202 | // PDB, TPI, DBI and IPI. |
| 203 | for (int I = 0; I < (int)pdb::kSpecialStreamCount; ++I) |
| 204 | ExitOnErr(Builder.getMsfBuilder().addStream(0)); |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 205 | |
Rui Ueyama | bb542b3 | 2016-09-16 22:51:17 +0000 | [diff] [blame] | 206 | // Add an Info stream. |
| 207 | auto &InfoBuilder = Builder.getInfoBuilder(); |
Saleem Abdulrasool | 0acd6dd | 2017-02-07 04:28:02 +0000 | [diff] [blame] | 208 | InfoBuilder.setAge(DI ? DI->PDB70.Age : 0); |
| 209 | |
| 210 | pdb::PDB_UniqueId uuid{}; |
| 211 | if (DI) |
| 212 | memcpy(&uuid, &DI->PDB70.Signature, sizeof(uuid)); |
| 213 | InfoBuilder.setGuid(uuid); |
Rui Ueyama | bb542b3 | 2016-09-16 22:51:17 +0000 | [diff] [blame] | 214 | // Should be the current time, but set 0 for reproducibilty. |
| 215 | InfoBuilder.setSignature(0); |
Rui Ueyama | bb542b3 | 2016-09-16 22:51:17 +0000 | [diff] [blame] | 216 | InfoBuilder.setVersion(pdb::PdbRaw_ImplVer::PdbImplVC70); |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 217 | |
Rui Ueyama | 1343fac | 2016-10-06 22:52:01 +0000 | [diff] [blame] | 218 | // Add an empty DPI stream. |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame^] | 219 | pdb::DbiStreamBuilder &DbiBuilder = Builder.getDbiBuilder(); |
Rui Ueyama | 1343fac | 2016-10-06 22:52:01 +0000 | [diff] [blame] | 220 | DbiBuilder.setVersionHeader(pdb::PdbDbiV110); |
| 221 | |
Reid Kleckner | 13fc411 | 2017-04-04 00:56:34 +0000 | [diff] [blame] | 222 | codeview::TypeTableBuilder TypeTable(BAlloc); |
| 223 | codeview::TypeTableBuilder IDTable(BAlloc); |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame^] | 224 | addObjectsToPDB(Symtab, Builder, TypeTable, IDTable); |
Rui Ueyama | d381c98 | 2016-10-05 21:37:25 +0000 | [diff] [blame] | 225 | |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 226 | // Add Section Contributions. |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame^] | 227 | addSectionContribs(Symtab, DbiBuilder); |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 228 | |
Rui Ueyama | 20df4ec | 2016-10-31 21:09:21 +0000 | [diff] [blame] | 229 | // Add Section Map stream. |
| 230 | ArrayRef<object::coff_section> Sections = { |
Rui Ueyama | 6294a24 | 2016-11-04 17:41:29 +0000 | [diff] [blame] | 231 | (const object::coff_section *)SectionTable.data(), |
Rui Ueyama | 20df4ec | 2016-10-31 21:09:21 +0000 | [diff] [blame] | 232 | SectionTable.size() / sizeof(object::coff_section)}; |
| 233 | std::vector<pdb::SecMapEntry> SectionMap = |
| 234 | pdb::DbiStreamBuilder::createSectionMap(Sections); |
| 235 | DbiBuilder.setSectionMap(SectionMap); |
| 236 | |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame] | 237 | ExitOnErr(DbiBuilder.addModuleInfo("* Linker *")); |
Rui Ueyama | c91f716 | 2016-11-16 01:10:46 +0000 | [diff] [blame] | 238 | |
Rui Ueyama | 9f66f82 | 2016-10-11 19:45:07 +0000 | [diff] [blame] | 239 | // Add COFF section header stream. |
| 240 | ExitOnErr( |
| 241 | DbiBuilder.addDbgStream(pdb::DbgHeaderType::SectionHdr, SectionTable)); |
| 242 | |
Rui Ueyama | 3e9d6bb | 2016-09-26 23:53:55 +0000 | [diff] [blame] | 243 | // Write to a file. |
Rui Ueyama | 5c82eea | 2016-09-30 20:39:04 +0000 | [diff] [blame] | 244 | ExitOnErr(Builder.commit(Path)); |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 245 | } |