diff options
Diffstat (limited to 'llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp')
-rw-r--r-- | llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp index 2c26dd388c05..37d81e4b0af1 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp @@ -53,8 +53,8 @@ ARMELFObjectWriter::ARMELFObjectWriter(uint8_t OSABI) bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym, unsigned Type) const { - // FIXME: This is extremely conservative. This really needs to use a - // whitelist with a clear explanation for why each realocation needs to + // FIXME: This is extremely conservative. This really needs to use an + // explicit list with a clear explanation for why each realocation needs to // point to the symbol, not to the section. switch (Type) { default: @@ -79,6 +79,9 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel, MCContext &Ctx) const { + unsigned Kind = Fixup.getTargetKind(); + if (Kind >= FirstLiteralRelocationKind) + return Kind - FirstLiteralRelocationKind; MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant(); if (IsPCRel) { @@ -89,9 +92,18 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target, case FK_Data_4: switch (Modifier) { default: - llvm_unreachable("Unsupported Modifier"); - case MCSymbolRefExpr::VK_None: + Ctx.reportError(Fixup.getLoc(), + "invalid fixup for 4-byte pc-relative data relocation"); + return ELF::R_ARM_NONE; + case MCSymbolRefExpr::VK_None: { + if (const MCSymbolRefExpr *SymRef = Target.getSymA()) { + // For GNU AS compatibility expressions such as + // _GLOBAL_OFFSET_TABLE_ - label emit a R_ARM_BASE_PREL relocation. + if (SymRef->getSymbol().getName() == "_GLOBAL_OFFSET_TABLE_") + return ELF::R_ARM_BASE_PREL; + } return ELF::R_ARM_REL32; + } case MCSymbolRefExpr::VK_GOTTPOFF: return ELF::R_ARM_TLS_IE32; case MCSymbolRefExpr::VK_ARM_GOT_PREL: @@ -145,30 +157,34 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target, return ELF::R_ARM_THM_BF18; } } - switch (Fixup.getTargetKind()) { + switch (Kind) { default: Ctx.reportFatalError(Fixup.getLoc(), "unsupported relocation on symbol"); return ELF::R_ARM_NONE; - case FK_NONE: - return ELF::R_ARM_NONE; case FK_Data_1: switch (Modifier) { default: - llvm_unreachable("unsupported Modifier"); + Ctx.reportError(Fixup.getLoc(), + "invalid fixup for 1-byte data relocation"); + return ELF::R_ARM_NONE; case MCSymbolRefExpr::VK_None: return ELF::R_ARM_ABS8; } case FK_Data_2: switch (Modifier) { default: - llvm_unreachable("unsupported modifier"); + Ctx.reportError(Fixup.getLoc(), + "invalid fixup for 2-byte data relocation"); + return ELF::R_ARM_NONE; case MCSymbolRefExpr::VK_None: return ELF::R_ARM_ABS16; } case FK_Data_4: switch (Modifier) { default: - llvm_unreachable("Unsupported Modifier"); + Ctx.reportError(Fixup.getLoc(), + "invalid fixup for 4-byte data relocation"); + return ELF::R_ARM_NONE; case MCSymbolRefExpr::VK_ARM_NONE: return ELF::R_ARM_NONE; case MCSymbolRefExpr::VK_GOT: @@ -210,7 +226,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target, case ARM::fixup_arm_movt_hi16: switch (Modifier) { default: - llvm_unreachable("Unsupported Modifier"); + Ctx.reportError(Fixup.getLoc(), "invalid fixup for ARM MOVT instruction"); + return ELF::R_ARM_NONE; case MCSymbolRefExpr::VK_None: return ELF::R_ARM_MOVT_ABS; case MCSymbolRefExpr::VK_ARM_SBREL: @@ -219,7 +236,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target, case ARM::fixup_arm_movw_lo16: switch (Modifier) { default: - llvm_unreachable("Unsupported Modifier"); + Ctx.reportError(Fixup.getLoc(), "invalid fixup for ARM MOVW instruction"); + return ELF::R_ARM_NONE; case MCSymbolRefExpr::VK_None: return ELF::R_ARM_MOVW_ABS_NC; case MCSymbolRefExpr::VK_ARM_SBREL: @@ -228,7 +246,9 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target, case ARM::fixup_t2_movt_hi16: switch (Modifier) { default: - llvm_unreachable("Unsupported Modifier"); + Ctx.reportError(Fixup.getLoc(), + "invalid fixup for Thumb MOVT instruction"); + return ELF::R_ARM_NONE; case MCSymbolRefExpr::VK_None: return ELF::R_ARM_THM_MOVT_ABS; case MCSymbolRefExpr::VK_ARM_SBREL: @@ -237,7 +257,9 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target, case ARM::fixup_t2_movw_lo16: switch (Modifier) { default: - llvm_unreachable("Unsupported Modifier"); + Ctx.reportError(Fixup.getLoc(), + "invalid fixup for Thumb MOVW instruction"); + return ELF::R_ARM_NONE; case MCSymbolRefExpr::VK_None: return ELF::R_ARM_THM_MOVW_ABS_NC; case MCSymbolRefExpr::VK_ARM_SBREL: |