Coverage Report

Created: 2019-05-19 14:56

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Arch/Mips.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- MIPS.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 "InputFiles.h"
10
#include "OutputSections.h"
11
#include "Symbols.h"
12
#include "SyntheticSections.h"
13
#include "Target.h"
14
#include "Thunks.h"
15
#include "lld/Common/ErrorHandler.h"
16
#include "llvm/Object/ELF.h"
17
#include "llvm/Support/Endian.h"
18
19
using namespace llvm;
20
using namespace llvm::object;
21
using namespace llvm::support::endian;
22
using namespace llvm::ELF;
23
using namespace lld;
24
using namespace lld::elf;
25
26
namespace {
27
template <class ELFT> class MIPS final : public TargetInfo {
28
public:
29
  MIPS();
30
  uint32_t calcEFlags() const override;
31
  RelExpr getRelExpr(RelType Type, const Symbol &S,
32
                     const uint8_t *Loc) const override;
33
  int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override;
34
  RelType getDynRel(RelType Type) const override;
35
  void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;
36
  void writePltHeader(uint8_t *Buf) const override;
37
  void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,
38
                int32_t Index, unsigned RelOff) const override;
39
  bool needsThunk(RelExpr Expr, RelType Type, const InputFile *File,
40
                  uint64_t BranchAddr, const Symbol &S) const override;
41
  void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
42
  bool usesOnlyLowPageBits(RelType Type) const override;
43
};
44
} // namespace
45
46
199
template <class ELFT> MIPS<ELFT>::MIPS() {
47
199
  GotPltHeaderEntriesNum = 2;
48
199
  DefaultMaxPageSize = 65536;
49
199
  GotEntrySize = sizeof(typename ELFT::uint);
50
199
  GotPltEntrySize = sizeof(typename ELFT::uint);
51
199
  GotBaseSymInGotPlt = false;
52
199
  PltEntrySize = 16;
53
199
  PltHeaderSize = 32;
54
199
  CopyRel = R_MIPS_COPY;
55
199
  NoneRel = R_MIPS_NONE;
56
199
  PltRel = R_MIPS_JUMP_SLOT;
57
199
  NeedsThunks = true;
58
199
59
199
  // Set `sigrie 1` as a trap instruction.
60
199
  write32(TrapInstr.data(), 0x04170001);
61
199
62
199
  if (ELFT::Is64Bits) {
63
49
    RelativeRel = (R_MIPS_64 << 8) | R_MIPS_REL32;
64
49
    TlsGotRel = R_MIPS_TLS_TPREL64;
65
49
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD64;
66
49
    TlsOffsetRel = R_MIPS_TLS_DTPREL64;
67
150
  } else {
68
150
    RelativeRel = R_MIPS_REL32;
69
150
    TlsGotRel = R_MIPS_TLS_TPREL32;
70
150
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD32;
71
150
    TlsOffsetRel = R_MIPS_TLS_DTPREL32;
72
150
  }
73
199
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::MIPS()
Line
Count
Source
46
23
template <class ELFT> MIPS<ELFT>::MIPS() {
47
23
  GotPltHeaderEntriesNum = 2;
48
23
  DefaultMaxPageSize = 65536;
49
23
  GotEntrySize = sizeof(typename ELFT::uint);
50
23
  GotPltEntrySize = sizeof(typename ELFT::uint);
51
23
  GotBaseSymInGotPlt = false;
52
23
  PltEntrySize = 16;
53
23
  PltHeaderSize = 32;
54
23
  CopyRel = R_MIPS_COPY;
55
23
  NoneRel = R_MIPS_NONE;
56
23
  PltRel = R_MIPS_JUMP_SLOT;
57
23
  NeedsThunks = true;
58
23
59
23
  // Set `sigrie 1` as a trap instruction.
60
23
  write32(TrapInstr.data(), 0x04170001);
61
23
62
23
  if (ELFT::Is64Bits) {
63
0
    RelativeRel = (R_MIPS_64 << 8) | R_MIPS_REL32;
64
0
    TlsGotRel = R_MIPS_TLS_TPREL64;
65
0
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD64;
66
0
    TlsOffsetRel = R_MIPS_TLS_DTPREL64;
67
23
  } else {
68
23
    RelativeRel = R_MIPS_REL32;
69
23
    TlsGotRel = R_MIPS_TLS_TPREL32;
70
23
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD32;
71
23
    TlsOffsetRel = R_MIPS_TLS_DTPREL32;
72
23
  }
73
23
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::MIPS()
Line
Count
Source
46
127
template <class ELFT> MIPS<ELFT>::MIPS() {
47
127
  GotPltHeaderEntriesNum = 2;
48
127
  DefaultMaxPageSize = 65536;
49
127
  GotEntrySize = sizeof(typename ELFT::uint);
50
127
  GotPltEntrySize = sizeof(typename ELFT::uint);
51
127
  GotBaseSymInGotPlt = false;
52
127
  PltEntrySize = 16;
53
127
  PltHeaderSize = 32;
54
127
  CopyRel = R_MIPS_COPY;
55
127
  NoneRel = R_MIPS_NONE;
56
127
  PltRel = R_MIPS_JUMP_SLOT;
57
127
  NeedsThunks = true;
58
127
59
127
  // Set `sigrie 1` as a trap instruction.
60
127
  write32(TrapInstr.data(), 0x04170001);
61
127
62
127
  if (ELFT::Is64Bits) {
63
0
    RelativeRel = (R_MIPS_64 << 8) | R_MIPS_REL32;
64
0
    TlsGotRel = R_MIPS_TLS_TPREL64;
65
0
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD64;
66
0
    TlsOffsetRel = R_MIPS_TLS_DTPREL64;
67
127
  } else {
68
127
    RelativeRel = R_MIPS_REL32;
69
127
    TlsGotRel = R_MIPS_TLS_TPREL32;
70
127
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD32;
71
127
    TlsOffsetRel = R_MIPS_TLS_DTPREL32;
72
127
  }
73
127
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::MIPS()
Line
Count
Source
46
3
template <class ELFT> MIPS<ELFT>::MIPS() {
47
3
  GotPltHeaderEntriesNum = 2;
48
3
  DefaultMaxPageSize = 65536;
49
3
  GotEntrySize = sizeof(typename ELFT::uint);
50
3
  GotPltEntrySize = sizeof(typename ELFT::uint);
51
3
  GotBaseSymInGotPlt = false;
52
3
  PltEntrySize = 16;
53
3
  PltHeaderSize = 32;
54
3
  CopyRel = R_MIPS_COPY;
55
3
  NoneRel = R_MIPS_NONE;
56
3
  PltRel = R_MIPS_JUMP_SLOT;
57
3
  NeedsThunks = true;
58
3
59
3
  // Set `sigrie 1` as a trap instruction.
60
3
  write32(TrapInstr.data(), 0x04170001);
61
3
62
3
  if (ELFT::Is64Bits) {
63
3
    RelativeRel = (R_MIPS_64 << 8) | R_MIPS_REL32;
64
3
    TlsGotRel = R_MIPS_TLS_TPREL64;
65
3
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD64;
66
3
    TlsOffsetRel = R_MIPS_TLS_DTPREL64;
67
3
  } else {
68
0
    RelativeRel = R_MIPS_REL32;
69
0
    TlsGotRel = R_MIPS_TLS_TPREL32;
70
0
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD32;
71
0
    TlsOffsetRel = R_MIPS_TLS_DTPREL32;
72
0
  }
73
3
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::MIPS()
Line
Count
Source
46
46
template <class ELFT> MIPS<ELFT>::MIPS() {
47
46
  GotPltHeaderEntriesNum = 2;
48
46
  DefaultMaxPageSize = 65536;
49
46
  GotEntrySize = sizeof(typename ELFT::uint);
50
46
  GotPltEntrySize = sizeof(typename ELFT::uint);
51
46
  GotBaseSymInGotPlt = false;
52
46
  PltEntrySize = 16;
53
46
  PltHeaderSize = 32;
54
46
  CopyRel = R_MIPS_COPY;
55
46
  NoneRel = R_MIPS_NONE;
56
46
  PltRel = R_MIPS_JUMP_SLOT;
57
46
  NeedsThunks = true;
58
46
59
46
  // Set `sigrie 1` as a trap instruction.
60
46
  write32(TrapInstr.data(), 0x04170001);
61
46
62
46
  if (ELFT::Is64Bits) {
63
46
    RelativeRel = (R_MIPS_64 << 8) | R_MIPS_REL32;
64
46
    TlsGotRel = R_MIPS_TLS_TPREL64;
65
46
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD64;
66
46
    TlsOffsetRel = R_MIPS_TLS_DTPREL64;
67
46
  } else {
68
0
    RelativeRel = R_MIPS_REL32;
69
0
    TlsGotRel = R_MIPS_TLS_TPREL32;
70
0
    TlsModuleIndexRel = R_MIPS_TLS_DTPMOD32;
71
0
    TlsOffsetRel = R_MIPS_TLS_DTPREL32;
72
0
  }
73
46
}
74
75
197
template <class ELFT> uint32_t MIPS<ELFT>::calcEFlags() const {
76
197
  return calcMipsEFlags<ELFT>();
77
197
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::calcEFlags() const
Line
Count
Source
75
23
template <class ELFT> uint32_t MIPS<ELFT>::calcEFlags() const {
76
23
  return calcMipsEFlags<ELFT>();
77
23
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::calcEFlags() const
Line
Count
Source
75
126
template <class ELFT> uint32_t MIPS<ELFT>::calcEFlags() const {
76
126
  return calcMipsEFlags<ELFT>();
77
126
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::calcEFlags() const
Line
Count
Source
75
3
template <class ELFT> uint32_t MIPS<ELFT>::calcEFlags() const {
76
3
  return calcMipsEFlags<ELFT>();
77
3
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::calcEFlags() const
Line
Count
Source
75
45
template <class ELFT> uint32_t MIPS<ELFT>::calcEFlags() const {
76
45
  return calcMipsEFlags<ELFT>();
77
45
}
78
79
template <class ELFT>
80
RelExpr MIPS<ELFT>::getRelExpr(RelType Type, const Symbol &S,
81
10.3k
                               const uint8_t *Loc) const {
82
10.3k
  // See comment in the calculateMipsRelChain.
83
10.3k
  if (ELFT::Is64Bits || 
Config->MipsN32Abi320
)
84
10.0k
    Type &= 0xff;
85
10.3k
86
10.3k
  switch (Type) {
87
10.3k
  case R_MIPS_JALR:
88
1
  case R_MICROMIPS_JALR:
89
1
    return R_HINT;
90
28
  case R_MIPS_GPREL16:
91
28
  case R_MIPS_GPREL32:
92
28
  case R_MICROMIPS_GPREL16:
93
28
  case R_MICROMIPS_GPREL7_S2:
94
28
    return R_MIPS_GOTREL;
95
76
  case R_MIPS_26:
96
76
  case R_MICROMIPS_26_S1:
97
76
    return R_PLT;
98
76
  case R_MICROMIPS_PC26_S1:
99
6
    return R_PLT_PC;
100
81
  case R_MIPS_HI16:
101
81
  case R_MIPS_LO16:
102
81
  case R_MIPS_HIGHER:
103
81
  case R_MIPS_HIGHEST:
104
81
  case R_MICROMIPS_HI16:
105
81
  case R_MICROMIPS_LO16:
106
81
    // R_MIPS_HI16/R_MIPS_LO16 relocations against _gp_disp calculate
107
81
    // offset between start of function and 'gp' value which by default
108
81
    // equal to the start of .got section. In that case we consider these
109
81
    // relocations as relative.
110
81
    if (&S == ElfSym::MipsGpDisp)
111
20
      return R_MIPS_GOT_GP_PC;
112
61
    if (&S == ElfSym::MipsLocalGp)
113
2
      return R_MIPS_GOT_GP;
114
59
    LLVM_FALLTHROUGH;
115
94
  case R_MIPS_32:
116
94
  case R_MIPS_64:
117
94
  case R_MIPS_GOT_OFST:
118
94
  case R_MIPS_SUB:
119
94
  case R_MIPS_TLS_DTPREL_HI16:
120
94
  case R_MIPS_TLS_DTPREL_LO16:
121
94
  case R_MIPS_TLS_DTPREL32:
122
94
  case R_MIPS_TLS_DTPREL64:
123
94
  case R_MIPS_TLS_TPREL_HI16:
124
94
  case R_MIPS_TLS_TPREL_LO16:
125
94
  case R_MIPS_TLS_TPREL32:
126
94
  case R_MIPS_TLS_TPREL64:
127
94
  case R_MICROMIPS_TLS_DTPREL_HI16:
128
94
  case R_MICROMIPS_TLS_DTPREL_LO16:
129
94
  case R_MICROMIPS_TLS_TPREL_HI16:
130
94
  case R_MICROMIPS_TLS_TPREL_LO16:
131
94
    return R_ABS;
132
94
  case R_MIPS_PC32:
133
20
  case R_MIPS_PC16:
134
20
  case R_MIPS_PC19_S2:
135
20
  case R_MIPS_PC21_S2:
136
20
  case R_MIPS_PC26_S2:
137
20
  case R_MIPS_PCHI16:
138
20
  case R_MIPS_PCLO16:
139
20
  case R_MICROMIPS_PC7_S1:
140
20
  case R_MICROMIPS_PC10_S1:
141
20
  case R_MICROMIPS_PC16_S1:
142
20
  case R_MICROMIPS_PC18_S3:
143
20
  case R_MICROMIPS_PC19_S2:
144
20
  case R_MICROMIPS_PC23_S2:
145
20
  case R_MICROMIPS_PC21_S1:
146
20
    return R_PC;
147
50
  case R_MIPS_GOT16:
148
50
  case R_MICROMIPS_GOT16:
149
50
    if (S.isLocal())
150
23
      return R_MIPS_GOT_LOCAL_PAGE;
151
27
    LLVM_FALLTHROUGH;
152
10.0k
  case R_MIPS_CALL16:
153
10.0k
  case R_MIPS_GOT_DISP:
154
10.0k
  case R_MIPS_TLS_GOTTPREL:
155
10.0k
  case R_MICROMIPS_CALL16:
156
10.0k
  case R_MICROMIPS_TLS_GOTTPREL:
157
10.0k
    return R_MIPS_GOT_OFF;
158
10.0k
  case R_MIPS_CALL_HI16:
159
16
  case R_MIPS_CALL_LO16:
160
16
  case R_MIPS_GOT_HI16:
161
16
  case R_MIPS_GOT_LO16:
162
16
  case R_MICROMIPS_CALL_HI16:
163
16
  case R_MICROMIPS_CALL_LO16:
164
16
  case R_MICROMIPS_GOT_HI16:
165
16
  case R_MICROMIPS_GOT_LO16:
166
16
    return R_MIPS_GOT_OFF32;
167
16
  case R_MIPS_GOT_PAGE:
168
12
    return R_MIPS_GOT_LOCAL_PAGE;
169
16
  case R_MIPS_TLS_GD:
170
12
  case R_MICROMIPS_TLS_GD:
171
12
    return R_MIPS_TLSGD;
172
12
  case R_MIPS_TLS_LDM:
173
6
  case R_MICROMIPS_TLS_LDM:
174
6
    return R_MIPS_TLSLD;
175
6
  case R_MIPS_NONE:
176
0
    return R_NONE;
177
6
  default:
178
0
    error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +
179
0
          ") against symbol " + toString(S));
180
0
    return R_NONE;
181
10.3k
  }
182
10.3k
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getRelExpr(unsigned int, lld::elf::Symbol const&, unsigned char const*) const
Line
Count
Source
81
27
                               const uint8_t *Loc) const {
82
27
  // See comment in the calculateMipsRelChain.
83
27
  if (ELFT::Is64Bits || Config->MipsN32Abi)
84
0
    Type &= 0xff;
85
27
86
27
  switch (Type) {
87
27
  case R_MIPS_JALR:
88
1
  case R_MICROMIPS_JALR:
89
1
    return R_HINT;
90
1
  case R_MIPS_GPREL16:
91
1
  case R_MIPS_GPREL32:
92
1
  case R_MICROMIPS_GPREL16:
93
1
  case R_MICROMIPS_GPREL7_S2:
94
1
    return R_MIPS_GOTREL;
95
2
  case R_MIPS_26:
96
2
  case R_MICROMIPS_26_S1:
97
2
    return R_PLT;
98
3
  case R_MICROMIPS_PC26_S1:
99
3
    return R_PLT_PC;
100
4
  case R_MIPS_HI16:
101
4
  case R_MIPS_LO16:
102
4
  case R_MIPS_HIGHER:
103
4
  case R_MIPS_HIGHEST:
104
4
  case R_MICROMIPS_HI16:
105
4
  case R_MICROMIPS_LO16:
106
4
    // R_MIPS_HI16/R_MIPS_LO16 relocations against _gp_disp calculate
107
4
    // offset between start of function and 'gp' value which by default
108
4
    // equal to the start of .got section. In that case we consider these
109
4
    // relocations as relative.
110
4
    if (&S == ElfSym::MipsGpDisp)
111
2
      return R_MIPS_GOT_GP_PC;
112
2
    if (&S == ElfSym::MipsLocalGp)
113
0
      return R_MIPS_GOT_GP;
114
2
    LLVM_FALLTHROUGH;
115
5
  case R_MIPS_32:
116
5
  case R_MIPS_64:
117
5
  case R_MIPS_GOT_OFST:
118
5
  case R_MIPS_SUB:
119
5
  case R_MIPS_TLS_DTPREL_HI16:
120
5
  case R_MIPS_TLS_DTPREL_LO16:
121
5
  case R_MIPS_TLS_DTPREL32:
122
5
  case R_MIPS_TLS_DTPREL64:
123
5
  case R_MIPS_TLS_TPREL_HI16:
124
5
  case R_MIPS_TLS_TPREL_LO16:
125
5
  case R_MIPS_TLS_TPREL32:
126
5
  case R_MIPS_TLS_TPREL64:
127
5
  case R_MICROMIPS_TLS_DTPREL_HI16:
128
5
  case R_MICROMIPS_TLS_DTPREL_LO16:
129
5
  case R_MICROMIPS_TLS_TPREL_HI16:
130
5
  case R_MICROMIPS_TLS_TPREL_LO16:
131
5
    return R_ABS;
132
5
  case R_MIPS_PC32:
133
5
  case R_MIPS_PC16:
134
5
  case R_MIPS_PC19_S2:
135
5
  case R_MIPS_PC21_S2:
136
5
  case R_MIPS_PC26_S2:
137
5
  case R_MIPS_PCHI16:
138
5
  case R_MIPS_PCLO16:
139
5
  case R_MICROMIPS_PC7_S1:
140
5
  case R_MICROMIPS_PC10_S1:
141
5
  case R_MICROMIPS_PC16_S1:
142
5
  case R_MICROMIPS_PC18_S3:
143
5
  case R_MICROMIPS_PC19_S2:
144
5
  case R_MICROMIPS_PC23_S2:
145
5
  case R_MICROMIPS_PC21_S1:
146
5
    return R_PC;
147
7
  case R_MIPS_GOT16:
148
7
  case R_MICROMIPS_GOT16:
149
7
    if (S.isLocal())
150
2
      return R_MIPS_GOT_LOCAL_PAGE;
151
5
    LLVM_FALLTHROUGH;
152
6
  case R_MIPS_CALL16:
153
6
  case R_MIPS_GOT_DISP:
154
6
  case R_MIPS_TLS_GOTTPREL:
155
6
  case R_MICROMIPS_CALL16:
156
6
  case R_MICROMIPS_TLS_GOTTPREL:
157
6
    return R_MIPS_GOT_OFF;
158
6
  case R_MIPS_CALL_HI16:
159
0
  case R_MIPS_CALL_LO16:
160
0
  case R_MIPS_GOT_HI16:
161
0
  case R_MIPS_GOT_LO16:
162
0
  case R_MICROMIPS_CALL_HI16:
163
0
  case R_MICROMIPS_CALL_LO16:
164
0
  case R_MICROMIPS_GOT_HI16:
165
0
  case R_MICROMIPS_GOT_LO16:
166
0
    return R_MIPS_GOT_OFF32;
167
0
  case R_MIPS_GOT_PAGE:
168
0
    return R_MIPS_GOT_LOCAL_PAGE;
169
0
  case R_MIPS_TLS_GD:
170
0
  case R_MICROMIPS_TLS_GD:
171
0
    return R_MIPS_TLSGD;
172
0
  case R_MIPS_TLS_LDM:
173
0
  case R_MICROMIPS_TLS_LDM:
174
0
    return R_MIPS_TLSLD;
175
0
  case R_MIPS_NONE:
176
0
    return R_NONE;
177
0
  default:
178
0
    error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +
179
0
          ") against symbol " + toString(S));
180
0
    return R_NONE;
181
27
  }
182
27
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getRelExpr(unsigned int, lld::elf::Symbol const&, unsigned char const*) const
Line
Count
Source
81
293
                               const uint8_t *Loc) const {
82
293
  // See comment in the calculateMipsRelChain.
83
293
  if (ELFT::Is64Bits || Config->MipsN32Abi)
84
5
    Type &= 0xff;
85
293
86
293
  switch (Type) {
87
293
  case R_MIPS_JALR:
88
0
  case R_MICROMIPS_JALR:
89
0
    return R_HINT;
90
16
  case R_MIPS_GPREL16:
91
16
  case R_MIPS_GPREL32:
92
16
  case R_MICROMIPS_GPREL16:
93
16
  case R_MICROMIPS_GPREL7_S2:
94
16
    return R_MIPS_GOTREL;
95
72
  case R_MIPS_26:
96
72
  case R_MICROMIPS_26_S1:
97
72
    return R_PLT;
98
72
  case R_MICROMIPS_PC26_S1:
99
3
    return R_PLT_PC;
100
73
  case R_MIPS_HI16:
101
73
  case R_MIPS_LO16:
102
73
  case R_MIPS_HIGHER:
103
73
  case R_MIPS_HIGHEST:
104
73
  case R_MICROMIPS_HI16:
105
73
  case R_MICROMIPS_LO16:
106
73
    // R_MIPS_HI16/R_MIPS_LO16 relocations against _gp_disp calculate
107
73
    // offset between start of function and 'gp' value which by default
108
73
    // equal to the start of .got section. In that case we consider these
109
73
    // relocations as relative.
110
73
    if (&S == ElfSym::MipsGpDisp)
111
18
      return R_MIPS_GOT_GP_PC;
112
55
    if (&S == ElfSym::MipsLocalGp)
113
2
      return R_MIPS_GOT_GP;
114
53
    LLVM_FALLTHROUGH;
115
73
  case R_MIPS_32:
116
73
  case R_MIPS_64:
117
73
  case R_MIPS_GOT_OFST:
118
73
  case R_MIPS_SUB:
119
73
  case R_MIPS_TLS_DTPREL_HI16:
120
73
  case R_MIPS_TLS_DTPREL_LO16:
121
73
  case R_MIPS_TLS_DTPREL32:
122
73
  case R_MIPS_TLS_DTPREL64:
123
73
  case R_MIPS_TLS_TPREL_HI16:
124
73
  case R_MIPS_TLS_TPREL_LO16:
125
73
  case R_MIPS_TLS_TPREL32:
126
73
  case R_MIPS_TLS_TPREL64:
127
73
  case R_MICROMIPS_TLS_DTPREL_HI16:
128
73
  case R_MICROMIPS_TLS_DTPREL_LO16:
129
73
  case R_MICROMIPS_TLS_TPREL_HI16:
130
73
  case R_MICROMIPS_TLS_TPREL_LO16:
131
73
    return R_ABS;
132
73
  case R_MIPS_PC32:
133
14
  case R_MIPS_PC16:
134
14
  case R_MIPS_PC19_S2:
135
14
  case R_MIPS_PC21_S2:
136
14
  case R_MIPS_PC26_S2:
137
14
  case R_MIPS_PCHI16:
138
14
  case R_MIPS_PCLO16:
139
14
  case R_MICROMIPS_PC7_S1:
140
14
  case R_MICROMIPS_PC10_S1:
141
14
  case R_MICROMIPS_PC16_S1:
142
14
  case R_MICROMIPS_PC18_S3:
143
14
  case R_MICROMIPS_PC19_S2:
144
14
  case R_MICROMIPS_PC23_S2:
145
14
  case R_MICROMIPS_PC21_S1:
146
14
    return R_PC;
147
43
  case R_MIPS_GOT16:
148
43
  case R_MICROMIPS_GOT16:
149
43
    if (S.isLocal())
150
21
      return R_MIPS_GOT_LOCAL_PAGE;
151
22
    LLVM_FALLTHROUGH;
152
47
  case R_MIPS_CALL16:
153
47
  case R_MIPS_GOT_DISP:
154
47
  case R_MIPS_TLS_GOTTPREL:
155
47
  case R_MICROMIPS_CALL16:
156
47
  case R_MICROMIPS_TLS_GOTTPREL:
157
47
    return R_MIPS_GOT_OFF;
158
47
  case R_MIPS_CALL_HI16:
159
16
  case R_MIPS_CALL_LO16:
160
16
  case R_MIPS_GOT_HI16:
161
16
  case R_MIPS_GOT_LO16:
162
16
  case R_MICROMIPS_CALL_HI16:
163
16
  case R_MICROMIPS_CALL_LO16:
164
16
  case R_MICROMIPS_GOT_HI16:
165
16
  case R_MICROMIPS_GOT_LO16:
166
16
    return R_MIPS_GOT_OFF32;
167
16
  case R_MIPS_GOT_PAGE:
168
0
    return R_MIPS_GOT_LOCAL_PAGE;
169
16
  case R_MIPS_TLS_GD:
170
7
  case R_MICROMIPS_TLS_GD:
171
7
    return R_MIPS_TLSGD;
172
7
  case R_MIPS_TLS_LDM:
173
4
  case R_MICROMIPS_TLS_LDM:
174
4
    return R_MIPS_TLSLD;
175
4
  case R_MIPS_NONE:
176
0
    return R_NONE;
177
4
  default:
178
0
    error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +
179
0
          ") against symbol " + toString(S));
180
0
    return R_NONE;
181
293
  }
182
293
}
Unexecuted instantiation: Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getRelExpr(unsigned int, lld::elf::Symbol const&, unsigned char const*) const
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getRelExpr(unsigned int, lld::elf::Symbol const&, unsigned char const*) const
Line
Count
Source
81
10.0k
                               const uint8_t *Loc) const {
82
10.0k
  // See comment in the calculateMipsRelChain.
83
10.0k
  if (ELFT::Is64Bits || 
Config->MipsN32Abi0
)
84
10.0k
    Type &= 0xff;
85
10.0k
86
10.0k
  switch (Type) {
87
10.0k
  case R_MIPS_JALR:
88
0
  case R_MICROMIPS_JALR:
89
0
    return R_HINT;
90
11
  case R_MIPS_GPREL16:
91
11
  case R_MIPS_GPREL32:
92
11
  case R_MICROMIPS_GPREL16:
93
11
  case R_MICROMIPS_GPREL7_S2:
94
11
    return R_MIPS_GOTREL;
95
11
  case R_MIPS_26:
96
2
  case R_MICROMIPS_26_S1:
97
2
    return R_PLT;
98
2
  case R_MICROMIPS_PC26_S1:
99
0
    return R_PLT_PC;
100
4
  case R_MIPS_HI16:
101
4
  case R_MIPS_LO16:
102
4
  case R_MIPS_HIGHER:
103
4
  case R_MIPS_HIGHEST:
104
4
  case R_MICROMIPS_HI16:
105
4
  case R_MICROMIPS_LO16:
106
4
    // R_MIPS_HI16/R_MIPS_LO16 relocations against _gp_disp calculate
107
4
    // offset between start of function and 'gp' value which by default
108
4
    // equal to the start of .got section. In that case we consider these
109
4
    // relocations as relative.
110
4
    if (&S == ElfSym::MipsGpDisp)
111
0
      return R_MIPS_GOT_GP_PC;
112
4
    if (&S == ElfSym::MipsLocalGp)
113
0
      return R_MIPS_GOT_GP;
114
4
    LLVM_FALLTHROUGH;
115
16
  case R_MIPS_32:
116
16
  case R_MIPS_64:
117
16
  case R_MIPS_GOT_OFST:
118
16
  case R_MIPS_SUB:
119
16
  case R_MIPS_TLS_DTPREL_HI16:
120
16
  case R_MIPS_TLS_DTPREL_LO16:
121
16
  case R_MIPS_TLS_DTPREL32:
122
16
  case R_MIPS_TLS_DTPREL64:
123
16
  case R_MIPS_TLS_TPREL_HI16:
124
16
  case R_MIPS_TLS_TPREL_LO16:
125
16
  case R_MIPS_TLS_TPREL32:
126
16
  case R_MIPS_TLS_TPREL64:
127
16
  case R_MICROMIPS_TLS_DTPREL_HI16:
128
16
  case R_MICROMIPS_TLS_DTPREL_LO16:
129
16
  case R_MICROMIPS_TLS_TPREL_HI16:
130
16
  case R_MICROMIPS_TLS_TPREL_LO16:
131
16
    return R_ABS;
132
16
  case R_MIPS_PC32:
133
1
  case R_MIPS_PC16:
134
1
  case R_MIPS_PC19_S2:
135
1
  case R_MIPS_PC21_S2:
136
1
  case R_MIPS_PC26_S2:
137
1
  case R_MIPS_PCHI16:
138
1
  case R_MIPS_PCLO16:
139
1
  case R_MICROMIPS_PC7_S1:
140
1
  case R_MICROMIPS_PC10_S1:
141
1
  case R_MICROMIPS_PC16_S1:
142
1
  case R_MICROMIPS_PC18_S3:
143
1
  case R_MICROMIPS_PC19_S2:
144
1
  case R_MICROMIPS_PC23_S2:
145
1
  case R_MICROMIPS_PC21_S1:
146
1
    return R_PC;
147
1
  case R_MIPS_GOT16:
148
0
  case R_MICROMIPS_GOT16:
149
0
    if (S.isLocal())
150
0
      return R_MIPS_GOT_LOCAL_PAGE;
151
0
    LLVM_FALLTHROUGH;
152
10.0k
  case R_MIPS_CALL16:
153
10.0k
  case R_MIPS_GOT_DISP:
154
10.0k
  case R_MIPS_TLS_GOTTPREL:
155
10.0k
  case R_MICROMIPS_CALL16:
156
10.0k
  case R_MICROMIPS_TLS_GOTTPREL:
157
10.0k
    return R_MIPS_GOT_OFF;
158
10.0k
  case R_MIPS_CALL_HI16:
159
0
  case R_MIPS_CALL_LO16:
160
0
  case R_MIPS_GOT_HI16:
161
0
  case R_MIPS_GOT_LO16:
162
0
  case R_MICROMIPS_CALL_HI16:
163
0
  case R_MICROMIPS_CALL_LO16:
164
0
  case R_MICROMIPS_GOT_HI16:
165
0
  case R_MICROMIPS_GOT_LO16:
166
0
    return R_MIPS_GOT_OFF32;
167
12
  case R_MIPS_GOT_PAGE:
168
12
    return R_MIPS_GOT_LOCAL_PAGE;
169
5
  case R_MIPS_TLS_GD:
170
5
  case R_MICROMIPS_TLS_GD:
171
5
    return R_MIPS_TLSGD;
172
5
  case R_MIPS_TLS_LDM:
173
2
  case R_MICROMIPS_TLS_LDM:
174
2
    return R_MIPS_TLSLD;
175
2
  case R_MIPS_NONE:
176
0
    return R_NONE;
177
2
  default:
178
0
    error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +
179
0
          ") against symbol " + toString(S));
180
0
    return R_NONE;
181
10.0k
  }
182
10.0k
}
183
184
4
template <class ELFT> RelType MIPS<ELFT>::getDynRel(RelType Type) const {
185
4
  if (Type == R_MIPS_32 || 
Type == R_MIPS_642
)
186
4
    return RelativeRel;
187
0
  return R_MIPS_NONE;
188
0
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getDynRel(unsigned int) const
Line
Count
Source
184
1
template <class ELFT> RelType MIPS<ELFT>::getDynRel(RelType Type) const {
185
1
  if (Type == R_MIPS_32 || 
Type == R_MIPS_640
)
186
1
    return RelativeRel;
187
0
  return R_MIPS_NONE;
188
0
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getDynRel(unsigned int) const
Line
Count
Source
184
1
template <class ELFT> RelType MIPS<ELFT>::getDynRel(RelType Type) const {
185
1
  if (Type == R_MIPS_32 || 
Type == R_MIPS_640
)
186
1
    return RelativeRel;
187
0
  return R_MIPS_NONE;
188
0
}
Unexecuted instantiation: Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::getDynRel(unsigned int) const
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::getDynRel(unsigned int) const
Line
Count
Source
184
2
template <class ELFT> RelType MIPS<ELFT>::getDynRel(RelType Type) const {
185
2
  if (Type == R_MIPS_32 || Type == R_MIPS_64)
186
2
    return RelativeRel;
187
0
  return R_MIPS_NONE;
188
0
}
189
190
template <class ELFT>
191
17
void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &) const {
192
17
  uint64_t VA = In.Plt->getVA();
193
17
  if (isMicroMips())
194
6
    VA |= 1;
195
17
  write32<ELFT::TargetEndianness>(Buf, VA);
196
17
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::writeGotPlt(unsigned char*, lld::elf::Symbol const&) const
Line
Count
Source
191
2
void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &) const {
192
2
  uint64_t VA = In.Plt->getVA();
193
2
  if (isMicroMips())
194
2
    VA |= 1;
195
2
  write32<ELFT::TargetEndianness>(Buf, VA);
196
2
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::writeGotPlt(unsigned char*, lld::elf::Symbol const&) const
Line
Count
Source
191
13
void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &) const {
192
13
  uint64_t VA = In.Plt->getVA();
193
13
  if (isMicroMips())
194
4
    VA |= 1;
195
13
  write32<ELFT::TargetEndianness>(Buf, VA);
196
13
}
Unexecuted instantiation: Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::writeGotPlt(unsigned char*, lld::elf::Symbol const&) const
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::writeGotPlt(unsigned char*, lld::elf::Symbol const&) const
Line
Count
Source
191
2
void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &) const {
192
2
  uint64_t VA = In.Plt->getVA();
193
2
  if (isMicroMips())
194
0
    VA |= 1;
195
2
  write32<ELFT::TargetEndianness>(Buf, VA);
196
2
}
197
198
38
template <endianness E> static uint32_t readShuffle(const uint8_t *Loc) {
199
38
  // The major opcode of a microMIPS instruction needs to appear
200
38
  // in the first 16-bit word (lowest address) for efficient hardware
201
38
  // decode so that it knows if the instruction is 16-bit or 32-bit
202
38
  // as early as possible. To do so, little-endian binaries keep 16-bit
203
38
  // words in a big-endian order. That is why we have to swap these
204
38
  // words to get a correct value.
205
38
  uint32_t V = read32<E>(Loc);
206
38
  if (E == support::little)
207
12
    return (V << 16) | (V >> 16);
208
26
  return V;
209
26
}
Mips.cpp:unsigned int readShuffle<(llvm::support::endianness)1>(unsigned char const*)
Line
Count
Source
198
12
template <endianness E> static uint32_t readShuffle(const uint8_t *Loc) {
199
12
  // The major opcode of a microMIPS instruction needs to appear
200
12
  // in the first 16-bit word (lowest address) for efficient hardware
201
12
  // decode so that it knows if the instruction is 16-bit or 32-bit
202
12
  // as early as possible. To do so, little-endian binaries keep 16-bit
203
12
  // words in a big-endian order. That is why we have to swap these
204
12
  // words to get a correct value.
205
12
  uint32_t V = read32<E>(Loc);
206
12
  if (E == support::little)
207
12
    return (V << 16) | (V >> 16);
208
0
  return V;
209
0
}
Mips.cpp:unsigned int readShuffle<(llvm::support::endianness)0>(unsigned char const*)
Line
Count
Source
198
26
template <endianness E> static uint32_t readShuffle(const uint8_t *Loc) {
199
26
  // The major opcode of a microMIPS instruction needs to appear
200
26
  // in the first 16-bit word (lowest address) for efficient hardware
201
26
  // decode so that it knows if the instruction is 16-bit or 32-bit
202
26
  // as early as possible. To do so, little-endian binaries keep 16-bit
203
26
  // words in a big-endian order. That is why we have to swap these
204
26
  // words to get a correct value.
205
26
  uint32_t V = read32<E>(Loc);
206
26
  if (E == support::little)
207
0
    return (V << 16) | (V >> 16);
208
26
  return V;
209
26
}
210
211
template <endianness E>
212
static void writeValue(uint8_t *Loc, uint64_t V, uint8_t BitsSize,
213
10.5k
                       uint8_t Shift) {
214
10.5k
  uint32_t Instr = read32<E>(Loc);
215
10.5k
  uint32_t Mask = 0xffffffff >> (32 - BitsSize);
216
10.5k
  uint32_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);
217
10.5k
  write32<E>(Loc, Data);
218
10.5k
}
Mips.cpp:void writeValue<(llvm::support::endianness)1>(unsigned char*, unsigned long long, unsigned char, unsigned char)
Line
Count
Source
213
30
                       uint8_t Shift) {
214
30
  uint32_t Instr = read32<E>(Loc);
215
30
  uint32_t Mask = 0xffffffff >> (32 - BitsSize);
216
30
  uint32_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);
217
30
  write32<E>(Loc, Data);
218
30
}
Mips.cpp:void writeValue<(llvm::support::endianness)0>(unsigned char*, unsigned long long, unsigned char, unsigned char)
Line
Count
Source
213
10.4k
                       uint8_t Shift) {
214
10.4k
  uint32_t Instr = read32<E>(Loc);
215
10.4k
  uint32_t Mask = 0xffffffff >> (32 - BitsSize);
216
10.4k
  uint32_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);
