173
|
1 //===- Target.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 LLD_MACHO_TARGET_H
|
|
10 #define LLD_MACHO_TARGET_H
|
|
11
|
|
12 #include <cstddef>
|
|
13 #include <cstdint>
|
|
14
|
|
15 namespace lld {
|
|
16 namespace macho {
|
|
17
|
|
18 class DylibSymbol;
|
|
19
|
|
20 enum {
|
|
21 // We are currently only supporting 64-bit targets since macOS and iOS are
|
|
22 // deprecating 32-bit apps.
|
|
23 WordSize = 8,
|
|
24 PageSize = 4096,
|
|
25 ImageBase = 4096,
|
|
26 MaxAlignmentPowerOf2 = 32,
|
|
27 };
|
|
28
|
|
29 class TargetInfo {
|
|
30 public:
|
|
31 virtual ~TargetInfo() = default;
|
|
32
|
|
33 virtual uint64_t getImplicitAddend(const uint8_t *loc,
|
|
34 uint8_t type) const = 0;
|
|
35 virtual void relocateOne(uint8_t *loc, uint8_t type, uint64_t val) const = 0;
|
|
36
|
|
37 // Write code for lazy binding. See the comments on StubsSection for more
|
|
38 // details.
|
|
39 virtual void writeStub(uint8_t *buf, const DylibSymbol &) const = 0;
|
|
40 virtual void writeStubHelperHeader(uint8_t *buf) const = 0;
|
|
41 virtual void writeStubHelperEntry(uint8_t *buf, const DylibSymbol &,
|
|
42 uint64_t entryAddr) const = 0;
|
|
43
|
|
44 // Dylib symbols are referenced via either the GOT or the stubs section,
|
|
45 // depending on the relocation type. prepareDylibSymbolRelocation() will set
|
|
46 // up the GOT/stubs entries, and getDylibSymbolVA() will return the addresses
|
|
47 // of those entries.
|
|
48 virtual void prepareDylibSymbolRelocation(DylibSymbol &, uint8_t type) = 0;
|
|
49 virtual uint64_t getDylibSymbolVA(const DylibSymbol &,
|
|
50 uint8_t type) const = 0;
|
|
51
|
|
52 uint32_t cpuType;
|
|
53 uint32_t cpuSubtype;
|
|
54
|
|
55 size_t stubSize;
|
|
56 size_t stubHelperHeaderSize;
|
|
57 size_t stubHelperEntrySize;
|
|
58 };
|
|
59
|
|
60 TargetInfo *createX86_64TargetInfo();
|
|
61
|
|
62 extern TargetInfo *target;
|
|
63
|
|
64 } // namespace macho
|
|
65 } // namespace lld
|
|
66
|
|
67 #endif
|