Coverage Report

Created: 2017-09-19 22:28

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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 "Error.h"
29
#include "InputFiles.h"
30
#include "OutputSections.h"
31
#include "SymbolTable.h"
32
#include "Symbols.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
78
std::string lld::toString(uint32_t Type) {
44
78
  StringRef S = getELFRelocationTypeName(elf::Config->EMachine, Type);
45
78
  if (S == "Unknown")
46
3
    return ("Unknown (" + Twine(Type) + ")").str();
47
75
  return S;
48
75
}
49
50
1.63k
TargetInfo *elf::getTarget() {
51
1.63k
  switch (Config->EMachine) {
52
101
  case EM_386:
53
101
  case EM_IAMCU:
54
101
    return getX86TargetInfo();
55
72
  case EM_AARCH64:
56
72
    return getAArch64TargetInfo();
57
3
  case EM_AMDGPU:
58
3
    return getAMDGPUTargetInfo();
59
80
  case EM_ARM:
60
80
    return getARMTargetInfo();
61
0
  case EM_AVR:
62
0
    return getAVRTargetInfo();
63
138
  case EM_MIPS:
64
138
    switch (Config->EKind) {
65
14
    case ELF32LEKind:
66
14
      return getMipsTargetInfo<ELF32LE>();
67
94
    case ELF32BEKind:
68
94
      return getMipsTargetInfo<ELF32BE>();
69
2
    case ELF64LEKind:
70
2
      return getMipsTargetInfo<ELF64LE>();
71
28
    case ELF64BEKind:
72
28
      return getMipsTargetInfo<ELF64BE>();
73
0
    default:
74
0
      fatal("unsupported MIPS target");
75
0
    }
76
2
  case EM_PPC:
77
2
    return getPPCTargetInfo();
78
18
  case EM_PPC64:
79
18
    return getPPC64TargetInfo();
80
1
  case EM_SPARCV9:
81
1
    return getSPARCV9TargetInfo();
82
1.22k
  case EM_X86_64:
83
1.22k
    if (Config->EKind == ELF32LEKind)
84
3
      return getX32TargetInfo();
85
1.21k
    return getX86_64TargetInfo();
86
0
  }
87
0
  fatal("unknown target machine");
88
0
}
89
90
36
template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) {
91
60
  for (InputSectionBase *D : InputSections) {
92
60
    auto *IS = dyn_cast_or_null<InputSection>(D);
93
60
    if (
!IS || 60
!IS->getParent()60
)
94
0
      continue;
95
60
96
60
    uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
97
60
    if (
ISLoc <= Loc && 60
Loc < ISLoc + IS->getSize()60
)
98
36
      return IS->template getLocation<ELFT>(Loc - ISLoc) + ": ";
99
0
  }
100
0
  return "";
101
0
}
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*)
Line
Count
Source
90
9
template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) {
91
9
  for (InputSectionBase *D : InputSections) {
92
9
    auto *IS = dyn_cast_or_null<InputSection>(D);
93
9
    if (
!IS || 9
!IS->getParent()9
)
94
0
      continue;
95
9
96
9
    uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
97
9
    if (
ISLoc <= Loc && 9
Loc < ISLoc + IS->getSize()9
)
98
9
      return IS->template getLocation<ELFT>(Loc - ISLoc) + ": ";
99
0
  }
100
0
  return "";
101
0
}
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*)
Line
Count
Source
90
1
template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) {
91
1
  for (InputSectionBase *D : InputSections) {
92
1
    auto *IS = dyn_cast_or_null<InputSection>(D);
93
1
    if (
!IS || 1
!IS->getParent()1
)
94
0
      continue;
95
1
96
1
    uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
97
1
    if (
ISLoc <= Loc && 1
Loc < ISLoc + IS->getSize()1
)
98
1
      return IS->template getLocation<ELFT>(Loc - ISLoc) + ": ";
99
0
  }
100
0
  return "";
101
0
}
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
25
template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) {
91
49
  for (InputSectionBase *D : InputSections) {
92
49
    auto *IS = dyn_cast_or_null<InputSection>(D);
93
49
    if (
!IS || 49
!IS->getParent()49
)
94
0
      continue;
95
49
96
49
    uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
97
49
    if (
ISLoc <= Loc && 49
Loc < ISLoc + IS->getSize()49
)
98
25
      return IS->template getLocation<ELFT>(Loc - ISLoc) + ": ";
99
0
  }
100
0
  return "";
101
0
}
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
template <class ELFT> static std::string getErrorLoc(const uint8_t *Loc) {
91
1
  for (InputSectionBase *D : InputSections) {
92
1
    auto *IS = dyn_cast_or_null<InputSection>(D);
93
1
    if (
!IS || 1
!IS->getParent()1
)
94
0
      continue;
95
1
96
1
    uint8_t *ISLoc = IS->getParent()->Loc + IS->OutSecOff;
97
1
    if (
ISLoc <= Loc && 1
Loc < ISLoc + IS->getSize()1
)
98
1
      return IS->template getLocation<ELFT>(Loc - ISLoc) + ": ";
99
0
  }
100
0
  return "";
101
0
}
102
103
36
std::string elf::getErrorLocation(const uint8_t *Loc) {
104
36
  switch (Config->EKind) {
105
9
  case ELF32LEKind:
106
9
    return getErrorLoc<ELF32LE>(Loc);
107
1
  case ELF32BEKind:
108
1
    return getErrorLoc<ELF32BE>(Loc);
109
25
  case ELF64LEKind:
110
25
    return getErrorLoc<ELF64LE>(Loc);
111
1
  case ELF64BEKind:
112
1
    return getErrorLoc<ELF64BE>(Loc);
113
0
  default:
114
0
    llvm_unreachable("unknown ELF type");
115
0
  }
116
0
}
117
118
1.63k
TargetInfo::~TargetInfo() {}
119
120
2
int64_t TargetInfo::getImplicitAddend(const uint8_t *Buf, uint32_t Type) const {
121
2
  return 0;
122
2
}
123
124
81
bool TargetInfo::usesOnlyLowPageBits(uint32_t Type) const { return false; }
125
126
bool TargetInfo::needsThunk(RelExpr Expr, uint32_t RelocType,
127
0
                            const InputFile *File, const SymbolBody &S) const {
128
0
  return false;
129
0
}
130
131
bool TargetInfo::inBranchRange(uint32_t RelocType, uint64_t Src,
132
0
                               uint64_t Dst) const {
133
0
  return true;
134
0
}
135
136
15
void TargetInfo::writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const {
137
15
  writeGotPlt(Buf, S);
138
15
}
139
140
RelExpr TargetInfo::adjustRelaxExpr(uint32_t Type, const uint8_t *Data,
141
3
                                    RelExpr Expr) const {
142
3
  return Expr;
143
3
}
144
145
0
void TargetInfo::relaxGot(uint8_t *Loc, uint64_t Val) const {
146
0
  llvm_unreachable("Should not have claimed to be relaxable");
147
0
}
148
149
void TargetInfo::relaxTlsGdToLe(uint8_t *Loc, uint32_t Type,
150
0
                                uint64_t Val) const {
151
0
  llvm_unreachable("Should not have claimed to be relaxable");
152
0
}
153
154
void TargetInfo::relaxTlsGdToIe(uint8_t *Loc, uint32_t Type,
155
0
                                uint64_t Val) const {
156
0
  llvm_unreachable("Should not have claimed to be relaxable");
157
0
}
158
159
void TargetInfo::relaxTlsIeToLe(uint8_t *Loc, uint32_t Type,
160
0
                                uint64_t Val) const {
161
0
  llvm_unreachable("Should not have claimed to be relaxable");
162
0
}
163
164
void TargetInfo::relaxTlsLdToLe(uint8_t *Loc, uint32_t Type,
165
0
                                uint64_t Val) const {
166
0
  llvm_unreachable("Should not have claimed to be relaxable");
167
0
}