217
10.4k
  write32<E>(Loc, Data);
218
10.4k
}
219
220
template <endianness E>
221
static void writeShuffleValue(uint8_t *Loc, uint64_t V, uint8_t BitsSize,
222
64
                              uint8_t Shift) {
223
64
  // See comments in readShuffle for purpose of this code.
224
64
  uint16_t *Words = (uint16_t *)Loc;
225
64
  if (E == support::little)
226
22
    std::swap(Words[0], Words[1]);
227
64
228
64
  writeValue<E>(Loc, V, BitsSize, Shift);
229
64
230
64
  if (E == support::little)
231
22
    std::swap(Words[0], Words[1]);
232
64
}
Mips.cpp:void writeShuffleValue<(llvm::support::endianness)1>(unsigned char*, unsigned long long, unsigned char, unsigned char)
Line
Count
Source
222
22
                              uint8_t Shift) {
223
22
  // See comments in readShuffle for purpose of this code.
224
22
  uint16_t *Words = (uint16_t *)Loc;
225
22
  if (E == support::little)
226
22
    std::swap(Words[0], Words[1]);
227
22
228
22
  writeValue<E>(Loc, V, BitsSize, Shift);
229
22
230
22
  if (E == support::little)
231
22
    std::swap(Words[0], Words[1]);
232
22
}
Mips.cpp:void writeShuffleValue<(llvm::support::endianness)0>(unsigned char*, unsigned long long, unsigned char, unsigned char)
Line
Count
Source
222
42
                              uint8_t Shift) {
223
42
  // See comments in readShuffle for purpose of this code.
224
42
  uint16_t *Words = (uint16_t *)Loc;
225
42
  if (E == support::little)
226
0
    std::swap(Words[0], Words[1]);
227
42
228
42
  writeValue<E>(Loc, V, BitsSize, Shift);
229
42
230
42
  if (E == support::little)
231
0
    std::swap(Words[0], Words[1]);
232
42
}
233
234
template <endianness E>
235
static void writeMicroRelocation16(uint8_t *Loc, uint64_t V, uint8_t BitsSize,
236
5
                                   uint8_t Shift) {
237
5
  uint16_t Instr = read16<E>(Loc);
238
5
  uint16_t Mask = 0xffff >> (16 - BitsSize);
239
5
  uint16_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);
