1 //===- PDB.cpp ------------------------------------------------------------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
13 #include "llvm/Support/Endian.h"
14 #include "llvm/Support/FileOutputBuffer.h"
18 using namespace llvm::support;
19 using namespace llvm::support::endian;
21 const int PageSize = 4096;
22 const uint8_t Magic[32] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0\0";
29 ulittle32_t PageCount;
32 ulittle32_t RootPointer;
36 void lld::coff::createPDB(StringRef Path) {
38 size_t FileSize = PageSize * 3;
39 ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
40 FileOutputBuffer::create(Path, FileSize);
41 if (auto EC = BufferOrErr.getError())
42 fatal(EC, "failed to open " + Path);
43 std::unique_ptr<FileOutputBuffer> Buffer = std::move(*BufferOrErr);
45 // Write the file header.
46 uint8_t *Buf = Buffer->getBufferStart();
47 auto *Hdr = reinterpret_cast<PDBHeader *>(Buf);
48 memcpy(Hdr->Magic, Magic, sizeof(Magic));
49 Hdr->PageSize = PageSize;
50 // I don't know what FpmPage field means, but it must not be 0.
52 Hdr->PageCount = FileSize / PageSize;
53 // Root directory is empty, containing only the length field.
55 // Root directory is on page 1.
58 // Write the root directory. Root stream is on page 2.
59 write32le(Buf + PageSize, 2);