• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- MachOWriter.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 #include "../Buffer.h"
10 #include "MachOLayoutBuilder.h"
11 #include "MachOObjcopy.h"
12 #include "Object.h"
13 #include "llvm/BinaryFormat/MachO.h"
14 #include "llvm/Object/MachO.h"
15 
16 namespace llvm {
17 class Error;
18 
19 namespace objcopy {
20 namespace macho {
21 
22 class MachOWriter {
23   Object &O;
24   bool Is64Bit;
25   bool IsLittleEndian;
26   uint64_t PageSize;
27   Buffer &B;
28   MachOLayoutBuilder LayoutBuilder;
29 
30   size_t headerSize() const;
31   size_t loadCommandsSize() const;
32   size_t symTableSize() const;
33   size_t strTableSize() const;
34 
35   void writeHeader();
36   void writeLoadCommands();
37   template <typename StructType>
38   void writeSectionInLoadCommand(const Section &Sec, uint8_t *&Out);
39   void writeSections();
40   void writeSymbolTable();
41   void writeStringTable();
42   void writeRebaseInfo();
43   void writeBindInfo();
44   void writeWeakBindInfo();
45   void writeLazyBindInfo();
46   void writeExportInfo();
47   void writeIndirectSymbolTable();
48   void writeLinkData(Optional<size_t> LCIndex, const LinkData &LD);
49   void writeCodeSignatureData();
50   void writeDataInCodeData();
51   void writeFunctionStartsData();
52   void writeTail();
53 
54 public:
MachOWriter(Object & O,bool Is64Bit,bool IsLittleEndian,uint64_t PageSize,Buffer & B)55   MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian, uint64_t PageSize,
56               Buffer &B)
57       : O(O), Is64Bit(Is64Bit), IsLittleEndian(IsLittleEndian),
58         PageSize(PageSize), B(B), LayoutBuilder(O, Is64Bit, PageSize) {}
59 
60   size_t totalSize() const;
61   Error finalize();
62   Error write();
63 };
64 
65 } // end namespace macho
66 } // end namespace objcopy
67 } // end namespace llvm
68