240
5
  write16<E>(Loc, Data);
241
5
}
Mips.cpp:void writeMicroRelocation16<(llvm::support::endianness)1>(unsigned char*, unsigned long long, unsigned char, unsigned char)
Line
Count
Source
236
2
                                   uint8_t Shift) {
237
2
  uint16_t Instr = read16<E>(Loc);
238
2
  uint16_t Mask = 0xffff >> (16 - BitsSize);
239
2
  uint16_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);
240
2
  write16<E>(Loc, Data);
241
2
}
Mips.cpp:void writeMicroRelocation16<(llvm::support::endianness)0>(unsigned char*, unsigned long long, unsigned char, unsigned char)
Line
Count
Source
236
3
                                   uint8_t Shift) {
237
3
  uint16_t Instr = read16<E>(Loc);
238
3
  uint16_t Mask = 0xffff >> (16 - BitsSize);
239
3
  uint16_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);
240
3
  write16<E>(Loc, Data);
241
3
}
242
243
15
template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const {
244
15
  const endianness E = ELFT::TargetEndianness;
245
15
  if (isMicroMips()) {
246
6
    uint64_t GotPlt = In.GotPlt->getVA();
247
6
    uint64_t Plt = In.Plt->getVA();
248
6
    // Overwrite trap instructions written by Writer::writeTrapInstr.
249
6
    memset(Buf, 0, PltHeaderSize);
250
6
251
6
    write16<E>(Buf, isMipsR6() ? 
0x78602
:
0x79804
); // addiupc v1, (GOTPLT) - .
252
6
    write16<E>(Buf + 4, 0xff23);    // lw      $25, 0($3)
253
6
    write16<E>(Buf + 8, 0x0535);    // subu16  $2,  $2, $3
254
6
    write16<E>(Buf + 10, 0x2525);   // srl16   $2,  $2, 2
255
6
    write16<E>(Buf + 12, 0x3302);   // addiu   $24, $2, -2
256
6
    write16<E>(Buf + 14, 0xfffe);
257
6
    write16<E>(Buf + 16, 0x0dff);   // move    $15, $31
258
6
    if (isMipsR6()) {
259
2
      write16<E>(Buf + 18, 0x0f83); // move    $28, $3
260
2
      write16<E>(Buf + 20, 0x472b); // jalrc   $25
261
2
      write16<E>(Buf + 22, 0x0c00); // nop
262
2
      relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPlt - Plt);
263
4
    } else {
264
4
      write16<E>(Buf + 18, 0x45f9); // jalrc   $25
265
4
      write16<E>(Buf + 20, 0x0f83); // move    $28, $3
266
4
      write16<E>(Buf + 22, 0x0c00); // nop
267
4
      relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPlt - Plt);
268
4
    }
269
6
    return;
270
6
  }
271
9
272
9
  if (Config->MipsN32Abi) {
273
2
    write32<E>(Buf, 0x3c0e0000);      // lui   $14, %hi(&GOTPLT[0])
274
2
    write32<E>(Buf + 4, 0x8dd90000);  // lw    $25, %lo(&GOTPLT[0])($14)
275
2
    write32<E>(Buf + 8, 0x25ce0000);  // addiu $14, $14, %lo(&GOTPLT[0])
276
2
    write32<E>(Buf + 12, 0x030ec023); // subu  $24, $24, $14
277
2
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
278
2
    write32<E>(Buf + 20, 0x0018c082); // srl   $24, $24, 2
279
7
  } else if (ELFT::Is64Bits) {
280
2
    write32<E>(Buf, 0x3c0e0000);      // lui   $14, %hi(&GOTPLT[0])
281
2
    write32<E>(Buf + 4, 0xddd90000);  // ld    $25, %lo(&GOTPLT[0])($14)
282
2
    write32<E>(Buf + 8, 0x25ce0000);  // addiu $14, $14, %lo(&GOTPLT[0])
283
2
    write32<E>(Buf + 12, 0x030ec023); // subu  $24, $24, $14
284
2
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
285
2
    write32<E>(Buf + 20, 0x0018c0c2); // srl   $24, $24, 3
286
5
  } else {
287
5
    write32<E>(Buf, 0x3c1c0000);      // lui   $28, %hi(&GOTPLT[0])
288
5
    write32<E>(Buf + 4, 0x8f990000);  // lw    $25, %lo(&GOTPLT[0])($28)
289
5
    write32<E>(Buf + 8, 0x279c0000);  // addiu $28, $28, %lo(&GOTPLT[0])
290
5
    write32<E>(Buf + 12, 0x031cc023); // subu  $24, $24, $28
291
5
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
292
5
    write32<E>(Buf + 20, 0x0018c082); // srl   $24, $24, 2
293
5
  }
294
9
295
9
  uint32_t JalrInst = Config->ZHazardplt ? 
0x0320fc093
:
0x0320f8096
;
296
9
  write32<E>(Buf + 24, JalrInst); // jalr.hb $25 or jalr $25
297
9
  write32<E>(Buf + 28, 0x2718fffe); // subu  $24, $24, 2
298
9
299
9
  uint64_t GotPlt = In.GotPlt->getVA();
300
9
  writeValue<E>(Buf, GotPlt + 0x8000, 16, 16);
301
9
  writeValue<E>(Buf + 4, GotPlt, 16, 0);
302
9
  writeValue<E>(Buf + 8, GotPlt, 16, 0);
303
9
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::writePltHeader(unsigned char*) const
Line
Count
Source
243
2
template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const {
244
2
  const endianness E = ELFT::TargetEndianness;
245
2
  if (isMicroMips()) {
246
2
    uint64_t GotPlt = In.GotPlt->getVA();
247
2
    uint64_t Plt = In.Plt->getVA();
248
2
    // Overwrite trap instructions written by Writer::writeTrapInstr.
249
2
    memset(Buf, 0, PltHeaderSize);
250
2
251
2
    write16<E>(Buf, isMipsR6() ? 
0x78601
:
0x79801
); // addiupc v1, (GOTPLT) - .
252
2
    write16<E>(Buf + 4, 0xff23);    // lw      $25, 0($3)
253
2
    write16<E>(Buf + 8, 0x0535);    // subu16  $2,  $2, $3
254
2
    write16<E>(Buf + 10, 0x2525);   // srl16   $2,  $2, 2
255
2
    write16<E>(Buf + 12, 0x3302);   // addiu   $24, $2, -2
256
2
    write16<E>(Buf + 14, 0xfffe);
257
2
    write16<E>(Buf + 16, 0x0dff);   // move    $15, $31
258
2
    if (isMipsR6()) {
259
1
      write16<E>(Buf + 18, 0x0f83); // move    $28, $3
260
1
      write16<E>(Buf + 20, 0x472b); // jalrc   $25
261
1
      write16<E>(Buf + 22, 0x0c00); // nop
262
1
      relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPlt - Plt);
263
1
    } else {
264
1
      write16<E>(Buf + 18, 0x45f9); // jalrc   $25
265
1
      write16<E>(Buf + 20, 0x0f83); // move    $28, $3
266
1
      write16<E>(Buf + 22, 0x0c00); // nop
267
1
      relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPlt - Plt);
268
1
    }
269
2
    return;
270
2
  }
271
0
272
0
  if (Config->MipsN32Abi) {
273
0
    write32<E>(Buf, 0x3c0e0000);      // lui   $14, %hi(&GOTPLT[0])
274
0
    write32<E>(Buf + 4, 0x8dd90000);  // lw    $25, %lo(&GOTPLT[0])($14)
275
0
    write32<E>(Buf + 8, 0x25ce0000);  // addiu $14, $14, %lo(&GOTPLT[0])
276
0
    write32<E>(Buf + 12, 0x030ec023); // subu  $24, $24, $14
277
0
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
278
0
    write32<E>(Buf + 20, 0x0018c082); // srl   $24, $24, 2
279
0
  } else if (ELFT::Is64Bits) {
280
0
    write32<E>(Buf, 0x3c0e0000);      // lui   $14, %hi(&GOTPLT[0])
281
0
    write32<E>(Buf + 4, 0xddd90000);  // ld    $25, %lo(&GOTPLT[0])($14)
282
0
    write32<E>(Buf + 8, 0x25ce0000);  // addiu $14, $14, %lo(&GOTPLT[0])
283
0
    write32<E>(Buf + 12, 0x030ec023); // subu  $24, $24, $14
284
0
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
285
0
    write32<E>(Buf + 20, 0x0018c0c2); // srl   $24, $24, 3
286
0
  } else {
287
0
    write32<E>(Buf, 0x3c1c0000);      // lui   $28, %hi(&GOTPLT[0])
288
0
    write32<E>(Buf + 4, 0x8f990000);  // lw    $25, %lo(&GOTPLT[0])($28)
289
0
    write32<E>(Buf + 8, 0x279c0000);  // addiu $28, $28, %lo(&GOTPLT[0])
290
0
    write32<E>(Buf + 12, 0x031cc023); // subu  $24, $24, $28
291
0
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
292
0
    write32<E>(Buf + 20, 0x0018c082); // srl   $24, $24, 2
293
0
  }
294
0
295
0
  uint32_t JalrInst = Config->ZHazardplt ? 0x0320fc09 : 0x0320f809;
296
0
  write32<E>(Buf + 24, JalrInst); // jalr.hb $25 or jalr $25
297
0
  write32<E>(Buf + 28, 0x2718fffe); // subu  $24, $24, 2
298
0
299
0
  uint64_t GotPlt = In.GotPlt->getVA();
300
0
  writeValue<E>(Buf, GotPlt + 0x8000, 16, 16);
301
0
  writeValue<E>(Buf + 4, GotPlt, 16, 0);
302
0
  writeValue<E>(Buf + 8, GotPlt, 16, 0);
303
0
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::writePltHeader(unsigned char*) const
Line
Count
Source
243
11
template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const {
244
11
  const endianness E = ELFT::TargetEndianness;
245
11
  if (isMicroMips()) {
246
4
    uint64_t GotPlt = In.GotPlt->getVA();
247
4
    uint64_t Plt = In.Plt->getVA();
248
4
    // Overwrite trap instructions written by Writer::writeTrapInstr.
249
4
    memset(Buf, 0, PltHeaderSize);
250
4
251
4
    write16<E>(Buf, isMipsR6() ? 
0x78601
:
0x79803
); // addiupc v1, (GOTPLT) - .
252
4
    write16<E>(Buf + 4, 0xff23);    // lw      $25, 0($3)
253
4
    write16<E>(Buf + 8, 0x0535);    // subu16  $2,  $2, $3
254
4
    write16<E>(Buf + 10, 0x2525);   // srl16   $2,  $2, 2
255
4
    write16<E>(Buf + 12, 0x3302);   // addiu   $24, $2, -2
256
4
    write16<E>(Buf + 14, 0xfffe);
257
4
    write16<E>(Buf + 16, 0x0dff);   // move    $15, $31
258
4
    if (isMipsR6()) {
259
1
      write16<E>(Buf + 18, 0x0f83); // move    $28, $3
260
1
      write16<E>(Buf + 20, 0x472b); // jalrc   $25
261
1
      write16<E>(Buf + 22, 0x0c00); // nop
262
1
      relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPlt - Plt);
263
3
    } else {
264
3
      write16<E>(Buf + 18, 0x45f9); // jalrc   $25
265
3
      write16<E>(Buf + 20, 0x0f83); // move    $28, $3
266
3
      write16<E>(Buf + 22, 0x0c00); // nop
267
3
      relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPlt - Plt);
268
3
    }
269
4
    return;
270
4
  }
271
7
272
7
  if (Config->MipsN32Abi) {
273
2
    write32<E>(Buf, 0x3c0e0000);      // lui   $14, %hi(&GOTPLT[0])
274
2
    write32<E>(Buf + 4, 0x8dd90000);  // lw    $25, %lo(&GOTPLT[0])($14)
275
2
    write32<E>(Buf + 8, 0x25ce0000);  // addiu $14, $14, %lo(&GOTPLT[0])
276
2
    write32<E>(Buf + 12, 0x030ec023); // subu  $24, $24, $14
277
2
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
278
2
    write32<E>(Buf + 20, 0x0018c082); // srl   $24, $24, 2
279
5
  } else if (ELFT::Is64Bits) {
280
0
    write32<E>(Buf, 0x3c0e0000);      // lui   $14, %hi(&GOTPLT[0])
281
0
    write32<E>(Buf + 4, 0xddd90000);  // ld    $25, %lo(&GOTPLT[0])($14)
282
0
    write32<E>(Buf + 8, 0x25ce0000);  // addiu $14, $14, %lo(&GOTPLT[0])
283
0
    write32<E>(Buf + 12, 0x030ec023); // subu  $24, $24, $14
284
0
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
285
0
    write32<E>(Buf + 20, 0x0018c0c2); // srl   $24, $24, 3
286
5
  } else {
287
5
    write32<E>(Buf, 0x3c1c0000);      // lui   $28, %hi(&GOTPLT[0])
288
5
    write32<E>(Buf + 4, 0x8f990000);  // lw    $25, %lo(&GOTPLT[0])($28)
289
5
    write32<E>(Buf + 8, 0x279c0000);  // addiu $28, $28, %lo(&GOTPLT[0])
290
5
    write32<E>(Buf + 12, 0x031cc023); // subu  $24, $24, $28
291
5
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
292
5
    write32<E>(Buf + 20, 0x0018c082); // srl   $24, $24, 2
293
5
  }
294
7
295
7
  uint32_t JalrInst = Config->ZHazardplt ? 
0x0320fc092
:
0x0320f8095
;
296
7
  write32<E>(Buf + 24, JalrInst); // jalr.hb $25 or jalr $25
297
7
  write32<E>(Buf + 28, 0x2718fffe); // subu  $24, $24, 2
298
7
299
7
  uint64_t GotPlt = In.GotPlt->getVA();
300
7
  writeValue<E>(Buf, GotPlt + 0x8000, 16, 16);
301
7
  writeValue<E>(Buf + 4, GotPlt, 16, 0);
302
7
  writeValue<E>(Buf + 8, GotPlt, 16, 0);
