]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/ReaderWriter/PECOFF/PDBPass.h
Vendor import of lld trunk r233088:
[FreeBSD/FreeBSD.git] / lib / ReaderWriter / PECOFF / PDBPass.h
1 //===- lib/ReaderWriter/PECOFF/PDBPass.h ----------------------------------===//
2 //
3 //                             The LLVM Linker
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLD_READER_WRITER_PE_COFF_PDB_PASS_H
11 #define LLD_READER_WRITER_PE_COFF_PDB_PASS_H
12
13 #include "lld/Core/Pass.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Process.h"
16
17 namespace lld {
18 namespace pecoff {
19
20 class PDBPass : public lld::Pass {
21 public:
22   PDBPass(PECOFFLinkingContext &ctx) : _ctx(ctx) {}
23
24   void perform(std::unique_ptr<MutableFile> &file) override {
25     if (_ctx.getDebug())
26       touch(_ctx.getPDBFilePath());
27   }
28
29 private:
30   void touch(StringRef path) {
31     int fd;
32     if (llvm::sys::fs::openFileForWrite(path, fd, llvm::sys::fs::F_Append))
33       llvm::report_fatal_error("failed to create a PDB file");
34     llvm::sys::Process::SafelyCloseFileDescriptor(fd);
35   }
36
37   PECOFFLinkingContext &_ctx;
38 };
39
40 } // namespace pecoff
41 } // namespace lld
42
43 #endif