1 //===- Relocations.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_RELOCATIONS_H
11 #define LLD_ELF_RELOCATIONS_H
13 #include "lld/Core/LLVM.h"
18 class InputSectionData;
19 template <class ELFT> class InputSection;
20 template <class ELFT> class InputSectionBase;
22 // List of target-independent relocation types. Relocations read
23 // from files are converted to these types so that the main code
24 // doesn't have to know about architecture-specific details.
29 R_GOTONLY_PC_FROM_END,
37 R_MIPS_GOT_LOCAL_PAGE,
55 R_RELAX_TLS_GD_TO_IE_END,
56 R_RELAX_TLS_GD_TO_IE_ABS,
57 R_RELAX_TLS_GD_TO_IE_PAGE_PC,
59 R_RELAX_TLS_GD_TO_LE_NEG,
76 // Build a bitmask with one bit set for each RelExpr.
78 // Constexpr function arguments can't be used in static asserts, so we
79 // use template arguments to build the mask.
80 // But function template partial specializations don't exist (needed
81 // for base case of the recursion), so we need a dummy struct.
82 template <RelExpr... Exprs> struct RelExprMaskBuilder {
83 static inline uint64_t build() { return 0; }
86 // Specialization for recursive case.
87 template <RelExpr Head, RelExpr... Tail>
88 struct RelExprMaskBuilder<Head, Tail...> {
89 static inline uint64_t build() {
90 static_assert(0 <= Head && Head < 64,
91 "RelExpr is too large for 64-bit mask!");
92 return (uint64_t(1) << Head) | RelExprMaskBuilder<Tail...>::build();
96 // Return true if `Expr` is one of `Exprs`.
97 // There are fewer than 64 RelExpr's, so we can represent any set of
98 // RelExpr's as a constant bit mask and test for membership with a
99 // couple cheap bitwise operations.
100 template <RelExpr... Exprs> bool isRelExprOneOf(RelExpr Expr) {
101 assert(0 <= Expr && (int)Expr < 64 && "RelExpr is too large for 64-bit mask!");
102 return (uint64_t(1) << Expr) & RelExprMaskBuilder<Exprs...>::build();
105 // Architecture-neutral representation of relocation.
114 template <class ELFT> void scanRelocations(InputSectionBase<ELFT> &);
116 template <class ELFT> void createThunks(InputSectionBase<ELFT> &);
118 template <class ELFT>
119 static inline typename ELFT::uint getAddend(const typename ELFT::Rel &Rel) {
123 template <class ELFT>
124 static inline typename ELFT::uint getAddend(const typename ELFT::Rela &Rel) {