303
7
}
Unexecuted instantiation: Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::writePltHeader(unsigned char*) const
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::writePltHeader(unsigned char*) const
Line
Count
Source
243
2
template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const {
244
2
  const endianness E = ELFT::TargetEndianness;
245
2
  if (isMicroMips()) {
246
0
    uint64_t GotPlt = In.GotPlt->getVA();
247
0
    uint64_t Plt = In.Plt->getVA();
248
0
    // Overwrite trap instructions written by Writer::writeTrapInstr.
249
0
    memset(Buf, 0, PltHeaderSize);
250
0
251
0
    write16<E>(Buf, isMipsR6() ? 0x7860 : 0x7980);  // addiupc v1, (GOTPLT) - .
252
0
    write16<E>(Buf + 4, 0xff23);    // lw      $25, 0($3)
253
0
    write16<E>(Buf + 8, 0x0535);    // subu16  $2,  $2, $3
254
0
    write16<E>(Buf + 10, 0x2525);   // srl16   $2,  $2, 2
255
0
    write16<E>(Buf + 12, 0x3302);   // addiu   $24, $2, -2
256
0
    write16<E>(Buf + 14, 0xfffe);
257
0
    write16<E>(Buf + 16, 0x0dff);   // move    $15, $31
258
0
    if (isMipsR6()) {
259
0
      write16<E>(Buf + 18, 0x0f83); // move    $28, $3
260
0
      write16<E>(Buf + 20, 0x472b); // jalrc   $25
261
0
      write16<E>(Buf + 22, 0x0c00); // nop
262
0
      relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPlt - Plt);
263
0
    } else {
264
0
      write16<E>(Buf + 18, 0x45f9); // jalrc   $25
265
0
      write16<E>(Buf + 20, 0x0f83); // move    $28, $3
266
0
      write16<E>(Buf + 22, 0x0c00); // nop
267
0
      relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPlt - Plt);
268
0
    }
269
0
    return;
270
0
  }
271
2
272
2
  if (Config->MipsN32Abi) {
273
0
    write32<E>(Buf, 0x3c0e0000);      // lui   $14, %hi(&GOTPLT[0])
274
0
    write32<E>(Buf + 4, 0x8dd90000);  // lw    $25, %lo(&GOTPLT[0])($14)
275
0
    write32<E>(Buf + 8, 0x25ce0000);  // addiu $14, $14, %lo(&GOTPLT[0])
276
0
    write32<E>(Buf + 12, 0x030ec023); // subu  $24, $24, $14
277
0
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
278
0
    write32<E>(Buf + 20, 0x0018c082); // srl   $24, $24, 2
279
2
  } else if (ELFT::Is64Bits) {
280
2
    write32<E>(Buf, 0x3c0e0000);      // lui   $14, %hi(&GOTPLT[0])
281
2
    write32<E>(Buf + 4, 0xddd90000);  // ld    $25, %lo(&GOTPLT[0])($14)
282
2
    write32<E>(Buf + 8, 0x25ce0000);  // addiu $14, $14, %lo(&GOTPLT[0])
283
2
    write32<E>(Buf + 12, 0x030ec023); // subu  $24, $24, $14
284
2
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
285
2
    write32<E>(Buf + 20, 0x0018c0c2); // srl   $24, $24, 3
286
2
  } else {
287
0
    write32<E>(Buf, 0x3c1c0000);      // lui   $28, %hi(&GOTPLT[0])
288
0
    write32<E>(Buf + 4, 0x8f990000);  // lw    $25, %lo(&GOTPLT[0])($28)
289
0
    write32<E>(Buf + 8, 0x279c0000);  // addiu $28, $28, %lo(&GOTPLT[0])
290
0
    write32<E>(Buf + 12, 0x031cc023); // subu  $24, $24, $28
291
0
    write32<E>(Buf + 16, 0x03e07825); // move  $15, $31
292
0
    write32<E>(Buf + 20, 0x0018c082); // srl   $24, $24, 2
293
0
  }
294
2
295
2
  uint32_t JalrInst = Config->ZHazardplt ? 
0x0320fc091
:
0x0320f8091
;
296
2
  write32<E>(Buf + 24, JalrInst); // jalr.hb $25 or jalr $25
297
2
  write32<E>(Buf + 28, 0x2718fffe); // subu  $24, $24, 2
298
2
299
2
  uint64_t GotPlt = In.GotPlt->getVA();
300
2
  writeValue<E>(Buf, GotPlt + 0x8000, 16, 16);
301
2
  writeValue<E>(Buf + 4, GotPlt, 16, 0);
302
2
  writeValue<E>(Buf + 8, GotPlt, 16, 0);
303
2
}
304
305
template <class ELFT>
306
void MIPS<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,
307
                          uint64_t PltEntryAddr, int32_t Index,
308
17
                          unsigned RelOff) const {
309
17
  const endianness E = ELFT::TargetEndianness;
310
17
  if (isMicroMips()) {
311
6
    // Overwrite trap instructions written by Writer::writeTrapInstr.
312
6
    memset(Buf, 0, PltEntrySize);
313
6
314
6
    if (isMipsR6()) {
315
2
      write16<E>(Buf, 0x7840);      // addiupc $2, (GOTPLT) - .
316
2
      write16<E>(Buf + 4, 0xff22);  // lw $25, 0($2)
317
2
      write16<E>(Buf + 8, 0x0f02);  // move $24, $2
318
2
      write16<E>(Buf + 10, 0x4723); // jrc $25 / jr16 $25
319
2
      relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPltEntryAddr - PltEntryAddr);
320
4
    } else {
321
4
      write16<E>(Buf, 0x7900);      // addiupc $2, (GOTPLT) - .
322
4
      write16<E>(Buf + 4, 0xff22);  // lw $25, 0($2)
323
4
      write16<E>(Buf + 8, 0x4599);  // jrc $25 / jr16 $25
324
4
      write16<E>(Buf + 10, 0x0f02); // move $24, $2
325
4
      relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPltEntryAddr - PltEntryAddr);
326
4
    }
327
6
    return;
328
6
  }
329
11
330
11
  uint32_t LoadInst = ELFT::Is64Bits ? 
0xddf900002
:
0x8df900009
;
331
11
  uint32_t JrInst = isMipsR6() ? 
(Config->ZHazardplt 2
?
0x032004091
:
0x032000091
)
332
11
                               : 
(Config->ZHazardplt 9
?
0x032004082
:
0x032000087
);
333
11
  uint32_t AddInst = ELFT::Is64Bits ? 
0x65f800002
:
0x25f800009
;
334
11
335
11
  write32<E>(Buf, 0x3c0f0000);     // lui   $15, %hi(.got.plt entry)
336
11
  write32<E>(Buf + 4, LoadInst);   // l[wd] $25, %lo(.got.plt entry)($15)
337
11
  write32<E>(Buf + 8, JrInst);     // jr  $25 / jr.hb $25
338
11
  write32<E>(Buf + 12, AddInst);   // [d]addiu $24, $15, %lo(.got.plt entry)
339
11
  writeValue<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);
340
11
  writeValue<E>(Buf + 4, GotPltEntryAddr, 16, 0);
341
11
  writeValue<E>(Buf + 12, GotPltEntryAddr, 16, 0);
342
11
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::writePlt(unsigned char*, unsigned long long, unsigned long long, int, unsigned int) const
Line
Count
Source
308
2
                          unsigned RelOff) const {
309
2
  const endianness E = ELFT::TargetEndianness;
310
2
  if (isMicroMips()) {
311
2
    // Overwrite trap instructions written by Writer::writeTrapInstr.
312
2
    memset(Buf, 0, PltEntrySize);
313
2
314
2
    if (isMipsR6()) {
315
1
      write16<E>(Buf, 0x7840);      // addiupc $2, (GOTPLT) - .
316
1
      write16<E>(Buf + 4, 0xff22);  // lw $25, 0($2)
317
1
      write16<E>(Buf + 8, 0x0f02);  // move $24, $2
318
1
      write16<E>(Buf + 10, 0x4723); // jrc $25 / jr16 $25
319
1
      relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPltEntryAddr - PltEntryAddr);
320
1
    } else {
321
1
      write16<E>(Buf, 0x7900);      // addiupc $2, (GOTPLT) - .
322
1
      write16<E>(Buf + 4, 0xff22);  // lw $25, 0($2)
323
1
      write16<E>(Buf + 8, 0x4599);  // jrc $25 / jr16 $25
324
1
      write16<E>(Buf + 10, 0x0f02); // move $24, $2
325
1
      relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPltEntryAddr - PltEntryAddr);
326
1
    }
327
2
    return;
328
2
  }
329
0
330
0
  uint32_t LoadInst = ELFT::Is64Bits ? 0xddf90000 : 0x8df90000;
331
0
  uint32_t JrInst = isMipsR6() ? (Config->ZHazardplt ? 0x03200409 : 0x03200009)
332
0
                               : (Config->ZHazardplt ? 0x03200408 : 0x03200008);
333
0
  uint32_t AddInst = ELFT::Is64Bits ? 0x65f80000 : 0x25f80000;
334
0
335
0
  write32<E>(Buf, 0x3c0f0000);     // lui   $15, %hi(.got.plt entry)
336
0
  write32<E>(Buf + 4, LoadInst);   // l[wd] $25, %lo(.got.plt entry)($15)
337
0
  write32<E>(Buf + 8, JrInst);     // jr  $25 / jr.hb $25
338
0
  write32<E>(Buf + 12, AddInst);   // [d]addiu $24, $15, %lo(.got.plt entry)
339
0
  writeValue<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);
340
0
  writeValue<E>(Buf + 4, GotPltEntryAddr, 16, 0);
341
0
  writeValue<E>(Buf + 12, GotPltEntryAddr, 16, 0);
342
0
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::writePlt(unsigned char*, unsigned long long, unsigned long long, int, unsigned int) const
Line
Count
Source
308
13
                          unsigned RelOff) const {
309
13
  const endianness E = ELFT::TargetEndianness;
310
13
  if (isMicroMips()) {
311
4
    // Overwrite trap instructions written by Writer::writeTrapInstr.
312
4
    memset(Buf, 0, PltEntrySize);
313
4
314
4
    if (isMipsR6()) {
315
1
      write16<E>(Buf, 0x7840);      // addiupc $2, (GOTPLT) - .
316
1
      write16<E>(Buf + 4, 0xff22);  // lw $25, 0($2)
317
1
      write16<E>(Buf + 8, 0x0f02);  // move $24, $2
318
1
      write16<E>(Buf + 10, 0x4723); // jrc $25 / jr16 $25
319
1
      relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPltEntryAddr - PltEntryAddr);
320
3
    } else {
321
3
      write16<E>(Buf, 0x7900);      // addiupc $2, (GOTPLT) - .
322
3
      write16<E>(Buf + 4, 0xff22);  // lw $25, 0($2)
323
3
      write16<E>(Buf + 8, 0x4599);  // jrc $25 / jr16 $25
324
3
      write16<E>(Buf + 10, 0x0f02); // move $24, $2
325
3
      relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPltEntryAddr - PltEntryAddr);
326
3
    }
327
4
    return;
328
4
  }
329
9
330
9
  uint32_t LoadInst = ELFT::Is64Bits ? 
0xddf900000
: 0x8df90000;
331
9
  uint32_t JrInst = isMipsR6() ? 
(Config->ZHazardplt 2
?
0x032004091
:
0x032000091
)
332
9
                               : 
(Config->ZHazardplt 7
?
0x032004081
:
0x032000086
);
333
9
  uint32_t AddInst = ELFT::Is64Bits ? 
0x65f800000
: 0x25f80000;
334
9
335
9
  write32<E>(Buf, 0x3c0f0000);     // lui   $15, %hi(.got.plt entry)
336
9
  write32<E>(Buf + 4, LoadInst);   // l[wd] $25, %lo(.got.plt entry)($15)
337
9
  write32<E>(Buf + 8, JrInst);     // jr  $25 / jr.hb $25
338
9
  write32<E>(Buf + 12, AddInst);   // [d]addiu $24, $15, %lo(.got.plt entry)
339
9
  writeValue<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);
340
9
  writeValue<E>(Buf + 4, GotPltEntryAddr, 16, 0);
341
9
  writeValue<E>(Buf + 12, GotPltEntryAddr, 16, 0);
342
9
}
Unexecuted instantiation: Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::writePlt(unsigned char*, unsigned long long, unsigned long long, int, unsigned int) const
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::writePlt(unsigned char*, unsigned long long, unsigned long long, int, unsigned int) const
Line
Count
Source
308
2
                          unsigned RelOff) const {
309
2
  const endianness E = ELFT::TargetEndianness;
310
2
  if (isMicroMips()) {
311
0
    // Overwrite trap instructions written by Writer::writeTrapInstr.
312
0
    memset(Buf, 0, PltEntrySize);
313
0
314
0
    if (isMipsR6()) {
315
0
      write16<E>(Buf, 0x7840);      // addiupc $2, (GOTPLT) - .
316
0
      write16<E>(Buf + 4, 0xff22);  // lw $25, 0($2)
317
0
      write16<E>(Buf + 8, 0x0f02);  // move $24, $2
318
0
      write16<E>(Buf + 10, 0x4723); // jrc $25 / jr16 $25
319
0
      relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPltEntryAddr - PltEntryAddr);
320
0
    } else {
321
0
      write16<E>(Buf, 0x7900);      // addiupc $2, (GOTPLT) - .
322
0
      write16<E>(Buf + 4, 0xff22);  // lw $25, 0($2)
323
0
      write16<E>(Buf + 8, 0x4599);  // jrc $25 / jr16 $25
324
0
      write16<E>(Buf + 10, 0x0f02); // move $24, $2
325
0
      relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPltEntryAddr - PltEntryAddr);
326
0
    }
327
0
    return;
328
0
  }
329
2
330
2
  uint32_t LoadInst = ELFT::Is64Bits ? 0xddf90000 : 
0x8df900000
;
331
2
  uint32_t JrInst = isMipsR6() ? 
(Config->ZHazardplt 0
?
0x032004090
:
0x032000090
)
332
2
                               : (Config->ZHazardplt ? 
0x032004081
:
0x032000081
);
333
2
  uint32_t AddInst = ELFT::Is64Bits ? 0x65f80000 : 
0x25f800000
;
334
2
335
2
  write32<E>(Buf, 0x3c0f0000);     // lui   $15, %hi(.got.plt entry)
336
2
  write32<E>(Buf + 4, LoadInst);   // l[wd] $25, %lo(.got.plt entry)($15)
337
2
  write32<E>(Buf + 8, JrInst);     // jr  $25 / jr.hb $25
338
2
  write32<E>(Buf + 12, AddInst);   // [d]addiu $24, $15, %lo(.got.plt entry)
339
2
  writeValue<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);
340
2
  writeValue<E>(Buf + 4, GotPltEntryAddr, 16, 0);
341
2
  writeValue<E>(Buf + 12, GotPltEntryAddr, 16, 0);
342
2
}
343
344
template <class ELFT>
345
bool MIPS<ELFT>::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,
346
10.3k
                            uint64_t BranchAddr, const Symbol &S) const {
347
10.3k
  // Any MIPS PIC code function is invoked with its address in register $t9.
348
10.3k
  // So if we have a branch instruction from non-PIC code to the PIC one
349
10.3k
  // we cannot make the jump directly and need to create a small stubs
350
10.3k
  // to save the target function address.
351
10.3k
  // See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
352
10.3k
  if (Type != R_MIPS_26 && 
Type != R_MIPS_PC26_S210.2k
&&
353
10.3k
      
Type != R_MICROMIPS_26_S110.2k
&&
Type != R_MICROMIPS_PC26_S110.2k
)
354
10.2k
    return false;
355
94
  auto *F = dyn_cast_or_null<ObjFile<ELFT>>(File);
356
94
  if (!F)
357
0
    return false;
358
94
  // If current file has PIC code, LA25 stub is not required.
359
94
  if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)
360
0
    return false;
361
94
  auto *D = dyn_cast<Defined>(&S);
362
94
  // LA25 is required if target file has PIC code
363
94
  // or target symbol is a PIC symbol.
364
94
  return D && 
isMipsPIC<ELFT>(D)81
;
365
94
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::needsThunk(lld::elf::RelExpr, unsigned int, lld::elf::InputFile const*, unsigned long long, lld::elf::Symbol const&) const
Line
Count
Source
346
18
                            uint64_t BranchAddr, const Symbol &S) const {
347
18
  // Any MIPS PIC code function is invoked with its address in register $t9.
348
18
  // So if we have a branch instruction from non-PIC code to the PIC one
349
18
  // we cannot make the jump directly and need to create a small stubs
350
18
  // to save the target function address.
351
18
  // See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
352
18
  if (Type != R_MIPS_26 && Type != R_MIPS_PC26_S2 &&
353
18
      Type != R_MICROMIPS_26_S1 && 
Type != R_MICROMIPS_PC26_S116
)
354
13
    return false;
355
5
  auto *F = dyn_cast_or_null<ObjFile<ELFT>>(File);
356
5
  if (!F)
357
0
    return false;
358
5
  // If current file has PIC code, LA25 stub is not required.
359
5
  if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)
360
0
    return false;
361
5
  auto *D = dyn_cast<Defined>(&S);
362
5
  // LA25 is required if target file has PIC code
363
5
  // or target symbol is a PIC symbol.
364
5
  return D && 
isMipsPIC<ELFT>(D)3
;
365
5
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::needsThunk(lld::elf::RelExpr, unsigned int, lld::elf::InputFile const*, unsigned long long, lld::elf::Symbol const&) const
Line
Count
Source
346
269
                            uint64_t BranchAddr, const Symbol &S) const {
347
269
  // Any MIPS PIC code function is invoked with its address in register $t9.
348
269
  // So if we have a branch instruction from non-PIC code to the PIC one
349
269
  // we cannot make the jump directly and need to create a small stubs
350
269
  // to save the target function address.
351
269
  // See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
352
269
  if (Type != R_MIPS_26 && 
Type != R_MIPS_PC26_S2193
&&
353
269
      
Type != R_MICROMIPS_26_S1192
&&
Type != R_MICROMIPS_PC26_S1185
)
354
182
    return false;
355
87
  auto *F = dyn_cast_or_null<ObjFile<ELFT>>(File);
356
87
  if (!F)
357
0
    return false;
358
87
  // If current file has PIC code, LA25 stub is not required.
359
87
  if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)
