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 isPicRel(uint32_t Type) const { return true; }
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 void writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const;
33 virtual int64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const;
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 {}
40 virtual void writePlt(uint8_t *Buf, uint64_t GotEntryAddr,
41 uint64_t PltEntryAddr, int32_t Index,
42 unsigned RelOff) const {}
43 virtual void addPltHeaderSymbols(InputSectionBase *IS) const {}
44 virtual void addPltSymbols(InputSectionBase *IS, uint64_t Off) const {}
45 // Returns true if a relocation only uses the low bits of a value such that
46 // all those bits are in in the same page. For example, if the relocation
47 // only uses the low 12 bits in a system with 4k pages. If this is true, the
48 // bits will always have the same value at runtime and we don't have to emit
49 // a dynamic relocation.
50 virtual bool usesOnlyLowPageBits(uint32_t Type) const;
52 // Decide whether a Thunk is needed for the relocation from File
54 virtual bool needsThunk(RelExpr Expr, uint32_t RelocType,
55 const InputFile *File, const SymbolBody &S) const;
56 virtual RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
57 const uint8_t *Loc) const = 0;
58 virtual void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const = 0;
59 virtual ~TargetInfo();
61 unsigned TlsGdRelaxSkip = 1;
62 unsigned PageSize = 4096;
63 unsigned DefaultMaxPageSize = 4096;
65 // On FreeBSD x86_64 the first page cannot be mmaped.
66 // On Linux that is controled by vm.mmap_min_addr. At least on some x86_64
67 // installs that is 65536, so the first 15 pages cannot be used.
68 // Given that, the smallest value that can be used in here is 0x10000.
69 uint64_t DefaultImageBase = 0x10000;
75 uint32_t IRelativeRel;
78 uint32_t TlsModuleIndexRel;
79 uint32_t TlsOffsetRel;
80 unsigned GotEntrySize = 0;
81 unsigned GotPltEntrySize = 0;
82 unsigned PltEntrySize;
83 unsigned PltHeaderSize;
85 // At least on x86_64 positions 1 and 2 are used by the first plt entry
86 // to support lazy loading.
87 unsigned GotPltHeaderEntriesNum = 3;
89 // Set to 0 for variant 2
92 bool NeedsThunks = false;
94 // A 4-byte field corresponding to one or more trap instructions, used to pad
95 // executable OutputSections.
96 uint32_t TrapInstr = 0;
98 virtual RelExpr adjustRelaxExpr(uint32_t Type, const uint8_t *Data,
100 virtual void relaxGot(uint8_t *Loc, uint64_t Val) const;
101 virtual void relaxTlsGdToIe(uint8_t *Loc, uint32_t Type, uint64_t Val) const;
102 virtual void relaxTlsGdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const;
103 virtual void relaxTlsIeToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const;
104 virtual void relaxTlsLdToLe(uint8_t *Loc, uint32_t Type, uint64_t Val) const;
107 uint64_t getPPC64TocBase();
108 uint64_t getAArch64Page(uint64_t Expr);
110 extern TargetInfo *Target;
111 TargetInfo *createTarget();
114 std::string toString(uint32_t RelType);