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" |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h" |
| 19 | #include "llvm/DebugInfo/CodeView/DebugSubsectionVisitor.h" |
Zachary Turner | 526f4f2 | 2017-05-19 19:26:58 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" |
Rui Ueyama | 24625fd | 2016-11-22 23:51:34 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/CodeView/SymbolDumper.h" |
Zachary Turner | 629cb7d | 2017-01-11 23:24:22 +0000 | [diff] [blame] | 22 | #include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h" |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 23 | #include "llvm/DebugInfo/CodeView/TypeStreamMerger.h" |
| 24 | #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h" |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 25 | #include "llvm/DebugInfo/MSF/MSFBuilder.h" |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 26 | #include "llvm/DebugInfo/MSF/MSFCommon.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 27 | #include "llvm/DebugInfo/PDB/Native/DbiStream.h" |
| 28 | #include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h" |
| 29 | #include "llvm/DebugInfo/PDB/Native/InfoStream.h" |
| 30 | #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h" |
| 31 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
| 32 | #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h" |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame] | 33 | #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h" |
Rafael Espindola | a0f30da | 2017-05-02 20:19:42 +0000 | [diff] [blame] | 34 | #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h" |
Zachary Turner | 7b327d0 | 2017-02-16 23:35:45 +0000 | [diff] [blame] | 35 | #include "llvm/DebugInfo/PDB/Native/PDBTypeServerHandler.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame] | 36 | #include "llvm/DebugInfo/PDB/Native/TpiStream.h" |
| 37 | #include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h" |
Rui Ueyama | 20df4ec | 2016-10-31 21:09:21 +0000 | [diff] [blame] | 38 | #include "llvm/Object/COFF.h" |
Zachary Turner | d9dc282 | 2017-03-02 20:52:51 +0000 | [diff] [blame] | 39 | #include "llvm/Support/BinaryByteStream.h" |
Rui Ueyama | 1763c0d | 2015-12-08 18:39:55 +0000 | [diff] [blame] | 40 | #include "llvm/Support/Endian.h" |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 41 | #include "llvm/Support/FileOutputBuffer.h" |
Zachary Turner | 7b327d0 | 2017-02-16 23:35:45 +0000 | [diff] [blame] | 42 | #include "llvm/Support/Path.h" |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 43 | #include "llvm/Support/ScopedPrinter.h" |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 44 | #include <memory> |
| 45 | |
Rui Ueyama | 1d99ab3 | 2016-09-15 22:24:51 +0000 | [diff] [blame] | 46 | using namespace lld; |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 47 | using namespace lld::coff; |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 48 | using namespace llvm; |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 49 | using namespace llvm::codeview; |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 50 | |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 51 | using llvm::object::coff_section; |
| 52 | |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 53 | static ExitOnError ExitOnErr; |
| 54 | |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 55 | // Returns a list of all SectionChunks. |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame] | 56 | static void addSectionContribs(SymbolTable *Symtab, pdb::DbiStreamBuilder &DbiBuilder) { |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 57 | for (Chunk *C : Symtab->getChunks()) |
| 58 | if (auto *SC = dyn_cast<SectionChunk>(C)) |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame] | 59 | DbiBuilder.addSectionContrib(SC->File->ModuleDBI, SC->Header); |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Rui Ueyama | be939b3 | 2016-11-21 17:22:35 +0000 | [diff] [blame] | 62 | static SectionChunk *findByName(std::vector<SectionChunk *> &Sections, |
| 63 | StringRef Name) { |
| 64 | for (SectionChunk *C : Sections) |
| 65 | if (C->getSectionName() == Name) |
| 66 | return C; |
| 67 | return nullptr; |
| 68 | } |
| 69 | |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 70 | static ArrayRef<uint8_t> consumeDebugMagic(ArrayRef<uint8_t> Data, |
| 71 | StringRef SecName) { |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 72 | // First 4 bytes are section magic. |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 73 | if (Data.size() < 4) |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 74 | fatal(SecName + " too short"); |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 75 | if (support::endian::read32le(Data.data()) != COFF::DEBUG_SECTION_MAGIC) |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 76 | fatal(SecName + " has an invalid magic"); |
Rui Ueyama | 26186c7 | 2016-12-09 04:46:54 +0000 | [diff] [blame] | 77 | return Data.slice(4); |
| 78 | } |
Rui Ueyama | c5cb737 | 2016-12-01 01:22:48 +0000 | [diff] [blame] | 79 | |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 80 | static ArrayRef<uint8_t> getDebugSection(ObjectFile *File, StringRef SecName) { |
| 81 | if (SectionChunk *Sec = findByName(File->getDebugChunks(), SecName)) |
| 82 | return consumeDebugMagic(Sec->getContents(), SecName); |
| 83 | return {}; |
| 84 | } |
| 85 | |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 86 | static void addTypeInfo(pdb::TpiStreamBuilder &TpiBuilder, |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 87 | TypeTableBuilder &TypeTable) { |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 88 | // Start the TPI or IPI stream header. |
| 89 | TpiBuilder.setVersionHeader(pdb::PdbTpiV80); |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 90 | |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 91 | // Flatten the in memory type table. |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 92 | TypeTable.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Rec) { |
Reid Kleckner | 13fc411 | 2017-04-04 00:56:34 +0000 | [diff] [blame] | 93 | // FIXME: Hash types. |
| 94 | TpiBuilder.addTypeRecord(Rec, None); |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 95 | }); |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 98 | static void mergeDebugT(ObjectFile *File, |
| 99 | TypeTableBuilder &IDTable, |
| 100 | TypeTableBuilder &TypeTable, |
| 101 | SmallVectorImpl<TypeIndex> &TypeIndexMap, |
| 102 | pdb::PDBTypeServerHandler &Handler) { |
| 103 | ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T"); |
| 104 | if (Data.empty()) |
| 105 | return; |
| 106 | |
| 107 | BinaryByteStream Stream(Data, support::little); |
| 108 | CVTypeArray Types; |
| 109 | BinaryStreamReader Reader(Stream); |
| 110 | Handler.addSearchPath(sys::path::parent_path(File->getName())); |
| 111 | if (auto EC = Reader.readArray(Types, Reader.getLength())) |
| 112 | fatal(EC, "Reader::readArray failed"); |
| 113 | if (auto Err = mergeTypeAndIdRecords(IDTable, TypeTable, |
| 114 | TypeIndexMap, &Handler, Types)) |
| 115 | fatal(Err, "codeview::mergeTypeStreams failed"); |
| 116 | } |
| 117 | |
| 118 | // Allocate memory for a .debug$S section and relocate it. |
| 119 | static ArrayRef<uint8_t> relocateDebugChunk(BumpPtrAllocator &Alloc, |
| 120 | SectionChunk *DebugChunk) { |
| 121 | uint8_t *Buffer = Alloc.Allocate<uint8_t>(DebugChunk->getSize()); |
| 122 | assert(DebugChunk->OutputSectionOff == 0 && |
| 123 | "debug sections should not be in output sections"); |
| 124 | DebugChunk->writeTo(Buffer); |
| 125 | return consumeDebugMagic(makeArrayRef(Buffer, DebugChunk->getSize()), |
| 126 | ".debug$S"); |
| 127 | } |
| 128 | |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame] | 129 | // Add all object files to the PDB. Merge .debug$T sections into IpiData and |
| 130 | // TpiData. |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 131 | static void addObjectsToPDB(BumpPtrAllocator &Alloc, SymbolTable *Symtab, |
| 132 | pdb::PDBFileBuilder &Builder, |
| 133 | TypeTableBuilder &TypeTable, |
| 134 | TypeTableBuilder &IDTable) { |
Zachary Turner | 2897e03 | 2017-05-25 21:16:03 +0000 | [diff] [blame] | 135 | // Follow type servers. If the same type server is encountered more than |
| 136 | // once for this instance of `PDBTypeServerHandler` (for example if many |
| 137 | // object files reference the same TypeServer), the types from the |
| 138 | // TypeServer will only be visited once. |
| 139 | pdb::PDBTypeServerHandler Handler; |
| 140 | |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 141 | // PDBs use a single global string table for filenames in the file checksum |
| 142 | // table. |
| 143 | auto PDBStrTab = std::make_shared<DebugStringTableSubsection>(); |
| 144 | |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 145 | // Visit all .debug$T sections to add them to Builder. |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 146 | for (ObjectFile *File : Symtab->ObjectFiles) { |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame] | 147 | // Add a module descriptor for every object file. We need to put an absolute |
| 148 | // path to the object into the PDB. If this is a plain object, we make its |
| 149 | // path absolute. If it's an object in an archive, we make the archive path |
| 150 | // absolute. |
| 151 | bool InArchive = !File->ParentName.empty(); |
| 152 | SmallString<128> Path = InArchive ? File->ParentName : File->getName(); |
| 153 | sys::fs::make_absolute(Path); |
| 154 | StringRef Name = InArchive ? File->getName() : StringRef(Path); |
| 155 | File->ModuleDBI = &ExitOnErr(Builder.getDbiBuilder().addModuleInfo(Name)); |
| 156 | File->ModuleDBI->setObjFileName(Path); |
| 157 | |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 158 | // Before we can process symbol substreams from .debug$S, we need to process |
| 159 | // type information, file checksums, and the string table. Add type info to |
| 160 | // the PDB first, so that we can get the map from object file type and item |
| 161 | // indices to PDB type and item indices. |
| 162 | SmallVector<TypeIndex, 128> TypeIndexMap; |
| 163 | mergeDebugT(File, IDTable, TypeTable, TypeIndexMap, Handler); |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame] | 164 | |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 165 | // Now do all line info. |
| 166 | for (SectionChunk *DebugChunk : File->getDebugChunks()) { |
| 167 | // FIXME: Debug chunks do not have a correct isLive() bit. |
| 168 | // FIXME: When linker GC is off we need to ignore debug info whose |
| 169 | // associated symbol was discarded. |
| 170 | if (DebugChunk->getSectionName() != ".debug$S") |
| 171 | continue; |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 172 | |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 173 | ArrayRef<uint8_t> RelocatedDebugContents = |
| 174 | relocateDebugChunk(Alloc, DebugChunk); |
| 175 | if (RelocatedDebugContents.empty()) |
| 176 | continue; |
| 177 | |
| 178 | DebugSubsectionArray Subsections; |
| 179 | BinaryStreamReader Reader(RelocatedDebugContents, support::little); |
| 180 | ExitOnErr(Reader.readArray(Subsections, RelocatedDebugContents.size())); |
| 181 | |
| 182 | DebugStringTableSubsectionRef CVStrTab; |
| 183 | DebugChecksumsSubsectionRef Checksums; |
| 184 | for (const DebugSubsectionRecord &SS : Subsections) { |
| 185 | switch (SS.kind()) { |
| 186 | case DebugSubsectionKind::StringTable: |
| 187 | ExitOnErr(CVStrTab.initialize(SS.getRecordData())); |
| 188 | break; |
| 189 | case DebugSubsectionKind::FileChecksums: |
| 190 | ExitOnErr(Checksums.initialize(SS.getRecordData())); |
| 191 | break; |
| 192 | case DebugSubsectionKind::Lines: |
| 193 | // We can add the relocated line table directly to the PDB without |
| 194 | // modification because the file checksum offsets will stay the same. |
| 195 | File->ModuleDBI->addDebugSubsection(SS); |
| 196 | break; |
| 197 | default: |
| 198 | // FIXME: Process the rest of the subsections. |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (Checksums.valid()) { |
| 204 | // Make a new file checksum table that refers to offsets in the PDB-wide |
| 205 | // string table. Generally the string table subsection appears after the |
| 206 | // checksum table, so we have to do this after looping over all the |
| 207 | // subsections. |
| 208 | if (!CVStrTab.valid()) |
| 209 | fatal(".debug$S sections must have both a string table subsection " |
| 210 | "and a checksum subsection table or neither"); |
| 211 | auto NewChecksums = |
Reid Kleckner | adea0ce | 2017-06-19 17:27:31 +0000 | [diff] [blame^] | 212 | make_unique<DebugChecksumsSubsection>(*PDBStrTab); |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 213 | for (FileChecksumEntry &FC : Checksums) { |
| 214 | StringRef FileName = ExitOnErr(CVStrTab.getString(FC.FileNameOffset)); |
| 215 | ExitOnErr(Builder.getDbiBuilder().addModuleSourceFile( |
| 216 | *File->ModuleDBI, FileName)); |
| 217 | NewChecksums->addChecksum(FileName, FC.Kind, FC.Checksum); |
| 218 | } |
| 219 | File->ModuleDBI->addDebugSubsection(std::move(NewChecksums)); |
| 220 | } |
| 221 | } |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 224 | Builder.getStringTableBuilder().setStrings(*PDBStrTab); |
| 225 | |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 226 | // Construct TPI stream contents. |
Reid Kleckner | 13fc411 | 2017-04-04 00:56:34 +0000 | [diff] [blame] | 227 | addTypeInfo(Builder.getTpiBuilder(), TypeTable); |
Reid Kleckner | 5d57752 | 2017-03-24 17:26:38 +0000 | [diff] [blame] | 228 | |
| 229 | // Construct IPI stream contents. |
Reid Kleckner | 13fc411 | 2017-04-04 00:56:34 +0000 | [diff] [blame] | 230 | addTypeInfo(Builder.getIpiBuilder(), IDTable); |
Rui Ueyama | 5289662 | 2017-01-12 03:09:25 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 233 | // Creates a PDB file. |
| 234 | void coff::createPDB(StringRef Path, SymbolTable *Symtab, |
Saleem Abdulrasool | df8a13b | 2017-01-04 17:56:54 +0000 | [diff] [blame] | 235 | ArrayRef<uint8_t> SectionTable, |
| 236 | const llvm::codeview::DebugInfo *DI) { |
Rui Ueyama | b28c6d4 | 2016-09-16 04:32:33 +0000 | [diff] [blame] | 237 | BumpPtrAllocator Alloc; |
| 238 | pdb::PDBFileBuilder Builder(Alloc); |
Rui Ueyama | 1297954 | 2016-09-30 20:53:45 +0000 | [diff] [blame] | 239 | ExitOnErr(Builder.initialize(4096)); // 4096 is blocksize |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 240 | |
Rui Ueyama | 8d3fb5d | 2016-10-05 22:08:58 +0000 | [diff] [blame] | 241 | // Create streams in MSF for predefined streams, namely |
| 242 | // PDB, TPI, DBI and IPI. |
| 243 | for (int I = 0; I < (int)pdb::kSpecialStreamCount; ++I) |
| 244 | ExitOnErr(Builder.getMsfBuilder().addStream(0)); |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 245 | |
Rui Ueyama | bb542b3 | 2016-09-16 22:51:17 +0000 | [diff] [blame] | 246 | // Add an Info stream. |
| 247 | auto &InfoBuilder = Builder.getInfoBuilder(); |
Saleem Abdulrasool | 0acd6dd | 2017-02-07 04:28:02 +0000 | [diff] [blame] | 248 | InfoBuilder.setAge(DI ? DI->PDB70.Age : 0); |
| 249 | |
| 250 | pdb::PDB_UniqueId uuid{}; |
| 251 | if (DI) |
| 252 | memcpy(&uuid, &DI->PDB70.Signature, sizeof(uuid)); |
| 253 | InfoBuilder.setGuid(uuid); |
Rui Ueyama | bb542b3 | 2016-09-16 22:51:17 +0000 | [diff] [blame] | 254 | // Should be the current time, but set 0 for reproducibilty. |
| 255 | InfoBuilder.setSignature(0); |
Rui Ueyama | bb542b3 | 2016-09-16 22:51:17 +0000 | [diff] [blame] | 256 | InfoBuilder.setVersion(pdb::PdbRaw_ImplVer::PdbImplVC70); |
Rui Ueyama | 7f38299 | 2016-09-15 18:55:18 +0000 | [diff] [blame] | 257 | |
Rui Ueyama | 1343fac | 2016-10-06 22:52:01 +0000 | [diff] [blame] | 258 | // Add an empty DPI stream. |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame] | 259 | pdb::DbiStreamBuilder &DbiBuilder = Builder.getDbiBuilder(); |
Rui Ueyama | 1343fac | 2016-10-06 22:52:01 +0000 | [diff] [blame] | 260 | DbiBuilder.setVersionHeader(pdb::PdbDbiV110); |
| 261 | |
Reid Kleckner | 44cdb10 | 2017-06-19 17:21:45 +0000 | [diff] [blame] | 262 | TypeTableBuilder TypeTable(BAlloc); |
| 263 | TypeTableBuilder IDTable(BAlloc); |
| 264 | addObjectsToPDB(Alloc, Symtab, Builder, TypeTable, IDTable); |
Rui Ueyama | d381c98 | 2016-10-05 21:37:25 +0000 | [diff] [blame] | 265 | |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 266 | // Add Section Contributions. |
Reid Kleckner | 8cbdd0c | 2017-06-13 15:49:13 +0000 | [diff] [blame] | 267 | addSectionContribs(Symtab, DbiBuilder); |
Rui Ueyama | 09e0b5f | 2016-11-12 00:00:51 +0000 | [diff] [blame] | 268 | |
Rui Ueyama | 20df4ec | 2016-10-31 21:09:21 +0000 | [diff] [blame] | 269 | // Add Section Map stream. |
| 270 | ArrayRef<object::coff_section> Sections = { |
Rui Ueyama | 6294a24 | 2016-11-04 17:41:29 +0000 | [diff] [blame] | 271 | (const object::coff_section *)SectionTable.data(), |
Rui Ueyama | 20df4ec | 2016-10-31 21:09:21 +0000 | [diff] [blame] | 272 | SectionTable.size() / sizeof(object::coff_section)}; |
| 273 | std::vector<pdb::SecMapEntry> SectionMap = |
| 274 | pdb::DbiStreamBuilder::createSectionMap(Sections); |
| 275 | DbiBuilder.setSectionMap(SectionMap); |
| 276 | |
Zachary Turner | ea4e607 | 2017-03-15 22:18:53 +0000 | [diff] [blame] | 277 | ExitOnErr(DbiBuilder.addModuleInfo("* Linker *")); |
Rui Ueyama | c91f716 | 2016-11-16 01:10:46 +0000 | [diff] [blame] | 278 | |
Rui Ueyama | 9f66f82 | 2016-10-11 19:45:07 +0000 | [diff] [blame] | 279 | // Add COFF section header stream. |
| 280 | ExitOnErr( |
| 281 | DbiBuilder.addDbgStream(pdb::DbgHeaderType::SectionHdr, SectionTable)); |
| 282 | |
Rui Ueyama | 3e9d6bb | 2016-09-26 23:53:55 +0000 | [diff] [blame] | 283 | // Write to a file. |
Rui Ueyama | 5c82eea | 2016-09-30 20:39:04 +0000 | [diff] [blame] | 284 | ExitOnErr(Builder.commit(Path)); |
Rui Ueyama | e737824 | 2015-12-04 23:11:05 +0000 | [diff] [blame] | 285 | } |