xref: /netbsd-src/external/apache2/llvm/dist/llvm/tools/llvm-objcopy/MachO/MachOLayoutBuilder.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
17330f729Sjoerg //===- MachOLayoutBuilder.h -------------------------------------*- C++ -*-===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg 
97330f729Sjoerg #ifndef LLVM_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H
107330f729Sjoerg #define LLVM_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H
117330f729Sjoerg 
127330f729Sjoerg #include "MachOObjcopy.h"
137330f729Sjoerg #include "Object.h"
147330f729Sjoerg 
157330f729Sjoerg namespace llvm {
167330f729Sjoerg namespace objcopy {
177330f729Sjoerg namespace macho {
187330f729Sjoerg 
197330f729Sjoerg class MachOLayoutBuilder {
207330f729Sjoerg   Object &O;
217330f729Sjoerg   bool Is64Bit;
227330f729Sjoerg   uint64_t PageSize;
237330f729Sjoerg 
247330f729Sjoerg   // Points to the __LINKEDIT segment if it exists.
257330f729Sjoerg   MachO::macho_load_command *LinkEditLoadCommand = nullptr;
26*82d56013Sjoerg   StringTableBuilder StrTableBuilder;
277330f729Sjoerg 
287330f729Sjoerg   uint32_t computeSizeOfCmds() const;
297330f729Sjoerg   void constructStringTable();
307330f729Sjoerg   void updateSymbolIndexes();
317330f729Sjoerg   void updateDySymTab(MachO::macho_load_command &MLC);
327330f729Sjoerg   uint64_t layoutSegments();
337330f729Sjoerg   uint64_t layoutRelocations(uint64_t Offset);
347330f729Sjoerg   Error layoutTail(uint64_t Offset);
357330f729Sjoerg 
36*82d56013Sjoerg   static StringTableBuilder::Kind getStringTableBuilderKind(const Object &O,
37*82d56013Sjoerg                                                             bool Is64Bit);
38*82d56013Sjoerg 
397330f729Sjoerg public:
MachOLayoutBuilder(Object & O,bool Is64Bit,uint64_t PageSize)407330f729Sjoerg   MachOLayoutBuilder(Object &O, bool Is64Bit, uint64_t PageSize)
41*82d56013Sjoerg       : O(O), Is64Bit(Is64Bit), PageSize(PageSize),
42*82d56013Sjoerg         StrTableBuilder(getStringTableBuilderKind(O, Is64Bit)) {}
437330f729Sjoerg 
447330f729Sjoerg   // Recomputes and updates fields in the given object such as file offsets.
457330f729Sjoerg   Error layout();
467330f729Sjoerg 
getStringTableBuilder()477330f729Sjoerg   StringTableBuilder &getStringTableBuilder() { return StrTableBuilder; }
487330f729Sjoerg };
497330f729Sjoerg 
507330f729Sjoerg } // end namespace macho
517330f729Sjoerg } // end namespace objcopy
527330f729Sjoerg } // end namespace llvm
537330f729Sjoerg 
547330f729Sjoerg #endif // LLVM_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H
55