1 //===- MachOLayoutBuilder.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_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H 10 #define LLVM_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H 11 12 #include "MachOObjcopy.h" 13 #include "Object.h" 14 15 namespace llvm { 16 namespace objcopy { 17 namespace macho { 18 19 class MachOLayoutBuilder { 20 Object &O; 21 bool Is64Bit; 22 uint64_t PageSize; 23 24 // Points to the __LINKEDIT segment if it exists. 25 MachO::macho_load_command *LinkEditLoadCommand = nullptr; 26 StringTableBuilder StrTableBuilder; 27 28 uint32_t computeSizeOfCmds() const; 29 void constructStringTable(); 30 void updateSymbolIndexes(); 31 void updateDySymTab(MachO::macho_load_command &MLC); 32 uint64_t layoutSegments(); 33 uint64_t layoutRelocations(uint64_t Offset); 34 Error layoutTail(uint64_t Offset); 35 36 static StringTableBuilder::Kind getStringTableBuilderKind(const Object &O, 37 bool Is64Bit); 38 39 public: MachOLayoutBuilder(Object & O,bool Is64Bit,uint64_t PageSize)40 MachOLayoutBuilder(Object &O, bool Is64Bit, uint64_t PageSize) 41 : O(O), Is64Bit(Is64Bit), PageSize(PageSize), 42 StrTableBuilder(getStringTableBuilderKind(O, Is64Bit)) {} 43 44 // Recomputes and updates fields in the given object such as file offsets. 45 Error layout(); 46 getStringTableBuilder()47 StringTableBuilder &getStringTableBuilder() { return StrTableBuilder; } 48 }; 49 50 } // end namespace macho 51 } // end namespace objcopy 52 } // end namespace llvm 53 54 #endif // LLVM_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H 55