Coverage Report

Created: 2018-01-17 21:32

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Target.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Target.cpp ---------------------------------------------------------===//
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
// Machine-specific things, such as applying relocations, creation of
11
// GOT or PLT entries, etc., are handled in this file.
12
//
13
// Refer the ELF spec for the single letter variables, S, A or P, used
14
// in this file.
15
//
16
// Some functions defined in this file has "relaxTls" as part of their names.
17
// They do peephole optimization for TLS variables by rewriting instructions.
18
// They are not part of the ABI but optional optimization, so you can skip
19
// them if you are not interested in how TLS variables are optimized.
20
// See the following paper for the details.
21
//
22
//   Ulrich Drepper, ELF Handling For Thread-Local Storage
23
//   http://www.akkadia.org/drepper/tls.pdf
24
//
25
//===----------------------------------------------------------------------===//
26
27
#include "Target.h"
28
#include "InputFiles.h"
29
#include "OutputSections.h"
30
#include "SymbolTable.h"
31
#include "Symbols.h"
32
#include "lld/Common/ErrorHandler.h"
33
#include "llvm/Object/ELF.h"
34
35
using namespace llvm;
36
using namespace llvm::object;
37
using namespace llvm::ELF;
38
using namespace lld;
39
using namespace lld::elf;
40
41
TargetInfo *elf::Target;
42
43
1.84k
std::string lld::toString(RelType Type) {
44
1.84k
  StringRef S = getELFRelocationTypeName(elf::Config->EMachine, Type);
45
1.84k
  if (S == "Unknown")
46
1
    return ("Unknown (" + Twine(Type) + ")").str();
47
1.84k
  return S;
48
1.84k
}
49
50
966
TargetInfo *elf::getTarget() {
51
966
  switch (Config->EMachine) {
52
966
  case EM_386:
53
60
  case EM_IAMCU:
54
60
    return getX86TargetInfo();
55
60
  case EM_AARCH64:
56
44
    return getAArch64TargetInfo();
57
60
  case EM_AMDGPU:
58
3
    return getAMDGPUTargetInfo();
59
60
  case EM_ARM:
60
58
    return getARMTargetInfo();
61
60
  case EM_AVR:
62
0
    return getAVRTargetInfo();
63
76
  case EM_MIPS:
64
76
    switch (Config->EKind) {
65
76
    case ELF32LEKind:
66
4
      return getMipsTargetInfo<ELF32LE>();
67
76
    case ELF32BEKind:
68
53
      return getMipsTargetInfo<ELF32BE>();
69
76
    case ELF64LEKind:
70
0
      return getMipsTargetInfo<ELF64LE>();
71
76
    case ELF64BEKind:
72
19
      return getMipsTargetInfo<ELF64BE>();
73
76
    default:
74
0
      fatal("unsupported MIPS target");
75
0
    }
76
1
  case EM_PPC:
77
1
    return getPPCTargetInfo();
78
10
  case EM_PPC64:
79
10
    return getPPC64TargetInfo();
80
1
  case EM_SPARCV9:
81
1
    return getSPARCV9TargetInfo();
82
713
  case EM_X86_64:
83
713
    if (Config->EKind == ELF32LEKind)
84
1
      return getX32TargetInfo();
85
712
    return getX86_64TargetInfo();
86
0
  }
87
0
  fatal("unknown target machine");
88
0
}
89
90
1.83k
template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) {
91
1.87k
  for (InputSectionBase *D : InputSections) {
92
1.87k
    auto *IS = dyn_cast<InputSection>(D);
93
1.87k
    if (!IS || !IS->getParent())
94
0
      continue;
95
1.87k
96
1.87k
    uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
97
1.87k
    if (ISLoc <= Loc && Loc < ISLoc + IS->getSize())
98
1.82k
      return IS->template getLocation<ELFT>(Loc - ISLoc) + ": ";
99
1.87k
  }
100
1.83k
  
return ""2
;
101
1.83k
}
Unexecuted instantiation: Target.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > getErrorLoc<llvm::object::ELFType<(llvm::support::endianness)1, false> >(unsigned char const*)
Unexecuted instantiation: Target.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > getErrorLoc<llvm::object::ELFType<(llvm::support::endianness)0, false> >(unsigned char const*)
Target.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > getErrorLoc<llvm::object::ELFType<(llvm::support::endianness)1, true> >(unsigned char const*)
Line
Count
Source
90
17
template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) {
91
65
  for (InputSectionBase *D : InputSections) {
92
65
    auto *IS = dyn_cast<InputSection>(D);
93
65
    if (!IS || !IS->getParent())
94
0
      continue;
95
65
96
65
    uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
97
65
    if (ISLoc <= Loc && Loc < ISLoc + IS->getSize())
98
15
      return IS->template getLocation<ELFT>(Loc - ISLoc) + ": ";
99
65
  }
100
17
  
return ""2
;
101
17
}
Target.cpp:std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > getErrorLoc<llvm::object::ELFType<(llvm::support::endianness)0, true> >(unsigned char const*)
Line
Count
Source
90
1.81k
template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) {
91
1.81k
  for (InputSectionBase *D : InputSections) {
92
1.81k
    auto *IS = dyn_cast<InputSection>(D);
93
1.81k
    if (!IS || !IS->getParent())
94
0
      continue;
95
1.81k
96
1.81k
    uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
97
1.81k
    if (ISLoc <= Loc && Loc < ISLoc + IS->getSize())
98
1.81k
      return IS->template getLocation<ELFT>(Loc - ISLoc) + ": ";
99
1.81k
  }
100
1.81k
  
return ""0
;
101
1.81k
}
102
103
1.83k
std::string elf::getErrorLocation(const uint8_t *Loc) {
104
1.83k
  switch (Config->EKind) {
105
1.83k
  case ELF32LEKind:
106
0
    return getErrorLoc<ELF32LE>(Loc);
107
1.83k
  case ELF32BEKind:
108
0
    return getErrorLoc<ELF32BE>(Loc);
109
1.83k
  case ELF64LEKind:
110
17
    return getErrorLoc<ELF64LE>(Loc);
111
1.83k
  case ELF64BEKind:
112
1.81k
    return getErrorLoc<ELF64BE>(Loc);
113
1.83k
  default:
114
0
    llvm_unreachable("unknown ELF type");
115
0
  }
116
0
}
117
118
966
TargetInfo::~TargetInfo() {}
119
120
0
int64_t TargetInfo::getImplicitAddend(const uint8_t *Buf, RelType Type) const {
121
0
  return 0;
122
0
}
123
124
80
bool TargetInfo::usesOnlyLowPageBits(RelType Type) const { return false; }
125
126
bool TargetInfo::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,
127
0
                            uint64_t BranchAddr, const Symbol &S) const {
128
0
  return false;
129
0
}
130
131
26
bool TargetInfo::inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const {
132
26
  return true;
133
26
}
134
135
11
void TargetInfo::writeIgotPlt(uint8_t *Buf, const Symbol &S) const {
136
11
  writeGotPlt(Buf, S);
137
11
}
138
139
RelExpr TargetInfo::adjustRelaxExpr(RelType Type, const uint8_t *Data,
140
1
                                    RelExpr Expr) const {
141
1
  return Expr;
142
1
}
143
144
0
void TargetInfo::relaxGot(uint8_t *Loc, uint64_t Val) const {
145
0
  llvm_unreachable("Should not have claimed to be relaxable");
146
0
}
147
148
void TargetInfo::relaxTlsGdToLe(uint8_t *Loc, RelType Type,
149
0
                                uint64_t Val) const {
150
0
  llvm_unreachable("Should not have claimed to be relaxable");
151
0
}
152
153
void TargetInfo::relaxTlsGdToIe(uint8_t *Loc, RelType Type,
154
0
                                uint64_t Val) const {
155
0
  llvm_unreachable("Should not have claimed to be relaxable");
156
0
}
157
158
void TargetInfo::relaxTlsIeToLe(uint8_t *Loc, RelType Type,
159
0
                                uint64_t Val) const {
160
0
  llvm_unreachable("Should not have claimed to be relaxable");
161
0
}
162
163
void TargetInfo::relaxTlsLdToLe(uint8_t *Loc, RelType Type,
164
0
                                uint64_t Val) const {
165
0
  llvm_unreachable("Should not have claimed to be relaxable");
166
0
}
167
168
913
uint64_t TargetInfo::getImageBase() {
169
913
  // Use -image-base if set. Fall back to the target default if not.
170
913
  if (Config->ImageBase)
171
1
    return *Config->ImageBase;
172
912
  return Config->Pic ? 
0415
:
DefaultImageBase497
;
173
912
}