Coverage Report

Created: 2019-05-19 14:56

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Relocations.h
Line
Count
Source
1
//===- Relocations.h -------------------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLD_ELF_RELOCATIONS_H
10
#define LLD_ELF_RELOCATIONS_H
11
12
#include "lld/Common/LLVM.h"
13
#include "llvm/ADT/DenseMap.h"
14
#include <map>
15
#include <vector>
16
17
namespace lld {
18
namespace elf {
19
class Symbol;
20
class InputSection;
21
class InputSectionBase;
22
class OutputSection;
23
class SectionBase;
24
25
// Represents a relocation type, such as R_X86_64_PC32 or R_ARM_THM_CALL.
26
using RelType = uint32_t;
27
28
// List of target-independent relocation types. Relocations read
29
// from files are converted to these types so that the main code
30
// doesn't have to know about architecture-specific details.
31
enum RelExpr {
32
  R_ABS,
33
  R_ADDEND,
34
  R_DTPREL,
35
  R_GOT,
36
  R_GOT_OFF,
37
  R_GOT_PC,
38
  R_GOTONLY_PC,
39
  R_GOTPLTONLY_PC,
40
  R_GOTPLT,
41
  R_GOTPLTREL,
42
  R_GOTREL,
43
  R_HINT,
44
  R_NEG_TLS,
45
  R_NONE,
46
  R_PC,
47
  R_PLT,
48
  R_PLT_PC,
49
  R_RELAX_GOT_PC,
50
  R_RELAX_GOT_PC_NOPIC,
51
  R_RELAX_TLS_GD_TO_IE,
52
  R_RELAX_TLS_GD_TO_IE_ABS,
53
  R_RELAX_TLS_GD_TO_IE_GOT_OFF,
54
  R_RELAX_TLS_GD_TO_IE_GOTPLT,
55
  R_RELAX_TLS_GD_TO_LE,
56
  R_RELAX_TLS_GD_TO_LE_NEG,
57
  R_RELAX_TLS_IE_TO_LE,
58
  R_RELAX_TLS_LD_TO_LE,
59
  R_RELAX_TLS_LD_TO_LE_ABS,
60
  R_SIZE,
61
  R_TLS,
62
  R_TLSDESC,
63
  R_TLSDESC_CALL,
64
  R_TLSGD_GOT,
65
  R_TLSGD_GOTPLT,
66
  R_TLSGD_PC,
67
  R_TLSIE_HINT,
68
  R_TLSLD_GOT,
69
  R_TLSLD_GOTPLT,
70
  R_TLSLD_GOT_OFF,
71
  R_TLSLD_HINT,
72
  R_TLSLD_PC,
73
74
  // The following is abstract relocation types used for only one target.
75
  //
76
  // Even though RelExpr is intended to be a target-neutral representation
77
  // of a relocation type, there are some relocations whose semantics are
78
  // unique to a target. Such relocation are marked with R_<TARGET_NAME>.
79
  R_AARCH64_GOT_PAGE_PC,
80
  R_AARCH64_PAGE_PC,
81
  R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC,
82
  R_AARCH64_TLSDESC_PAGE,
83
  R_ARM_SBREL,
84
  R_HEXAGON_GOT,
85
  R_MIPS_GOTREL,
86
  R_MIPS_GOT_GP,
87
  R_MIPS_GOT_GP_PC,
88
  R_MIPS_GOT_LOCAL_PAGE,
89
  R_MIPS_GOT_OFF,
90
  R_MIPS_GOT_OFF32,
91
  R_MIPS_TLSGD,
92
  R_MIPS_TLSLD,
93
  R_PPC_CALL,
94
  R_PPC_CALL_PLT,
95
  R_PPC_TOC,
96
  R_PPC64_RELAX_TOC,
97
  R_RISCV_PC_INDIRECT,
98
};
99
100
// Architecture-neutral representation of relocation.
101
struct Relocation {
102
  RelExpr Expr;
103
  RelType Type;
104
  uint64_t Offset;
105
  int64_t Addend;
106
  Symbol *Sym;
107
};
108
109
template <class ELFT> void scanRelocations(InputSectionBase &);
110
111
void addIRelativeRelocs();
112
113
class ThunkSection;
114
class Thunk;
115
struct InputSectionDescription;
116
117
class ThunkCreator {
118
public:
119
  // Return true if Thunks have been added to OutputSections
120
  bool createThunks(ArrayRef<OutputSection *> OutputSections);
121
122
  // The number of completed passes of createThunks this permits us
123
  // to do one time initialization on Pass 0 and put a limit on the
124
  // number of times it can be called to prevent infinite loops.
125
  uint32_t Pass = 0;
126
127
private:
128
  void mergeThunks(ArrayRef<OutputSection *> OutputSections);
129
130
  ThunkSection *getISDThunkSec(OutputSection *OS, InputSection *IS,
131
                               InputSectionDescription *ISD, uint32_t Type,
132
                               uint64_t Src);
133
134
  ThunkSection *getISThunkSec(InputSection *IS);
135
136
  void createInitialThunkSections(ArrayRef<OutputSection *> OutputSections);
137
138
  std::pair<Thunk *, bool> getThunk(Symbol &Sym, RelType Type, uint64_t Src);
139
140
  ThunkSection *addThunkSection(OutputSection *OS, InputSectionDescription *,
141
                                uint64_t Off);
142
143
  bool normalizeExistingThunk(Relocation &Rel, uint64_t Src);
144
145
  // Record all the available Thunks for a Symbol
146
  llvm::DenseMap<std::pair<SectionBase *, uint64_t>, std::vector<Thunk *>>
147
      ThunkedSymbolsBySection;
148
  llvm::DenseMap<Symbol *, std::vector<Thunk *>> ThunkedSymbols;
149
150
  // Find a Thunk from the Thunks symbol definition, we can use this to find
151
  // the Thunk from a relocation to the Thunks symbol definition.
152
  llvm::DenseMap<Symbol *, Thunk *> Thunks;
153
154
  // Track InputSections that have an inline ThunkSection placed in front
155
  // an inline ThunkSection may have control fall through to the section below
156
  // so we need to make sure that there is only one of them.
157
  // The Mips LA25 Thunk is an example of an inline ThunkSection.
158
  llvm::DenseMap<InputSection *, ThunkSection *> ThunkedSections;
159
};
160
161
// Return a int64_t to make sure we get the sign extension out of the way as
162
// early as possible.
163
template <class ELFT>
164
49
static inline int64_t getAddend(const typename ELFT::Rel &Rel) {
165
49
  return 0;
166
49
}
DWARF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::Rel const&)
Line
Count
Source
164
6
static inline int64_t getAddend(const typename ELFT::Rel &Rel) {
165
6
  return 0;
166
6
}
Unexecuted instantiation: DWARF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::Rel const&)
Unexecuted instantiation: DWARF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Rel const&)
Unexecuted instantiation: DWARF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Rel const&)
ICF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::Rel const&)
Line
Count
Source
164
2
static inline int64_t getAddend(const typename ELFT::Rel &Rel) {
165
2
  return 0;
166
2
}
Unexecuted instantiation: ICF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::Rel const&)
Unexecuted instantiation: ICF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Rel const&)
Unexecuted instantiation: ICF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Rel const&)
InputSection.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::Rel const&)
Line
Count
Source
164
24
static inline int64_t getAddend(const typename ELFT::Rel &Rel) {
165
24
  return 0;
166
24
}
InputSection.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::Rel const&)
Line
Count
Source
164
17
static inline int64_t getAddend(const typename ELFT::Rel &Rel) {
165
17
  return 0;
166
17
}
Unexecuted instantiation: InputSection.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Rel const&)
Unexecuted instantiation: InputSection.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Rel const&)
Unexecuted instantiation: Relocations.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::Rel const&)
Unexecuted instantiation: Relocations.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::Rel const&)
Unexecuted instantiation: Relocations.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Rel const&)
Unexecuted instantiation: Relocations.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Rel const&)
167
template <class ELFT>
168
13.4k
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
13.4k
  return Rel.r_addend;
