Convert a few assert failures into proper errors.

Fixes PR25944.

llvm-svn: 257697
This commit is contained in:
Rafael Espindola 2016-01-13 22:56:57 +00:00
parent 3dd0ff3b62
commit 8340f94df1
13 changed files with 79 additions and 44 deletions

View File

@ -17,6 +17,7 @@
namespace llvm {
class MCAssembler;
class MCContext;
class MCFixup;
class MCFragment;
class MCObjectWriter;
@ -64,8 +65,8 @@ public:
virtual ~MCELFObjectTargetWriter() {}
virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const = 0;
virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const = 0;
virtual bool needsRelocateWithSymbol(const MCSymbol &Sym,
unsigned Type) const;

View File

@ -129,9 +129,9 @@ class ELFObjectWriter : public MCObjectWriter {
bool hasRelocationAddend() const {
return TargetObjectWriter->hasRelocationAddend();
}
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const {
return TargetObjectWriter->GetRelocType(Target, Fixup, IsPCRel);
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const {
return TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);
}
void align(unsigned Alignment);
@ -682,7 +682,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
}
}
unsigned Type = GetRelocType(Target, Fixup, IsPCRel);
unsigned Type = getRelocType(Ctx, Target, Fixup, IsPCRel);
bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type);
if (!RelocateWithSymbol && SymA && !SymA->isUndefined())
C += Layout.getSymbolOffset(*SymA);

View File

