2015-12-05 07:11:05 +08:00
|
|
|
//===- PDB.cpp ------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Driver.h"
|
|
|
|
#include "Error.h"
|
|
|
|
#include "Symbols.h"
|
2015-12-09 02:39:55 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
2015-12-05 07:11:05 +08:00
|
|
|
#include "llvm/Support/FileOutputBuffer.h"
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
using namespace llvm;
|
2015-12-09 02:39:55 +08:00
|
|
|
using namespace llvm::support;
|
|
|
|
using namespace llvm::support::endian;
|
2015-12-05 07:11:05 +08:00
|
|
|
|
|
|
|
const int PageSize = 4096;
|
|
|
|
const uint8_t Magic[32] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0\0";
|
|
|
|
|
2015-12-09 02:39:55 +08:00
|
|
|
namespace {
|
|
|
|
struct PDBHeader {
|
|
|
|
uint8_t Magic[32];
|
|
|
|
ulittle32_t PageSize;
|
|
|
|
ulittle32_t FpmPage;
|
|
|
|
ulittle32_t PageCount;
|
|
|
|
ulittle32_t RootSize;
|
|
|
|
ulittle32_t Reserved;
|
|
|
|
ulittle32_t RootPointer;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-12-05 07:11:05 +08:00
|
|
|
void lld::coff::createPDB(StringRef Path) {
|
|
|
|
// Create a file.
|
|
|
|
size_t FileSize = PageSize * 3;
|
2015-12-09 02:39:55 +08:00
|
|
|
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
|
2015-12-05 07:11:05 +08:00
|
|
|
FileOutputBuffer::create(Path, FileSize);
|
2016-07-15 08:40:46 +08:00
|
|
|
if (auto EC = BufferOrErr.getError())
|
|
|
|
fatal(EC, "failed to open " + Path);
|
2015-12-09 02:39:55 +08:00
|
|
|
std::unique_ptr<FileOutputBuffer> Buffer = std::move(*BufferOrErr);
|
|
|
|
|
|
|
|
// Write the file header.
|
|
|
|
uint8_t *Buf = Buffer->getBufferStart();
|
|
|
|
auto *Hdr = reinterpret_cast<PDBHeader *>(Buf);
|
|
|
|
memcpy(Hdr->Magic, Magic, sizeof(Magic));
|
|
|
|
Hdr->PageSize = PageSize;
|
|
|
|
// I don't know what FpmPage field means, but it must not be 0.
|
|
|
|
Hdr->FpmPage = 1;
|
|
|
|
Hdr->PageCount = FileSize / PageSize;
|
|
|
|
// Root directory is empty, containing only the length field.
|
|
|
|
Hdr->RootSize = 4;
|
|
|
|
// Root directory is on page 1.
|
|
|
|
Hdr->RootPointer = 1;
|
2015-12-05 07:11:05 +08:00
|
|
|
|
2015-12-09 02:39:55 +08:00
|
|
|
// Write the root directory. Root stream is on page 2.
|
|
|
|
write32le(Buf + PageSize, 2);
|
|
|
|
Buffer->commit();
|
2015-12-05 07:11:05 +08:00
|
|
|
}
|