Coverage Report

Created: 2019-05-22 02:55

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Arch/PPC.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- PPC.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 "Symbols.h"
10
#include "Target.h"
11
#include "lld/Common/ErrorHandler.h"
12
#include "llvm/Support/Endian.h"
13
14
using namespace llvm;
15
using namespace llvm::support::endian;
16
using namespace llvm::ELF;
17
using namespace lld;
18
using namespace lld::elf;
19
20
namespace {
21
class PPC final : public TargetInfo {
22
public:
23
  PPC();
24
  void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
25
  RelExpr getRelExpr(RelType Type, const Symbol &S,
26
                     const uint8_t *Loc) const override;
27
};
28
} // namespace
29
30
4
PPC::PPC() {
31
4
  NoneRel = R_PPC_NONE;
32
4
  GotBaseSymInGotPlt = false;
33
4
}
34
35
RelExpr PPC::getRelExpr(RelType Type, const Symbol &S,
36
9
                        const uint8_t *Loc) const {
37
9
  switch (Type) {
38
9
  case R_PPC_REL14:
39
3
  case R_PPC_REL24:
40
3
  case R_PPC_REL32:
41
3
    return R_PC;
42
3
  case R_PPC_PLTREL24:
43
1
    return R_PLT_PC;
44
5
  default:
45
5
    return R_ABS;
46
9
  }
47
9
}
48
49
8
void PPC::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
50
8
  switch (Type) {
51
8
  case R_PPC_ADDR16_HA:
52
1
    write16be(Loc, (Val + 0x8000) >> 16);
53
1
    break;
54
8
  case R_PPC_ADDR16_HI:
55
1
    write16be(Loc, Val >> 16);
56
1
    break;
57
8
  case R_PPC_ADDR16_LO:
58
1
    write16be(Loc, Val);
59
1
    break;
60
8
  case R_PPC_ADDR32:
61
2
  case R_PPC_REL32:
62
2
    write32be(Loc, Val);
63
2
    break;
64
2
  case R_PPC_REL14:
65
1
    write32be(Loc, read32be(Loc) | (Val & 0xFFFC));
66
1
    break;
67
2
  case R_PPC_PLTREL24:
68
2
  case R_PPC_REL24:
69
2
    write32be(Loc, read32be(Loc) | (Val & 0x3FFFFFC));
70
2
    break;
71
2
  default:
72
0
    error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
73
8
  }
74
8
}
75
76
4
TargetInfo *elf::getPPCTargetInfo() {
77
4
  static PPC Target;
78
4
  return &Target;
79
4
}