[yaml2obj/obj2yaml] - Add support for .stack_sizes sections.
[llvm-complete.git] / tools / llvm-objcopy / MachO / MachOLayoutBuilder.h
blob21cbe56605de3af191d20d65cb4c95bf66262cc6
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H
10 #define LLVM_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H
12 #include "MachOObjcopy.h"
13 #include "Object.h"
15 namespace llvm {
16 namespace objcopy {
17 namespace macho {
19 class MachOLayoutBuilder {
20 Object &O;
21 bool Is64Bit;
22 uint64_t PageSize;
24 // Points to the __LINKEDIT segment if it exists.
25 MachO::macho_load_command *LinkEditLoadCommand = nullptr;
26 StringTableBuilder StrTableBuilder{StringTableBuilder::MachO};
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);
36 public:
37 MachOLayoutBuilder(Object &O, bool Is64Bit, uint64_t PageSize)
38 : O(O), Is64Bit(Is64Bit), PageSize(PageSize) {}
40 // Recomputes and updates fields in the given object such as file offsets.
41 Error layout();
43 StringTableBuilder &getStringTableBuilder() { return StrTableBuilder; }
46 } // end namespace macho
47 } // end namespace objcopy
48 } // end namespace llvm
50 #endif // LLVM_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H