@ -29,8 +29,8 @@ public:
~AArch64ELFObjectWriter() override;
protected:
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const override;
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
private:
};
@ -43,9 +43,10 @@ AArch64ELFObjectWriter::AArch64ELFObjectWriter(uint8_t OSABI,
AArch64ELFObjectWriter::~AArch64ELFObjectWriter() {}
unsigned AArch64ELFObjectWriter::GetRelocType(const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {
unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {
AArch64MCExpr::VariantKind RefKind =
static_cast<AArch64MCExpr::VariantKind>(Target.getRefKind());
AArch64MCExpr::VariantKind SymLoc = AArch64MCExpr::getSymbolLoc(RefKind);

View File

@ -20,8 +20,8 @@ class AMDGPUELFObjectWriter : public MCELFObjectTargetWriter {
public:
AMDGPUELFObjectWriter(bool Is64Bit);
protected:
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const override {
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override {
return Fixup.getKind();
}

View File

@ -34,8 +34,8 @@ namespace {
~ARMELFObjectWriter() override;
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const override;
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
bool needsRelocateWithSymbol(const MCSymbol &Sym,
unsigned Type) const override;
@ -67,7 +67,7 @@ bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
// Need to examine the Fixup when determining whether to
// emit the relocation as an explicit symbol or as a section relative
// offset
unsigned ARMELFObjectWriter::GetRelocType(const MCValue &Target,
unsigned ARMELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {
return GetRelocTypeInner(Target, Fixup, IsPCRel);

View File

@ -22,8 +22,8 @@ public:
~BPFELFObjectWriter() override;
protected:
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const override;
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
};
}
@ -33,7 +33,7 @@ BPFELFObjectWriter::BPFELFObjectWriter(uint8_t OSABI)
BPFELFObjectWriter::~BPFELFObjectWriter() {}
unsigned BPFELFObjectWriter::GetRelocType(const MCValue &Target,
unsigned BPFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {
// determine the type of the relocation

View File

@ -28,8 +28,8 @@ private:
public:
HexagonELFObjectWriter(uint8_t OSABI, StringRef C);
unsigned GetRelocType(MCValue const &Target, MCFixup const &Fixup,
bool IsPCRel) const override;
unsigned getRelocType(MCContext &Ctx, MCValue const &Target,
MCFixup const &Fixup, bool IsPCRel) const override;
};
}
@ -38,7 +38,8 @@ HexagonELFObjectWriter::HexagonELFObjectWriter(uint8_t OSABI, StringRef C)
/*HasRelocationAddend*/ true),
CPU(C) {}
unsigned HexagonELFObjectWriter::GetRelocType(MCValue const & /*Target*/,
unsigned HexagonELFObjectWriter::getRelocType(MCContext &Ctx,
MCValue const & /*Target*/,
MCFixup const &Fixup,
bool IsPCRel) const {
switch ((unsigned)Fixup.getKind()) {

View File

@ -44,8 +44,8 @@ struct MipsRelocationEntry {
~MipsELFObjectWriter() override;
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const override;
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
bool needsRelocateWithSymbol(const MCSymbol &Sym,
unsigned Type) const override;
virtual void sortRelocs(const MCAssembler &Asm,
@ -61,7 +61,8 @@ MipsELFObjectWriter::MipsELFObjectWriter(bool _is64Bit, uint8_t OSABI,
MipsELFObjectWriter::~MipsELFObjectWriter() {}
unsigned MipsELFObjectWriter::GetRelocType(const MCValue &Target,
unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {
// Determine the type of the relocation.

View File

@ -25,8 +25,8 @@ namespace {
PPCELFObjectWriter(bool Is64Bit, uint8_t OSABI);
protected:
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const override;
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
bool needsRelocateWithSymbol(const MCSymbol &Sym,
unsigned Type) const override;
@ -66,7 +66,7 @@ static MCSymbolRefExpr::VariantKind getAccessVariant(const MCValue &Target,
llvm_unreachable("unknown PPCMCExpr kind");
}
unsigned PPCELFObjectWriter::GetRelocType(const MCValue &Target,
unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {
MCSymbolRefExpr::VariantKind Modifier = getAccessVariant(Target, Fixup);

View File

@ -29,8 +29,8 @@ namespace {
~SparcELFObjectWriter() override {}
protected:
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const override;
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
bool needsRelocateWithSymbol(const MCSymbol &Sym,
unsigned Type) const override;
@ -38,7 +38,8 @@ namespace {
};
}
unsigned SparcELFObjectWriter::GetRelocType(const MCValue &Target,
unsigned SparcELFObjectWriter::getRelocType(MCContext &Ctx,
const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {

View File

@ -24,8 +24,8 @@ public:
protected:
// Override MCELFObjectTargetWriter.
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const override;
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
};
} // end anonymous namespace
@ -106,7 +106,8 @@ static unsigned getPLTReloc(unsigned Kind) {
llvm_unreachable("Unsupported absolute address");
}
unsigned SystemZObjectWriter::GetRelocType(const MCValue &Target,
unsigned SystemZObjectWriter::getRelocType(MCContext &Ctx,
const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {
MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();

View File

@ -9,6 +9,7 @@
#include "MCTargetDesc/X86FixupKinds.h"
#include "MCTargetDesc/X86MCTargetDesc.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCELFObjectWriter.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCValue.h"
@ -25,8 +26,8 @@ namespace {
~X86ELFObjectWriter() override;
protected:
unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
bool IsPCRel) const override;
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup, bool IsPCRel) const override;
};
}
@ -77,7 +78,14 @@ static X86_64RelType getType64(unsigned Kind,
}
}
static unsigned getRelocType64(MCSymbolRefExpr::VariantKind Modifier,
static void checkIs32(MCContext &Ctx, SMLoc Loc, X86_64RelType Type) {
if (Type != RT64_32)
Ctx.reportError(Loc,
"32 bit reloc applied to a field with a different size");
}
static unsigned getRelocType64(MCContext &Ctx, SMLoc Loc,
MCSymbolRefExpr::VariantKind Modifier,
X86_64RelType Type, bool IsPCRel) {
switch (Modifier) {
default:
@ -147,19 +155,19 @@ static unsigned getRelocType64(MCSymbolRefExpr::VariantKind Modifier,
llvm_unreachable("Unimplemented");
}
case MCSymbolRefExpr::VK_TLSGD:
assert(Type == RT64_32);
checkIs32(Ctx, Loc, Type);
return ELF::R_X86_64_TLSGD;
case MCSymbolRefExpr::VK_GOTTPOFF:
assert(Type == RT64_32);
checkIs32(Ctx, Loc, Type);
return ELF::R_X86_64_GOTTPOFF;
case MCSymbolRefExpr::VK_TLSLD:
assert(Type == RT64_32);
checkIs32(Ctx, Loc, Type);
return ELF::R_X86_64_TLSLD;
case MCSymbolRefExpr::VK_PLT:
assert(Type == RT64_32);
checkIs32(Ctx, Loc, Type);
return ELF::R_X86_64_PLT32;
case MCSymbolRefExpr::VK_GOTPCREL:
assert(Type == RT64_32);
checkIs32(Ctx, Loc, Type);
return ELF::R_X86_64_GOTPCREL;
}
}
@ -240,13 +248,13 @@ static unsigned getRelocType32(MCSymbolRefExpr::VariantKind Modifier,
}
}
unsigned X86ELFObjectWriter::GetRelocType(const MCValue &Target,
unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
const MCFixup &Fixup,
bool IsPCRel) const {
MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();
X86_64RelType Type = getType64(Fixup.getKind(), Modifier, IsPCRel);
if (getEMachine() == ELF::EM_X86_64)
return getRelocType64(Modifier, Type, IsPCRel);
return getRelocType64(Ctx, Fixup.getLoc(), Modifier, Type, IsPCRel);
assert((getEMachine() == ELF::EM_386 || getEMachine() == ELF::EM_IAMCU) &&
"Unsupported ELF machine type.");

View File

@ -0,0 +1,21 @@
// RUN: not llvm-mc %s -o %t.o -filetype=obj 2>&1 | FileCheck %s
.quad foo@gotpcrel
// CHECK: 32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@gotpcrel
.quad foo@plt
// CHECK: 32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@plt
.quad foo@tlsld
// CHECK: 32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@tlsld
.quad foo@gottpoff
// CHECK: 32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@gottpoff
.quad foo@tlsgd
// CHECK: 32 bit reloc applied to a field with a different size
// CHECK-NEXT: .quad foo@tlsgd