• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- Writer.h -------------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_TOOLS_OBJCOPY_COFF_WRITER_H
10 #define LLVM_TOOLS_OBJCOPY_COFF_WRITER_H
11 
12 #include "Buffer.h"
13 #include "llvm/MC/StringTableBuilder.h"
14 #include "llvm/Support/Error.h"
15 #include <cstddef>
16 #include <utility>
17 
18 namespace llvm {
19 namespace objcopy {
20 namespace coff {
21 
22 struct Object;
23 
24 class COFFWriter {
25   Object &Obj;
26   Buffer &Buf;
27 
28   size_t FileSize;
29   size_t FileAlignment;
30   size_t SizeOfInitializedData;
31   StringTableBuilder StrTabBuilder;
32 
33   template <class SymbolTy> std::pair<size_t, size_t> finalizeSymbolTable();
34   Error finalizeRelocTargets();
35   Error finalizeSymbolContents();
36   void layoutSections();
37   size_t finalizeStringTable();
38 
39   Error finalize(bool IsBigObj);
40 
41   void writeHeaders(bool IsBigObj);
42   void writeSections();
43   template <class SymbolTy> void writeSymbolStringTables();
44 
45   Error write(bool IsBigObj);
46 
47   Error patchDebugDirectory();
48   Expected<uint32_t> virtualAddressToFileAddress(uint32_t RVA);
49 
50 public:
~COFFWriter()51   virtual ~COFFWriter() {}
52   Error write();
53 
COFFWriter(Object & Obj,Buffer & Buf)54   COFFWriter(Object &Obj, Buffer &Buf)
55       : Obj(Obj), Buf(Buf), StrTabBuilder(StringTableBuilder::WinCOFF) {}
56 };
57 
58 } // end namespace coff
59 } // end namespace objcopy
60 } // end namespace llvm
61 
62 #endif // LLVM_TOOLS_OBJCOPY_COFF_WRITER_H
63