Coverage Report

Created: 2018-08-19 21:11

/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
5
AMDGPU::AMDGPU() {
36
5
  RelativeRel = R_AMDGPU_RELATIVE64;
37
5
  GotRel = R_AMDGPU_ABS64;
38
5
  GotEntrySize = 8;
39
5
}
40
41
7
static uint32_t getEFlags(InputFile *File) {
42
7
  return cast<ObjFile<ELF64LE>>(File)->getObj().getHeader()->e_flags;
43
7
}
44
45
5
uint32_t AMDGPU::calcEFlags() const {
46
5
  assert(!ObjectFiles.empty());
47
5
  uint32_t Ret = getEFlags(ObjectFiles[0]);
48
5
49
5
  // Verify that all input files have the same e_flags.
50
5
  for (InputFile *F : makeArrayRef(ObjectFiles).slice(1)) {
51
2
    if (Ret == getEFlags(F))
52
1
      continue;
53
1
    error("incompatible e_flags: " + toString(F));
54
1
    return 0;
55
1
  }
56
5
  
return Ret4
;
57
5
}
58
59
25
void AMDGPU::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
60
25
  switch (Type) {
61
25
  case R_AMDGPU_ABS32:
62
18
  case R_AMDGPU_GOTPCREL:
63
18
  case R_AMDGPU_GOTPCREL32_LO:
64
18
  case R_AMDGPU_REL32:
65
18
  case R_AMDGPU_REL32_LO:
66
18
    write32le(Loc, Val);
67
18
    break;
68
18
  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
    error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
78
25
  }
79
25
}
80
81
RelExpr AMDGPU::getRelExpr(RelType Type, const Symbol &S,
82
27
                           const uint8_t *Loc) const {
83
27
  switch (Type) {
84
27
  case R_AMDGPU_ABS32:
85
8
  case R_AMDGPU_ABS64:
86
8
    return R_ABS;
87
8
  case R_AMDGPU_REL32:
88
4
  case R_AMDGPU_REL32_LO:
89
4
  case R_AMDGPU_REL32_HI:
90
4
  case R_AMDGPU_REL64:
91
4
    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
    return R_INVALID;
98
27
  }
99
27
}
100
101
5
TargetInfo *elf::getAMDGPUTargetInfo() {
102
5
  static AMDGPU Target;
103
5
  return &Target;
104
5
}