Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- HexagonELFObjectWriter.cpp - Hexagon Target Descriptions ----------===//
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 "MCTargetDesc/HexagonFixupKinds.h"
10
#include "MCTargetDesc/HexagonMCTargetDesc.h"
11
#include "llvm/MC/MCAssembler.h"
12
#include "llvm/MC/MCELFObjectWriter.h"
13
#include "llvm/MC/MCObjectWriter.h"
14
#include "llvm/MC/MCValue.h"
15
#include "llvm/Support/Debug.h"
16
#include "llvm/Support/raw_ostream.h"
17
18
#define DEBUG_TYPE "hexagon-elf-writer"
19
20
using namespace llvm;
21
using namespace Hexagon;
22
23
namespace {
24
25
class HexagonELFObjectWriter : public MCELFObjectTargetWriter {
26
private:
27
  StringRef CPU;
28
29
public:
30
  HexagonELFObjectWriter(uint8_t OSABI, StringRef C);
31
32
  unsigned getRelocType(MCContext &Ctx, MCValue const &Target,
33
                        MCFixup const &Fixup, bool IsPCRel) const override;
34
};
35
}
36
37
HexagonELFObjectWriter::HexagonELFObjectWriter(uint8_t OSABI, StringRef C)
38
    : MCELFObjectTargetWriter(/*Is64bit*/ false, OSABI, ELF::EM_HEXAGON,
39
                              /*HasRelocationAddend*/ true),
40
1.05k
      CPU(C) {}
