LLVM  16.0.0git
MachOWriter.h
Go to the documentation of this file.
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 #ifndef LLVM_LIB_OBJCOPY_MACHO_MACHOWRITER_H
10 #define LLVM_LIB_OBJCOPY_MACHO_MACHOWRITER_H
11 
12 #include "MachOLayoutBuilder.h"
13 #include "MachOObject.h"
16 #include "llvm/Object/MachO.h"
17 
18 namespace llvm {
19 class Error;
20 
21 namespace objcopy {
22 namespace macho {
23 
24 class MachOWriter {
25  Object &O;
26  bool Is64Bit;
27  bool IsLittleEndian;
28  uint64_t PageSize;
29  std::unique_ptr<WritableMemoryBuffer> Buf;
30  raw_ostream &Out;
31  MachOLayoutBuilder LayoutBuilder;
32 
33  size_t headerSize() const;
34  size_t loadCommandsSize() const;
35  size_t symTableSize() const;
36  size_t strTableSize() const;
37 
38  void writeHeader();
39  void writeLoadCommands();
40  template <typename StructType>
41  void writeSectionInLoadCommand(const Section &Sec, uint8_t *&Out);
42  void writeSections();
43  void writeSymbolTable();
44  void writeStringTable();
45  void writeRebaseInfo();
46  void writeBindInfo();
47  void writeWeakBindInfo();
48  void writeLazyBindInfo();
49  void writeExportInfo();
50  void writeIndirectSymbolTable();
51  void writeLinkData(Optional<size_t> LCIndex, const LinkData &LD);
52  void writeCodeSignatureData();
53  void writeDataInCodeData();
54  void writeLinkerOptimizationHint();
55  void writeFunctionStartsData();
56  void writeChainedFixupsData();
57  void writeExportsTrieData();
58  void writeTail();
59 
60 public:
61  MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian,
62  StringRef OutputFileName, uint64_t PageSize, raw_ostream &Out)
63  : O(O), Is64Bit(Is64Bit), IsLittleEndian(IsLittleEndian),
64  PageSize(PageSize), Out(Out),
65  LayoutBuilder(O, Is64Bit, OutputFileName, PageSize) {}
66 
67  size_t totalSize() const;
68  Error finalize();
69  Error write();
70 };
71 
72 } // end namespace macho
73 } // end namespace objcopy
74 } // end namespace llvm
75 
76 #endif // LLVM_LIB_OBJCOPY_MACHO_MACHOWRITER_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
llvm::ARM_MB::LD
@ LD
Definition: ARMBaseInfo.h:72
llvm::Optional< size_t >
llvm::objcopy::macho::MachOLayoutBuilder
Definition: MachOLayoutBuilder.h:56
MachO.h
llvm::objcopy::macho::LinkData
Definition: MachOObject.h:298
llvm::objcopy::macho::Object
Definition: MachOObject.h:302
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::objcopy::macho::MachOWriter
Definition: MachOWriter.h:24
uint64_t
llvm::objcopy::macho::MachOWriter::MachOWriter
MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian, StringRef OutputFileName, uint64_t PageSize, raw_ostream &Out)
Definition: MachOWriter.h:61
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::objcopy::macho::MachOWriter::write
Error write()
Definition: MachOWriter.cpp:646
MachOObjcopy.h
MachOObject.h
llvm::objcopy::macho::MachOWriter::finalize
Error finalize()
Definition: MachOWriter.cpp:644
llvm::objcopy::macho::MachOWriter::totalSize
size_t totalSize() const
Definition: MachOWriter.cpp:39
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
MachOLayoutBuilder.h
llvm::objcopy::macho::Section
Definition: MachOObject.h:39
MachO.h