360
0
    return false;
361
87
  auto *D = dyn_cast<Defined>(&S);
362
87
  // LA25 is required if target file has PIC code
363
87
  // or target symbol is a PIC symbol.
364
87
  return D && 
isMipsPIC<ELFT>(D)78
;
365
87
}
Unexecuted instantiation: Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::needsThunk(lld::elf::RelExpr, unsigned int, lld::elf::InputFile const*, unsigned long long, lld::elf::Symbol const&) const
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::needsThunk(lld::elf::RelExpr, unsigned int, lld::elf::InputFile const*, unsigned long long, lld::elf::Symbol const&) const
Line
Count
Source
346
10.0k
                            uint64_t BranchAddr, const Symbol &S) const {
347
10.0k
  // Any MIPS PIC code function is invoked with its address in register $t9.
348
10.0k
  // So if we have a branch instruction from non-PIC code to the PIC one
349
10.0k
  // we cannot make the jump directly and need to create a small stubs
350
10.0k
  // to save the target function address.
351
10.0k
  // See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
352
10.0k
  if (Type != R_MIPS_26 && 
Type != R_MIPS_PC26_S210.0k
&&
353
10.0k
      
Type != R_MICROMIPS_26_S110.0k
&&
Type != R_MICROMIPS_PC26_S110.0k
)
354
10.0k
    return false;
355
2
  auto *F = dyn_cast_or_null<ObjFile<ELFT>>(File);
356
2
  if (!F)
357
0
    return false;
358
2
  // If current file has PIC code, LA25 stub is not required.
359
2
  if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)
360
0
    return false;
361
2
  auto *D = dyn_cast<Defined>(&S);
362
2
  // LA25 is required if target file has PIC code
363
2
  // or target symbol is a PIC symbol.
364
2
  return D && 
isMipsPIC<ELFT>(D)0
;
365
2
}
366
367
template <class ELFT>
368
357
int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *Buf, RelType Type) const {
369
357
  const endianness E = ELFT::TargetEndianness;
370
357
  switch (Type) {
371
357
  case R_MIPS_32:
372
29
  case R_MIPS_GPREL32:
373
29
  case R_MIPS_TLS_DTPREL32:
374
29
  case R_MIPS_TLS_TPREL32:
375
29
    return SignExtend64<32>(read32<E>(Buf));
376
64
  case R_MIPS_26:
377
64
    // FIXME (simon): If the relocation target symbol is not a PLT entry
378
64
    // we should use another expression for calculation:
379
64
    // ((A << 2) | (P & 0xf0000000)) >> 2
380
64
    return SignExtend64<28>(read32<E>(Buf) << 2);
381
70
  case R_MIPS_GOT16:
382
70
  case R_MIPS_HI16:
383
70
  case R_MIPS_PCHI16:
384
70
    return SignExtend64<16>(read32<E>(Buf)) << 16;
385
94
  case R_MIPS_GPREL16:
386
94
  case R_MIPS_LO16:
387
94
  case R_MIPS_PCLO16:
388
94
  case R_MIPS_TLS_DTPREL_HI16:
389
94
  case R_MIPS_TLS_DTPREL_LO16:
390
94
  case R_MIPS_TLS_TPREL_HI16:
391
94
  case R_MIPS_TLS_TPREL_LO16:
392
94
    return SignExtend64<16>(read32<E>(Buf));
393
94
  case R_MICROMIPS_GOT16:
394
7
  case R_MICROMIPS_HI16:
395
7
    return SignExtend64<16>(readShuffle<E>(Buf)) << 16;
396
9
  case R_MICROMIPS_GPREL16:
397
9
  case R_MICROMIPS_LO16:
398
9
  case R_MICROMIPS_TLS_DTPREL_HI16:
399
9
  case R_MICROMIPS_TLS_DTPREL_LO16:
400
9
  case R_MICROMIPS_TLS_TPREL_HI16:
401
9
  case R_MICROMIPS_TLS_TPREL_LO16:
402
9
    return SignExtend64<16>(readShuffle<E>(Buf));
403
9
  case R_MICROMIPS_GPREL7_S2:
404
0
    return SignExtend64<9>(readShuffle<E>(Buf) << 2);
405
9
  case R_MIPS_PC16:
406
2
    return SignExtend64<18>(read32<E>(Buf) << 2);
407
9
  case R_MIPS_PC19_S2:
408
1
    return SignExtend64<21>(read32<E>(Buf) << 2);
409
9
  case R_MIPS_PC21_S2:
410
1
    return SignExtend64<23>(read32<E>(Buf) << 2);
411
9
  case R_MIPS_PC26_S2:
412
1
    return SignExtend64<28>(read32<E>(Buf) << 2);
413
9
  case R_MIPS_PC32:
414
1
    return SignExtend64<32>(read32<E>(Buf));
415
9
  case R_MICROMIPS_26_S1:
416
8
    return SignExtend64<27>(readShuffle<E>(Buf) << 1);
417
9
  case R_MICROMIPS_PC7_S1:
418
2
    return SignExtend64<8>(read16<E>(Buf) << 1);
419
9
  case R_MICROMIPS_PC10_S1:
420
3
    return SignExtend64<11>(read16<E>(Buf) << 1);
421
9
  case R_MICROMIPS_PC16_S1:
422
2
    return SignExtend64<17>(readShuffle<E>(Buf) << 1);
423
9
  case R_MICROMIPS_PC18_S3:
424
0
    return SignExtend64<21>(readShuffle<E>(Buf) << 3);
425
9
  case R_MICROMIPS_PC19_S2:
426
2
    return SignExtend64<21>(readShuffle<E>(Buf) << 2);
427
9
  case R_MICROMIPS_PC21_S1:
428
2
    return SignExtend64<22>(readShuffle<E>(Buf) << 1);
429
9
  case R_MICROMIPS_PC23_S2:
430
0
    return SignExtend64<25>(readShuffle<E>(Buf) << 2);
431
9
  case R_MICROMIPS_PC26_S1:
432
6
    return SignExtend64<27>(readShuffle<E>(Buf) << 1);
433
53
  default:
434
53
    return 0;
435
357
  }
436
357
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::getImplicitAddend(unsigned char const*, unsigned int) const
Line
Count
Source
368
27
int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *Buf, RelType Type) const {
369
27
  const endianness E = ELFT::TargetEndianness;
370
27
  switch (Type) {
371
27
  case R_MIPS_32:
372
4
  case R_MIPS_GPREL32:
373
4
  case R_MIPS_TLS_DTPREL32:
374
4
  case R_MIPS_TLS_TPREL32:
375
4
    return SignExtend64<32>(read32<E>(Buf));
376
4
  case R_MIPS_26:
377
0
    // FIXME (simon): If the relocation target symbol is not a PLT entry
378
0
    // we should use another expression for calculation:
379
0
    // ((A << 2) | (P & 0xf0000000)) >> 2
380
0
    return SignExtend64<28>(read32<E>(Buf) << 2);
381
6
  case R_MIPS_GOT16:
382
6
  case R_MIPS_HI16:
383
6
  case R_MIPS_PCHI16:
384
6
    return SignExtend64<16>(read32<E>(Buf)) << 16;
385
6
  case R_MIPS_GPREL16:
386
2
  case R_MIPS_LO16:
387
2
  case R_MIPS_PCLO16:
388
2
  case R_MIPS_TLS_DTPREL_HI16:
389
2
  case R_MIPS_TLS_DTPREL_LO16:
390
2
  case R_MIPS_TLS_TPREL_HI16:
391
2
  case R_MIPS_TLS_TPREL_LO16:
392
2
    return SignExtend64<16>(read32<E>(Buf));
393
2
  case R_MICROMIPS_GOT16:
394
2
  case R_MICROMIPS_HI16:
395
2
    return SignExtend64<16>(readShuffle<E>(Buf)) << 16;
396
2
  case R_MICROMIPS_GPREL16:
397
2
  case R_MICROMIPS_LO16:
398
2
  case R_MICROMIPS_TLS_DTPREL_HI16:
399
2
  case R_MICROMIPS_TLS_DTPREL_LO16:
400
2
  case R_MICROMIPS_TLS_TPREL_HI16:
401
2
  case R_MICROMIPS_TLS_TPREL_LO16:
402
2
    return SignExtend64<16>(readShuffle<E>(Buf));
403
2
  case R_MICROMIPS_GPREL7_S2:
404
0
    return SignExtend64<9>(readShuffle<E>(Buf) << 2);
405
2
  case R_MIPS_PC16:
406
0
    return SignExtend64<18>(read32<E>(Buf) << 2);
407
2
  case R_MIPS_PC19_S2:
408
0
    return SignExtend64<21>(read32<E>(Buf) << 2);
409
2
  case R_MIPS_PC21_S2:
410
0
    return SignExtend64<23>(read32<E>(Buf) << 2);
411
2
  case R_MIPS_PC26_S2:
412
0
    return SignExtend64<28>(read32<E>(Buf) << 2);
413
2
  case R_MIPS_PC32:
414
0
    return SignExtend64<32>(read32<E>(Buf));
415
2
  case R_MICROMIPS_26_S1:
416
2
    return SignExtend64<27>(readShuffle<E>(Buf) << 1);
417
2
  case R_MICROMIPS_PC7_S1:
418
1
    return SignExtend64<8>(read16<E>(Buf) << 1);
419
2
  case R_MICROMIPS_PC10_S1:
420
1
    return SignExtend64<11>(read16<E>(Buf) << 1);
421
2
  case R_MICROMIPS_PC16_S1:
422
1
    return SignExtend64<17>(readShuffle<E>(Buf) << 1);
423
2
  case R_MICROMIPS_PC18_S3:
424
0
    return SignExtend64<21>(readShuffle<E>(Buf) << 3);
425
2
  case R_MICROMIPS_PC19_S2:
426
1
    return SignExtend64<21>(readShuffle<E>(Buf) << 2);
427
2
  case R_MICROMIPS_PC21_S1:
428
1
    return SignExtend64<22>(readShuffle<E>(Buf) << 1);
429
2
  case R_MICROMIPS_PC23_S2:
430
0
    return SignExtend64<25>(readShuffle<E>(Buf) << 2);
431
3
  case R_MICROMIPS_PC26_S1:
432
3
    return SignExtend64<27>(readShuffle<E>(Buf) << 1);
433
2
  default:
434
1
    return 0;
435
27
  }
436
27
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::getImplicitAddend(unsigned char const*, unsigned int) const
Line
Count
Source
368
330
int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *Buf, RelType Type) const {
369
330
  const endianness E = ELFT::TargetEndianness;
370
330
  switch (Type) {
371
330
  case R_MIPS_32:
372
25
  case R_MIPS_GPREL32:
373
25
  case R_MIPS_TLS_DTPREL32:
374
25
  case R_MIPS_TLS_TPREL32:
375
25
    return SignExtend64<32>(read32<E>(Buf));
376
64
  case R_MIPS_26:
377
64
    // FIXME (simon): If the relocation target symbol is not a PLT entry
378
64
    // we should use another expression for calculation:
379
64
    // ((A << 2) | (P & 0xf0000000)) >> 2
380
64
    return SignExtend64<28>(read32<E>(Buf) << 2);
381
64
  case R_MIPS_GOT16:
382
64
  case R_MIPS_HI16:
383
64
  case R_MIPS_PCHI16:
384
64
    return SignExtend64<16>(read32<E>(Buf)) << 16;
385
92
  case R_MIPS_GPREL16:
386
92
  case R_MIPS_LO16:
387
92
  case R_MIPS_PCLO16:
388
92
  case R_MIPS_TLS_DTPREL_HI16:
389
92
  case R_MIPS_TLS_DTPREL_LO16:
390
92
  case R_MIPS_TLS_TPREL_HI16:
391
92
  case R_MIPS_TLS_TPREL_LO16:
392
92
    return SignExtend64<16>(read32<E>(Buf));
393
92
  case R_MICROMIPS_GOT16:
394
5
  case R_MICROMIPS_HI16:
395
5
    return SignExtend64<16>(readShuffle<E>(Buf)) << 16;
396
7
  case R_MICROMIPS_GPREL16:
397
7
  case R_MICROMIPS_LO16:
398
7
  case R_MICROMIPS_TLS_DTPREL_HI16:
399
7
  case R_MICROMIPS_TLS_DTPREL_LO16:
400
7
  case R_MICROMIPS_TLS_TPREL_HI16:
401
7
  case R_MICROMIPS_TLS_TPREL_LO16:
402
7
    return SignExtend64<16>(readShuffle<E>(Buf));
403
7
  case R_MICROMIPS_GPREL7_S2:
404
0
    return SignExtend64<9>(readShuffle<E>(Buf) << 2);
405
7
  case R_MIPS_PC16:
406
2
    return SignExtend64<18>(read32<E>(Buf) << 2);
407
7
  case R_MIPS_PC19_S2:
408
1
    return SignExtend64<21>(read32<E>(Buf) << 2);
409
7
  case R_MIPS_PC21_S2:
410
1
    return SignExtend64<23>(read32<E>(Buf) << 2);
411
7
  case R_MIPS_PC26_S2:
412
1
    return SignExtend64<28>(read32<E>(Buf) << 2);
413
7
  case R_MIPS_PC32:
414
1
    return SignExtend64<32>(read32<E>(Buf));
415
7
  case R_MICROMIPS_26_S1:
416
6
    return SignExtend64<27>(readShuffle<E>(Buf) << 1);
417
7
  case R_MICROMIPS_PC7_S1:
418
1
    return SignExtend64<8>(read16<E>(Buf) << 1);
419
7
  case R_MICROMIPS_PC10_S1:
420
2
    return SignExtend64<11>(read16<E>(Buf) << 1);
421
7
  case R_MICROMIPS_PC16_S1:
422
1
    return SignExtend64<17>(readShuffle<E>(Buf) << 1);
423
7
  case R_MICROMIPS_PC18_S3:
424
0
    return SignExtend64<21>(readShuffle<E>(Buf) << 3);
425
7
  case R_MICROMIPS_PC19_S2:
426
1
    return SignExtend64<21>(readShuffle<E>(Buf) << 2);
427
7
  case R_MICROMIPS_PC21_S1:
428
1
    return SignExtend64<22>(readShuffle<E>(Buf) << 1);
429
7
  case R_MICROMIPS_PC23_S2:
430
0
    return SignExtend64<25>(readShuffle<E>(Buf) << 2);
431
7
  case R_MICROMIPS_PC26_S1:
432
3
    return SignExtend64<27>(readShuffle<E>(Buf) << 1);
433
52
  default:
434
52
    return 0;
435
330
  }
436
330
}
437
438
static std::pair<uint32_t, uint64_t>
439
10.0k
calculateMipsRelChain(uint8_t *Loc, RelType Type, uint64_t Val) {
440
10.0k
  // MIPS N64 ABI packs multiple relocations into the single relocation
441
10.0k
  // record. In general, all up to three relocations can have arbitrary
442
10.0k
  // types. In fact, Clang and GCC uses only a few combinations. For now,
443
10.0k
  // we support two of them. That is allow to pass at least all LLVM
444
10.0k
  // test suite cases.
445
10.0k
  // <any relocation> / R_MIPS_SUB / R_MIPS_HI16 | R_MIPS_LO16
446
10.0k
  // <any relocation> / R_MIPS_64 / R_MIPS_NONE
447
10.0k
  // The first relocation is a 'real' relocation which is calculated
448
10.0k
  // using the corresponding symbol's value. The second and the third
449
10.0k
  // relocations used to modify result of the first one: extend it to
450
10.0k
  // 64-bit, extract high or low part etc. For details, see part 2.9 Relocation
451
10.0k
  // at the https://dmz-portal.mips.com/mw/images/8/82/007-4658-001.pdf
452
10.0k
  RelType Type2 = (Type >> 8) & 0xff;
453
10.0k
  RelType Type3 = (Type >> 16) & 0xff;
454
10.0k
  if (Type2 == R_MIPS_NONE && 
Type3 == R_MIPS_NONE10.0k
)
455
10.0k
    return std::make_pair(Type, Val);
456
12
  if (Type2 == R_MIPS_64 && 
Type3 == R_MIPS_NONE1
)
457
1
    return std::make_pair(Type2, Val);
458
11
  if (Type2 == R_MIPS_SUB && (Type3 == R_MIPS_HI16 || 
Type3 == R_MIPS_LO164
))
459
11
    return std::make_pair(Type3, -Val);
460
0
  error(getErrorLocation(Loc) + "unsupported relocations combination " +
461
0
        Twine(Type));
462
0
  return std::make_pair(Type & 0xff, Val);
463
0
}
464
465
52
static bool isBranchReloc(RelType Type) {
466
52
  return Type == R_MIPS_26 || 
Type == R_MIPS_PC26_S250
||
467
52
         
Type == R_MIPS_PC21_S250
||
Type == R_MIPS_PC1650
;
468
52
}
469
470
10.4k
static bool isMicroBranchReloc(RelType Type) {
471
10.4k
  return Type == R_MICROMIPS_26_S1 || 
Type == R_MICROMIPS_PC16_S110.4k
||
472
10.4k
         
Type == R_MICROMIPS_PC10_S110.4k
||
Type == R_MICROMIPS_PC7_S110.4k
;
473
10.4k
}
474
475
template <class ELFT>
476
10.4k
static uint64_t fixupCrossModeJump(uint8_t *Loc, RelType Type, uint64_t Val) {
477
10.4k
  // Here we need to detect jump/branch from regular MIPS code
478
10.4k
  // to a microMIPS target and vice versa. In that cases jump
479
10.4k
  // instructions need to be replaced by their "cross-mode"
480
10.4k
  // equivalents.
481
10.4k
  const endianness E = ELFT::TargetEndianness;
482
10.4k
  bool IsMicroTgt = Val & 0x1;
483
10.4k
  bool IsCrossJump = (IsMicroTgt && 
isBranchReloc(Type)52
) ||
484
10.4k
                     
(10.4k
!IsMicroTgt10.4k
&&
isMicroBranchReloc(Type)10.4k
);
485
10.4k
  if (!IsCrossJump)
486
10.4k
    return Val;
487
5
488
5
  switch (Type) {
489
5
  case R_MIPS_26: {
490
2
    uint32_t Inst = read32<E>(Loc) >> 26;
491
2
    if (Inst == 0x3 || 
Inst == 0x1d0
) { // JAL or JALX
492
2
      writeValue<E>(Loc, 0x1d << 26, 32, 0);
493
2
      return Val;
494
2
    }
495
0
    break;
496
0
  }
497
2
  case R_MICROMIPS_26_S1: {
498
2
    uint32_t Inst = readShuffle<E>(Loc) >> 26;
499
2
    if (Inst == 0x3d || 
Inst == 0x3c0
) { // JAL32 or JALX32
500
2
      Val >>= 1;
501
2
      writeShuffleValue<E>(Loc, 0x3c << 26, 32, 0);
502
2
      return Val;
503
2
    }
504
0
    break;
505
0
  }
506
2
  case R_MIPS_PC26_S2:
507
2
  case R_MIPS_PC21_S2:
508
2
  case R_MIPS_PC16:
509
2
  case R_MICROMIPS_PC16_S1:
510
2
  case R_MICROMIPS_PC10_S1:
511
2
  case R_MICROMIPS_PC7_S1:
512
2
    // FIXME (simon): Support valid branch relocations.
513
2
    break;
514
2
  default:
515
0
    llvm_unreachable("unexpected jump/branch relocation");
516
2
  }
517
2
518
2
  error(getErrorLocation(Loc) +
519
2
        "unsupported jump/branch instruction between ISA modes referenced by " +
520
2
        toString(Type) + " relocation");
521
2
  return Val;
522
2
}
Mips.cpp:unsigned long long fixupCrossModeJump<llvm::object::ELFType<(llvm::support::endianness)1, false> >(unsigned char*, unsigned int, unsigned long long)
Line
Count
Source
476
36
static uint64_t fixupCrossModeJump(uint8_t *Loc, RelType Type, uint64_t Val) {
477
36
  // Here we need to detect jump/branch from regular MIPS code
478
36
  // to a microMIPS target and vice versa. In that cases jump
479
36
  // instructions need to be replaced by their "cross-mode"
480
36
  // equivalents.
481
36
  const endianness E = ELFT::TargetEndianness;
482
36
  bool IsMicroTgt = Val & 0x1;
483
36
  bool IsCrossJump = (IsMicroTgt && 
isBranchReloc(Type)19
) ||
484
36
                     (!IsMicroTgt && 
isMicroBranchReloc(Type)17
);
485
36
  if (!IsCrossJump)
486
36
    return Val;
487
0
488
0
  switch (Type) {
489
0
  case R_MIPS_26: {
490
0
    uint32_t Inst = read32<E>(Loc) >> 26;
491
0
    if (Inst == 0x3 || Inst == 0x1d) { // JAL or JALX
492
0
      writeValue<E>(Loc, 0x1d << 26, 32, 0);
493
0
      return Val;
494
0
    }
495
0
    break;
496
0
  }
497
0
  case R_MICROMIPS_26_S1: {
498
0
    uint32_t Inst = readShuffle<E>(Loc) >> 26;
499
0
    if (Inst == 0x3d || Inst == 0x3c) { // JAL32 or JALX32
500
0
      Val >>= 1;
501
0
      writeShuffleValue<E>(Loc, 0x3c << 26, 32, 0);
502
0
      return Val;
503
0
    }
504
0
    break;
505
0
  }
506
0
  case R_MIPS_PC26_S2:
507
0
  case R_MIPS_PC21_S2:
508
0
  case R_MIPS_PC16:
509
0
  case R_MICROMIPS_PC16_S1:
510
0
  case R_MICROMIPS_PC10_S1:
511
0
  case R_MICROMIPS_PC7_S1:
512
0
    // FIXME (simon): Support valid branch relocations.
513
0
    break;
514
0
  default:
515
0
    llvm_unreachable("unexpected jump/branch relocation");
516
0
  }
517
0
518
0
  error(getErrorLocation(Loc) +
519
0
        "unsupported jump/branch instruction between ISA modes referenced by " +
520
0
        toString(Type) + " relocation");
521
0
  return Val;
522
0
}
Mips.cpp:unsigned long long fixupCrossModeJump<llvm::object::ELFType<(llvm::support::endianness)0, false> >(unsigned char*, unsigned int, unsigned long long)
Line
Count
Source
476
385
static uint64_t fixupCrossModeJump(uint8_t *Loc, RelType Type, uint64_t Val) {
477
385
  // Here we need to detect jump/branch from regular MIPS code
478
385
  // to a microMIPS target and vice versa. In that cases jump
479
385
  // instructions need to be replaced by their "cross-mode"
480
385
  // equivalents.
481
385
  const endianness E = ELFT::TargetEndianness;
482
385
  bool IsMicroTgt = Val & 0x1;
483
385
  bool IsCrossJump = (IsMicroTgt && 
isBranchReloc(Type)31
) ||
484
385
                     
(382
!IsMicroTgt382
&&
isMicroBranchReloc(Type)354
);
485
385
  if (!IsCrossJump)
486
380
    return Val;
487
5
488
5
  switch (Type) {
489
5
  case R_MIPS_26: {
490
2
    uint32_t Inst = read32<E>(Loc) >> 26;
491
2
    if (Inst == 0x3 || 
Inst == 0x1d0
) { // JAL or JALX
492
2
      writeValue<E>(Loc, 0x1d << 26, 32, 0);
493
2
      return Val;
494
2
    }
495
0
    break;
496
0
  }
497
2
  case R_MICROMIPS_26_S1: {
498
2
    uint32_t Inst = readShuffle<E>(Loc) >> 26;
499
2
    if (Inst == 0x3d || 
Inst == 0x3c0
) { // JAL32 or JALX32
500
2
      Val >>= 1;
501
2
      writeShuffleValue<E>(Loc, 0x3c << 26, 32, 0);
502
2
      return Val;
503
2
    }
504
0
    break;
505
0
  }
506
2
  case R_MIPS_PC26_S2:
507
2
  case R_MIPS_PC21_S2:
508
2
  case R_MIPS_PC16:
509
2
  case R_MICROMIPS_PC16_S1:
510
2
  case R_MICROMIPS_PC10_S1:
511
2
  case R_MICROMIPS_PC7_S1:
512
2
    // FIXME (simon): Support valid branch relocations.
513
2
    break;
514
2
  default:
515
0
    llvm_unreachable("unexpected jump/branch relocation");
516
2
  }
517
2
518
2
  error(getErrorLocation(Loc) +
519
2
        "unsupported jump/branch instruction between ISA modes referenced by " +
520
2
        toString(Type) + " relocation");
521
2
  return Val;
522
2
}
Unexecuted instantiation: Mips.cpp:unsigned long long fixupCrossModeJump<llvm::object::ELFType<(llvm::support::endianness)1, true> >(unsigned char*, unsigned int, unsigned long long)
Mips.cpp:unsigned long long fixupCrossModeJump<llvm::object::ELFType<(llvm::support::endianness)0, true> >(unsigned char*, unsigned int, unsigned long long)
Line
Count
Source
476
10.0k
static uint64_t fixupCrossModeJump(uint8_t *Loc, RelType Type, uint64_t Val) {
477
10.0k
  // Here we need to detect jump/branch from regular MIPS code
478
10.0k
  // to a microMIPS target and vice versa. In that cases jump
479
10.0k
  // instructions need to be replaced by their "cross-mode"
480
10.0k
  // equivalents.
481
10.0k
  const endianness E = ELFT::TargetEndianness;
482
10.0k
  bool IsMicroTgt = Val & 0x1;
483
10.0k
  bool IsCrossJump = (IsMicroTgt && 
isBranchReloc(Type)2
) ||
484
10.0k
                     (!IsMicroTgt && 
isMicroBranchReloc(Type)10.0k
);
485
10.0k
  if (!IsCrossJump)
486
10.0k
    return Val;
487
0
488
0
  switch (Type) {
489
0
  case R_MIPS_26: {
490
0
    uint32_t Inst = read32<E>(Loc) >> 26;
491
0
    if (Inst == 0x3 || Inst == 0x1d) { // JAL or JALX
492
0
      writeValue<E>(Loc, 0x1d << 26, 32, 0);
493
0
      return Val;
494
0
    }
495
0
    break;
496
0
  }
497
0
  case R_MICROMIPS_26_S1: {
498
0
    uint32_t Inst = readShuffle<E>(Loc) >> 26;
499
0
    if (Inst == 0x3d || Inst == 0x3c) { // JAL32 or JALX32
500
0
      Val >>= 1;
501
0
      writeShuffleValue<E>(Loc, 0x3c << 26, 32, 0);
502
0
      return Val;
503
0
    }
504
0
    break;
505
0
  }
506
0
  case R_MIPS_PC26_S2:
507
0
  case R_MIPS_PC21_S2:
508
0
  case R_MIPS_PC16:
509
0
  case R_MICROMIPS_PC16_S1:
510
0
  case R_MICROMIPS_PC10_S1:
511
0
  case R_MICROMIPS_PC7_S1:
512
0
    // FIXME (simon): Support valid branch relocations.
513
0
    break;
514
0
  default:
515
0
    llvm_unreachable("unexpected jump/branch relocation");
516
0
  }
517
0
518
0
  error(getErrorLocation(Loc) +
519
0
        "unsupported jump/branch instruction between ISA modes referenced by " +
520
0
        toString(Type) + " relocation");
521
0
  return Val;
522
0
}
523
524
template <class ELFT>
525
10.4k
void MIPS<ELFT>::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
526
10.4k
  const endianness E = ELFT::TargetEndianness;
