]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/ELF/Target.h
Merge lld trunk r300422 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 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;
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   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;
51
52   // Decide whether a Thunk is needed for the relocation from File
53   // targeting S.
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();
60
61   unsigned TlsGdRelaxSkip = 1;
62   unsigned PageSize = 4096;
63   unsigned DefaultMaxPageSize = 4096;
64
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;
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 GotEntrySize = 0;
81   unsigned GotPltEntrySize = 0;
82   unsigned PltEntrySize;
83   unsigned PltHeaderSize;
84
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;
88
89   // Set to 0 for variant 2
90   unsigned TcbSize = 0;
91
92   bool NeedsThunks = false;
93
94   // A 4-byte field corresponding to one or more trap instructions, used to pad
95   // executable OutputSections.
96   uint32_t TrapInstr = 0;
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 uint64_t getPPC64TocBase();
108 uint64_t getAArch64Page(uint64_t Expr);
109
110 extern TargetInfo *Target;
111 TargetInfo *createTarget();
112 }
113
114 std::string toString(uint32_t RelType);
115 }
116
117 #endif