1 //===- Target.h -------------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_ELF_TARGET_H
11 #define LLD_ELF_TARGET_H
13 #include "InputSection.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Object/ELF.h"
26 virtual bool isTlsInitialExecRel(uint32_t Type) const;
27 virtual bool isTlsLocalDynamicRel(uint32_t Type) const;
28 virtual bool isTlsGlobalDynamicRel(uint32_t Type) const;
29 virtual uint32_t getDynRel(uint32_t Type) const { return Type; }
30 virtual void writeGotPltHeader(uint8_t *Buf) const {}
31 virtual void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const {};
32 virtual uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const;
34 // If lazy binding is supported, the first entry of the PLT has code
35 // to call the dynamic linker to resolve PLT entries the first time
36 // they are called. This function writes that code.
37 virtual void writePltHeader(uint8_t *Buf) const {}
39 virtual void writePlt(uint8_t *Buf, uint64_t GotEntryAddr,
40 uint64_t PltEntryAddr, int32_t Index,
41 unsigned RelOff) const {}
43 // Returns true if a relocation only uses the low bits of a value such that
44 // all those bits are in in the same page. For example, if the relocation
45 // only uses the low 12 bits in a system with 4k pages. If this is true, the
46 // bits will always have the same value at runtime and we don't have to emit
47 // a dynamic relocation.
48 virtual bool usesOnlyLowPageBits(uint32_t Type) const;
50 // Decide whether a Thunk is needed for the relocation from File
51 // targeting S. Returns one of:
52 // Expr if there is no Thunk required
53 // R_THUNK_ABS if thunk is required and expression is absolute
54 // R_THUNK_PC if thunk is required and expression is pc rel
55 // R_THUNK_PLT_PC if thunk is required to PLT entry and expression is pc rel
56 virtual RelExpr getThunkExpr(RelExpr Expr, uint32_t RelocType,
57 const InputFile &File,
58 const SymbolBody &S) const;
59 virtual RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const = 0;
60 virtual void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const = 0;
61 virtual ~TargetInfo();
63 unsigned TlsGdRelaxSkip = 1;
64 unsigned PageSize = 4096;
66 // On freebsd x86_64 the first page cannot be mmaped.
67 // On linux that is controled by vm.mmap_min_addr. At least on some x86_64
68 // installs that is 65536, so the first 15 pages cannot be used.
69 // Given that, the smallest value that can be used in here is 0x10000.
70 // If using 2MB pages, the smallest page aligned address that works is
71 // 0x200000, but it looks like every OS uses 4k pages for executables.
72 uint64_t DefaultImageBase = 0x10000;
78 uint32_t IRelativeRel;
81 uint32_t TlsModuleIndexRel;
82 uint32_t TlsOffsetRel;
83 unsigned GotEntrySize;
84 unsigned GotPltEntrySize;
85 unsigned PltEntrySize;
86 unsigned PltHeaderSize;
88 // At least on x86_64 positions 1 and 2 are used by the first plt entry
89 // to support lazy loading.
90 unsigned GotPltHeaderEntriesNum = 3;
92 // Set to 0 for variant 2
95 virtual RelExpr adjustRelaxExpr(uint32_t Type, const uint8_t *Data,
97 virtual void relaxGot(uint8_t *Loc, uint64_t Val) const;
98 virtual void relaxTlsGdToIe(uint8_t *Loc, uint32_t Type, uint64_t Val) const;
99 virtual void relaxTlsGdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const;
100 virtual void relaxTlsIeToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const;
101 virtual void relaxTlsLdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const;
104 StringRef getRelName(uint32_t Type);
105 uint64_t getPPC64TocBase();
107 const unsigned MipsGPOffset = 0x7ff0;
109 extern TargetInfo *Target;
110 TargetInfo *createTarget();