527
10.4k
528
10.4k
  if (ELFT::Is64Bits || 
Config->MipsN32Abi421
)
529
10.0k
    std::tie(Type, Val) = calculateMipsRelChain(Loc, Type, Val);
530
10.4k
531
10.4k
  // Detect cross-mode jump/branch and fix instruction.
532
10.4k
  Val = fixupCrossModeJump<ELFT>(Loc, Type, Val);
533
10.4k
534
10.4k
  // Thread pointer and DRP offsets from the start of TLS data area.
535
10.4k
  // https://www.linux-mips.org/wiki/NPTL
536
10.4k
  if (Type == R_MIPS_TLS_DTPREL_HI16 || 
Type == R_MIPS_TLS_DTPREL_LO1610.4k
||
537
10.4k
      
Type == R_MIPS_TLS_DTPREL3210.4k
||
Type == R_MIPS_TLS_DTPREL6410.4k
||
538
10.4k
      
Type == R_MICROMIPS_TLS_DTPREL_HI1610.4k
||
539
10.4k
      
Type == R_MICROMIPS_TLS_DTPREL_LO1610.4k
) {
540
6
    Val -= 0x8000;
541
10.4k
  } else if (Type == R_MIPS_TLS_TPREL_HI16 || 
Type == R_MIPS_TLS_TPREL_LO1610.4k
||
542
10.4k
             
Type == R_MIPS_TLS_TPREL3210.4k
||
Type == R_MIPS_TLS_TPREL6410.4k
||
543
10.4k
             
Type == R_MICROMIPS_TLS_TPREL_HI1610.4k
||
544
10.4k
             
Type == R_MICROMIPS_TLS_TPREL_LO1610.4k
) {
545
6
    Val -= 0x7000;
546
6
  }
547
10.4k
548
10.4k
  switch (Type) {
549
10.4k
  case R_MIPS_32:
550
33
  case R_MIPS_GPREL32:
551
33
  case R_MIPS_TLS_DTPREL32:
552
33
  case R_MIPS_TLS_TPREL32:
553
33
    write32<E>(Loc, Val);
554
33
    break;
555
33
  case R_MIPS_64:
556
8
  case R_MIPS_TLS_DTPREL64:
557
8
  case R_MIPS_TLS_TPREL64:
558
8
    write64<E>(Loc, Val);
559
8
    break;
560
68
  case R_MIPS_26:
561
68
    writeValue<E>(Loc, Val, 26, 2);
562
68
    break;
563
46
  case R_MIPS_GOT16:
564
46
    // The R_MIPS_GOT16 relocation's value in "relocatable" linking mode
565
46
    // is updated addend (not a GOT index). In that case write high 16 bits
566
46
    // to store a correct addend value.
567
46
    if (Config->Relocatable) {
568
6
      writeValue<E>(Loc, Val + 0x8000, 16, 16);
569
40
    } else {
570
40
      checkInt(Loc, Val, 16, Type);
571
40
      writeValue<E>(Loc, Val, 16, 0);
572
40
    }
573
46
    break;
574
8
  case R_MICROMIPS_GOT16:
575
4
    if (Config->Relocatable) {
576
0
      writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
577
4
    } else {
578
4
      checkInt(Loc, Val, 16, Type);
579
4
      writeShuffleValue<E>(Loc, Val, 16, 0);
580
4
    }
581
4
    break;
582
10.0k
  case R_MIPS_CALL16:
583
10.0k
  case R_MIPS_GOT_DISP:
584
10.0k
  case R_MIPS_GOT_PAGE:
585
10.0k
  case R_MIPS_GPREL16:
586
10.0k
  case R_MIPS_TLS_GD:
587
10.0k
  case R_MIPS_TLS_GOTTPREL:
588
10.0k
  case R_MIPS_TLS_LDM:
589
10.0k
    checkInt(Loc, Val, 16, Type);
590
10.0k
    LLVM_FALLTHROUGH;
591
10.1k
  case R_MIPS_CALL_LO16:
592
10.1k
  case R_MIPS_GOT_LO16:
593
10.1k
  case R_MIPS_GOT_OFST:
594
10.1k
  case R_MIPS_LO16:
595
10.1k
  case R_MIPS_PCLO16:
596
10.1k
  case R_MIPS_TLS_DTPREL_LO16:
597
10.1k
  case R_MIPS_TLS_TPREL_LO16:
598
10.1k
    writeValue<E>(Loc, Val, 16, 0);
599
10.1k
    break;
600
10.1k
  case R_MICROMIPS_GPREL16:
601
0
  case R_MICROMIPS_TLS_GD:
602
0
  case R_MICROMIPS_TLS_LDM:
603
0
    checkInt(Loc, Val, 16, Type);
604
0
    writeShuffleValue<E>(Loc, Val, 16, 0);
605
0
    break;
606
13
  case R_MICROMIPS_CALL16:
607
13
  case R_MICROMIPS_CALL_LO16:
608
13
  case R_MICROMIPS_LO16:
609
13
  case R_MICROMIPS_TLS_DTPREL_LO16:
610
13
  case R_MICROMIPS_TLS_GOTTPREL:
611
13
  case R_MICROMIPS_TLS_TPREL_LO16:
612
13
    writeShuffleValue<E>(Loc, Val, 16, 0);
613
13
    break;
614
13
  case R_MICROMIPS_GPREL7_S2:
615
0
    checkInt(Loc, Val, 7, Type);
616
0
    writeShuffleValue<E>(Loc, Val, 7, 2);
617
0
    break;
618
80
  case R_MIPS_CALL_HI16:
619
80
  case R_MIPS_GOT_HI16:
620
80
  case R_MIPS_HI16:
621
80
  case R_MIPS_PCHI16:
622
80
  case R_MIPS_TLS_DTPREL_HI16:
623
80
  case R_MIPS_TLS_TPREL_HI16:
624
80
    writeValue<E>(Loc, Val + 0x8000, 16, 16);
625
80
    break;
626
80
  case R_MICROMIPS_CALL_HI16:
627
8
  case R_MICROMIPS_GOT_HI16:
628
8
  case R_MICROMIPS_HI16:
629
8
  case R_MICROMIPS_TLS_DTPREL_HI16:
630
8
  case R_MICROMIPS_TLS_TPREL_HI16:
631
8
    writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
632
8
    break;
633
8
  case R_MIPS_HIGHER:
634
2
    writeValue<E>(Loc, Val + 0x80008000, 16, 32);
635
2
    break;
636
8
  case R_MIPS_HIGHEST:
637
2
    writeValue<E>(Loc, Val + 0x800080008000, 16, 48);
638
2
    break;
639
8
  case R_MIPS_JALR:
640
0
  case R_MICROMIPS_JALR:
641
0
    // Ignore this optimization relocation for now
642
0
    break;
643
2
  case R_MIPS_PC16:
644
2
    checkAlignment(Loc, Val, 4, Type);
645
2
    checkInt(Loc, Val, 18, Type);
646
2
    writeValue<E>(Loc, Val, 16, 2);
647
2
    break;
648
1
  case R_MIPS_PC19_S2:
649
1
    checkAlignment(Loc, Val, 4, Type);
650
1
    checkInt(Loc, Val, 21, Type);
651
1
    writeValue<E>(Loc, Val, 19, 2);
652
1
    break;
653
1
  case R_MIPS_PC21_S2:
654
1
    checkAlignment(Loc, Val, 4, Type);
655
1
    checkInt(Loc, Val, 23, Type);
656
1
    writeValue<E>(Loc, Val, 21, 2);
657
1
    break;
658
1
  case R_MIPS_PC26_S2:
659
1
    checkAlignment(Loc, Val, 4, Type);
660
1
    checkInt(Loc, Val, 28, Type);
661
1
    writeValue<E>(Loc, Val, 26, 2);
662
1
    break;
663
2
  case R_MIPS_PC32:
664
2
    writeValue<E>(Loc, Val, 32, 0);
665
2
    break;
666
19
  case R_MICROMIPS_26_S1:
667
19
  case R_MICROMIPS_PC26_S1:
668
19
    checkInt(Loc, Val, 27, Type);
669
19
    writeShuffleValue<E>(Loc, Val, 26, 1);
670
19
    break;
671
19
  case R_MICROMIPS_PC7_S1:
672
2
    checkInt(Loc, Val, 8, Type);
673
2
    writeMicroRelocation16<E>(Loc, Val, 7, 1);
674
2
    break;
675
19
  case R_MICROMIPS_PC10_S1:
676
3
    checkInt(Loc, Val, 11, Type);
677
3
    writeMicroRelocation16<E>(Loc, Val, 10, 1);
678
3
    break;
679
19
  case R_MICROMIPS_PC16_S1:
680
2
    checkInt(Loc, Val, 17, Type);
681
2
    writeShuffleValue<E>(Loc, Val, 16, 1);
682
2
    break;
683
19
  case R_MICROMIPS_PC18_S3:
684
0
    checkInt(Loc, Val, 21, Type);
685
0
    writeShuffleValue<E>(Loc, Val, 18, 3);
686
0
    break;
687
19
  case R_MICROMIPS_PC19_S2:
688
6
    checkInt(Loc, Val, 21, Type);
689
6
    writeShuffleValue<E>(Loc, Val, 19, 2);
690
6
    break;
691
19
  case R_MICROMIPS_PC21_S1:
692
2
    checkInt(Loc, Val, 22, Type);
693
2
    writeShuffleValue<E>(Loc, Val, 21, 1);
694
2
    break;
695
19
  case R_MICROMIPS_PC23_S2:
696
8
    checkInt(Loc, Val, 25, Type);
697
8
    writeShuffleValue<E>(Loc, Val, 23, 2);
698
8
    break;
699
19
  default:
700
0
    llvm_unreachable("unknown relocation");
701
10.4k
  }
