blob: 2287dda39d3c8aa9bc14be3fb38fd685f5c770df [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 Ueyama09e0b5f2016-11-12 00:00:51 +000011#include "Chunks.h"
Rui Ueyamabe939b32016-11-21 17:22:35 +000012#include "Config.h"
Peter Collingbourne75257bc2017-10-20 19:48:26 +000013#include "Driver.h"
Rui Ueyama09e0b5f2016-11-12 00:00:51 +000014#include "SymbolTable.h"
15#include "Symbols.h"
Reid Klecknereacdf042017-07-27 18:25:59 +000016#include "Writer.h"
Bob Haarmanb8a59c82017-10-25 22:28:38 +000017#include "lld/Common/ErrorHandler.h"
Zachary Turner727f1532018-01-17 19:16:26 +000018#include "lld/Common/Timer.h"
Saleem Abdulrasooldf8a13b2017-01-04 17:56:54 +000019#include "llvm/DebugInfo/CodeView/CVDebugRecord.h"
Reid Kleckner44cdb102017-06-19 17:21:45 +000020#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
Zachary Turner0d07a8e2017-12-14 18:07:04 +000021#include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h"
Zachary Turner526f4f22017-05-19 19:26:58 +000022#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
Zachary Turnerca6dbf12017-11-30 18:39:50 +000023#include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
Zachary Turneree9906d2017-08-11 19:00:03 +000024#include "llvm/DebugInfo/CodeView/RecordName.h"
Zachary Turner59e3ae82017-08-08 18:34:44 +000025#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
Zachary Turner6708e0b2017-07-10 21:01:37 +000026#include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
Reid Kleckner651db912017-07-18 00:21:25 +000027#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
Zachary Turner629cb7d2017-01-11 23:24:22 +000028#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
Reid Klecknerd0e6e242017-06-21 17:25:56 +000029#include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h"
Rui Ueyama52896622017-01-12 03:09:25 +000030#include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
Rui Ueyamab28c6d42016-09-16 04:32:33 +000031#include "llvm/DebugInfo/MSF/MSFBuilder.h"
Rui Ueyama7f382992016-09-15 18:55:18 +000032#include "llvm/DebugInfo/MSF/MSFCommon.h"
Reid Kleckner651db912017-07-18 00:21:25 +000033#include "llvm/DebugInfo/PDB/GenericError.h"
Zachary Turner6708e0b2017-07-10 21:01:37 +000034#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptorBuilder.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000035#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
36#include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h"
Zachary Turner946204c2017-08-09 04:23:25 +000037#include "llvm/DebugInfo/PDB/Native/GSIStreamBuilder.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000038#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
39#include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
Reid Kleckner651db912017-07-18 00:21:25 +000040#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000041#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
42#include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
Rafael Espindolaa0f30da2017-05-02 20:19:42 +000043#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
Reid Klecknerd91ca762017-07-19 17:26:07 +000044#include "llvm/DebugInfo/PDB/Native/TpiHashing.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000045#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
46#include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h"
Reid Kleckner651db912017-07-18 00:21:25 +000047#include "llvm/DebugInfo/PDB/PDB.h"
Rui Ueyama20df4ec2016-10-31 21:09:21 +000048#include "llvm/Object/COFF.h"
Zachary Turnerd9dc2822017-03-02 20:52:51 +000049#include "llvm/Support/BinaryByteStream.h"
Rui Ueyama1763c0d2015-12-08 18:39:55 +000050#include "llvm/Support/Endian.h"
Zachary Turner60478582018-01-05 19:12:40 +000051#include "llvm/Support/FormatVariadic.h"
Zachary Turner676386ff2017-08-07 20:23:45 +000052#include "llvm/Support/JamCRC.h"
Zachary Turner7b327d02017-02-16 23:35:45 +000053#include "llvm/Support/Path.h"
Rui Ueyamabe939b32016-11-21 17:22:35 +000054#include "llvm/Support/ScopedPrinter.h"
Rui Ueyamae7378242015-12-04 23:11:05 +000055#include <memory>
56
Rui Ueyama1d99ab32016-09-15 22:24:51 +000057using namespace lld;
Rui Ueyama09e0b5f2016-11-12 00:00:51 +000058using namespace lld::coff;
Rui Ueyamae7378242015-12-04 23:11:05 +000059using namespace llvm;
Rui Ueyamabe939b32016-11-21 17:22:35 +000060using namespace llvm::codeview;
Rui Ueyamae7378242015-12-04 23:11:05 +000061
Rui Ueyama09e0b5f2016-11-12 00:00:51 +000062using llvm::object::coff_section;
63
Rui Ueyamab28c6d42016-09-16 04:32:33 +000064static ExitOnError ExitOnErr;
65
Zachary Turner727f1532018-01-17 19:16:26 +000066static Timer TotalPdbLinkTimer("PDB Emission (Cumulative)", Timer::root());
67
68static Timer AddObjectsTimer("Add Objects", TotalPdbLinkTimer);
69static Timer TypeMergingTimer("Type Merging", AddObjectsTimer);
70static Timer SymbolMergingTimer("Symbol Merging", AddObjectsTimer);
71static Timer GlobalsLayoutTimer("Globals Stream Layout", TotalPdbLinkTimer);
72static Timer TpiStreamLayoutTimer("TPI Stream Layout", TotalPdbLinkTimer);
73static Timer DiskCommitTimer("Commit to Disk", TotalPdbLinkTimer);
74
Reid Kleckner0faf6d72017-07-14 00:14:58 +000075namespace {
Reid Kleckner651db912017-07-18 00:21:25 +000076/// Map from type index and item index in a type server PDB to the
77/// corresponding index in the destination PDB.
78struct CVIndexMap {
79 SmallVector<TypeIndex, 0> TPIMap;
80 SmallVector<TypeIndex, 0> IPIMap;
81 bool IsTypeServerMap = false;
82};
83
Reid Kleckner0faf6d72017-07-14 00:14:58 +000084class PDBLinker {
85public:
86 PDBLinker(SymbolTable *Symtab)
Sam Cleggea244bf2017-12-14 21:09:31 +000087 : Alloc(), Symtab(Symtab), Builder(Alloc), TypeTable(Alloc),
Zachary Turnera6fb5362018-03-23 18:43:39 +000088 IDTable(Alloc), GlobalTypeTable(Alloc), GlobalIDTable(Alloc) {
89 // This isn't strictly necessary, but link.exe usually puts an empty string
90 // as the first "valid" string in the string table, so we do the same in
91 // order to maintain as much byte-for-byte compatibility as possible.
92 PDBStrTab.insert("");
93 }
Reid Kleckner0faf6d72017-07-14 00:14:58 +000094
95 /// Emit the basic PDB structure: initial streams, headers, etc.
Zachary Turner024323c2017-08-15 21:31:41 +000096 void initialize(const llvm::codeview::DebugInfo &BuildId);
Reid Kleckner0faf6d72017-07-14 00:14:58 +000097
98 /// Link CodeView from each object file in the symbol table into the PDB.
99 void addObjectsToPDB();
100
101 /// Link CodeView from a single object file into the PDB.
Rui Ueyamae1b48e02017-07-26 23:05:24 +0000102 void addObjFile(ObjFile *File);
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000103
Reid Kleckner651db912017-07-18 00:21:25 +0000104 /// Produce a mapping from the type and item indices used in the object
105 /// file to those in the destination PDB.
106 ///
107 /// If the object file uses a type server PDB (compiled with /Zi), merge TPI
108 /// and IPI from the type server PDB and return a map for it. Each unique type
109 /// server PDB is merged at most once, so this may return an existing index
110 /// mapping.
111 ///
112 /// If the object does not use a type server PDB (compiled with /Z7), we merge
113 /// all the type and item records from the .debug$S stream and fill in the
114 /// caller-provided ObjectIndexMap.
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000115 Expected<const CVIndexMap&> mergeDebugT(ObjFile *File,
116 CVIndexMap &ObjectIndexMap);
Reid Kleckner651db912017-07-18 00:21:25 +0000117
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000118 Expected<const CVIndexMap&> maybeMergeTypeServerPDB(ObjFile *File,
119 TypeServer2Record &TS);
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000120
121 /// Add the section map and section contributions to the PDB.
Reid Kleckner175af4b2017-08-03 21:15:09 +0000122 void addSections(ArrayRef<OutputSection *> OutputSections,
123 ArrayRef<uint8_t> SectionTable);
124
125 void addSectionContrib(pdb::DbiModuleDescriptorBuilder &LinkerModule,
126 OutputSection *OS, Chunk *C);
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000127
128 /// Write the PDB to disk.
129 void commit();
130
131private:
132 BumpPtrAllocator Alloc;
133
134 SymbolTable *Symtab;
135
136 pdb::PDBFileBuilder Builder;
137
138 /// Type records that will go into the PDB TPI stream.
Zachary Turnerca6dbf12017-11-30 18:39:50 +0000139 MergingTypeTableBuilder TypeTable;
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000140
141 /// Item records that will go into the PDB IPI stream.
Zachary Turnerca6dbf12017-11-30 18:39:50 +0000142 MergingTypeTableBuilder IDTable;
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000143
Zachary Turner0d07a8e2017-12-14 18:07:04 +0000144 /// Type records that will go into the PDB TPI stream (for /DEBUG:GHASH)
145 GlobalTypeTableBuilder GlobalTypeTable;
146
147 /// Item records that will go into the PDB IPI stream (for /DEBUG:GHASH)
148 GlobalTypeTableBuilder GlobalIDTable;
149
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000150 /// PDBs use a single global string table for filenames in the file checksum
151 /// table.
152 DebugStringTableSubsection PDBStrTab;
153
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000154 llvm::SmallString<128> NativePath;
155
Zachary Turner3868cfd2018-02-28 18:09:18 +0000156 /// A list of other PDBs which are loaded during the linking process and which
157 /// we need to keep around since the linking operation may reference pointers
158 /// inside of these PDBs.
159 llvm::SmallVector<std::unique_ptr<pdb::NativeSession>, 2> LoadedPDBs;
160
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000161 std::vector<pdb::SecMapEntry> SectionMap;
Reid Kleckner651db912017-07-18 00:21:25 +0000162
163 /// Type index mappings of type server PDBs that we've loaded so far.
164 std::map<GUID, CVIndexMap> TypeServerIndexMappings;
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000165
166 /// List of TypeServer PDBs which cannot be loaded.
167 /// Cached to prevent repeated load attempts.
168 std::set<GUID> MissingTypeServerPDBs;
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000169};
170}
171
Sam Clegg0fb6faa2017-12-08 01:09:21 +0000172static SectionChunk *findByName(ArrayRef<SectionChunk *> Sections,
Rui Ueyamabe939b32016-11-21 17:22:35 +0000173 StringRef Name) {
174 for (SectionChunk *C : Sections)
175 if (C->getSectionName() == Name)
176 return C;
177 return nullptr;
178}
179
Reid Kleckner44cdb102017-06-19 17:21:45 +0000180static ArrayRef<uint8_t> consumeDebugMagic(ArrayRef<uint8_t> Data,
181 StringRef SecName) {
Rui Ueyamac5cb7372016-12-01 01:22:48 +0000182 // First 4 bytes are section magic.
Rui Ueyamac5cb7372016-12-01 01:22:48 +0000183 if (Data.size() < 4)
Rui Ueyama52896622017-01-12 03:09:25 +0000184 fatal(SecName + " too short");
Reid Kleckner44cdb102017-06-19 17:21:45 +0000185 if (support::endian::read32le(Data.data()) != COFF::DEBUG_SECTION_MAGIC)
Rui Ueyama52896622017-01-12 03:09:25 +0000186 fatal(SecName + " has an invalid magic");
Rui Ueyama26186c72016-12-09 04:46:54 +0000187 return Data.slice(4);
188}
Rui Ueyamac5cb7372016-12-01 01:22:48 +0000189
Rui Ueyamae1b48e02017-07-26 23:05:24 +0000190static ArrayRef<uint8_t> getDebugSection(ObjFile *File, StringRef SecName) {
Reid Kleckner44cdb102017-06-19 17:21:45 +0000191 if (SectionChunk *Sec = findByName(File->getDebugChunks(), SecName))
192 return consumeDebugMagic(Sec->getContents(), SecName);
193 return {};
194}
195
Zachary Turner0d07a8e2017-12-14 18:07:04 +0000196// A COFF .debug$H section is currently a clang extension. This function checks
197// if a .debug$H section is in a format that we expect / understand, so that we
198// can ignore any sections which are coincidentally also named .debug$H but do
199// not contain a format we recognize.
200static bool canUseDebugH(ArrayRef<uint8_t> DebugH) {
201 if (DebugH.size() < sizeof(object::debug_h_header))
202 return false;
203 auto *Header =
204 reinterpret_cast<const object::debug_h_header *>(DebugH.data());
205 DebugH = DebugH.drop_front(sizeof(object::debug_h_header));
206 return Header->Magic == COFF::DEBUG_HASHES_SECTION_MAGIC &&
207 Header->Version == 0 &&
208 Header->HashAlgorithm == uint16_t(GlobalTypeHashAlg::SHA1) &&
209 (DebugH.size() % 20 == 0);
210}
211
212static Optional<ArrayRef<uint8_t>> getDebugH(ObjFile *File) {
213 SectionChunk *Sec = findByName(File->getDebugChunks(), ".debug$H");
214 if (!Sec)
215 return llvm::None;
216 ArrayRef<uint8_t> Contents = Sec->getContents();
217 if (!canUseDebugH(Contents))
218 return None;
219 return Contents;
220}
221
222static ArrayRef<GloballyHashedType>
223getHashesFromDebugH(ArrayRef<uint8_t> DebugH) {
224 assert(canUseDebugH(DebugH));
225
226 DebugH = DebugH.drop_front(sizeof(object::debug_h_header));
227 uint32_t Count = DebugH.size() / sizeof(GloballyHashedType);
228 return {reinterpret_cast<const GloballyHashedType *>(DebugH.data()), Count};
229}
230
Reid Kleckner5d577522017-03-24 17:26:38 +0000231static void addTypeInfo(pdb::TpiStreamBuilder &TpiBuilder,
Zachary Turner3e3936d2017-11-29 19:35:21 +0000232 TypeCollection &TypeTable) {
Reid Kleckner5d577522017-03-24 17:26:38 +0000233 // Start the TPI or IPI stream header.
234 TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
Rui Ueyama52896622017-01-12 03:09:25 +0000235
Reid Klecknerd91ca762017-07-19 17:26:07 +0000236 // Flatten the in memory type table and hash each type.
Zachary Turner3e3936d2017-11-29 19:35:21 +0000237 TypeTable.ForEachRecord([&](TypeIndex TI, const CVType &Type) {
Reid Klecknerd91ca762017-07-19 17:26:07 +0000238 auto Hash = pdb::hashTypeRecord(Type);
239 if (auto E = Hash.takeError())
240 fatal("type hashing error");
Zachary Turner3e3936d2017-11-29 19:35:21 +0000241 TpiBuilder.addTypeRecord(Type.RecordData, *Hash);
Reid Kleckner5d577522017-03-24 17:26:38 +0000242 });
Reid Kleckner5d577522017-03-24 17:26:38 +0000243}
244
Reid Kleckner651db912017-07-18 00:21:25 +0000245static Optional<TypeServer2Record>
246maybeReadTypeServerRecord(CVTypeArray &Types) {
247 auto I = Types.begin();
248 if (I == Types.end())
249 return None;
250 const CVType &Type = *I;
251 if (Type.kind() != LF_TYPESERVER2)
252 return None;
253 TypeServer2Record TS;
254 if (auto EC = TypeDeserializer::deserializeAs(const_cast<CVType &>(Type), TS))
Bob Haarmanb8a59c82017-10-25 22:28:38 +0000255 fatal("error reading type server record: " + toString(std::move(EC)));
Reid Kleckner651db912017-07-18 00:21:25 +0000256 return std::move(TS);
257}
258
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000259Expected<const CVIndexMap&> PDBLinker::mergeDebugT(ObjFile *File,
260 CVIndexMap &ObjectIndexMap) {
Zachary Turner727f1532018-01-17 19:16:26 +0000261 ScopedTimer T(TypeMergingTimer);
262
Reid Kleckner44cdb102017-06-19 17:21:45 +0000263 ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T");
264 if (Data.empty())
Reid Kleckner651db912017-07-18 00:21:25 +0000265 return ObjectIndexMap;
Reid Kleckner6597c282017-07-13 20:12:23 +0000266
Reid Kleckner44cdb102017-06-19 17:21:45 +0000267 BinaryByteStream Stream(Data, support::little);
268 CVTypeArray Types;
269 BinaryStreamReader Reader(Stream);
Reid Kleckner44cdb102017-06-19 17:21:45 +0000270 if (auto EC = Reader.readArray(Types, Reader.getLength()))
Bob Haarmanb8a59c82017-10-25 22:28:38 +0000271 fatal("Reader::readArray failed: " + toString(std::move(EC)));
Reid Kleckner651db912017-07-18 00:21:25 +0000272
273 // Look through type servers. If we've already seen this type server, don't
274 // merge any type information.
275 if (Optional<TypeServer2Record> TS = maybeReadTypeServerRecord(Types))
276 return maybeMergeTypeServerPDB(File, *TS);
277
278 // This is a /Z7 object. Fill in the temporary, caller-provided
279 // ObjectIndexMap.
Zachary Turner0d07a8e2017-12-14 18:07:04 +0000280 if (Config->DebugGHashes) {
281 ArrayRef<GloballyHashedType> Hashes;
282 std::vector<GloballyHashedType> OwnedHashes;
283 if (Optional<ArrayRef<uint8_t>> DebugH = getDebugH(File))
284 Hashes = getHashesFromDebugH(*DebugH);
285 else {
286 OwnedHashes = GloballyHashedType::hashTypes(Types);
287 Hashes = OwnedHashes;
288 }
289
290 if (auto Err = mergeTypeAndIdRecords(GlobalIDTable, GlobalTypeTable,
291 ObjectIndexMap.TPIMap, Types, Hashes))
292 fatal("codeview::mergeTypeAndIdRecords failed: " +
293 toString(std::move(Err)));
294 } else {
295 if (auto Err = mergeTypeAndIdRecords(IDTable, TypeTable,
296 ObjectIndexMap.TPIMap, Types))
297 fatal("codeview::mergeTypeAndIdRecords failed: " +
298 toString(std::move(Err)));
299 }
Reid Kleckner651db912017-07-18 00:21:25 +0000300 return ObjectIndexMap;
301}
302
303static Expected<std::unique_ptr<pdb::NativeSession>>
304tryToLoadPDB(const GUID &GuidFromObj, StringRef TSPath) {
Peter Collingbourne75257bc2017-10-20 19:48:26 +0000305 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getFile(
306 TSPath, /*FileSize=*/-1, /*RequiresNullTerminator=*/false);
307 if (!MBOrErr)
308 return errorCodeToError(MBOrErr.getError());
309
Reid Kleckner651db912017-07-18 00:21:25 +0000310 std::unique_ptr<pdb::IPDBSession> ThisSession;
Peter Collingbourne75257bc2017-10-20 19:48:26 +0000311 if (auto EC = pdb::NativeSession::createFromPdb(
312 MemoryBuffer::getMemBuffer(Driver->takeBuffer(std::move(*MBOrErr)),
313 /*RequiresNullTerminator=*/false),
314 ThisSession))
Reid Kleckner651db912017-07-18 00:21:25 +0000315 return std::move(EC);
316
317 std::unique_ptr<pdb::NativeSession> NS(
318 static_cast<pdb::NativeSession *>(ThisSession.release()));
319 pdb::PDBFile &File = NS->getPDBFile();
320 auto ExpectedInfo = File.getPDBInfoStream();
321 // All PDB Files should have an Info stream.
322 if (!ExpectedInfo)
323 return ExpectedInfo.takeError();
324
325 // Just because a file with a matching name was found and it was an actual
326 // PDB file doesn't mean it matches. For it to match the InfoStream's GUID
327 // must match the GUID specified in the TypeServer2 record.
328 if (ExpectedInfo->getGuid() != GuidFromObj)
329 return make_error<pdb::GenericError>(
330 pdb::generic_error_code::type_server_not_found, TSPath);
331
332 return std::move(NS);
333}
334
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000335Expected<const CVIndexMap&> PDBLinker::maybeMergeTypeServerPDB(ObjFile *File,
336 TypeServer2Record &TS) {
337 const GUID& TSId = TS.getGuid();
338 StringRef TSPath = TS.getName();
339
340 // First, check if the PDB has previously failed to load.
341 if (MissingTypeServerPDBs.count(TSId))
342 return make_error<pdb::GenericError>(
343 pdb::generic_error_code::type_server_not_found, TSPath);
344
345 // Second, check if we already loaded a PDB with this GUID. Return the type
Reid Kleckner651db912017-07-18 00:21:25 +0000346 // index mapping if we have it.
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000347 auto Insertion = TypeServerIndexMappings.insert({TSId, CVIndexMap()});
Reid Kleckner651db912017-07-18 00:21:25 +0000348 CVIndexMap &IndexMap = Insertion.first->second;
349 if (!Insertion.second)
350 return IndexMap;
351
352 // Mark this map as a type server map.
353 IndexMap.IsTypeServerMap = true;
354
355 // Check for a PDB at:
356 // 1. The given file path
357 // 2. Next to the object file or archive file
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000358 auto ExpectedSession = tryToLoadPDB(TSId, TSPath);
Reid Kleckner651db912017-07-18 00:21:25 +0000359 if (!ExpectedSession) {
360 consumeError(ExpectedSession.takeError());
361 StringRef LocalPath =
362 !File->ParentName.empty() ? File->ParentName : File->getName();
363 SmallString<128> Path = sys::path::parent_path(LocalPath);
Reid Klecknerf8522d82017-07-18 00:33:53 +0000364 sys::path::append(
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000365 Path, sys::path::filename(TSPath, sys::path::Style::windows));
366 ExpectedSession = tryToLoadPDB(TSId, Path);
Reid Kleckner651db912017-07-18 00:21:25 +0000367 }
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000368 if (auto E = ExpectedSession.takeError()) {
369 TypeServerIndexMappings.erase(TSId);
370 MissingTypeServerPDBs.emplace(TSId);
371 return std::move(E);
372 }
Reid Kleckner651db912017-07-18 00:21:25 +0000373
Zachary Turner3868cfd2018-02-28 18:09:18 +0000374 pdb::NativeSession *Session = ExpectedSession->get();
375
376 // Keep a strong reference to this PDB, so that it's safe to hold pointers
377 // into the file.
378 LoadedPDBs.push_back(std::move(*ExpectedSession));
379
380 auto ExpectedTpi = Session->getPDBFile().getPDBTpiStream();
Reid Kleckner651db912017-07-18 00:21:25 +0000381 if (auto E = ExpectedTpi.takeError())
Bob Haarmanb8a59c82017-10-25 22:28:38 +0000382 fatal("Type server does not have TPI stream: " + toString(std::move(E)));
Zachary Turner3868cfd2018-02-28 18:09:18 +0000383 auto ExpectedIpi = Session->getPDBFile().getPDBIpiStream();
Reid Kleckner651db912017-07-18 00:21:25 +0000384 if (auto E = ExpectedIpi.takeError())
Bob Haarmanb8a59c82017-10-25 22:28:38 +0000385 fatal("Type server does not have TPI stream: " + toString(std::move(E)));
Zachary Turner0d07a8e2017-12-14 18:07:04 +0000386
387 if (Config->DebugGHashes) {
388 // PDBs do not actually store global hashes, so when merging a type server
389 // PDB we have to synthesize global hashes. To do this, we first synthesize
390 // global hashes for the TPI stream, since it is independent, then we
391 // synthesize hashes for the IPI stream, using the hashes for the TPI stream
392 // as inputs.
393 auto TpiHashes = GloballyHashedType::hashTypes(ExpectedTpi->typeArray());
394 auto IpiHashes =
395 GloballyHashedType::hashIds(ExpectedIpi->typeArray(), TpiHashes);
396
397 // Merge TPI first, because the IPI stream will reference type indices.
398 if (auto Err = mergeTypeRecords(GlobalTypeTable, IndexMap.TPIMap,
399 ExpectedTpi->typeArray(), TpiHashes))
400 fatal("codeview::mergeTypeRecords failed: " + toString(std::move(Err)));
401
402 // Merge IPI.
403 if (auto Err =
404 mergeIdRecords(GlobalIDTable, IndexMap.TPIMap, IndexMap.IPIMap,
405 ExpectedIpi->typeArray(), IpiHashes))
406 fatal("codeview::mergeIdRecords failed: " + toString(std::move(Err)));
407 } else {
408 // Merge TPI first, because the IPI stream will reference type indices.
409 if (auto Err = mergeTypeRecords(TypeTable, IndexMap.TPIMap,
410 ExpectedTpi->typeArray()))
411 fatal("codeview::mergeTypeRecords failed: " + toString(std::move(Err)));
412
413 // Merge IPI.
414 if (auto Err = mergeIdRecords(IDTable, IndexMap.TPIMap, IndexMap.IPIMap,
415 ExpectedIpi->typeArray()))
416 fatal("codeview::mergeIdRecords failed: " + toString(std::move(Err)));
417 }
Reid Kleckner651db912017-07-18 00:21:25 +0000418
419 return IndexMap;
Reid Kleckner44cdb102017-06-19 17:21:45 +0000420}
421
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000422static bool remapTypeIndex(TypeIndex &TI, ArrayRef<TypeIndex> TypeIndexMap) {
423 if (TI.isSimple())
424 return true;
425 if (TI.toArrayIndex() >= TypeIndexMap.size())
426 return false;
427 TI = TypeIndexMap[TI.toArrayIndex()];
428 return true;
429}
430
Reid Kleckner8aa32ff2017-10-24 17:02:40 +0000431static void remapTypesInSymbolRecord(ObjFile *File, SymbolKind SymKind,
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000432 MutableArrayRef<uint8_t> Contents,
Reid Kleckner651db912017-07-18 00:21:25 +0000433 const CVIndexMap &IndexMap,
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000434 ArrayRef<TiReference> TypeRefs) {
435 for (const TiReference &Ref : TypeRefs) {
436 unsigned ByteSize = Ref.Count * sizeof(TypeIndex);
Reid Kleckner03b5baf2017-07-12 18:49:43 +0000437 if (Contents.size() < Ref.Offset + ByteSize)
438 fatal("symbol record too short");
Reid Kleckner651db912017-07-18 00:21:25 +0000439
440 // This can be an item index or a type index. Choose the appropriate map.
441 ArrayRef<TypeIndex> TypeOrItemMap = IndexMap.TPIMap;
Reid Kleckner8aa32ff2017-10-24 17:02:40 +0000442 bool IsItemIndex = Ref.Kind == TiRefKind::IndexRef;
443 if (IsItemIndex && IndexMap.IsTypeServerMap)
Reid Kleckner651db912017-07-18 00:21:25 +0000444 TypeOrItemMap = IndexMap.IPIMap;
445
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000446 MutableArrayRef<TypeIndex> TIs(
447 reinterpret_cast<TypeIndex *>(Contents.data() + Ref.Offset), Ref.Count);
Reid Kleckner03b5baf2017-07-12 18:49:43 +0000448 for (TypeIndex &TI : TIs) {
Reid Kleckner651db912017-07-18 00:21:25 +0000449 if (!remapTypeIndex(TI, TypeOrItemMap)) {
Reid Kleckner8aa32ff2017-10-24 17:02:40 +0000450 log("ignoring symbol record of kind 0x" + utohexstr(SymKind) + " in " +
451 File->getName() + " with bad " + (IsItemIndex ? "item" : "type") +
452 " index 0x" + utohexstr(TI.getIndex()));
Reid Kleckner5d82f682017-10-23 22:44:51 +0000453 TI = TypeIndex(SimpleTypeKind::NotTranslated);
Reid Kleckner03b5baf2017-07-12 18:49:43 +0000454 continue;
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000455 }
Reid Kleckner03b5baf2017-07-12 18:49:43 +0000456 }
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000457 }
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000458}
459
Zachary Turner60478582018-01-05 19:12:40 +0000460static void
461recordStringTableReferenceAtOffset(MutableArrayRef<uint8_t> Contents,
462 uint32_t Offset,
463 std::vector<ulittle32_t *> &StrTableRefs) {
464 Contents =
465 Contents.drop_front(Offset).take_front(sizeof(support::ulittle32_t));
466 ulittle32_t *Index = reinterpret_cast<ulittle32_t *>(Contents.data());
467 StrTableRefs.push_back(Index);
468}
469
470static void
471recordStringTableReferences(SymbolKind Kind, MutableArrayRef<uint8_t> Contents,
472 std::vector<ulittle32_t *> &StrTableRefs) {
473 // For now we only handle S_FILESTATIC, but we may need the same logic for
474 // S_DEFRANGE and S_DEFRANGE_SUBFIELD. However, I cannot seem to generate any
475 // PDBs that contain these types of records, so because of the uncertainty
476 // they are omitted here until we can prove that it's necessary.
477 switch (Kind) {
478 case SymbolKind::S_FILESTATIC:
479 // FileStaticSym::ModFileOffset
480 recordStringTableReferenceAtOffset(Contents, 4, StrTableRefs);
481 break;
482 case SymbolKind::S_DEFRANGE:
483 case SymbolKind::S_DEFRANGE_SUBFIELD:
484 log("Not fixing up string table reference in S_DEFRANGE / "
485 "S_DEFRANGE_SUBFIELD record");
486 break;
Zachary Turner9e52e502018-01-05 19:28:39 +0000487 default:
488 break;
Zachary Turner60478582018-01-05 19:12:40 +0000489 }
490}
491
Zachary Turner59e3ae82017-08-08 18:34:44 +0000492static SymbolKind symbolKind(ArrayRef<uint8_t> RecordData) {
493 const RecordPrefix *Prefix =
494 reinterpret_cast<const RecordPrefix *>(RecordData.data());
495 return static_cast<SymbolKind>(uint16_t(Prefix->RecordKind));
496}
497
498/// MSVC translates S_PROC_ID_END to S_END, and S_[LG]PROC32_ID to S_[LG]PROC32
499static void translateIdSymbols(MutableArrayRef<uint8_t> &RecordData,
Zachary Turner3e3936d2017-11-29 19:35:21 +0000500 TypeCollection &IDTable) {
Zachary Turner59e3ae82017-08-08 18:34:44 +0000501 RecordPrefix *Prefix = reinterpret_cast<RecordPrefix *>(RecordData.data());
502
503 SymbolKind Kind = symbolKind(RecordData);
504
505 if (Kind == SymbolKind::S_PROC_ID_END) {
506 Prefix->RecordKind = SymbolKind::S_END;
507 return;
508 }
509
510 // In an object file, GPROC32_ID has an embedded reference which refers to the
511 // single object file type index namespace. This has already been translated
512 // to the PDB file's ID stream index space, but we need to convert this to a
513 // symbol that refers to the type stream index space. So we remap again from
514 // ID index space to type index space.
515 if (Kind == SymbolKind::S_GPROC32_ID || Kind == SymbolKind::S_LPROC32_ID) {
516 SmallVector<TiReference, 1> Refs;
517 auto Content = RecordData.drop_front(sizeof(RecordPrefix));
518 CVSymbol Sym(Kind, RecordData);
519 discoverTypeIndicesInSymbol(Sym, Refs);
520 assert(Refs.size() == 1);
521 assert(Refs.front().Count == 1);
522
523 TypeIndex *TI =
524 reinterpret_cast<TypeIndex *>(Content.data() + Refs[0].Offset);
525 // `TI` is the index of a FuncIdRecord or MemberFuncIdRecord which lives in
526 // the IPI stream, whose `FunctionType` member refers to the TPI stream.
527 // Note that LF_FUNC_ID and LF_MEMFUNC_ID have the same record layout, and
528 // in both cases we just need the second type index.
529 if (!TI->isSimple() && !TI->isNoneType()) {
Zachary Turner3e3936d2017-11-29 19:35:21 +0000530 CVType FuncIdData = IDTable.getType(*TI);
Zachary Turner59e3ae82017-08-08 18:34:44 +0000531 SmallVector<TypeIndex, 2> Indices;
532 discoverTypeIndices(FuncIdData, Indices);
533 assert(Indices.size() == 2);
534 *TI = Indices[1];
535 }
536
537 Kind = (Kind == SymbolKind::S_GPROC32_ID) ? SymbolKind::S_GPROC32
538 : SymbolKind::S_LPROC32;
539 Prefix->RecordKind = uint16_t(Kind);
540 }
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000541}
542
543/// Copy the symbol record. In a PDB, symbol records must be 4 byte aligned.
544/// The object file may not be aligned.
545static MutableArrayRef<uint8_t> copySymbolForPdb(const CVSymbol &Sym,
546 BumpPtrAllocator &Alloc) {
547 size_t Size = alignTo(Sym.length(), alignOf(CodeViewContainer::Pdb));
548 assert(Size >= 4 && "record too short");
549 assert(Size <= MaxRecordLength && "record too long");
550 void *Mem = Alloc.Allocate(Size, 4);
551
552 // Copy the symbol record and zero out any padding bytes.
553 MutableArrayRef<uint8_t> NewData(reinterpret_cast<uint8_t *>(Mem), Size);
554 memcpy(NewData.data(), Sym.data().data(), Sym.length());
555 memset(NewData.data() + Sym.length(), 0, Size - Sym.length());
556
557 // Update the record prefix length. It should point to the beginning of the
Zachary Turner59e3ae82017-08-08 18:34:44 +0000558 // next record.
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000559 auto *Prefix = reinterpret_cast<RecordPrefix *>(Mem);
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000560 Prefix->RecordLen = Size - 2;
561 return NewData;
562}
563
Reid Kleckner3f851922017-07-06 16:39:32 +0000564/// Return true if this symbol opens a scope. This implies that the symbol has
565/// "parent" and "end" fields, which contain the offset of the S_END or
566/// S_INLINESITE_END record.
567static bool symbolOpensScope(SymbolKind Kind) {
568 switch (Kind) {
569 case SymbolKind::S_GPROC32:
570 case SymbolKind::S_LPROC32:
571 case SymbolKind::S_LPROC32_ID:
572 case SymbolKind::S_GPROC32_ID:
573 case SymbolKind::S_BLOCK32:
574 case SymbolKind::S_SEPCODE:
575 case SymbolKind::S_THUNK32:
576 case SymbolKind::S_INLINESITE:
577 case SymbolKind::S_INLINESITE2:
578 return true;
579 default:
580 break;
581 }
582 return false;
583}
584
585static bool symbolEndsScope(SymbolKind Kind) {
586 switch (Kind) {
587 case SymbolKind::S_END:
588 case SymbolKind::S_PROC_ID_END:
589 case SymbolKind::S_INLINESITE_END:
590 return true;
591 default:
592 break;
593 }
594 return false;
595}
596
597struct ScopeRecord {
598 ulittle32_t PtrParent;
599 ulittle32_t PtrEnd;
600};
601
602struct SymbolScope {
603 ScopeRecord *OpeningRecord;
604 uint32_t ScopeOffset;
605};
606
607static void scopeStackOpen(SmallVectorImpl<SymbolScope> &Stack,
608 uint32_t CurOffset, CVSymbol &Sym) {
609 assert(symbolOpensScope(Sym.kind()));
610 SymbolScope S;
611 S.ScopeOffset = CurOffset;
612 S.OpeningRecord = const_cast<ScopeRecord *>(
613 reinterpret_cast<const ScopeRecord *>(Sym.content().data()));
614 S.OpeningRecord->PtrParent = Stack.empty() ? 0 : Stack.back().ScopeOffset;
615 Stack.push_back(S);
616}
617
618static void scopeStackClose(SmallVectorImpl<SymbolScope> &Stack,
Rui Ueyamae1b48e02017-07-26 23:05:24 +0000619 uint32_t CurOffset, ObjFile *File) {
Reid Kleckner3f851922017-07-06 16:39:32 +0000620 if (Stack.empty()) {
621 warn("symbol scopes are not balanced in " + File->getName());
622 return;
623 }
624 SymbolScope S = Stack.pop_back_val();
625 S.OpeningRecord->PtrEnd = CurOffset;
626}
627
Zachary Turneree9906d2017-08-11 19:00:03 +0000628static bool symbolGoesInModuleStream(const CVSymbol &Sym) {
629 switch (Sym.kind()) {
630 case SymbolKind::S_GDATA32:
631 case SymbolKind::S_CONSTANT:
632 case SymbolKind::S_UDT:
633 // We really should not be seeing S_PROCREF and S_LPROCREF in the first place
634 // since they are synthesized by the linker in response to S_GPROC32 and
635 // S_LPROC32, but if we do see them, don't put them in the module stream I
636 // guess.
637 case SymbolKind::S_PROCREF:
638 case SymbolKind::S_LPROCREF:
639 return false;
640 // S_GDATA32 does not go in the module stream, but S_LDATA32 does.
641 case SymbolKind::S_LDATA32:
642 default:
643 return true;
644 }
645}
646
647static bool symbolGoesInGlobalsStream(const CVSymbol &Sym) {
648 switch (Sym.kind()) {
649 case SymbolKind::S_CONSTANT:
Zachary Turneree9906d2017-08-11 19:00:03 +0000650 case SymbolKind::S_GDATA32:
651 // S_LDATA32 goes in both the module stream and the globals stream.
652 case SymbolKind::S_LDATA32:
653 case SymbolKind::S_GPROC32:
654 case SymbolKind::S_LPROC32:
655 // We really should not be seeing S_PROCREF and S_LPROCREF in the first place
656 // since they are synthesized by the linker in response to S_GPROC32 and
657 // S_LPROC32, but if we do see them, copy them straight through.
658 case SymbolKind::S_PROCREF:
659 case SymbolKind::S_LPROCREF:
660 return true;
Zachary Turner302dc8b2017-08-14 18:44:58 +0000661 // FIXME: For now, we drop all S_UDT symbols (i.e. they don't go in the
662 // globals stream or the modules stream). These have special handling which
663 // needs more investigation before we can get right, but by putting them all
664 // into the globals stream WinDbg fails to display local variables of class
665 // types saying that it cannot find the type Foo *. So as a stopgap just to
666 // keep things working, we drop them.
667 case SymbolKind::S_UDT:
Zachary Turneree9906d2017-08-11 19:00:03 +0000668 default:
669 return false;
670 }
671}
672
673static void addGlobalSymbol(pdb::GSIStreamBuilder &Builder, ObjFile &File,
674 const CVSymbol &Sym) {
675 switch (Sym.kind()) {
676 case SymbolKind::S_CONSTANT:
677 case SymbolKind::S_UDT:
678 case SymbolKind::S_GDATA32:
679 case SymbolKind::S_LDATA32:
680 case SymbolKind::S_PROCREF:
681 case SymbolKind::S_LPROCREF:
682 Builder.addGlobalSymbol(Sym);
683 break;
684 case SymbolKind::S_GPROC32:
685 case SymbolKind::S_LPROC32: {
686 SymbolRecordKind K = SymbolRecordKind::ProcRefSym;
687 if (Sym.kind() == SymbolKind::S_LPROC32)
688 K = SymbolRecordKind::LocalProcRef;
689 ProcRefSym PS(K);
690 PS.Module = static_cast<uint16_t>(File.ModuleDBI->getModuleIndex());
691 // For some reason, MSVC seems to add one to this value.
692 ++PS.Module;
693 PS.Name = getSymbolName(Sym);
694 PS.SumName = 0;
695 PS.SymOffset = File.ModuleDBI->getNextSymbolOffset();
696 Builder.addGlobalSymbol(PS);
697 break;
698 }
699 default:
700 llvm_unreachable("Invalid symbol kind!");
701 }
702}
703
Rui Ueyamae1b48e02017-07-26 23:05:24 +0000704static void mergeSymbolRecords(BumpPtrAllocator &Alloc, ObjFile *File,
Zachary Turneree9906d2017-08-11 19:00:03 +0000705 pdb::GSIStreamBuilder &GsiBuilder,
Reid Kleckner651db912017-07-18 00:21:25 +0000706 const CVIndexMap &IndexMap,
Zachary Turner3e3936d2017-11-29 19:35:21 +0000707 TypeCollection &IDTable,
Zachary Turner60478582018-01-05 19:12:40 +0000708 std::vector<ulittle32_t *> &StringTableRefs,
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000709 BinaryStreamRef SymData) {
710 // FIXME: Improve error recovery by warning and skipping records when
711 // possible.
Zachary Turner1bc2ce62018-01-18 18:35:01 +0000712 ArrayRef<uint8_t> SymsBuffer;
713 cantFail(SymData.readBytes(0, SymData.getLength(), SymsBuffer));
Reid Kleckner3f851922017-07-06 16:39:32 +0000714 SmallVector<SymbolScope, 4> Scopes;
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000715
Zachary Turner1bc2ce62018-01-18 18:35:01 +0000716 auto EC = forEachCodeViewRecord<CVSymbol>(
717 SymsBuffer, [&](const CVSymbol &Sym) -> llvm::Error {
718 // Discover type index references in the record. Skip it if we don't
719 // know where they are.
720 SmallVector<TiReference, 32> TypeRefs;
721 if (!discoverTypeIndicesInSymbol(Sym, TypeRefs)) {
722 log("ignoring unknown symbol record with kind 0x" +
723 utohexstr(Sym.kind()));
724 return Error::success();
725 }
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000726
Zachary Turner1bc2ce62018-01-18 18:35:01 +0000727 // Copy the symbol record so we can mutate it.
728 MutableArrayRef<uint8_t> NewData = copySymbolForPdb(Sym, Alloc);
Zachary Turner59e3ae82017-08-08 18:34:44 +0000729
Zachary Turner1bc2ce62018-01-18 18:35:01 +0000730 // Re-map all the type index references.
731 MutableArrayRef<uint8_t> Contents =
732 NewData.drop_front(sizeof(RecordPrefix));
733 remapTypesInSymbolRecord(File, Sym.kind(), Contents, IndexMap,
734 TypeRefs);
Zachary Turner59e3ae82017-08-08 18:34:44 +0000735
Zachary Turner1bc2ce62018-01-18 18:35:01 +0000736 // An object file may have S_xxx_ID symbols, but these get converted to
737 // "real" symbols in a PDB.
738 translateIdSymbols(NewData, IDTable);
Zachary Turner60478582018-01-05 19:12:40 +0000739
Zachary Turner1bc2ce62018-01-18 18:35:01 +0000740 // If this record refers to an offset in the object file's string table,
741 // add that item to the global PDB string table and re-write the index.
742 recordStringTableReferences(Sym.kind(), Contents, StringTableRefs);
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000743
Zachary Turner1bc2ce62018-01-18 18:35:01 +0000744 SymbolKind NewKind = symbolKind(NewData);
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000745
Zachary Turner1bc2ce62018-01-18 18:35:01 +0000746 // Fill in "Parent" and "End" fields by maintaining a stack of scopes.
747 CVSymbol NewSym(NewKind, NewData);
748 if (symbolOpensScope(NewKind))
749 scopeStackOpen(Scopes, File->ModuleDBI->getNextSymbolOffset(),
750 NewSym);
751 else if (symbolEndsScope(NewKind))
752 scopeStackClose(Scopes, File->ModuleDBI->getNextSymbolOffset(), File);
Zachary Turneree9906d2017-08-11 19:00:03 +0000753
Zachary Turner1bc2ce62018-01-18 18:35:01 +0000754 // Add the symbol to the globals stream if necessary. Do this before
755 // adding the symbol to the module since we may need to get the next
756 // symbol offset, and writing to the module's symbol stream will update
757 // that offset.
758 if (symbolGoesInGlobalsStream(NewSym))
759 addGlobalSymbol(GsiBuilder, *File, NewSym);
760
761 // Add the symbol to the module.
762 if (symbolGoesInModuleStream(NewSym))
763 File->ModuleDBI->addSymbol(NewSym);
764 return Error::success();
765 });
766 cantFail(std::move(EC));
Reid Klecknerd0e6e242017-06-21 17:25:56 +0000767}
768
Reid Kleckner44cdb102017-06-19 17:21:45 +0000769// Allocate memory for a .debug$S section and relocate it.
770static ArrayRef<uint8_t> relocateDebugChunk(BumpPtrAllocator &Alloc,
771 SectionChunk *DebugChunk) {
772 uint8_t *Buffer = Alloc.Allocate<uint8_t>(DebugChunk->getSize());
773 assert(DebugChunk->OutputSectionOff == 0 &&
774 "debug sections should not be in output sections");
775 DebugChunk->writeTo(Buffer);
776 return consumeDebugMagic(makeArrayRef(Buffer, DebugChunk->getSize()),
777 ".debug$S");
778}
779
Rui Ueyamae1b48e02017-07-26 23:05:24 +0000780void PDBLinker::addObjFile(ObjFile *File) {
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000781 // Add a module descriptor for every object file. We need to put an absolute
782 // path to the object into the PDB. If this is a plain object, we make its
783 // path absolute. If it's an object in an archive, we make the archive path
784 // absolute.
785 bool InArchive = !File->ParentName.empty();
786 SmallString<128> Path = InArchive ? File->ParentName : File->getName();
787 sys::fs::make_absolute(Path);
788 sys::path::native(Path, sys::path::Style::windows);
789 StringRef Name = InArchive ? File->getName() : StringRef(Path);
Zachary Turner2897e032017-05-25 21:16:03 +0000790
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000791 File->ModuleDBI = &ExitOnErr(Builder.getDbiBuilder().addModuleInfo(Name));
792 File->ModuleDBI->setObjFileName(Path);
Reid Kleckner44cdb102017-06-19 17:21:45 +0000793
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000794 // Before we can process symbol substreams from .debug$S, we need to process
795 // type information, file checksums, and the string table. Add type info to
796 // the PDB first, so that we can get the map from object file type and item
797 // indices to PDB type and item indices.
Reid Kleckner651db912017-07-18 00:21:25 +0000798 CVIndexMap ObjectIndexMap;
Colden Cullenb9b6ed92018-01-31 17:48:04 +0000799 auto IndexMapResult = mergeDebugT(File, ObjectIndexMap);
800
801 // If the .debug$T sections fail to merge, assume there is no debug info.
802 if (!IndexMapResult) {
803 warn("Type server PDB for " + Name + " is invalid, ignoring debug info. " +
804 toString(IndexMapResult.takeError()));
805 return;
806 }
807
808 const CVIndexMap &IndexMap = *IndexMapResult;
Zachary Turner448dea42017-07-07 18:46:14 +0000809
Zachary Turner727f1532018-01-17 19:16:26 +0000810 ScopedTimer T(SymbolMergingTimer);
811
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000812 // Now do all live .debug$S sections.
Zachary Turner60478582018-01-05 19:12:40 +0000813 DebugStringTableSubsectionRef CVStrTab;
814 DebugChecksumsSubsectionRef Checksums;
815 std::vector<ulittle32_t *> StringTableReferences;
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000816 for (SectionChunk *DebugChunk : File->getDebugChunks()) {
817 if (!DebugChunk->isLive() || DebugChunk->getSectionName() != ".debug$S")
818 continue;
Reid Kleckner8cbdd0c2017-06-13 15:49:13 +0000819
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000820 ArrayRef<uint8_t> RelocatedDebugContents =
821 relocateDebugChunk(Alloc, DebugChunk);
822 if (RelocatedDebugContents.empty())
823 continue;
Reid Kleckner8cbdd0c2017-06-13 15:49:13 +0000824
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000825 DebugSubsectionArray Subsections;
826 BinaryStreamReader Reader(RelocatedDebugContents, support::little);
827 ExitOnErr(Reader.readArray(Subsections, RelocatedDebugContents.size()));
Rui Ueyama52896622017-01-12 03:09:25 +0000828
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000829 for (const DebugSubsectionRecord &SS : Subsections) {
830 switch (SS.kind()) {
Zachary Turner60478582018-01-05 19:12:40 +0000831 case DebugSubsectionKind::StringTable: {
832 auto Data = SS.getRecordData();
833 ArrayRef<uint8_t> Buffer;
834 cantFail(Data.readLongestContiguousChunk(0, Buffer));
835 assert(!CVStrTab.valid() &&
836 "Encountered multiple string table subsections!");
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000837 ExitOnErr(CVStrTab.initialize(SS.getRecordData()));
838 break;
Zachary Turner60478582018-01-05 19:12:40 +0000839 }
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000840 case DebugSubsectionKind::FileChecksums:
Zachary Turner60478582018-01-05 19:12:40 +0000841 assert(!Checksums.valid() &&
842 "Encountered multiple checksum subsections!");
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000843 ExitOnErr(Checksums.initialize(SS.getRecordData()));
844 break;
845 case DebugSubsectionKind::Lines:
846 // We can add the relocated line table directly to the PDB without
847 // modification because the file checksum offsets will stay the same.
848 File->ModuleDBI->addDebugSubsection(SS);
849 break;
850 case DebugSubsectionKind::Symbols:
Zachary Turner0d07a8e2017-12-14 18:07:04 +0000851 if (Config->DebugGHashes) {
852 mergeSymbolRecords(Alloc, File, Builder.getGsiBuilder(), IndexMap,
Zachary Turner60478582018-01-05 19:12:40 +0000853 GlobalIDTable, StringTableReferences,
854 SS.getRecordData());
Zachary Turner0d07a8e2017-12-14 18:07:04 +0000855 } else {
856 mergeSymbolRecords(Alloc, File, Builder.getGsiBuilder(), IndexMap,
Zachary Turner60478582018-01-05 19:12:40 +0000857 IDTable, StringTableReferences,
858 SS.getRecordData());
Zachary Turner0d07a8e2017-12-14 18:07:04 +0000859 }
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000860 break;
861 default:
862 // FIXME: Process the rest of the subsections.
863 break;
Reid Kleckner44cdb102017-06-19 17:21:45 +0000864 }
865 }
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000866 }
Zachary Turner60478582018-01-05 19:12:40 +0000867
868 // We should have seen all debug subsections across the entire object file now
869 // which means that if a StringTable subsection and Checksums subsection were
870 // present, now is the time to handle them.
871 if (!CVStrTab.valid()) {
872 if (Checksums.valid())
873 fatal(".debug$S sections with a checksums subsection must also contain a "
874 "string table subsection");
875
876 if (!StringTableReferences.empty())
877 warn("No StringTable subsection was encountered, but there are string "
878 "table references");
879 return;
880 }
881
882 // Rewrite each string table reference based on the value that the string
883 // assumes in the final PDB.
884 for (ulittle32_t *Ref : StringTableReferences) {
885 auto ExpectedString = CVStrTab.getString(*Ref);
886 if (!ExpectedString) {
887 warn("Invalid string table reference");
888 consumeError(ExpectedString.takeError());
889 continue;
890 }
891
892 *Ref = PDBStrTab.insert(*ExpectedString);
893 }
894
895 // Make a new file checksum table that refers to offsets in the PDB-wide
896 // string table. Generally the string table subsection appears after the
897 // checksum table, so we have to do this after looping over all the
898 // subsections.
899 auto NewChecksums = make_unique<DebugChecksumsSubsection>(PDBStrTab);
900 for (FileChecksumEntry &FC : Checksums) {
901 StringRef FileName = ExitOnErr(CVStrTab.getString(FC.FileNameOffset));
902 ExitOnErr(Builder.getDbiBuilder().addModuleSourceFile(*File->ModuleDBI,
903 FileName));
904 NewChecksums->addChecksum(FileName, FC.Kind, FC.Checksum);
905 }
906 File->ModuleDBI->addDebugSubsection(std::move(NewChecksums));
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000907}
908
Reid Klecknereacdf042017-07-27 18:25:59 +0000909static PublicSym32 createPublic(Defined *Def) {
910 PublicSym32 Pub(SymbolKind::S_PUB32);
911 Pub.Name = Def->getName();
912 if (auto *D = dyn_cast<DefinedCOFF>(Def)) {
913 if (D->getCOFFSymbol().isFunctionDefinition())
914 Pub.Flags = PublicSymFlags::Function;
915 } else if (isa<DefinedImportThunk>(Def)) {
916 Pub.Flags = PublicSymFlags::Function;
917 }
918
919 OutputSection *OS = Def->getChunk()->getOutputSection();
920 assert(OS && "all publics should be in final image");
921 Pub.Offset = Def->getRVA() - OS->getRVA();
922 Pub.Segment = OS->SectionIndex;
923 return Pub;
924}
925
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000926// Add all object files to the PDB. Merge .debug$T sections into IpiData and
927// TpiData.
928void PDBLinker::addObjectsToPDB() {
Zachary Turner727f1532018-01-17 19:16:26 +0000929 ScopedTimer T1(AddObjectsTimer);
Rui Ueyamaacd632d2017-07-27 00:45:26 +0000930 for (ObjFile *File : ObjFile::Instances)
Rui Ueyamae1b48e02017-07-26 23:05:24 +0000931 addObjFile(File);
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000932
933 Builder.getStringTableBuilder().setStrings(PDBStrTab);
Zachary Turner727f1532018-01-17 19:16:26 +0000934 T1.stop();
Reid Kleckner44cdb102017-06-19 17:21:45 +0000935
Zachary Turner0d07a8e2017-12-14 18:07:04 +0000936 // Construct TPI and IPI stream contents.
Zachary Turner727f1532018-01-17 19:16:26 +0000937 ScopedTimer T2(TpiStreamLayoutTimer);
Zachary Turner0d07a8e2017-12-14 18:07:04 +0000938 if (Config->DebugGHashes) {
939 addTypeInfo(Builder.getTpiBuilder(), GlobalTypeTable);
940 addTypeInfo(Builder.getIpiBuilder(), GlobalIDTable);
941 } else {
942 addTypeInfo(Builder.getTpiBuilder(), TypeTable);
943 addTypeInfo(Builder.getIpiBuilder(), IDTable);
944 }
Zachary Turner727f1532018-01-17 19:16:26 +0000945 T2.stop();
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000946
Zachary Turner727f1532018-01-17 19:16:26 +0000947 ScopedTimer T3(GlobalsLayoutTimer);
Zachary Turneree9906d2017-08-11 19:00:03 +0000948 // Compute the public and global symbols.
949 auto &GsiBuilder = Builder.getGsiBuilder();
Reid Klecknereacdf042017-07-27 18:25:59 +0000950 std::vector<PublicSym32> Publics;
Rui Ueyamaf52496e2017-11-03 21:21:47 +0000951 Symtab->forEachSymbol([&Publics](Symbol *S) {
Reid Klecknereacdf042017-07-27 18:25:59 +0000952 // Only emit defined, live symbols that have a chunk.
Rui Ueyama616cd992017-10-31 16:10:24 +0000953 auto *Def = dyn_cast<Defined>(S);
Reid Klecknereacdf042017-07-27 18:25:59 +0000954 if (Def && Def->isLive() && Def->getChunk())
955 Publics.push_back(createPublic(Def));
956 });
Reid Kleckner0faf6d72017-07-14 00:14:58 +0000957
Reid Klecknereacdf042017-07-27 18:25:59 +0000958 if (!Publics.empty()) {
959 // Sort the public symbols and add them to the stream.
960 std::sort(Publics.begin(), Publics.end(),
961 [](const PublicSym32 &L, const PublicSym32 &R) {
962 return L.Name < R.Name;
963 });
Reid Klecknereacdf042017-07-27 18:25:59 +0000964 for (const PublicSym32 &Pub : Publics)
Zachary Turner946204c2017-08-09 04:23:25 +0000965 GsiBuilder.addPublicSymbol(Pub);
Reid Klecknereacdf042017-07-27 18:25:59 +0000966 }
Rui Ueyama52896622017-01-12 03:09:25 +0000967}
968
Zachary Turner28e31ee2017-08-11 20:46:28 +0000969static void addCommonLinkerModuleSymbols(StringRef Path,
970 pdb::DbiModuleDescriptorBuilder &Mod,
971 BumpPtrAllocator &Allocator) {
Zachary Turner28e31ee2017-08-11 20:46:28 +0000972 ObjNameSym ONS(SymbolRecordKind::ObjNameSym);
973 Compile3Sym CS(SymbolRecordKind::Compile3Sym);
974 EnvBlockSym EBS(SymbolRecordKind::EnvBlockSym);
Zachary Turner6708e0b2017-07-10 21:01:37 +0000975
976 ONS.Name = "* Linker *";
977 ONS.Signature = 0;
978
979 CS.Machine = Config->is64() ? CPUType::X64 : CPUType::Intel80386;
Zachary Turnerb57884e2017-08-11 21:14:01 +0000980 // Interestingly, if we set the string to 0.0.0.0, then when trying to view
981 // local variables WinDbg emits an error that private symbols are not present.
982 // By setting this to a valid MSVC linker version string, local variables are
983 // displayed properly. As such, even though it is not representative of
Zachary Turnerf6822c82017-08-11 20:46:47 +0000984 // LLVM's version information, we need this for compatibility.
Zachary Turner6708e0b2017-07-10 21:01:37 +0000985 CS.Flags = CompileSym3Flags::None;
Zachary Turnerf6822c82017-08-11 20:46:47 +0000986 CS.VersionBackendBuild = 25019;
987 CS.VersionBackendMajor = 14;
988 CS.VersionBackendMinor = 10;
Zachary Turner6708e0b2017-07-10 21:01:37 +0000989 CS.VersionBackendQFE = 0;
Zachary Turnerf6822c82017-08-11 20:46:47 +0000990
991 // MSVC also sets the frontend to 0.0.0.0 since this is specifically for the
992 // linker module (which is by definition a backend), so we don't need to do
993 // anything here. Also, it seems we can use "LLVM Linker" for the linker name
994 // without any problems. Only the backend version has to be hardcoded to a
995 // magic number.
Zachary Turner6708e0b2017-07-10 21:01:37 +0000996 CS.VersionFrontendBuild = 0;
997 CS.VersionFrontendMajor = 0;
998 CS.VersionFrontendMinor = 0;
999 CS.VersionFrontendQFE = 0;
1000 CS.Version = "LLVM Linker";
1001 CS.setLanguage(SourceLanguage::Link);
1002
1003 ArrayRef<StringRef> Args = makeArrayRef(Config->Argv).drop_front();
1004 std::string ArgStr = llvm::join(Args, " ");
1005 EBS.Fields.push_back("cwd");
1006 SmallString<64> cwd;
Reid Kleckner0faf6d72017-07-14 00:14:58 +00001007 sys::fs::current_path(cwd);
Zachary Turner6708e0b2017-07-10 21:01:37 +00001008 EBS.Fields.push_back(cwd);
1009 EBS.Fields.push_back("exe");
Zachary Turnerf6822c82017-08-11 20:46:47 +00001010 SmallString<64> exe = Config->Argv[0];
1011 llvm::sys::fs::make_absolute(exe);
1012 EBS.Fields.push_back(exe);
Zachary Turner6708e0b2017-07-10 21:01:37 +00001013 EBS.Fields.push_back("pdb");
1014 EBS.Fields.push_back(Path);
1015 EBS.Fields.push_back("cmd");
1016 EBS.Fields.push_back(ArgStr);
1017 Mod.addSymbol(codeview::SymbolSerializer::writeOneSymbol(
1018 ONS, Allocator, CodeViewContainer::Pdb));
1019 Mod.addSymbol(codeview::SymbolSerializer::writeOneSymbol(
1020 CS, Allocator, CodeViewContainer::Pdb));
1021 Mod.addSymbol(codeview::SymbolSerializer::writeOneSymbol(
1022 EBS, Allocator, CodeViewContainer::Pdb));
1023}
1024
Zachary Turner28e31ee2017-08-11 20:46:28 +00001025static void addLinkerModuleSectionSymbol(pdb::DbiModuleDescriptorBuilder &Mod,
1026 OutputSection &OS,
1027 BumpPtrAllocator &Allocator) {
1028 SectionSym Sym(SymbolRecordKind::SectionSym);
Zachary Turnerf6822c82017-08-11 20:46:47 +00001029 Sym.Alignment = 12; // 2^12 = 4KB
Zachary Turner28e31ee2017-08-11 20:46:28 +00001030 Sym.Characteristics = OS.getCharacteristics();
1031 Sym.Length = OS.getVirtualSize();
Peter Collingbourne435b09912018-03-15 21:13:46 +00001032 Sym.Name = OS.Name;
Zachary Turner28e31ee2017-08-11 20:46:28 +00001033 Sym.Rva = OS.getRVA();
1034 Sym.SectionNumber = OS.SectionIndex;
1035 Mod.addSymbol(codeview::SymbolSerializer::writeOneSymbol(
1036 Sym, Allocator, CodeViewContainer::Pdb));
1037}
1038
Rui Ueyama09e0b5f2016-11-12 00:00:51 +00001039// Creates a PDB file.
Reid Kleckner175af4b2017-08-03 21:15:09 +00001040void coff::createPDB(SymbolTable *Symtab,
1041 ArrayRef<OutputSection *> OutputSections,
1042 ArrayRef<uint8_t> SectionTable,
Zachary Turner024323c2017-08-15 21:31:41 +00001043 const llvm::codeview::DebugInfo &BuildId) {
Zachary Turner727f1532018-01-17 19:16:26 +00001044 ScopedTimer T1(TotalPdbLinkTimer);
Reid Kleckner0faf6d72017-07-14 00:14:58 +00001045 PDBLinker PDB(Symtab);
Zachary Turner024323c2017-08-15 21:31:41 +00001046 PDB.initialize(BuildId);
Reid Kleckner0faf6d72017-07-14 00:14:58 +00001047 PDB.addObjectsToPDB();
Reid Kleckner175af4b2017-08-03 21:15:09 +00001048 PDB.addSections(OutputSections, SectionTable);
Zachary Turner727f1532018-01-17 19:16:26 +00001049
1050 ScopedTimer T2(DiskCommitTimer);
Reid Kleckner0faf6d72017-07-14 00:14:58 +00001051 PDB.commit();
1052}
1053
Zachary Turner024323c2017-08-15 21:31:41 +00001054void PDBLinker::initialize(const llvm::codeview::DebugInfo &BuildId) {
Rui Ueyama12979542016-09-30 20:53:45 +00001055 ExitOnErr(Builder.initialize(4096)); // 4096 is blocksize
Rui Ueyama7f382992016-09-15 18:55:18 +00001056
Rui Ueyama8d3fb5d2016-10-05 22:08:58 +00001057 // Create streams in MSF for predefined streams, namely
1058 // PDB, TPI, DBI and IPI.
1059 for (int I = 0; I < (int)pdb::kSpecialStreamCount; ++I)
1060 ExitOnErr(Builder.getMsfBuilder().addStream(0));
Rui Ueyama7f382992016-09-15 18:55:18 +00001061
Rui Ueyamabb542b32016-09-16 22:51:17 +00001062 // Add an Info stream.
1063 auto &InfoBuilder = Builder.getInfoBuilder();
Zachary Turner024323c2017-08-15 21:31:41 +00001064 GUID uuid;
1065 memcpy(&uuid, &BuildId.PDB70.Signature, sizeof(uuid));
Zachary Turnerc6a75a62018-03-01 18:00:29 +00001066 InfoBuilder.setAge(BuildId.PDB70.Age);
Saleem Abdulrasool0acd6dd2017-02-07 04:28:02 +00001067 InfoBuilder.setGuid(uuid);
Rui Ueyamabb542b32016-09-16 22:51:17 +00001068 InfoBuilder.setVersion(pdb::PdbRaw_ImplVer::PdbImplVC70);
Rui Ueyama7f382992016-09-15 18:55:18 +00001069
Zachary Turner6c4bfba2017-07-07 05:04:36 +00001070 // Add an empty DBI stream.
Reid Kleckner8cbdd0c2017-06-13 15:49:13 +00001071 pdb::DbiStreamBuilder &DbiBuilder = Builder.getDbiBuilder();
Zachary Turner024323c2017-08-15 21:31:41 +00001072 DbiBuilder.setAge(BuildId.PDB70.Age);
Zachary Turnerc1e93e52017-07-07 18:45:56 +00001073 DbiBuilder.setVersionHeader(pdb::PdbDbiV70);
Reid Kleckner0faf6d72017-07-14 00:14:58 +00001074}
Rui Ueyama1343fac2016-10-06 22:52:01 +00001075
Reid Kleckner175af4b2017-08-03 21:15:09 +00001076void PDBLinker::addSectionContrib(pdb::DbiModuleDescriptorBuilder &LinkerModule,
1077 OutputSection *OS, Chunk *C) {
1078 pdb::SectionContrib SC;
1079 memset(&SC, 0, sizeof(SC));
1080 SC.ISect = OS->SectionIndex;
1081 SC.Off = C->getRVA() - OS->getRVA();
1082 SC.Size = C->getSize();
1083 if (auto *SecChunk = dyn_cast<SectionChunk>(C)) {
1084 SC.Characteristics = SecChunk->Header->Characteristics;
1085 SC.Imod = SecChunk->File->ModuleDBI->getModuleIndex();
Zachary Turner676386ff2017-08-07 20:23:45 +00001086 ArrayRef<uint8_t> Contents = SecChunk->getContents();
1087 JamCRC CRC(0);
1088 ArrayRef<char> CharContents = makeArrayRef(
1089 reinterpret_cast<const char *>(Contents.data()), Contents.size());
1090 CRC.update(CharContents);
1091 SC.DataCrc = CRC.getCRC();
Reid Kleckner175af4b2017-08-03 21:15:09 +00001092 } else {
1093 SC.Characteristics = OS->getCharacteristics();
1094 // FIXME: When we start creating DBI for import libraries, use those here.
1095 SC.Imod = LinkerModule.getModuleIndex();
1096 }
Reid Kleckner175af4b2017-08-03 21:15:09 +00001097 SC.RelocCrc = 0; // FIXME
1098 Builder.getDbiBuilder().addSectionContrib(SC);
1099}
Rui Ueyama09e0b5f2016-11-12 00:00:51 +00001100
Reid Kleckner175af4b2017-08-03 21:15:09 +00001101void PDBLinker::addSections(ArrayRef<OutputSection *> OutputSections,
1102 ArrayRef<uint8_t> SectionTable) {
Reid Kleckner0faf6d72017-07-14 00:14:58 +00001103 // It's not entirely clear what this is, but the * Linker * module uses it.
Reid Kleckner175af4b2017-08-03 21:15:09 +00001104 pdb::DbiStreamBuilder &DbiBuilder = Builder.getDbiBuilder();
Reid Kleckner0faf6d72017-07-14 00:14:58 +00001105 NativePath = Config->PDBPath;
1106 sys::fs::make_absolute(NativePath);
1107 sys::path::native(NativePath, sys::path::Style::windows);
1108 uint32_t PdbFilePathNI = DbiBuilder.addECName(NativePath);
Zachary Turner6c4bfba2017-07-07 05:04:36 +00001109 auto &LinkerModule = ExitOnErr(DbiBuilder.addModuleInfo("* Linker *"));
1110 LinkerModule.setPdbFilePathNI(PdbFilePathNI);
Zachary Turner28e31ee2017-08-11 20:46:28 +00001111 addCommonLinkerModuleSymbols(NativePath, LinkerModule, Alloc);
Rui Ueyamac91f7162016-11-16 01:10:46 +00001112
Reid Kleckner175af4b2017-08-03 21:15:09 +00001113 // Add section contributions. They must be ordered by ascending RVA.
Zachary Turner28e31ee2017-08-11 20:46:28 +00001114 for (OutputSection *OS : OutputSections) {
1115 addLinkerModuleSectionSymbol(LinkerModule, *OS, Alloc);
Reid Kleckner175af4b2017-08-03 21:15:09 +00001116 for (Chunk *C : OS->getChunks())
1117 addSectionContrib(LinkerModule, OS, C);
Zachary Turner28e31ee2017-08-11 20:46:28 +00001118 }
Reid Kleckner175af4b2017-08-03 21:15:09 +00001119
1120 // Add Section Map stream.
1121 ArrayRef<object::coff_section> Sections = {
1122 (const object::coff_section *)SectionTable.data(),
1123 SectionTable.size() / sizeof(object::coff_section)};
1124 SectionMap = pdb::DbiStreamBuilder::createSectionMap(Sections);
1125 DbiBuilder.setSectionMap(SectionMap);
1126
Rui Ueyama9f66f822016-10-11 19:45:07 +00001127 // Add COFF section header stream.
1128 ExitOnErr(
1129 DbiBuilder.addDbgStream(pdb::DbgHeaderType::SectionHdr, SectionTable));
Reid Kleckner0faf6d72017-07-14 00:14:58 +00001130}
Rui Ueyama9f66f822016-10-11 19:45:07 +00001131
Reid Kleckner0faf6d72017-07-14 00:14:58 +00001132void PDBLinker::commit() {
Rui Ueyama3e9d6bb2016-09-26 23:53:55 +00001133 // Write to a file.
Zachary Turner6708e0b2017-07-10 21:01:37 +00001134 ExitOnErr(Builder.commit(Config->PDBPath));
Rui Ueyamae7378242015-12-04 23:11:05 +00001135}