Coverage Report

Created: 2018-08-19 21:11

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