170
13.4k
}
PPC64.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Rela const&)
Line
Count
Source
168
44
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
44
  return Rel.r_addend;
170
44
}
PPC64.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Rela const&)
Line
Count
Source
168
22
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
22
  return Rel.r_addend;
170
22
}
Unexecuted instantiation: DWARF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::Rela const&)
Unexecuted instantiation: DWARF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::Rela const&)
DWARF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Rela const&)
Line
Count
Source
168
109
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
109
  return Rel.r_addend;
170
109
}
Unexecuted instantiation: DWARF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Rela const&)
Unexecuted instantiation: ICF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::Rela const&)
Unexecuted instantiation: ICF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::Rela const&)
ICF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Rela const&)
Line
Count
Source
168
40
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
40
  return Rel.r_addend;
170
40
}
Unexecuted instantiation: ICF.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Rela const&)
Unexecuted instantiation: InputSection.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::Rela const&)
Unexecuted instantiation: InputSection.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::Rela const&)
InputSection.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Rela const&)
Line
Count
Source
168
290
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
290
  return Rel.r_addend;
170
290
}
InputSection.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Rela const&)
Line
Count
Source
168
10
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
10
  return Rel.r_addend;
170
10
}
Relocations.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, false> >(llvm::object::ELFType<(llvm::support::endianness)1, false>::Rela const&)
Line
Count
Source
168
108
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
108
  return Rel.r_addend;
170
108
}
Relocations.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, false> >(llvm::object::ELFType<(llvm::support::endianness)0, false>::Rela const&)
Line
Count
Source
168
14
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
14
  return Rel.r_addend;
170
14
}
Relocations.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::object::ELFType<(llvm::support::endianness)1, true>::Rela const&)
Line
Count
Source
168
2.40k
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
2.40k
  return Rel.r_addend;
170
2.40k
}
Relocations.cpp:long long lld::elf::getAddend<llvm::object::ELFType<(llvm::support::endianness)0, true> >(llvm::object::ELFType<(llvm::support::endianness)0, true>::Rela const&)
Line
Count
Source
168
10.4k
static inline int64_t getAddend(const typename ELFT::Rela &Rel) {
169
10.4k
  return Rel.r_addend;
170
10.4k
}
171
} // namespace elf
172
} // namespace lld
173
174
#endif