702
10.4k
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::relocateOne(unsigned char*, unsigned int, unsigned long long) const
Line
Count
Source
525
36
void MIPS<ELFT>::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
526
36
  const endianness E = ELFT::TargetEndianness;
527
36
528
36
  if (ELFT::Is64Bits || Config->MipsN32Abi)
529
0
    std::tie(Type, Val) = calculateMipsRelChain(Loc, Type, Val);
530
36
531
36
  // Detect cross-mode jump/branch and fix instruction.
532
36
  Val = fixupCrossModeJump<ELFT>(Loc, Type, Val);
533
36
534
36
  // Thread pointer and DRP offsets from the start of TLS data area.
535
36
  // https://www.linux-mips.org/wiki/NPTL
536
36
  if (Type == R_MIPS_TLS_DTPREL_HI16 || Type == R_MIPS_TLS_DTPREL_LO16 ||
537
36
      Type == R_MIPS_TLS_DTPREL32 || Type == R_MIPS_TLS_DTPREL64 ||
538
36
      Type == R_MICROMIPS_TLS_DTPREL_HI16 ||
539
36
      Type == R_MICROMIPS_TLS_DTPREL_LO16) {
540
0
    Val -= 0x8000;
541
36
  } else if (Type == R_MIPS_TLS_TPREL_HI16 || Type == R_MIPS_TLS_TPREL_LO16 ||
542
36
             Type == R_MIPS_TLS_TPREL32 || Type == R_MIPS_TLS_TPREL64 ||
543
36
             Type == R_MICROMIPS_TLS_TPREL_HI16 ||
544
36
             Type == R_MICROMIPS_TLS_TPREL_LO16) {
545
0
    Val -= 0x7000;
546
0
  }
547
36
548
36
  switch (Type) {
549
36
  case R_MIPS_32:
550
4
  case R_MIPS_GPREL32:
551
4
  case R_MIPS_TLS_DTPREL32:
552
4
  case R_MIPS_TLS_TPREL32:
553
4
    write32<E>(Loc, Val);
554
4
    break;
555
4
  case R_MIPS_64:
556
0
  case R_MIPS_TLS_DTPREL64:
557
0
  case R_MIPS_TLS_TPREL64:
558
0
    write64<E>(Loc, Val);
559
0
    break;
560
0
  case R_MIPS_26:
561
0
    writeValue<E>(Loc, Val, 26, 2);
562
0
    break;
563
6
  case R_MIPS_GOT16:
564
6
    // The R_MIPS_GOT16 relocation's value in "relocatable" linking mode
565
6
    // is updated addend (not a GOT index). In that case write high 16 bits
566
6
    // to store a correct addend value.
567
6
    if (Config->Relocatable) {
568
2
      writeValue<E>(Loc, Val + 0x8000, 16, 16);
569
4
    } else {
570
4
      checkInt(Loc, Val, 16, Type);
571
4
      writeValue<E>(Loc, Val, 16, 0);
572
4
    }
573
6
    break;
574
1
  case R_MICROMIPS_GOT16:
575
1
    if (Config->Relocatable) {
576
0
      writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
577
1
    } else {
578
1
      checkInt(Loc, Val, 16, Type);
579
1
      writeShuffleValue<E>(Loc, Val, 16, 0);
580
1
    }
581
1
    break;
582
0
  case R_MIPS_CALL16:
583
0
  case R_MIPS_GOT_DISP:
584
0
  case R_MIPS_GOT_PAGE:
585
0
  case R_MIPS_GPREL16:
586
0
  case R_MIPS_TLS_GD:
587
0
  case R_MIPS_TLS_GOTTPREL:
588
0
  case R_MIPS_TLS_LDM:
589
0
    checkInt(Loc, Val, 16, Type);
590
0
    LLVM_FALLTHROUGH;
591
2
  case R_MIPS_CALL_LO16:
592
2
  case R_MIPS_GOT_LO16:
593
2
  case R_MIPS_GOT_OFST:
594
2
  case R_MIPS_LO16:
595
2
  case R_MIPS_PCLO16:
596
2
  case R_MIPS_TLS_DTPREL_LO16:
597
2
  case R_MIPS_TLS_TPREL_LO16:
598
2
    writeValue<E>(Loc, Val, 16, 0);
599
2
    break;
600
2
  case R_MICROMIPS_GPREL16:
601
0
  case R_MICROMIPS_TLS_GD:
602
0
  case R_MICROMIPS_TLS_LDM:
603
0
    checkInt(Loc, Val, 16, Type);
604
0
    writeShuffleValue<E>(Loc, Val, 16, 0);
605
0
    break;
606
4
  case R_MICROMIPS_CALL16:
607
4
  case R_MICROMIPS_CALL_LO16:
608
4
  case R_MICROMIPS_LO16:
609
4
  case R_MICROMIPS_TLS_DTPREL_LO16:
610
4
  case R_MICROMIPS_TLS_GOTTPREL:
611
4
  case R_MICROMIPS_TLS_TPREL_LO16:
612
4
    writeShuffleValue<E>(Loc, Val, 16, 0);
613
4
    break;
614
4
  case R_MICROMIPS_GPREL7_S2:
615
0
    checkInt(Loc, Val, 7, Type);
616
0
    writeShuffleValue<E>(Loc, Val, 7, 2);
617
0
    break;
618
4
  case R_MIPS_CALL_HI16:
619
0
  case R_MIPS_GOT_HI16:
620
0
  case R_MIPS_HI16:
621
0
  case R_MIPS_PCHI16:
622
0
  case R_MIPS_TLS_DTPREL_HI16:
623
0
  case R_MIPS_TLS_TPREL_HI16:
624
0
    writeValue<E>(Loc, Val + 0x8000, 16, 16);
625
0
    break;
626
3
  case R_MICROMIPS_CALL_HI16:
627
3
  case R_MICROMIPS_GOT_HI16:
628
3
  case R_MICROMIPS_HI16:
629
3
  case R_MICROMIPS_TLS_DTPREL_HI16:
630
3
  case R_MICROMIPS_TLS_TPREL_HI16:
631
3
    writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
632
3
    break;
633
3
  case R_MIPS_HIGHER:
634
0
    writeValue<E>(Loc, Val + 0x80008000, 16, 32);
635
0
    break;
636
3
  case R_MIPS_HIGHEST:
637
0
    writeValue<E>(Loc, Val + 0x800080008000, 16, 48);
638
0
    break;
639
3
  case R_MIPS_JALR:
640
0
  case R_MICROMIPS_JALR:
641
0
    // Ignore this optimization relocation for now
642
0
    break;
643
0
  case R_MIPS_PC16:
644
0
    checkAlignment(Loc, Val, 4, Type);
645
0
    checkInt(Loc, Val, 18, Type);
646
0
    writeValue<E>(Loc, Val, 16, 2);
647
0
    break;
648
0
  case R_MIPS_PC19_S2:
649
0
    checkAlignment(Loc, Val, 4, Type);
650
0
    checkInt(Loc, Val, 21, Type);
651
0
    writeValue<E>(Loc, Val, 19, 2);
652
0
    break;
653
0
  case R_MIPS_PC21_S2:
654
0
    checkAlignment(Loc, Val, 4, Type);
655
0
    checkInt(Loc, Val, 23, Type);
656
0
    writeValue<E>(Loc, Val, 21, 2);
657
0
    break;
658
0
  case R_MIPS_PC26_S2:
659
0
    checkAlignment(Loc, Val, 4, Type);
660
0
    checkInt(Loc, Val, 28, Type);
661
0
    writeValue<E>(Loc, Val, 26, 2);
662
0
    break;
663
0
  case R_MIPS_PC32:
664
0
    writeValue<E>(Loc, Val, 32, 0);
665
0
    break;
666
7
  case R_MICROMIPS_26_S1:
667
7
  case R_MICROMIPS_PC26_S1:
668
7
    checkInt(Loc, Val, 27, Type);
669
7
    writeShuffleValue<E>(Loc, Val, 26, 1);
670
7
    break;
671
7
  case R_MICROMIPS_PC7_S1:
672
1
    checkInt(Loc, Val, 8, Type);
673
1
    writeMicroRelocation16<E>(Loc, Val, 7, 1);
674
1
    break;
675
7
  case R_MICROMIPS_PC10_S1:
676
1
    checkInt(Loc, Val, 11, Type);
677
1
    writeMicroRelocation16<E>(Loc, Val, 10, 1);
678
1
    break;
679
7
  case R_MICROMIPS_PC16_S1:
680
1
    checkInt(Loc, Val, 17, Type);
681
1
    writeShuffleValue<E>(Loc, Val, 16, 1);
682
1
    break;
683
7
  case R_MICROMIPS_PC18_S3:
684
0
    checkInt(Loc, Val, 21, Type);
685
0
    writeShuffleValue<E>(Loc, Val, 18, 3);
686
0
    break;
687
7
  case R_MICROMIPS_PC19_S2:
688
3
    checkInt(Loc, Val, 21, Type);
689
3
    writeShuffleValue<E>(Loc, Val, 19, 2);
690
3
    break;
691
7
  case R_MICROMIPS_PC21_S1:
692
1
    checkInt(Loc, Val, 22, Type);
693
1
    writeShuffleValue<E>(Loc, Val, 21, 1);
694
1
    break;
695
7
  case R_MICROMIPS_PC23_S2:
696
2
    checkInt(Loc, Val, 25, Type);
697
2
    writeShuffleValue<E>(Loc, Val, 23, 2);
698
2
    break;
699
7
  default:
700
0
    llvm_unreachable("unknown relocation");
701
36
  }
702
36
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::relocateOne(unsigned char*, unsigned int, unsigned long long) const
Line
Count
Source
525
385
void MIPS<ELFT>::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
526
385
  const endianness E = ELFT::TargetEndianness;
527
385
528
385
  if (ELFT::Is64Bits || Config->MipsN32Abi)
529
5
    std::tie(Type, Val) = calculateMipsRelChain(Loc, Type, Val);
530
385
531
385
  // Detect cross-mode jump/branch and fix instruction.
532
385
  Val = fixupCrossModeJump<ELFT>(Loc, Type, Val);
533
385
534
385
  // Thread pointer and DRP offsets from the start of TLS data area.
535
385
  // https://www.linux-mips.org/wiki/NPTL
536
385
  if (Type == R_MIPS_TLS_DTPREL_HI16 || 
Type == R_MIPS_TLS_DTPREL_LO16381
||
537
385
      
Type == R_MIPS_TLS_DTPREL32379
||
Type == R_MIPS_TLS_DTPREL64378
||
538
385
      
Type == R_MICROMIPS_TLS_DTPREL_HI16379
||
539
385
      
Type == R_MICROMIPS_TLS_DTPREL_LO16379
) {
540
5
    Val -= 0x8000;
541
380
  } else if (Type == R_MIPS_TLS_TPREL_HI16 || 
Type == R_MIPS_TLS_TPREL_LO16377
||
542
380
             
Type == R_MIPS_TLS_TPREL32375
||
Type == R_MIPS_TLS_TPREL64373
||
543
380
             
Type == R_MICROMIPS_TLS_TPREL_HI16373
||
544
380
             
Type == R_MICROMIPS_TLS_TPREL_LO16373
) {
545
5
    Val -= 0x7000;
546
5
  }
547
385
548
385
  switch (Type) {
549
385
  case R_MIPS_32:
550
26
  case R_MIPS_GPREL32:
551
26
  case R_MIPS_TLS_DTPREL32:
552
26
  case R_MIPS_TLS_TPREL32:
553
26
    write32<E>(Loc, Val);
554
26
    break;
555
26
  case R_MIPS_64:
556
0
  case R_MIPS_TLS_DTPREL64:
557
0
  case R_MIPS_TLS_TPREL64:
558
0
    write64<E>(Loc, Val);
559
0
    break;
560
66
  case R_MIPS_26:
561
66
    writeValue<E>(Loc, Val, 26, 2);
562
66
    break;
563
40
  case R_MIPS_GOT16:
564
40
    // The R_MIPS_GOT16 relocation's value in "relocatable" linking mode
565
40
    // is updated addend (not a GOT index). In that case write high 16 bits
566
40
    // to store a correct addend value.
567
40
    if (Config->Relocatable) {
568
4
      writeValue<E>(Loc, Val + 0x8000, 16, 16);
569
36
    } else {
570
36
      checkInt(Loc, Val, 16, Type);
571
36
      writeValue<E>(Loc, Val, 16, 0);
572
36
    }
573
40
    break;
574
3
  case R_MICROMIPS_GOT16:
575
3
    if (Config->Relocatable) {
576
0
      writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
577
3
    } else {
578
3
      checkInt(Loc, Val, 16, Type);
579
3
      writeShuffleValue<E>(Loc, Val, 16, 0);
580
3
    }
581
3
    break;
582
34
  case R_MIPS_CALL16:
583
34
  case R_MIPS_GOT_DISP:
584
34
  case R_MIPS_GOT_PAGE:
585
34
  case R_MIPS_GPREL16:
586
34
  case R_MIPS_TLS_GD:
587
34
  case R_MIPS_TLS_GOTTPREL:
588
34
  case R_MIPS_TLS_LDM:
589
34
    checkInt(Loc, Val, 16, Type);
590
34
    LLVM_FALLTHROUGH;
591
129
  case R_MIPS_CALL_LO16:
592
129
  case R_MIPS_GOT_LO16:
593
129
  case R_MIPS_GOT_OFST:
594
129
  case R_MIPS_LO16:
595
129
  case R_MIPS_PCLO16:
596
129
  case R_MIPS_TLS_DTPREL_LO16:
597
129
  case R_MIPS_TLS_TPREL_LO16:
598
129
    writeValue<E>(Loc, Val, 16, 0);
599
129
    break;
600
129
  case R_MICROMIPS_GPREL16:
601
0
  case R_MICROMIPS_TLS_GD:
602
0
  case R_MICROMIPS_TLS_LDM:
603
0
    checkInt(Loc, Val, 16, Type);
604
0
    writeShuffleValue<E>(Loc, Val, 16, 0);
605
0
    break;
606
9
  case R_MICROMIPS_CALL16:
607
9
  case R_MICROMIPS_CALL_LO16:
608
9
  case R_MICROMIPS_LO16:
609
9
  case R_MICROMIPS_TLS_DTPREL_LO16:
610
9
  case R_MICROMIPS_TLS_GOTTPREL:
611
9
  case R_MICROMIPS_TLS_TPREL_LO16:
612
9
    writeShuffleValue<E>(Loc, Val, 16, 0);
613
9
    break;
614
9
  case R_MICROMIPS_GPREL7_S2:
615
0
    checkInt(Loc, Val, 7, Type);
616
0
    writeShuffleValue<E>(Loc, Val, 7, 2);
617
0
    break;
618
74
  case R_MIPS_CALL_HI16:
619
74
  case R_MIPS_GOT_HI16:
620
74
  case R_MIPS_HI16:
621
74
  case R_MIPS_PCHI16:
622
74
  case R_MIPS_TLS_DTPREL_HI16:
623
74
  case R_MIPS_TLS_TPREL_HI16:
624
74
    writeValue<E>(Loc, Val + 0x8000, 16, 16);
625
74
    break;
626
74
  case R_MICROMIPS_CALL_HI16:
627
5
  case R_MICROMIPS_GOT_HI16:
628
5
  case R_MICROMIPS_HI16:
629
5
  case R_MICROMIPS_TLS_DTPREL_HI16:
630
5
  case R_MICROMIPS_TLS_TPREL_HI16:
631
5
    writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
632
5
    break;
633
5
  case R_MIPS_HIGHER:
634
0
    writeValue<E>(Loc, Val + 0x80008000, 16, 32);
635
0
    break;
636
5
  case R_MIPS_HIGHEST:
637
0
    writeValue<E>(Loc, Val + 0x800080008000, 16, 48);
638
0
    break;
639
5
  case R_MIPS_JALR:
640
0
  case R_MICROMIPS_JALR:
641
0
    // Ignore this optimization relocation for now
642
0
    break;
643
2
  case R_MIPS_PC16:
644
2
    checkAlignment(Loc, Val, 4, Type);
645
2
    checkInt(Loc, Val, 18, Type);
646
2
    writeValue<E>(Loc, Val, 16, 2);
647
2
    break;
648
1
  case R_MIPS_PC19_S2:
649
1
    checkAlignment(Loc, Val, 4, Type);
650
1
    checkInt(Loc, Val, 21, Type);
651
1
    writeValue<E>(Loc, Val, 19, 2);
652
1
    break;
653
1
  case R_MIPS_PC21_S2:
654
1
    checkAlignment(Loc, Val, 4, Type);
655
1
    checkInt(Loc, Val, 23, Type);
656
1
    writeValue<E>(Loc, Val, 21, 2);
657
1
    break;
658
1
  case R_MIPS_PC26_S2:
659
1
    checkAlignment(Loc, Val, 4, Type);
660
1
    checkInt(Loc, Val, 28, Type);
661
1
    writeValue<E>(Loc, Val, 26, 2);
662
1
    break;
663
1
  case R_MIPS_PC32:
664
1
    writeValue<E>(Loc, Val, 32, 0);
665
1
    break;
666
12
  case R_MICROMIPS_26_S1:
667
12
  case R_MICROMIPS_PC26_S1:
668
12
    checkInt(Loc, Val, 27, Type);
669
12
    writeShuffleValue<E>(Loc, Val, 26, 1);
670
12
    break;
671
12
  case R_MICROMIPS_PC7_S1:
672
1
    checkInt(Loc, Val, 8, Type);
673
1
    writeMicroRelocation16<E>(Loc, Val, 7, 1);
674
1
    break;
675
12
  case R_MICROMIPS_PC10_S1:
676
2
    checkInt(Loc, Val, 11, Type);
677
2
    writeMicroRelocation16<E>(Loc, Val, 10, 1);
678
2
    break;
679
12
  case R_MICROMIPS_PC16_S1:
680
1
    checkInt(Loc, Val, 17, Type);
681
1
    writeShuffleValue<E>(Loc, Val, 16, 1);
682
1
    break;
683
12
  case R_MICROMIPS_PC18_S3:
684
0
    checkInt(Loc, Val, 21, Type);
685
0
    writeShuffleValue<E>(Loc, Val, 18, 3);
686
0
    break;
687
12
  case R_MICROMIPS_PC19_S2:
688
3
    checkInt(Loc, Val, 21, Type);
689
3
    writeShuffleValue<E>(Loc, Val, 19, 2);
690
3
    break;
691
12
  case R_MICROMIPS_PC21_S1:
692
1
    checkInt(Loc, Val, 22, Type);
693
1
    writeShuffleValue<E>(Loc, Val, 21, 1);
694
1
    break;
695
12
  case R_MICROMIPS_PC23_S2:
696
6
    checkInt(Loc, Val, 25, Type);
697
6
    writeShuffleValue<E>(Loc, Val, 23, 2);
698
6
    break;
699
12
  default:
700
0
    llvm_unreachable("unknown relocation");
701
385
  }
