diff options
-rw-r--r-- | lld/COFF/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lld/COFF/Driver.cpp | 2 | ||||
-rw-r--r-- | lld/COFF/Driver.h | 1 | ||||
-rw-r--r-- | lld/COFF/PDB.cpp | 32 |
4 files changed, 35 insertions, 1 deletions
diff --git a/lld/COFF/CMakeLists.txt b/lld/COFF/CMakeLists.txt index e76496bc4db..78dc34eff96 100644 --- a/lld/COFF/CMakeLists.txt +++ b/lld/COFF/CMakeLists.txt @@ -12,6 +12,7 @@ add_llvm_library(lldCOFF InputFiles.cpp MarkLive.cpp ModuleDef.cpp + PDB.cpp SymbolTable.cpp Symbols.cpp Writer.cpp diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index f4ce04aa914..f528dafd985 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -648,7 +648,7 @@ void LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) { // Create a dummy PDB file to satisfy build sytem rules. if (auto *Arg = Args.getLastArg(OPT_pdb)) - touchFile(Arg->getValue()); + createPDB(Arg->getValue()); // Identify unreferenced COMDAT sections. if (Config->DoGC) diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h index f3439682dc0..e50da20cbb0 100644 --- a/lld/COFF/Driver.h +++ b/lld/COFF/Driver.h @@ -164,6 +164,7 @@ std::unique_ptr<MemoryBuffer> convertResToCOFF(const std::vector<MemoryBufferRef> &MBs); void touchFile(StringRef Path); +void createPDB(StringRef Path); // Create enum with OPT_xxx values for each option in Options.td enum { diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp new file mode 100644 index 00000000000..62f9ba4df32 --- /dev/null +++ b/lld/COFF/PDB.cpp @@ -0,0 +1,32 @@ +//===- 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" +#include "llvm/Support/FileOutputBuffer.h" +#include <memory> + +using namespace llvm; + +const int PageSize = 4096; +const uint8_t Magic[32] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0\0"; + +void lld::coff::createPDB(StringRef Path) { + // Create a file. + size_t FileSize = PageSize * 3; + ErrorOr<std::unique_ptr<FileOutputBuffer>> BufOrErr = + FileOutputBuffer::create(Path, FileSize); + error(BufOrErr, Twine("failed to open ") + Path); + std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufOrErr); + + // Write the file magic. + uint8_t *P = Buf->getBufferStart(); + memcpy(P, Magic, sizeof(Magic)); +} |