@@ -140,8 +140,9 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
140140 }
141141 llvm_unreachable (" unexpected relocation type!" );
142142 case MCSymbolRefExpr::VK_GOTOFF:
143- assert (Type == RT64_64);
144143 assert (!IsPCRel);
144+ if (Type != RT64_64)
145+ Ctx.reportError (Loc, " unsupported relocation type" );
145146 return ELF::R_X86_64_GOTOFF64;
146147 case MCSymbolRefExpr::VK_TPOFF:
147148 assert (!IsPCRel);
@@ -229,7 +230,7 @@ static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
229230
230231enum X86_32RelType { RT32_NONE, RT32_32, RT32_16, RT32_8 };
231232
232- static unsigned getRelocType32 (MCContext &Ctx,
233+ static unsigned getRelocType32 (MCContext &Ctx, SMLoc Loc,
233234 MCSymbolRefExpr::VariantKind Modifier,
234235 X86_32RelType Type, bool IsPCRel,
235236 MCFixupKind Kind) {
@@ -252,7 +253,8 @@ static unsigned getRelocType32(MCContext &Ctx,
252253 }
253254 llvm_unreachable (" unexpected relocation type!" );
254255 case MCSymbolRefExpr::VK_GOT:
255- assert (Type == RT32_32);
256+ if (Type != RT32_32)
257+ break ;
256258 if (IsPCRel)
257259 return ELF::R_386_GOTPC;
258260 // 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,
264266 ? ELF::R_386_GOT32X
265267 : ELF::R_386_GOT32;
266268 case MCSymbolRefExpr::VK_GOTOFF:
267- assert (Type == RT32_32);
268269 assert (!IsPCRel);
270+ if (Type != RT32_32)
271+ break ;
269272 return ELF::R_386_GOTOFF;
270273 case MCSymbolRefExpr::VK_TLSCALL:
271274 return ELF::R_386_TLS_DESC_CALL;
272275 case MCSymbolRefExpr::VK_TLSDESC:
273276 return ELF::R_386_TLS_GOTDESC;
274277 case MCSymbolRefExpr::VK_TPOFF:
275- assert (Type == RT32_32);
278+ if (Type != RT32_32)
279+ break ;
276280 assert (!IsPCRel);
277281 return ELF::R_386_TLS_LE_32;
278282 case MCSymbolRefExpr::VK_DTPOFF:
279- assert (Type == RT32_32);
283+ if (Type != RT32_32)
284+ break ;
280285 assert (!IsPCRel);
281286 return ELF::R_386_TLS_LDO_32;
282287 case MCSymbolRefExpr::VK_TLSGD:
283- assert (Type == RT32_32);
288+ if (Type != RT32_32)
289+ break ;
284290 assert (!IsPCRel);
285291 return ELF::R_386_TLS_GD;
286292 case MCSymbolRefExpr::VK_GOTTPOFF:
287- assert (Type == RT32_32);
293+ if (Type != RT32_32)
294+ break ;
288295 assert (!IsPCRel);
289296 return ELF::R_386_TLS_IE_32;
290297 case MCSymbolRefExpr::VK_PLT:
291- assert (Type == RT32_32);
298+ if (Type != RT32_32)
299+ break ;
292300 return ELF::R_386_PLT32;
293301 case MCSymbolRefExpr::VK_INDNTPOFF:
294- assert (Type == RT32_32);
302+ if (Type != RT32_32)
303+ break ;
295304 assert (!IsPCRel);
296305 return ELF::R_386_TLS_IE;
297306 case MCSymbolRefExpr::VK_NTPOFF:
298- assert (Type == RT32_32);
307+ if (Type != RT32_32)
308+ break ;
299309 assert (!IsPCRel);
300310 return ELF::R_386_TLS_LE;
301311 case MCSymbolRefExpr::VK_GOTNTPOFF:
302- assert (Type == RT32_32);
312+ if (Type != RT32_32)
313+ break ;
303314 assert (!IsPCRel);
304315 return ELF::R_386_TLS_GOTIE;
305316 case MCSymbolRefExpr::VK_TLSLDM:
306- assert (Type == RT32_32);
317+ if (Type != RT32_32)
318+ break ;
307319 assert (!IsPCRel);
308320 return ELF::R_386_TLS_LDM;
309321 }
322+ Ctx.reportError (Loc, " unsupported relocation type" );
323+ return ELF::R_386_NONE;
310324}
311325
312326unsigned X86ELFObjectWriter::getRelocType (MCContext &Ctx, const MCValue &Target,
@@ -329,7 +343,7 @@ unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
329343 break ;
330344 case RT64_64:
331345 Ctx.reportError (Fixup.getLoc (), " unsupported relocation type" );
332- break ;
346+ return ELF::R_386_NONE ;
333347 case RT64_32:
334348 case RT64_32S:
335349 RelType = RT32_32;
@@ -341,7 +355,7 @@ unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
341355 RelType = RT32_8;
342356 break ;
343357 }
344- return getRelocType32 (Ctx, Modifier, RelType, IsPCRel, Kind);
358+ return getRelocType32 (Ctx, Fixup. getLoc (), Modifier, RelType, IsPCRel, Kind);
345359}
346360
347361std::unique_ptr<MCObjectTargetWriter>
0 commit comments