41
42
unsigned HexagonELFObjectWriter::getRelocType(MCContext &Ctx,
43
                                              MCValue const &Target,
44
                                              MCFixup const &Fixup,
45
317
                                              bool IsPCRel) const {
46
317
  MCSymbolRefExpr::VariantKind Variant = Target.getAccessVariant();
47
317
  switch ((unsigned)Fixup.getKind()) {
48
317
  default:
49
0
    report_fatal_error("Unrecognized relocation type");
50
317
    
break0
;
51
317
  case FK_Data_4:
52
69
    switch(Variant) {
53
69
    case MCSymbolRefExpr::VariantKind::VK_DTPREL:
54
1
      return ELF::R_HEX_DTPREL_32;
55
69
    case MCSymbolRefExpr::VariantKind::VK_GOT:
56
1
      return ELF::R_HEX_GOT_32;
57
69
    case MCSymbolRefExpr::VariantKind::VK_GOTREL:
58
1
      return ELF::R_HEX_GOTREL_32;
59
69
    case MCSymbolRefExpr::VariantKind::VK_Hexagon_GD_GOT:
60
1
      return ELF::R_HEX_GD_GOT_32;
61
69
    case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE:
62
1
      return ELF::R_HEX_IE_32;
63
69
    case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE_GOT:
64
1
      return ELF::R_HEX_IE_GOT_32;
65
69
    case MCSymbolRefExpr::VariantKind::VK_Hexagon_LD_GOT:
66
1
      return ELF::R_HEX_LD_GOT_32;
67
69
    case MCSymbolRefExpr::VariantKind::VK_Hexagon_PCREL:
68
1
      return ELF::R_HEX_32_PCREL;
69
69
    case MCSymbolRefExpr::VariantKind::VK_TPREL:
70
1
      return ELF::R_HEX_TPREL_32;
71
69
    case MCSymbolRefExpr::VariantKind::VK_None:
72
60
      return IsPCRel ? 
ELF::R_HEX_32_PCREL1
:
ELF::R_HEX_3259
;
73
69
    default:
74
0
      report_fatal_error("Unrecognized variant type");
75
0
    };
76
0
  case FK_PCRel_4:
77
0
    return ELF::R_HEX_32_PCREL;
78
6
  case FK_Data_2:
79
6
    switch(Variant) {
80
6
    case MCSymbolRefExpr::VariantKind::VK_DTPREL:
81
1
      return ELF::R_HEX_DTPREL_16;
82
6
    case MCSymbolRefExpr::VariantKind::VK_GOT:
83
1
      return ELF::R_HEX_GOT_16;
84
6
    case MCSymbolRefExpr::VariantKind::VK_Hexagon_GD_GOT:
85
1
      return ELF::R_HEX_GD_GOT_16;
86
6
    case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE_GOT:
87
1
      return ELF::R_HEX_IE_GOT_16;
88
6
    case MCSymbolRefExpr::VariantKind::VK_Hexagon_LD_GOT:
89
1
      return ELF::R_HEX_LD_GOT_16;
90
6
    case MCSymbolRefExpr::VariantKind::VK_TPREL:
91
0
      return ELF::R_HEX_TPREL_16;
92
6
    case MCSymbolRefExpr::VariantKind::VK_None:
93
1
      return ELF::R_HEX_16;
94
6
    default:
95
0
      report_fatal_error("Unrecognized variant type");
96
0
    };
97
1
  case FK_Data_1:
98
1
    return ELF::R_HEX_8;
99
8
  case fixup_Hexagon_B22_PCREL:
100
8
    return ELF::R_HEX_B22_PCREL;
101
3
  case fixup_Hexagon_B15_PCREL:
102
3
    return ELF::R_HEX_B15_PCREL;
103
1
  case fixup_Hexagon_B7_PCREL:
104
1
    return ELF::R_HEX_B7_PCREL;
105
2
  case fixup_Hexagon_LO16:
106
2
    return ELF::R_HEX_LO16;
107
2
  case fixup_Hexagon_HI16:
108
2
    return ELF::R_HEX_HI16;
109
0
  case fixup_Hexagon_32:
110
0
    return ELF::R_HEX_32;
111
0
  case fixup_Hexagon_16:
112
0
    return ELF::R_HEX_16;
113
0
  case fixup_Hexagon_8:
114
0
    return ELF::R_HEX_8;
115
1
  case fixup_Hexagon_GPREL16_0:
116
1
    return ELF::R_HEX_GPREL16_0;
117
1
  case fixup_Hexagon_GPREL16_1:
118
1
    return ELF::R_HEX_GPREL16_1;
119
20
  case fixup_Hexagon_GPREL16_2:
120
20
    return ELF::R_HEX_GPREL16_2;
121
7
  case fixup_Hexagon_GPREL16_3:
122
7
    return ELF::R_HEX_GPREL16_3;
123
0
  case fixup_Hexagon_HL16:
124
0
    return ELF::R_HEX_HL16;
125
2
  case fixup_Hexagon_B13_PCREL:
126
2
    return ELF::R_HEX_B13_PCREL;
127
2
  case fixup_Hexagon_B9_PCREL:
128
2
    return ELF::R_HEX_B9_PCREL;
129
21
  case fixup_Hexagon_B32_PCREL_X:
130
21
    return ELF::R_HEX_B32_PCREL_X;
131
43
  case fixup_Hexagon_32_6_X:
132
43
    return ELF::R_HEX_32_6_X;
133
6
  case fixup_Hexagon_B22_PCREL_X:
134
6
    return ELF::R_HEX_B22_PCREL_X;
135
5
  case fixup_Hexagon_B15_PCREL_X:
136
5
    return ELF::R_HEX_B15_PCREL_X;
137
0
  case fixup_Hexagon_B13_PCREL_X:
138
0
    return ELF::R_HEX_B13_PCREL_X;
139
1
  case fixup_Hexagon_B9_PCREL_X:
140
1
    return ELF::R_HEX_B9_PCREL_X;
141
1
  case fixup_Hexagon_B7_PCREL_X:
142
1
    return ELF::R_HEX_B7_PCREL_X;
143
6
  case fixup_Hexagon_16_X:
144
6
    return ELF::R_HEX_16_X;
145
1
  case fixup_Hexagon_12_X:
146
1
    return ELF::R_HEX_12_X;
147
2
  case fixup_Hexagon_11_X:
148
2
    return ELF::R_HEX_11_X;
149
1
  case fixup_Hexagon_10_X:
150
1
    return ELF::R_HEX_10_X;
151
1
  case fixup_Hexagon_9_X:
152
1
    return ELF::R_HEX_9_X;
153
4
  case fixup_Hexagon_8_X:
154
4
    return ELF::R_HEX_8_X;
155
0
  case fixup_Hexagon_7_X:
156
0
    return ELF::R_HEX_7_X;
157
28
  case fixup_Hexagon_6_X:
158
28
    return ELF::R_HEX_6_X;
159
0
  case fixup_Hexagon_32_PCREL:
160
0
    return ELF::R_HEX_32_PCREL;
161
0
  case fixup_Hexagon_COPY:
162
0
    return ELF::R_HEX_COPY;
163
0
  case fixup_Hexagon_GLOB_DAT:
164
0
    return ELF::R_HEX_GLOB_DAT;
165
0
  case fixup_Hexagon_JMP_SLOT:
166
0
    return ELF::R_HEX_JMP_SLOT;
167
0
  case fixup_Hexagon_RELATIVE:
168
0
    return ELF::R_HEX_RELATIVE;
169
2
  case fixup_Hexagon_PLT_B22_PCREL:
170
2
    return ELF::R_HEX_PLT_B22_PCREL;
171
0
  case fixup_Hexagon_GOTREL_LO16:
172
0
    return ELF::R_HEX_GOTREL_LO16;
173
0
  case fixup_Hexagon_GOTREL_HI16:
174
0
    return ELF::R_HEX_GOTREL_HI16;
175
0
  case fixup_Hexagon_GOTREL_32:
176
0
    return ELF::R_HEX_GOTREL_32;
177
0
  case fixup_Hexagon_GOT_LO16:
178
0
    return ELF::R_HEX_GOT_LO16;
179
0
  case fixup_Hexagon_GOT_HI16:
180
0
    return ELF::R_HEX_GOT_HI16;
181
0
  case fixup_Hexagon_GOT_32:
182
0
    return ELF::R_HEX_GOT_32;
183
0
  case fixup_Hexagon_GOT_16:
184
0
    return ELF::R_HEX_GOT_16;
185
0
  case fixup_Hexagon_DTPMOD_32:
186
0
    return ELF::R_HEX_DTPMOD_32;
187
0
  case fixup_Hexagon_DTPREL_LO16:
188
0
    return ELF::R_HEX_DTPREL_LO16;
189
0
  case fixup_Hexagon_DTPREL_HI16:
190
0
    return ELF::R_HEX_DTPREL_HI16;
191
0
  case fixup_Hexagon_DTPREL_32:
192
0
    return ELF::R_HEX_DTPREL_32;
193
1
  case fixup_Hexagon_DTPREL_16:
194
1
    return ELF::R_HEX_DTPREL_16;
195
1
  case fixup_Hexagon_GD_PLT_B22_PCREL:
196
1
    return ELF::R_HEX_GD_PLT_B22_PCREL;
197
1
  case fixup_Hexagon_LD_PLT_B22_PCREL:
198
1
    return ELF::R_HEX_LD_PLT_B22_PCREL;
199
0
  case fixup_Hexagon_GD_GOT_LO16:
200
0
    return ELF::R_HEX_GD_GOT_LO16;
201
0
  case fixup_Hexagon_GD_GOT_HI16:
202
0
    return ELF::R_HEX_GD_GOT_HI16;
203
0
  case fixup_Hexagon_GD_GOT_32:
204
0
    return ELF::R_HEX_GD_GOT_32;
205
0
  case fixup_Hexagon_GD_GOT_16:
206
0
    return ELF::R_HEX_GD_GOT_16;
207
0
  case fixup_Hexagon_LD_GOT_LO16:
208
0
    return ELF::R_HEX_LD_GOT_LO16;
209
0
  case fixup_Hexagon_LD_GOT_HI16:
210
0
    return ELF::R_HEX_LD_GOT_HI16;
211
0
  case fixup_Hexagon_LD_GOT_32:
212
0
    return ELF::R_HEX_LD_GOT_32;
213
0
  case fixup_Hexagon_LD_GOT_16:
214
0
    return ELF::R_HEX_LD_GOT_16;
215
0
  case fixup_Hexagon_IE_LO16:
216
0
    return ELF::R_HEX_IE_LO16;
217
0
  case fixup_Hexagon_IE_HI16:
218
0
    return ELF::R_HEX_IE_HI16;
219
0
  case fixup_Hexagon_IE_32:
220
0
    return ELF::R_HEX_IE_32;
221
0
  case fixup_Hexagon_IE_GOT_LO16:
222
0
    return ELF::R_HEX_IE_GOT_LO16;
223
0
  case fixup_Hexagon_IE_GOT_HI16:
224
0
    return ELF::R_HEX_IE_GOT_HI16;
225
0
  case fixup_Hexagon_IE_GOT_32:
226
0
    return ELF::R_HEX_IE_GOT_32;
227
0
  case fixup_Hexagon_IE_GOT_16:
228
0
    return ELF::R_HEX_IE_GOT_16;
229
0
  case fixup_Hexagon_TPREL_LO16:
230
0
    return ELF::R_HEX_TPREL_LO16;
231
0
  case fixup_Hexagon_TPREL_HI16:
232
0
    return ELF::R_HEX_TPREL_HI16;
233
0
  case fixup_Hexagon_TPREL_32:
234
0
    return ELF::R_HEX_TPREL_32;
235
2
  case fixup_Hexagon_TPREL_16:
236
2
    return ELF::R_HEX_TPREL_16;
237
8
  case fixup_Hexagon_6_PCREL_X:
238
8
    return ELF::R_HEX_6_PCREL_X;
239
3
  case fixup_Hexagon_GOTREL_32_6_X:
240
3
    return ELF::R_HEX_GOTREL_32_6_X;
241
2
  case fixup_Hexagon_GOTREL_16_X:
242
2
    return ELF::R_HEX_GOTREL_16_X;
243
1
  case fixup_Hexagon_GOTREL_11_X:
244
1
    return ELF::R_HEX_GOTREL_11_X;
245
6
  case fixup_Hexagon_GOT_32_6_X:
246
6
    return ELF::R_HEX_GOT_32_6_X;
247
3
  case fixup_Hexagon_GOT_16_X:
248
3
    return ELF::R_HEX_GOT_16_X;
249
3
  case fixup_Hexagon_GOT_11_X:
250
3
    return ELF::R_HEX_GOT_11_X;
251
3
  case fixup_Hexagon_DTPREL_32_6_X:
252
3
    return ELF::R_HEX_DTPREL_32_6_X;
253
2
  case fixup_Hexagon_DTPREL_16_X:
254
2
    return ELF::R_HEX_DTPREL_16_X;
255
1
  case fixup_Hexagon_DTPREL_11_X:
256
1
    return ELF::R_HEX_DTPREL_11_X;
257
3
  case fixup_Hexagon_GD_GOT_32_6_X:
258
3
    return ELF::R_HEX_GD_GOT_32_6_X;
259
2
  case fixup_Hexagon_GD_GOT_16_X:
260
2
    return ELF::R_HEX_GD_GOT_16_X;
261
1
  case fixup_Hexagon_GD_GOT_11_X:
262
1
    return ELF::R_HEX_GD_GOT_11_X;
263
3
  case fixup_Hexagon_LD_GOT_32_6_X:
264
3
    return ELF::R_HEX_LD_GOT_32_6_X;
265
2
  case fixup_Hexagon_LD_GOT_16_X:
266
2
    return ELF::R_HEX_LD_GOT_16_X;
267
1
  case fixup_Hexagon_LD_GOT_11_X:
268
1
    return ELF::R_HEX_LD_GOT_11_X;
269
2
  case fixup_Hexagon_IE_32_6_X:
270
2
    return ELF::R_HEX_IE_32_6_X;
271
2
  case fixup_Hexagon_IE_16_X:
272
2
    return ELF::R_HEX_IE_16_X;
273
3
  case fixup_Hexagon_IE_GOT_32_6_X:
274
3
    return ELF::R_HEX_IE_GOT_32_6_X;
275
2
  case fixup_Hexagon_IE_GOT_16_X:
276
2
    return ELF::R_HEX_IE_GOT_16_X;
277
1
  case fixup_Hexagon_IE_GOT_11_X:
278
1
    return ELF::R_HEX_IE_GOT_11_X;
279
3
  case fixup_Hexagon_TPREL_32_6_X:
280
3
    return ELF::R_HEX_TPREL_32_6_X;
281
2
  case fixup_Hexagon_TPREL_16_X:
282
2
    return ELF::R_HEX_TPREL_16_X;
283
1
  case fixup_Hexagon_TPREL_11_X:
284
1
    return ELF::R_HEX_TPREL_11_X;
285
0
  case fixup_Hexagon_23_REG:
286
0
    return ELF::R_HEX_23_REG;
287
1
  case fixup_Hexagon_27_REG:
288
1
    return ELF::R_HEX_27_REG;
289
1
  case fixup_Hexagon_GD_PLT_B22_PCREL_X:
290
1
    return ELF::R_HEX_GD_PLT_B22_PCREL_X;
291
1
  case fixup_Hexagon_GD_PLT_B32_PCREL_X:
292
1
    return ELF::R_HEX_GD_PLT_B32_PCREL_X;
293
1
  case fixup_Hexagon_LD_PLT_B22_PCREL_X:
294
1
    return ELF::R_HEX_LD_PLT_B22_PCREL_X;
295
1
  case fixup_Hexagon_LD_PLT_B32_PCREL_X:
296
1
    return ELF::R_HEX_LD_PLT_B32_PCREL_X;
297
317
  }
298
317
}
299
300
std::unique_ptr<MCObjectTargetWriter>
301
1.05k
llvm::createHexagonELFObjectWriter(uint8_t OSABI, StringRef CPU) {
302
1.05k
  return llvm::make_unique<HexagonELFObjectWriter>(OSABI, CPU);
303
1.05k
}