@@ -140,8 +140,9 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
140
140
}
141
141
llvm_unreachable (" unexpected relocation type!" );
142
142
case MCSymbolRefExpr::VK_GOTOFF:
143
- assert (Type == RT64_64);
144
143
assert (!IsPCRel);
144
+ if (Type != RT64_64)
145
+ Ctx.reportError (Loc, " unsupported relocation type" );
145
146
return ELF::R_X86_64_GOTOFF64;
146
147
case MCSymbolRefExpr::VK_TPOFF:
147
148
assert (!IsPCRel);
@@ -229,7 +230,7 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
229
230
230
231
enum X86_32RelType { RT32_NONE, RT32_32, RT32_16, RT32_8 };
231
232
232
- static unsigned getRelocType32 (MCContext &Ctx,
233
+ static unsigned getRelocType32 (MCContext &Ctx, SMLoc Loc,
233
234
MCSymbolRefExpr::VariantKind Modifier,
234
235
X86_32RelType Type, bool IsPCRel,
235
236
MCFixupKind Kind) {
@@ -252,7 +253,8 @@ static unsigned getRelocType32(MCContext &Ctx,
252
253
}
253
254
llvm_unreachable (" unexpected relocation type!" );
254
255
case MCSymbolRefExpr::VK_GOT:
255
- assert (Type == RT32_32);
256
+ if (Type != RT32_32)
257
+ break ;
256
258
if (IsPCRel)
257
259
return ELF::R_386_GOTPC;
258
260
// Older versions of ld.bfd/ld.gold/lld do not support R_386_GOT32X and we
@@ -264,49 +266,61 @@ static unsigned getRelocType32(MCContext &Ctx,
264
266
? ELF::R_386_GOT32X
265
267
: ELF::R_386_GOT32;
266
268
case MCSymbolRefExpr::VK_GOTOFF:
267
- assert (Type == RT32_32);
268
269
assert (!IsPCRel);
270
+ if (Type != RT32_32)
271
+ break ;
269
272
return ELF::R_386_GOTOFF;
270
273
case MCSymbolRefExpr::VK_TLSCALL:
271
274
return ELF::R_386_TLS_DESC_CALL;
272
275
case MCSymbolRefExpr::VK_TLSDESC:
273
276
return ELF::R_386_TLS_GOTDESC;
274
277
case MCSymbolRefExpr::VK_TPOFF:
275
- assert (Type == RT32_32);
278
+ if (Type != RT32_32)
279
+ break ;
276
280
assert (!IsPCRel);
277
281
return ELF::R_386_TLS_LE_32;
278
282
case MCSymbolRefExpr::VK_DTPOFF:
279
- assert (Type == RT32_32);
283
+ if (Type != RT32_32)
284
+ break ;
280
285
assert (!IsPCRel);
281
286
return ELF::R_386_TLS_LDO_32;
282
287
case MCSymbolRefExpr::VK_TLSGD:
283
- assert (Type == RT32_32);
288
+ if (Type != RT32_32)
289
+ break ;
284
290
assert (!IsPCRel);
285
291
return ELF::R_386_TLS_GD;
286
292
case MCSymbolRefExpr::VK_GOTTPOFF:
287
- assert (Type == RT32_32);
293
+ if (Type != RT32_32)
294
+ break ;
288
295
assert (!IsPCRel);
289
296
return ELF::R_386_TLS_IE_32;
290
297
case MCSymbolRefExpr::VK_PLT:
291
- assert (Type == RT32_32);
298
+ if (Type != RT32_32)
299
+ break ;
292
300
return ELF::R_386_PLT32;
293
301
case MCSymbolRefExpr::VK_INDNTPOFF:
294
- assert (Type == RT32_32);
302
+ if (Type != RT32_32)
303
+ break ;
295
304
assert (!IsPCRel);
296
305
return ELF::R_386_TLS_IE;
297
306
case MCSymbolRefExpr::VK_NTPOFF:
298
- assert (Type == RT32_32);
307
+ if (Type != RT32_32)
308
+ break ;
299
309
assert (!IsPCRel);
300
310
return ELF::R_386_TLS_LE;
301
311
case MCSymbolRefExpr::VK_GOTNTPOFF:
302
- assert (Type == RT32_32);
312
+ if (Type != RT32_32)
313
+ break ;
303
314
assert (!IsPCRel);
304
315
return ELF::R_386_TLS_GOTIE;
305
316
case MCSymbolRefExpr::VK_TLSLDM:
306
- assert (Type == RT32_32);
317
+ if (Type != RT32_32)
318
+ break ;
307
319
assert (!IsPCRel);
308
320
return ELF::R_386_TLS_LDM;
309
321
}
322
+ Ctx.reportError (Loc, " unsupported relocation type" );
323
+ return ELF::R_386_NONE;
310
324
}
311
325
312
326
unsigned X86ELFObjectWriter::getRelocType (MCContext &Ctx, const MCValue &Target,
@@ -329,7 +343,7 @@ unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
329
343
break ;
330
344
case RT64_64:
331
345
Ctx.reportError (Fixup.getLoc (), " unsupported relocation type" );
332
- break ;
346
+ return ELF::R_386_NONE ;
333
347
case RT64_32:
334
348
case RT64_32S:
335
349
RelType = RT32_32;
@@ -341,7 +355,7 @@ unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
341
355
RelType = RT32_8;
342
356
break ;
343
357
}
344
- return getRelocType32 (Ctx, Modifier, RelType, IsPCRel, Kind);
358
+ return getRelocType32 (Ctx, Fixup. getLoc (), Modifier, RelType, IsPCRel, Kind);
345
359
}
346
360
347
361
std::unique_ptr<MCObjectTargetWriter>
0 commit comments