Coverage Report

Created: 2019-05-19 14:56

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