]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Target.h
Update lld to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / ELF / Target.h
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   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 bool isPicRel(uint32_t Type) const { return true; }
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 void writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const;
34   virtual uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const;
35
36   // If lazy binding is supported, the first entry of the PLT has code
37   // to call the dynamic linker to resolve PLT entries the first time
38   // they are called. This function writes that code.
39   virtual void writePltHeader(uint8_t *Buf) const {}
40
41   virtual void writePlt(uint8_t *Buf, uint64_t GotEntryAddr,
42                         uint64_t PltEntryAddr, int32_t Index,
43                         unsigned RelOff) const {}
44
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;
51
52   // Decide whether a Thunk is needed for the relocation from File
53   // targeting S. Returns one of:
54   // Expr if there is no Thunk required
55   // R_THUNK_ABS if thunk is required and expression is absolute
56   // R_THUNK_PC if thunk is required and expression is pc rel
57   // R_THUNK_PLT_PC if thunk is required to PLT entry and expression is pc rel
58   virtual RelExpr getThunkExpr(RelExpr Expr, uint32_t RelocType,
59                                const InputFile &File,
60                                const SymbolBody &S) const;
61   virtual RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const = 0;
62   virtual void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const = 0;
63   virtual ~TargetInfo();
64
65   unsigned TlsGdRelaxSkip = 1;
66   unsigned PageSize = 4096;
67   unsigned DefaultMaxPageSize = 4096;
68
69   // On FreeBSD x86_64 the first page cannot be mmaped.
70   // On Linux that is controled by vm.mmap_min_addr. At least on some x86_64
71   // installs that is 65536, so the first 15 pages cannot be used.
72   // Given that, the smallest value that can be used in here is 0x10000.
73   uint64_t DefaultImageBase = 0x10000;
74
75   uint32_t CopyRel;
76   uint32_t GotRel;
77   uint32_t PltRel;
78   uint32_t RelativeRel;
79   uint32_t IRelativeRel;
80   uint32_t TlsDescRel;
81   uint32_t TlsGotRel;
82   uint32_t TlsModuleIndexRel;
83   uint32_t TlsOffsetRel;
84   unsigned GotEntrySize = 0;
85   unsigned GotPltEntrySize = 0;
86   unsigned PltEntrySize;
87   unsigned PltHeaderSize;
88
89   // At least on x86_64 positions 1 and 2 are used by the first plt entry
90   // to support lazy loading.
91   unsigned GotPltHeaderEntriesNum = 3;
92
93   // Set to 0 for variant 2
94   unsigned TcbSize = 0;
95
96   bool NeedsThunks = false;
97
98   virtual RelExpr adjustRelaxExpr(uint32_t Type, const uint8_t *Data,
99                                   RelExpr Expr) const;
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;
105 };
106
107 std::string toString(uint32_t RelType);
108 uint64_t getPPC64TocBase();
109 uint64_t getAArch64Page(uint64_t Expr);
110
111 extern TargetInfo *Target;
112 TargetInfo *createTarget();
113 }
114 }
115
116 #endif