1 //===- Target.h -------------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Linker 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLD_ELF_TARGET_H 11 #define LLD_ELF_TARGET_H 12 13 #include "InputSection.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/Object/ELF.h" 16 17 #include <memory> 18 19 namespace lld { 20 namespace elf { 21 class InputFile; 22 class SymbolBody; 23 24 class TargetInfo { 25 public: 26 uint64_t getVAStart() const; 27 virtual bool isTlsInitialExecRel(uint32_t Type) const; 28 virtual bool isTlsLocalDynamicRel(uint32_t Type) const; 29 virtual bool isTlsGlobalDynamicRel(uint32_t Type) const; 30 virtual uint32_t getDynRel(uint32_t Type) const { return Type; } 31 virtual void writeGotPltHeader(uint8_t *Buf) const {} 32 virtual void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const {}; 33 virtual uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const; 34 35 // If lazy binding is supported, the first entry of the PLT has code 36 // to call the dynamic linker to resolve PLT entries the first time 37 // they are called. This function writes that code. 38 virtual void writePltHeader(uint8_t *Buf) const {} 39 40 virtual void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, 41 uint64_t PltEntryAddr, int32_t Index, 42 unsigned RelOff) const {} 43 44 // Returns true if a relocation only uses the low bits of a value such that 45 // all those bits are in in the same page. For example, if the relocation 46 // only uses the low 12 bits in a system with 4k pages. If this is true, the 47 // bits will always have the same value at runtime and we don't have to emit 48 // a dynamic relocation. 49 virtual bool usesOnlyLowPageBits(uint32_t Type) const; 50 51 virtual bool needsThunk(uint32_t Type, const InputFile &File, 52 const SymbolBody &S) const; 53 54 virtual void writeThunk(uint8_t *Buf, uint64_t S) const {} 55 56 virtual RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const = 0; 57 virtual void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const = 0; 58 virtual ~TargetInfo(); 59 60 unsigned TlsGdRelaxSkip = 1; 61 unsigned PageSize = 4096; 62 63 // On freebsd x86_64 the first page cannot be mmaped. 64 // On linux that is controled by vm.mmap_min_addr. At least on some x86_64 65 // installs that is 65536, so the first 15 pages cannot be used. 66 // Given that, the smallest value that can be used in here is 0x10000. 67 // If using 2MB pages, the smallest page aligned address that works is 68 // 0x200000, but it looks like every OS uses 4k pages for executables. 69 uint64_t VAStart = 0x10000; 70 71 uint32_t CopyRel; 72 uint32_t GotRel; 73 uint32_t PltRel; 74 uint32_t RelativeRel; 75 uint32_t IRelativeRel; 76 uint32_t TlsDescRel; 77 uint32_t TlsGotRel; 78 uint32_t TlsModuleIndexRel; 79 uint32_t TlsOffsetRel; 80 unsigned PltEntrySize; 81 unsigned PltHeaderSize; 82 83 // At least on x86_64 positions 1 and 2 are used by the first plt entry 84 // to support lazy loading. 85 unsigned GotPltHeaderEntriesNum = 3; 86 87 // Set to 0 for variant 2 88 unsigned TcbSize = 0; 89 90 uint32_t ThunkSize = 0; 91 92 virtual RelExpr adjustRelaxExpr(uint32_t Type, const uint8_t *Data, 93 RelExpr Expr) const; 94 virtual void relaxGot(uint8_t *Loc, uint64_t Val) const; 95 virtual void relaxTlsGdToIe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; 96 virtual void relaxTlsGdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; 97 virtual void relaxTlsIeToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; 98 virtual void relaxTlsLdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const; 99 }; 100 101 StringRef getRelName(uint32_t Type); 102 uint64_t getPPC64TocBase(); 103 104 const unsigned MipsGPOffset = 0x7ff0; 105 106 extern TargetInfo *Target; 107 TargetInfo *createTarget(); 108 } 109 } 110 111 #endif 112