702
385
}
Unexecuted instantiation: Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::relocateOne(unsigned char*, unsigned int, unsigned long long) const
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::relocateOne(unsigned char*, unsigned int, unsigned long long) const
Line
Count
Source
525
10.0k
void MIPS<ELFT>::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
526
10.0k
  const endianness E = ELFT::TargetEndianness;
527
10.0k
528
10.0k
  if (ELFT::Is64Bits || 
Config->MipsN32Abi0
)
529
10.0k
    std::tie(Type, Val) = calculateMipsRelChain(Loc, Type, Val);
530
10.0k
531
10.0k
  // Detect cross-mode jump/branch and fix instruction.
532
10.0k
  Val = fixupCrossModeJump<ELFT>(Loc, Type, Val);
533
10.0k
534
10.0k
  // Thread pointer and DRP offsets from the start of TLS data area.
535
10.0k
  // https://www.linux-mips.org/wiki/NPTL
536
10.0k
  if (Type == R_MIPS_TLS_DTPREL_HI16 || Type == R_MIPS_TLS_DTPREL_LO16 ||
537
10.0k
      Type == R_MIPS_TLS_DTPREL32 || Type == R_MIPS_TLS_DTPREL64 ||
538
10.0k
      
Type == R_MICROMIPS_TLS_DTPREL_HI1610.0k
||
539
10.0k
      
Type == R_MICROMIPS_TLS_DTPREL_LO1610.0k
) {
540
1
    Val -= 0x8000;
541
10.0k
  } else if (Type == R_MIPS_TLS_TPREL_HI16 || Type == R_MIPS_TLS_TPREL_LO16 ||
542
10.0k
             Type == R_MIPS_TLS_TPREL32 || Type == R_MIPS_TLS_TPREL64 ||
543
10.0k
             
Type == R_MICROMIPS_TLS_TPREL_HI1610.0k
||
544
10.0k
             
Type == R_MICROMIPS_TLS_TPREL_LO1610.0k
) {
545
1
    Val -= 0x7000;
546
1
  }
547
10.0k
548
10.0k
  switch (Type) {
549
10.0k
  case R_MIPS_32:
550
3
  case R_MIPS_GPREL32:
551
3
  case R_MIPS_TLS_DTPREL32:
552
3
  case R_MIPS_TLS_TPREL32:
553
3
    write32<E>(Loc, Val);
554
3
    break;
555
8
  case R_MIPS_64:
556
8
  case R_MIPS_TLS_DTPREL64:
557
8
  case R_MIPS_TLS_TPREL64:
558
8
    write64<E>(Loc, Val);
559
8
    break;
560
8
  case R_MIPS_26:
561
2
    writeValue<E>(Loc, Val, 26, 2);
562
2
    break;
563
8
  case R_MIPS_GOT16:
564
0
    // The R_MIPS_GOT16 relocation's value in "relocatable" linking mode
565
0
    // is updated addend (not a GOT index). In that case write high 16 bits
566
0
    // to store a correct addend value.
567
0
    if (Config->Relocatable) {
568
0
      writeValue<E>(Loc, Val + 0x8000, 16, 16);
569
0
    } else {
570
0
      checkInt(Loc, Val, 16, Type);
571
0
      writeValue<E>(Loc, Val, 16, 0);
572
0
    }
573
0
    break;
574
8
  case R_MICROMIPS_GOT16:
575
0
    if (Config->Relocatable) {
576
0
      writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
577
0
    } else {
578
0
      checkInt(Loc, Val, 16, Type);
579
0
      writeShuffleValue<E>(Loc, Val, 16, 0);
580
0
    }
581
0
    break;
582
10.0k
  case R_MIPS_CALL16:
583
10.0k
  case R_MIPS_GOT_DISP:
584
10.0k
  case R_MIPS_GOT_PAGE:
585
10.0k
  case R_MIPS_GPREL16:
586
10.0k
  case R_MIPS_TLS_GD:
587
10.0k
  case R_MIPS_TLS_GOTTPREL:
588
10.0k
  case R_MIPS_TLS_LDM:
589
10.0k
    checkInt(Loc, Val, 16, Type);
590
10.0k
    LLVM_FALLTHROUGH;
591
10.0k
  case R_MIPS_CALL_LO16:
592
10.0k
  case R_MIPS_GOT_LO16:
593
10.0k
  case R_MIPS_GOT_OFST:
594
10.0k
  case R_MIPS_LO16:
595
10.0k
  case R_MIPS_PCLO16:
596
10.0k
  case R_MIPS_TLS_DTPREL_LO16:
597
10.0k
  case R_MIPS_TLS_TPREL_LO16:
598
10.0k
    writeValue<E>(Loc, Val, 16, 0);
599
10.0k
    break;
600
10.0k
  case R_MICROMIPS_GPREL16:
601
0
  case R_MICROMIPS_TLS_GD:
602
0
  case R_MICROMIPS_TLS_LDM:
603
0
    checkInt(Loc, Val, 16, Type);
604
0
    writeShuffleValue<E>(Loc, Val, 16, 0);
605
0
    break;
606
0
  case R_MICROMIPS_CALL16:
607
0
  case R_MICROMIPS_CALL_LO16:
608
0
  case R_MICROMIPS_LO16:
609
0
  case R_MICROMIPS_TLS_DTPREL_LO16:
610
0
  case R_MICROMIPS_TLS_GOTTPREL:
611
0
  case R_MICROMIPS_TLS_TPREL_LO16:
612
0
    writeShuffleValue<E>(Loc, Val, 16, 0);
613
0
    break;
614
0
  case R_MICROMIPS_GPREL7_S2:
615
0
    checkInt(Loc, Val, 7, Type);
616
0
    writeShuffleValue<E>(Loc, Val, 7, 2);
617
0
    break;
618
6
  case R_MIPS_CALL_HI16:
619
6
  case R_MIPS_GOT_HI16:
620
6
  case R_MIPS_HI16:
621
6
  case R_MIPS_PCHI16:
622
6
  case R_MIPS_TLS_DTPREL_HI16:
623
6
  case R_MIPS_TLS_TPREL_HI16:
624
6
    writeValue<E>(Loc, Val + 0x8000, 16, 16);
625
6
    break;
626
6
  case R_MICROMIPS_CALL_HI16:
627
0
  case R_MICROMIPS_GOT_HI16:
628
0
  case R_MICROMIPS_HI16:
629
0
  case R_MICROMIPS_TLS_DTPREL_HI16:
630
0
  case R_MICROMIPS_TLS_TPREL_HI16:
631
0
    writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
632
0
    break;
633
2
  case R_MIPS_HIGHER:
634
2
    writeValue<E>(Loc, Val + 0x80008000, 16, 32);
635
2
    break;
636
2
  case R_MIPS_HIGHEST:
637
2
    writeValue<E>(Loc, Val + 0x800080008000, 16, 48);
638
2
    break;
639
0
  case R_MIPS_JALR:
640
0
  case R_MICROMIPS_JALR:
641
0
    // Ignore this optimization relocation for now
642
0
    break;
643
0
  case R_MIPS_PC16:
644
0
    checkAlignment(Loc, Val, 4, Type);
645
0
    checkInt(Loc, Val, 18, Type);
646
0
    writeValue<E>(Loc, Val, 16, 2);
647
0
    break;
648
0
  case R_MIPS_PC19_S2:
649
0
    checkAlignment(Loc, Val, 4, Type);
650
0
    checkInt(Loc, Val, 21, Type);
651
0
    writeValue<E>(Loc, Val, 19, 2);
652
0
    break;
653
0
  case R_MIPS_PC21_S2:
654
0
    checkAlignment(Loc, Val, 4, Type);
655
0
    checkInt(Loc, Val, 23, Type);
656
0
    writeValue<E>(Loc, Val, 21, 2);
657
0
    break;
658
0
  case R_MIPS_PC26_S2:
659
0
    checkAlignment(Loc, Val, 4, Type);
660
0
    checkInt(Loc, Val, 28, Type);
661
0
    writeValue<E>(Loc, Val, 26, 2);
662
0
    break;
663
1
  case R_MIPS_PC32:
664
1
    writeValue<E>(Loc, Val, 32, 0);
665
1
    break;
666
0
  case R_MICROMIPS_26_S1:
667
0
  case R_MICROMIPS_PC26_S1:
668
0
    checkInt(Loc, Val, 27, Type);
669
0
    writeShuffleValue<E>(Loc, Val, 26, 1);
670
0
    break;
671
0
  case R_MICROMIPS_PC7_S1:
672
0
    checkInt(Loc, Val, 8, Type);
673
0
    writeMicroRelocation16<E>(Loc, Val, 7, 1);
674
0
    break;
675
0
  case R_MICROMIPS_PC10_S1:
676
0
    checkInt(Loc, Val, 11, Type);
677
0
    writeMicroRelocation16<E>(Loc, Val, 10, 1);
678
0
    break;
679
0
  case R_MICROMIPS_PC16_S1:
680
0
    checkInt(Loc, Val, 17, Type);
681
0
    writeShuffleValue<E>(Loc, Val, 16, 1);
682
0
    break;
683
0
  case R_MICROMIPS_PC18_S3:
684
0
    checkInt(Loc, Val, 21, Type);
685
0
    writeShuffleValue<E>(Loc, Val, 18, 3);
686
0
    break;
687
0
  case R_MICROMIPS_PC19_S2:
688
0
    checkInt(Loc, Val, 21, Type);
689
0
    writeShuffleValue<E>(Loc, Val, 19, 2);
690
0
    break;
691
0
  case R_MICROMIPS_PC21_S1:
692
0
    checkInt(Loc, Val, 22, Type);
693
0
    writeShuffleValue<E>(Loc, Val, 21, 1);
694
0
    break;
695
0
  case R_MICROMIPS_PC23_S2:
696
0
    checkInt(Loc, Val, 25, Type);
697
0
    writeShuffleValue<E>(Loc, Val, 23, 2);
698
0
    break;
699
0
  default:
700
0
    llvm_unreachable("unknown relocation");
701
10.0k
  }
702
10.0k
}
703
704
34
template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType Type) const {
705
34
  return Type == R_MIPS_LO16 || 
Type == R_MIPS_GOT_OFST18
||
706
34
         
Type == R_MICROMIPS_LO1617
;
707
34
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, false> >::usesOnlyLowPageBits(unsigned int) const
Line
Count
Source
704
2
template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType Type) const {
705
2
  return Type == R_MIPS_LO16 || Type == R_MIPS_GOT_OFST ||
706
2
         Type == R_MICROMIPS_LO16;
707
2
}
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, false> >::usesOnlyLowPageBits(unsigned int) const
Line
Count
Source
704
26
template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType Type) const {
705
26
  return Type == R_MIPS_LO16 || 
Type == R_MIPS_GOT_OFST10
||
706
26
         
Type == R_MICROMIPS_LO1610
;
707
26
}
Unexecuted instantiation: Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)1, true> >::usesOnlyLowPageBits(unsigned int) const
Mips.cpp:(anonymous namespace)::MIPS<llvm::object::ELFType<(llvm::support::endianness)0, true> >::usesOnlyLowPageBits(unsigned int) const
Line
Count
Source
704
6
template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType Type) const {
705
6
  return Type == R_MIPS_LO16 || Type == R_MIPS_GOT_OFST ||
706
6
         
Type == R_MICROMIPS_LO165
;
707
6
}
708
709
// Return true if the symbol is a PIC function.
710
163
template <class ELFT> bool elf::isMipsPIC(const Defined *Sym) {
711
163
  if (!Sym->isFunc())
712
79
    return false;
713
84
714
84
  if (Sym->StOther & STO_MIPS_PIC)
715
9
    return true;
716
75
717
75
  if (!Sym->Section)
718
0
    return false;
719
75
720
75
  ObjFile<ELFT> *File =
721
75
      cast<InputSectionBase>(Sym->Section)->template getFile<ELFT>();
722
75
  if (!File)
723
1
    return false;
724
74
725
74
  return File->getObj().getHeader()->e_flags & EF_MIPS_PIC;
726
74
}
bool lld::elf::isMipsPIC<llvm::object::ELFType<(llvm::support::endianness)1, false> >(lld::elf::Defined const*)
Line
Count
Source
710
8
template <class ELFT> bool elf::isMipsPIC(const Defined *Sym) {
711
8
  if (!Sym->isFunc())
712
5
    return false;
713
3
714
3
  if (Sym->StOther & STO_MIPS_PIC)
715
0
    return true;
716
3
717
3
  if (!Sym->Section)
718
0
    return false;
719
3
720
3
  ObjFile<ELFT> *File =
721
3
      cast<InputSectionBase>(Sym->Section)->template getFile<ELFT>();
722
3
  if (!File)
723
0
    return false;
724
3
725
3
  return File->getObj().getHeader()->e_flags & EF_MIPS_PIC;
726
3
}
bool lld::elf::isMipsPIC<llvm::object::ELFType<(llvm::support::endianness)0, false> >(lld::elf::Defined const*)
Line
Count
Source
710
144
template <class ELFT> bool elf::isMipsPIC(const Defined *Sym) {
711
144
  if (!Sym->isFunc())
712
63
    return false;
713
81
714
81
  if (Sym->StOther & STO_MIPS_PIC)
715
9
    return true;
716
72
717
72
  if (!Sym->Section)
718
0
    return false;
719
72
720
72
  ObjFile<ELFT> *File =
721
72
      cast<InputSectionBase>(Sym->Section)->template getFile<ELFT>();
722
72
  if (!File)
723
1
    return false;
724
71
725
71
  return File->getObj().getHeader()->e_flags & EF_MIPS_PIC;
726
71
}
Unexecuted instantiation: bool lld::elf::isMipsPIC<llvm::object::ELFType<(llvm::support::endianness)1, true> >(lld::elf::Defined const*)
bool lld::elf::isMipsPIC<llvm::object::ELFType<(llvm::support::endianness)0, true> >(lld::elf::Defined const*)
Line
Count
Source
710
11
template <class ELFT> bool elf::isMipsPIC(const Defined *Sym) {
711
11
  if (!Sym->isFunc())
712
11
    return false;
713
0
714
0
  if (Sym->StOther & STO_MIPS_PIC)
715
0
    return true;
716
0
717
0
  if (!Sym->Section)
718
0
    return false;
719
0
720
0
  ObjFile<ELFT> *File =
721
0
      cast<InputSectionBase>(Sym->Section)->template getFile<ELFT>();
722
0
  if (!File)
723
0
    return false;
724
0
725
0
  return File->getObj().getHeader()->e_flags & EF_MIPS_PIC;
726
0
}
727
728
199
template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {
729
199
  static MIPS<ELFT> Target;
730
199
  return &Target;
731
199
}
lld::elf::TargetInfo* lld::elf::getMipsTargetInfo<llvm::object::ELFType<(llvm::support::endianness)1, false> >()
Line
Count
Source
728
23
template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {
729
23
  static MIPS<ELFT> Target;
730
23
  return &Target;
731
23
}
lld::elf::TargetInfo* lld::elf::getMipsTargetInfo<llvm::object::ELFType<(llvm::support::endianness)0, false> >()
Line
Count
Source
728
127
template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {
729
127
  static MIPS<ELFT> Target;
730
127
  return &Target;
731
127
}
lld::elf::TargetInfo* lld::elf::getMipsTargetInfo<llvm::object::ELFType<(llvm::support::endianness)1, true> >()
Line
Count
Source
728
3
template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {
729
3
  static MIPS<ELFT> Target;
730
3
  return &Target;
731
3
}
lld::elf::TargetInfo* lld::elf::getMipsTargetInfo<llvm::object::ELFType<(llvm::support::endianness)0, true> >()
Line
Count
Source
728
46
template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {
729
46
  static MIPS<ELFT> Target;
730
46
  return &Target;
731
46
}
732
733
template TargetInfo *elf::getMipsTargetInfo<ELF32LE>();
734
template TargetInfo *elf::getMipsTargetInfo<ELF32BE>();
735
template TargetInfo *elf::getMipsTargetInfo<ELF64LE>();
736
template TargetInfo *elf::getMipsTargetInfo<ELF64BE>();
737
738
template bool elf::isMipsPIC<ELF32LE>(const Defined *);
739
template bool elf::isMipsPIC<ELF32BE>(const Defined *);
740
template bool elf::isMipsPIC<ELF64LE>(const Defined *);
741
template bool elf::isMipsPIC<ELF64BE>(const Defined *);