MachOWriter.h revision 360784
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 16namespace llvm { 17class Error; 18 19namespace objcopy { 20namespace macho { 21 22class 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 writeDataInCodeData(); 49 void writeFunctionStartsData(); 50 void writeTail(); 51 52public: 53 MachOWriter(Object &O, bool Is64Bit, bool IsLittleEndian, uint64_t PageSize, 54 Buffer &B) 55 : O(O), Is64Bit(Is64Bit), IsLittleEndian(IsLittleEndian), 56 PageSize(PageSize), B(B), LayoutBuilder(O, Is64Bit, PageSize) {} 57 58 size_t totalSize() const; 59 Error finalize(); 60 Error write(); 61}; 62 63} // end namespace macho 64} // end namespace objcopy 65} // end namespace llvm 66