mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-07 18:10:24 +00:00
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
This commit is contained in:
parent
b6306da405
commit
e737824d8a
@ -12,6 +12,7 @@ add_llvm_library(lldCOFF
|
||||
InputFiles.cpp
|
||||
MarkLive.cpp
|
||||
ModuleDef.cpp
|
||||
PDB.cpp
|
||||
SymbolTable.cpp
|
||||
Symbols.cpp
|
||||
Writer.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)
|
||||
|
@ -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 {
|
||||
|
32
lld/COFF/PDB.cpp
Normal file
32
lld/COFF/PDB.cpp
Normal file
@ -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));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user