Coverage Report

Created: 2019-01-21 03:01

/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
3
PPC::PPC() {
31
3
  NoneRel = R_PPC_NONE;
32
3
  GotBaseSymOff = 0x8000;
33
3
  GotBaseSymInGotPlt = false;
34
3
}
35
36
RelExpr PPC::getRelExpr(RelType Type, const Symbol &S,
37
9
                        const uint8_t *Loc) const {
38
9
  switch (Type) {
39
9
  case R_PPC_REL14:
40
3
  case R_PPC_REL24:
41
3
  case R_PPC_REL32:
42
3
    return R_PC;
43
3
  case R_PPC_PLTREL24:
44
1
    return R_PLT_PC;
45
5
  default:
46
5
    return R_ABS;
47
9
  }
48
9
}
49
50
8
void PPC::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
51
8
  switch (Type) {
52
8
  case R_PPC_ADDR16_HA:
53
1
    write16be(Loc, (Val + 0x8000) >> 16);
54
1
    break;
55
8
  case R_PPC_ADDR16_HI:
56
1
    write16be(Loc, Val >> 16);
57
1
    break;
58
8
  case R_PPC_ADDR16_LO:
59
1
    write16be(Loc, Val);
60
1
    break;
61
8
  case R_PPC_ADDR32:
62
2
  case R_PPC_REL32:
63
2
    write32be(Loc, Val);
64
2
    break;
65
2
  case R_PPC_REL14:
66
1
    write32be(Loc, read32be(Loc) | (Val & 0xFFFC));
67
1
    break;
68
2
  case R_PPC_PLTREL24:
69
2
  case R_PPC_REL24:
70
2
    write32be(Loc, read32be(Loc) | (Val & 0x3FFFFFC));
71
2
    break;
72
2
  default:
73
0
    error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
74
8
  }
75
8
}
76
77
3
TargetInfo *elf::getPPCTargetInfo() {
78
3
  static PPC Target;
79
3
  return &Target;
80
3
}