]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/tools/llvm-objcopy/MachO/MachOWriter.h
Move all sources from the llvm project into contrib/llvm-project.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / tools / llvm-objcopy / MachO / MachOWriter.h
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 "MachOObjcopy.h"
11 #include "Object.h"
12 #include "llvm/BinaryFormat/MachO.h"
13 #include "llvm/Object/MachO.h"
14
15 namespace llvm {
16 class Error;
17
18 namespace objcopy {
19 namespace macho {
20
21 class MachOWriter {
22   Object &O;
23   bool Is64Bit;
24   bool IsLittleEndian;
25   Buffer &B;
26   StringTableBuilder StrTableBuilder{StringTableBuilder::MachO};
27
28   size_t headerSize() const;
29   size_t loadCommandsSize() const;
30   size_t symTableSize() const;
31   size_t strTableSize() const;
32
33   void updateDySymTab(MachO::macho_load_command &MLC);
34   void updateSizeOfCmds();
35   void updateSymbolIndexes();
36   void constructStringTable();
37   Error layout();
38
39   void writeHeader();
40   void writeLoadCommands();
41   template <typename StructType>
42   void writeSectionInLoadCommand(const Section &Sec, uint8_t *&Out);
43   void writeSections();
44   void writeSymbolTable();
45   void writeStringTable();
46   void writeRebaseInfo();
47   void writeBindInfo();
48   void writeWeakBindInfo();
49   void writeLazyBindInfo();
50   void writeExportInfo();
51   void writeTail();
52
53 public:
54   MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian, Buffer &B)
55       : O(O), Is64Bit(Is64Bit), IsLittleEndian(IsLittleEndian), B(B) {}
56
57   size_t totalSize() const;
58   Error finalize();
59   Error write();
60 };
61
62 } // end namespace macho
63 } // end namespace objcopy
64 } // end namespace llvm