MachOLayoutBuilder.h revision 360784
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
15namespace llvm {
16namespace objcopy {
17namespace macho {
18
19class 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{StringTableBuilder::MachO};
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
36public:
37  MachOLayoutBuilder(Object &O, bool Is64Bit, uint64_t PageSize)
38      : O(O), Is64Bit(Is64Bit), PageSize(PageSize) {}
39
40  // Recomputes and updates fields in the given object such as file offsets.
41  Error layout();
42
43  StringTableBuilder &getStringTableBuilder() { return StrTableBuilder; }
44};
45
46} // end namespace macho
47} // end namespace objcopy
48} // end namespace llvm
49
50#endif // LLVM_OBJCOPY_MACHO_MACHOLAYOUTBUILDER_H
51