24
24
using namespace llvm ;
25
25
26
26
namespace {
27
+ enum X86_32RelType { RT32_NONE, RT32_32, RT32_16, RT32_8 };
28
+ enum X86_64RelType { RT64_NONE, RT64_64, RT64_32, RT64_32S, RT64_16, RT64_8 };
27
29
28
30
class X86ELFObjectWriter : public MCELFObjectTargetWriter {
29
31
public:
@@ -35,6 +37,15 @@ class X86ELFObjectWriter : public MCELFObjectTargetWriter {
35
37
const MCFixup &Fixup, bool IsPCRel) const override ;
36
38
bool needsRelocateWithSymbol (const MCValue &Val, const MCSymbol &Sym,
37
39
unsigned Type) const override ;
40
+
41
+ void checkIs32 (SMLoc Loc, X86_64RelType Type) const ;
42
+ void checkIs64 (SMLoc Loc, X86_64RelType Type) const ;
43
+ unsigned getRelocType32 (SMLoc Loc, X86MCExpr::Specifier Specifier,
44
+ X86_32RelType Type, bool IsPCRel,
45
+ MCFixupKind Kind) const ;
46
+ unsigned getRelocType64 (SMLoc Loc, X86MCExpr::Specifier Specifier,
47
+ X86_64RelType Type, bool IsPCRel,
48
+ MCFixupKind Kind) const ;
38
49
};
39
50
40
51
} // end anonymous namespace
@@ -47,8 +58,6 @@ X86ELFObjectWriter::X86ELFObjectWriter(bool IsELF64, uint8_t OSABI,
47
58
(EMachine != ELF::EM_386) &&
48
59
(EMachine != ELF::EM_IAMCU)) {}
49
60
50
- enum X86_64RelType { RT64_NONE, RT64_64, RT64_32, RT64_32S, RT64_16, RT64_8 };
51
-
52
61
static X86_64RelType getType64 (MCFixupKind Kind,
53
62
X86MCExpr::Specifier &Specifier, bool &IsPCRel) {
54
63
switch (unsigned (Kind)) {
@@ -89,22 +98,20 @@ static X86_64RelType getType64(MCFixupKind Kind,
89
98
}
90
99
}
91
100
92
- static void checkIs32 (MCContext &Ctx, SMLoc Loc, X86_64RelType Type) {
101
+ void X86ELFObjectWriter:: checkIs32 (SMLoc Loc, X86_64RelType Type) const {
93
102
if (Type != RT64_32)
94
- Ctx.reportError (Loc,
95
- " 32 bit reloc applied to a field with a different size" );
103
+ reportError (Loc, " 32 bit reloc applied to a field with a different size" );
96
104
}
97
105
98
- static void checkIs64 (MCContext &Ctx, SMLoc Loc, X86_64RelType Type) {
106
+ void X86ELFObjectWriter:: checkIs64 (SMLoc Loc, X86_64RelType Type) const {
99
107
if (Type != RT64_64)
100
- Ctx.reportError (Loc,
101
- " 64 bit reloc applied to a field with a different size" );
108
+ reportError (Loc, " 64 bit reloc applied to a field with a different size" );
102
109
}
103
110
104
- static unsigned getRelocType64 (MCContext &Ctx, SMLoc Loc,
105
- X86MCExpr::Specifier Specifier,
106
- X86_64RelType Type, bool IsPCRel,
107
- MCFixupKind Kind) {
111
+ unsigned X86ELFObjectWriter:: getRelocType64 (SMLoc Loc,
112
+ X86MCExpr::Specifier Specifier,
113
+ X86_64RelType Type, bool IsPCRel,
114
+ MCFixupKind Kind) const {
108
115
switch (Specifier) {
109
116
default :
110
117
llvm_unreachable (" Unimplemented" );
@@ -143,7 +150,7 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
143
150
case X86MCExpr::VK_GOTOFF:
144
151
assert (!IsPCRel);
145
152
if (Type != RT64_64)
146
- Ctx. reportError (Loc, " unsupported relocation type" );
153
+ reportError (Loc, " unsupported relocation type" );
147
154
return ELF::R_X86_64_GOTOFF64;
148
155
case X86MCExpr::VK_TPOFF:
149
156
assert (!IsPCRel);
@@ -194,28 +201,28 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
194
201
? ELF::R_X86_64_CODE_4_GOTPC32_TLSDESC
195
202
: ELF::R_X86_64_GOTPC32_TLSDESC;
196
203
case X86MCExpr::VK_TLSGD:
197
- checkIs32 (Ctx, Loc, Type);
204
+ checkIs32 (Loc, Type);
198
205
return ELF::R_X86_64_TLSGD;
199
206
case X86MCExpr::VK_GOTTPOFF:
200
- checkIs32 (Ctx, Loc, Type);
207
+ checkIs32 (Loc, Type);
201
208
if ((unsigned )Kind == X86::reloc_riprel_4byte_movq_load_rex2 ||
202
209
(unsigned )Kind == X86::reloc_riprel_4byte_relax_rex2)
203
210
return ELF::R_X86_64_CODE_4_GOTTPOFF;
204
211
else if ((unsigned )Kind == X86::reloc_riprel_4byte_relax_evex)
205
212
return ELF::R_X86_64_CODE_6_GOTTPOFF;
206
213
return ELF::R_X86_64_GOTTPOFF;
207
214
case X86MCExpr::VK_TLSLD:
208
- checkIs32 (Ctx, Loc, Type);
215
+ checkIs32 (Loc, Type);
209
216
return ELF::R_X86_64_TLSLD;
210
217
case X86MCExpr::VK_PLT:
211
- checkIs32 (Ctx, Loc, Type);
218
+ checkIs32 (Loc, Type);
212
219
return ELF::R_X86_64_PLT32;
213
220
case X86MCExpr::VK_GOTPCREL:
214
- checkIs32 (Ctx, Loc, Type);
221
+ checkIs32 (Loc, Type);
215
222
// Older versions of ld.bfd/ld.gold/lld
216
223
// do not support GOTPCRELX/REX_GOTPCRELX/CODE_4_GOTPCRELX,
217
224
// and we want to keep back-compatibility.
218
- if (!Ctx .getTargetOptions ()->X86RelaxRelocations )
225
+ if (!getContext () .getTargetOptions ()->X86RelaxRelocations )
219
226
return ELF::R_X86_64_GOTPCREL;
220
227
switch (unsigned (Kind)) {
221
228
default :
@@ -231,20 +238,18 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
231
238
}
232
239
llvm_unreachable (" unexpected relocation type!" );
233
240
case X86MCExpr::VK_GOTPCREL_NORELAX:
234
- checkIs32 (Ctx, Loc, Type);
241
+ checkIs32 (Loc, Type);
235
242
return ELF::R_X86_64_GOTPCREL;
236
243
case X86MCExpr::VK_PLTOFF:
237
- checkIs64 (Ctx, Loc, Type);
244
+ checkIs64 (Loc, Type);
238
245
return ELF::R_X86_64_PLTOFF64;
239
246
}
240
247
}
241
248
242
- enum X86_32RelType { RT32_NONE, RT32_32, RT32_16, RT32_8 };
243
-
244
- static unsigned getRelocType32 (MCContext &Ctx, SMLoc Loc,
245
- X86MCExpr::Specifier Specifier,
246
- X86_32RelType Type, bool IsPCRel,
247
- MCFixupKind Kind) {
249
+ unsigned X86ELFObjectWriter::getRelocType32 (SMLoc Loc,
250
+ X86MCExpr::Specifier Specifier,
251
+ X86_32RelType Type, bool IsPCRel,
252
+ MCFixupKind Kind) const {
248
253
switch (Specifier) {
249
254
default :
250
255
llvm_unreachable (" Unimplemented" );
@@ -270,7 +275,7 @@ static unsigned getRelocType32(MCContext &Ctx, SMLoc Loc,
270
275
return ELF::R_386_GOTPC;
271
276
// Older versions of ld.bfd/ld.gold/lld do not support R_386_GOT32X and we
272
277
// want to maintain compatibility.
273
- if (!Ctx .getTargetOptions ()->X86RelaxRelocations )
278
+ if (!getContext () .getTargetOptions ()->X86RelaxRelocations )
274
279
return ELF::R_386_GOT32;
275
280
276
281
return Kind == MCFixupKind (X86::reloc_signed_4byte_relax)
@@ -330,7 +335,7 @@ static unsigned getRelocType32(MCContext &Ctx, SMLoc Loc,
330
335
assert (!IsPCRel);
331
336
return ELF::R_386_TLS_LDM;
332
337
}
333
- Ctx. reportError (Loc, " unsupported relocation type" );
338
+ reportError (Loc, " unsupported relocation type" );
334
339
return ELF::R_386_NONE;
335
340
}
336
341
@@ -360,7 +365,7 @@ unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
360
365
361
366
X86_64RelType Type = getType64 (Kind, Specifier, IsPCRel);
362
367
if (getEMachine () == ELF::EM_X86_64)
363
- return getRelocType64 (Ctx, Fixup.getLoc (), Specifier, Type, IsPCRel, Kind);
368
+ return getRelocType64 (Fixup.getLoc (), Specifier, Type, IsPCRel, Kind);
364
369
365
370
assert ((getEMachine () == ELF::EM_386 || getEMachine () == ELF::EM_IAMCU) &&
366
371
" Unsupported ELF machine type." );
@@ -383,7 +388,7 @@ unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
383
388
RelType = RT32_8;
384
389
break ;
385
390
}
386
- return getRelocType32 (Ctx, Fixup.getLoc (), Specifier, RelType, IsPCRel, Kind);
391
+ return getRelocType32 (Fixup.getLoc (), Specifier, RelType, IsPCRel, Kind);
387
392
}
388
393
389
394
bool X86ELFObjectWriter::needsRelocateWithSymbol (const MCValue &V,
0 commit comments