Coverage Report

Created: 2018-01-17 21:32

/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
3
AMDGPU::AMDGPU() {
36
3
  RelativeRel = R_AMDGPU_RELATIVE64;
37
3
  GotRel = R_AMDGPU_ABS64;
38
3
  GotEntrySize = 8;
39
3
}
40
41
5
static uint32_t getEFlags(InputFile *File) {
42
5
  return cast<ObjFile<ELF64LE>>(File)->getObj().getHeader()->e_flags;
43
5
}
44
45
3
uint32_t AMDGPU::calcEFlags() const {
46
3
  assert(!ObjectFiles.empty());
47
3
  uint32_t Ret = getEFlags(ObjectFiles[0]);
48
3
49
3
  // Verify that all input files have the same e_flags.
50
3
  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
3
  
return Ret2
;
57
3
}
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
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
0
    write64le(Loc, Val);
70
0
    break;
71
18
  case R_AMDGPU_GOTPCREL32_HI:
72
6
  case R_AMDGPU_REL32_HI:
73
6
    write32le(Loc, Val >> 32);
74
6
    break;
75
6
  default:
76
0
    error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
77
24
  }
78
24
}
79
80
RelExpr AMDGPU::getRelExpr(RelType Type, const Symbol &S,
81
26
                           const uint8_t *Loc) const {
82
26
  switch (Type) {
83
26
  case R_AMDGPU_ABS32:
84
8
  case R_AMDGPU_ABS64:
85
8
    return R_ABS;
86
8
  case R_AMDGPU_REL32:
87
3
  case R_AMDGPU_REL32_LO:
88
3
  case R_AMDGPU_REL32_HI:
89
3
    return R_PC;
90
15
  case R_AMDGPU_GOTPCREL:
91
15
  case R_AMDGPU_GOTPCREL32_LO:
92
15
  case R_AMDGPU_GOTPCREL32_HI:
93
15
    return R_GOT_PC;
94
15
  default:
95
0
    return R_INVALID;
96
0
  }
97
0
}
98
99
3
TargetInfo *elf::getAMDGPUTargetInfo() {
100
3
  static AMDGPU Target;
101
3
  return &Target;
102
3
}