Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/ELF/Arch/SPARCV9.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- SPARCV9.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 "Error.h"
11
#include "InputFiles.h"
12
#include "Symbols.h"
13
#include "SyntheticSections.h"
14
#include "Target.h"
15
#include "llvm/Support/Endian.h"
16
17
using namespace llvm;
18
using namespace llvm::support::endian;
19
using namespace llvm::ELF;
20
using namespace lld;
21
using namespace lld::elf;
22
23
namespace {
24
class SPARCV9 final : public TargetInfo {
25
public:
26
  SPARCV9();
27
  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S, const InputFile &File,
28
                     const uint8_t *Loc) const override;
29
  void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr,
30
                int32_t Index, unsigned RelOff) const override;
31
  void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
32
};
33
} // namespace
34
35
1
SPARCV9::SPARCV9() {
36
1
  CopyRel = R_SPARC_COPY;
37
1
  GotRel = R_SPARC_GLOB_DAT;
38
1
  PltRel = R_SPARC_JMP_SLOT;
39
1
  RelativeRel = R_SPARC_RELATIVE;
40
1
  GotEntrySize = 8;
41
1
  PltEntrySize = 32;
42
1
  PltHeaderSize = 4 * PltEntrySize;
43
1
44
1
  PageSize = 8192;
45
1
  DefaultMaxPageSize = 0x100000;
46
1
  DefaultImageBase = 0x100000;
47
1
}
48
49
RelExpr SPARCV9::getRelExpr(uint32_t Type, const SymbolBody &S,
50
0
                            const InputFile &File, const uint8_t *Loc) const {
51
0
  switch (Type) {
52
0
  case R_SPARC_32:
53
0
  case R_SPARC_UA32:
54
0
  case R_SPARC_64:
55
0
  case R_SPARC_UA64:
56
0
    return R_ABS;
57
0
  case R_SPARC_PC10:
58
0
  case R_SPARC_PC22:
59
0
  case R_SPARC_DISP32:
60
0
  case R_SPARC_WDISP30:
61
0
    return R_PC;
62
0
  case R_SPARC_GOT10:
63
0
    return R_GOT_OFF;
64
0
  case R_SPARC_GOT22:
65
0
    return R_GOT_OFF;
66
0
  case R_SPARC_WPLT30:
67
0
    return R_PLT_PC;
68
0
  case R_SPARC_NONE:
69
0
    return R_NONE;
70
0
  default:
71
0
    error(toString(&File) + ": unknown relocation type: " + toString(Type));
72
0
    return R_HINT;
73
0
  }
74
0
}
75
76
void SPARCV9::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const {
77
  switch (Type) {
78
  case R_SPARC_32:
79
  case R_SPARC_UA32:
80
    // V-word32
81
    checkUInt<32>(Loc, Val, Type);
82
    write32be(Loc, Val);
83
    break;
84
  case R_SPARC_DISP32:
85
    // V-disp32
86
    checkInt<32>(Loc, Val, Type);
87
    write32be(Loc, Val);
88
    break;
89
  case R_SPARC_WDISP30:
90
  case R_SPARC_WPLT30:
91
    // V-disp30
92
    checkInt<32>(Loc, Val, Type);
93
    write32be(Loc, (read32be(Loc) & ~0x3fffffff) | ((Val >> 2) & 0x3fffffff));
94
    break;
95
  case R_SPARC_22:
96
    // V-imm22
97
    checkUInt<22>(Loc, Val, Type);
98
    write32be(Loc, (read32be(Loc) & ~0x003fffff) | (Val & 0x003fffff));
99
    break;
100
  case R_SPARC_GOT22:
101
  case R_SPARC_PC22:
102
    // T-imm22
103
    write32be(Loc, (read32be(Loc) & ~0x003fffff) | ((Val >> 10) & 0x003fffff));
104
    break;
105
  case R_SPARC_WDISP19:
106
    // V-disp19
107
    checkInt<21>(Loc, Val, Type);
108
    write32be(Loc, (read32be(Loc) & ~0x0007ffff) | ((Val >> 2) & 0x0007ffff));
109
    break;
110
  case R_SPARC_GOT10:
111
  case R_SPARC_PC10:
112
    // T-simm10
113
    write32be(Loc, (read32be(Loc) & ~0x000003ff) | (Val & 0x000003ff));
114
    break;
115
  case R_SPARC_64:
116
  case R_SPARC_UA64:
117
  case R_SPARC_GLOB_DAT:
118
    // V-xword64
119
    write64be(Loc, Val);
120
    break;
121
  default:
122
    error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
123
  }
124
}
125
126
void SPARCV9::writePlt(uint8_t *Buf, uint64_t GotEntryAddr,
127
                       uint64_t PltEntryAddr, int32_t Index,
128
0
                       unsigned RelOff) const {
129
0
  const uint8_t PltData[] = {
130
0
      0x03, 0x00, 0x00, 0x00, // sethi   (. - .PLT0), %g1
131
0
      0x30, 0x68, 0x00, 0x00, // ba,a    %xcc, .PLT1
132
0
      0x01, 0x00, 0x00, 0x00, // nop
133
0
      0x01, 0x00, 0x00, 0x00, // nop
134
0
      0x01, 0x00, 0x00, 0x00, // nop
135
0
      0x01, 0x00, 0x00, 0x00, // nop
136
0
      0x01, 0x00, 0x00, 0x00, // nop
137
0
      0x01, 0x00, 0x00, 0x00  // nop
138
0
  };
139
0
  memcpy(Buf, PltData, sizeof(PltData));
140
0
141
0
  uint64_t Off = PltHeaderSize + Index * PltEntrySize;
142
0
  relocateOne(Buf, R_SPARC_22, Off);
143
0
  relocateOne(Buf + 4, R_SPARC_WDISP19, -(Off + 4 - PltEntrySize));
144
0
}
145
146
1
TargetInfo *elf::getSPARCV9TargetInfo() {
147
1
  static SPARCV9 Target;
148
1
  return &Target;
149
1
}