Coverage Report

Created: 2018-10-20 06:24

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Arch/AMDGPU.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- AMDGPU.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
#include "InputFiles.h"
11
#include "Symbols.h"
12
#include "Target.h"
13
#include "lld/Common/ErrorHandler.h"
14
#include "llvm/Object/ELF.h"
15
#include "llvm/Support/Endian.h"
16
17
using namespace llvm;
18
using namespace llvm::object;
19
using namespace llvm::support::endian;
20
using namespace llvm::ELF;
21
using namespace lld;
22
using namespace lld::elf;
23
24
namespace {
25
class AMDGPU final : public TargetInfo {
26
public:
27
  AMDGPU();
28
  uint32_t calcEFlags() const override;
29
  void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
30
  RelExpr getRelExpr(RelType Type, const Symbol &S,
31
                     const uint8_t *Loc) const override;
32
};
33
} // namespace
34
35
7
AMDGPU::AMDGPU() {
36
7
  RelativeRel = R_AMDGPU_RELATIVE64;
37
7
  GotRel = R_AMDGPU_ABS64;
38
7
  NoneRel = R_AMDGPU_NONE;
39
7
  GotEntrySize = 8;
40
7
}
41
42
9
static uint32_t getEFlags(InputFile *File) {
43
9
  return cast<ObjFile<ELF64LE>>(File)->getObj().getHeader()->e_flags;
44
9
}
45
46
7
uint32_t AMDGPU::calcEFlags() const {
47
7
  assert(!ObjectFiles.empty());
48
7
  uint32_t Ret = getEFlags(ObjectFiles[0]);
49
7
50
7
  // Verify that all input files have the same e_flags.
51
7
  for (InputFile *F : makeArrayRef(ObjectFiles).slice(1)) {
52
2
    if (Ret == getEFlags(F))
53
1
      continue;
54
1
    error("incompatible e_flags: " + toString(F));
55
1
    return 0;
56
1
  }
57
7
  
return Ret6
;
58
7
}
59
60
25
void AMDGPU::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
61
25
  switch (Type) {
62
25
  case R_AMDGPU_ABS32:
63
18
  case R_AMDGPU_GOTPCREL:
64
18
  case R_AMDGPU_GOTPCREL32_LO:
65
18
  case R_AMDGPU_REL32:
66
18
  case R_AMDGPU_REL32_LO:
67
18
    write32le(Loc, Val);
68
18
    break;
69
18
  case R_AMDGPU_ABS64:
70
1
  case R_AMDGPU_REL64:
71
1
    write64le(Loc, Val);
72
1
    break;
73
6
  case R_AMDGPU_GOTPCREL32_HI:
74
6
  case R_AMDGPU_REL32_HI:
75
6
    write32le(Loc, Val >> 32);
76
6
    break;
77
6
  default:
78
0
    error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
79
25
  }
80
25
}
81
82
RelExpr AMDGPU::getRelExpr(RelType Type, const Symbol &S,
83
27
                           const uint8_t *Loc) const {
84
27
  switch (Type) {
85
27
  case R_AMDGPU_ABS32:
86
8
  case R_AMDGPU_ABS64:
87
8
    return R_ABS;
88
8
  case R_AMDGPU_REL32:
89
4
  case R_AMDGPU_REL32_LO:
90
4
  case R_AMDGPU_REL32_HI:
91
4
  case R_AMDGPU_REL64:
92
4
    return R_PC;
93
15
  case R_AMDGPU_GOTPCREL:
94
15
  case R_AMDGPU_GOTPCREL32_LO:
95
15
  case R_AMDGPU_GOTPCREL32_HI:
96
15
    return R_GOT_PC;
97
15
  default:
98
0
    return R_INVALID;
99
27
  }
100
27
}
101
102
7
TargetInfo *elf::getAMDGPUTargetInfo() {
103
7
  static AMDGPU Target;
104
7
  return &Target;
105
7
}