summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-12-04 23:11:05 +0000
committerRui Ueyama <ruiu@google.com>2015-12-04 23:11:05 +0000
commite737824d8a910282fa9505dbf98426d28f923cab (patch)
tree880b430f1f319fbc5c85d0f82b993f0cc2e92f91
parentb6306da4051906236101f56dfb9a381acb6e6a69 (diff)
downloadbcm5719-llvm-e737824d8a910282fa9505dbf98426d28f923cab.tar.gz
bcm5719-llvm-e737824d8a910282fa9505dbf98426d28f923cab.zip
COFF: Create a PDB file with the correct file signature.
Before this patch, we created an empty PDB file if /debug option is specified. For MSVC linker, such PDB file is completely broken, and linker exits without doing anything as soon as it finds an empty PDB file. A PDB file created in this patch has the correct file signature. MSVC linker still thinks that the file is broken, but it then removes and replaces with its output. This is an initial patch to support PDB in LLD. We aim to support PDB in order to make it 100% compatible with MSVC linker. PDB support is the last missing piece. llvm-svn: 254796
-rw-r--r--lld/COFF/CMakeLists.txt1
-rw-r--r--lld/COFF/Driver.cpp2
-rw-r--r--lld/COFF/Driver.h1
-rw-r--r--lld/COFF/PDB.cpp32
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));
+}
OpenPOWER on IntegriCloud