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 "llvm/BinaryFormat/MachO.h" 13 #include "llvm/Support/MemoryBuffer.h" 14 15 #include <cstddef> 16 #include <cstdint> 17 18 namespace lld { 19 namespace macho { 20 21 class Symbol; 22 class DylibSymbol; 23 class InputSection; 24 struct Reloc; 25 26 enum : uint64_t { 27 // We are currently only supporting 64-bit targets since macOS and iOS are 28 // deprecating 32-bit apps. 29 WordSize = 8, 30 PageSize = 4096, 31 PageZeroSize = 1ull << 32, // XXX should be 4096 for 32-bit targets 32 MaxAlignmentPowerOf2 = 32, 33 }; 34 35 class TargetInfo { 36 public: 37 virtual ~TargetInfo() = default; 38 39 // Validate the relocation structure and get its addend. 40 virtual uint64_t 41 getImplicitAddend(llvm::MemoryBufferRef, const llvm::MachO::section_64 &, 42 const llvm::MachO::relocation_info &) const = 0; 43 virtual void relocateOne(uint8_t *loc, const Reloc &, uint64_t val) const = 0; 44 45 // Write code for lazy binding. See the comments on StubsSection for more 46 // details. 47 virtual void writeStub(uint8_t *buf, const DylibSymbol &) const = 0; 48 virtual void writeStubHelperHeader(uint8_t *buf) const = 0; 49 virtual void writeStubHelperEntry(uint8_t *buf, const DylibSymbol &, 50 uint64_t entryAddr) const = 0; 51 52 // Symbols may be referenced via either the GOT or the stubs section, 53 // depending on the relocation type. prepareSymbolRelocation() will set up the 54 // GOT/stubs entries, and getSymbolVA() will return the addresses of those 55 // entries. 56 virtual void prepareSymbolRelocation(Symbol &, const InputSection *, 57 const Reloc &) = 0; 58 virtual uint64_t getSymbolVA(const Symbol &, uint8_t type) const = 0; 59 60 uint32_t cpuType; 61 uint32_t cpuSubtype; 62 63 size_t stubSize; 64 size_t stubHelperHeaderSize; 65 size_t stubHelperEntrySize; 66 }; 67 68 TargetInfo *createX86_64TargetInfo(); 69 70 extern TargetInfo *target; 71 72 } // namespace macho 73 } // namespace lld 74 75 #endif 76