From: Jack Carter Date: Fri, 13 Jul 2012 19:15:47 +0000 (+0000) Subject: The Mips specific relocation R_MIPS_GOT_DISP X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fd506efec628819f7e6fad8016a9dbb5d8612b8b;p=oota-llvm.git The Mips specific relocation R_MIPS_GOT_DISP is used in cases where global symbols are directly represented in the GOT and we use an offset into the global offset table. This patch adds direct object support for R_MIPS_GOT_DISP. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160183 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp index 575f2cfda5b..6fe0c11911d 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp @@ -40,6 +40,7 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) { case Mips::fixup_Mips_GPOFF_LO: case Mips::fixup_Mips_GOT_PAGE: case Mips::fixup_Mips_GOT_OFST: + case Mips::fixup_Mips_GOT_DISP: break; case Mips::fixup_Mips_PC16: // So far we are only using this type for branches. @@ -166,7 +167,8 @@ public: { "fixup_Mips_GPOFF_HI", 0, 16, 0 }, { "fixup_Mips_GPOFF_LO", 0, 16, 0 }, { "fixup_Mips_GOT_PAGE", 0, 16, 0 }, - { "fixup_Mips_GOT_OFST", 0, 16, 0 } + { "fixup_Mips_GOT_OFST", 0, 16, 0 }, + { "fixup_Mips_GOT_DISP", 0, 16, 0 } }; if (Kind < FirstTargetFixupKind) diff --git a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp index 9f9272886e0..77c1524531c 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp @@ -156,6 +156,9 @@ unsigned MipsELFObjectWriter::GetRelocType(const MCValue &Target, case Mips::fixup_Mips_GOT_OFST: Type = ELF::R_MIPS_GOT_OFST; break; + case Mips::fixup_Mips_GOT_DISP: + Type = ELF::R_MIPS_GOT_DISP; + break; case Mips::fixup_Mips_GPOFF_HI: Type = setRType((unsigned)ELF::R_MIPS_GPREL16, Type); Type = setRType2((unsigned)ELF::R_MIPS_SUB, Type); diff --git a/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h b/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h index 1f6000cc8ce..f5cbbd537d1 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h +++ b/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h @@ -107,6 +107,9 @@ namespace Mips { // resulting in - R_MIPS_GOT_OFST fixup_Mips_GOT_OFST, + // resulting in - R_MIPS_GOT_DISP + fixup_Mips_GOT_DISP, + // Marker LastTargetFixupKind, NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind diff --git a/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp b/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp index 1bd1420c91d..ff3b3a7ed1c 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp @@ -201,9 +201,6 @@ getMachineOpValue(const MCInst &MI, const MCOperand &MO, switch(cast(Expr)->getKind()) { default: llvm_unreachable("Unknown fixup kind!"); break; - case MCSymbolRefExpr::VK_Mips_GOT_DISP : - llvm_unreachable("fixup kind VK_Mips_GOT_DISP not supported for direct object!"); - break; case MCSymbolRefExpr::VK_Mips_GPOFF_HI : FixupKind = Mips::fixup_Mips_GPOFF_HI; break; @@ -216,6 +213,9 @@ getMachineOpValue(const MCInst &MI, const MCOperand &MO, case MCSymbolRefExpr::VK_Mips_GOT_OFST : FixupKind = Mips::fixup_Mips_GOT_OFST; break; + case MCSymbolRefExpr::VK_Mips_GOT_DISP : + FixupKind = Mips::fixup_Mips_GOT_DISP; + break; case MCSymbolRefExpr::VK_Mips_GPREL: FixupKind = Mips::fixup_Mips_GPREL16; break; diff --git a/test/MC/Mips/r-mips-got-disp.ll b/test/MC/Mips/r-mips-got-disp.ll new file mode 100644 index 00000000000..73396ac5139 --- /dev/null +++ b/test/MC/Mips/r-mips-got-disp.ll @@ -0,0 +1,18 @@ +; RUN: llc -march=mips64el -filetype=obj -mcpu=mips64r2 < %s -o - | elf-dump --dump-section-data | FileCheck %s + +; Check that the R_MIPS_GOT_DISP relocations were created. + +; CHECK: ('r_type', 0x13) + +@shl = global i64 1, align 8 +@.str = private unnamed_addr constant [8 x i8] c"0x%llx\0A\00", align 1 + +define i32 @main() nounwind { +entry: + %0 = load i64* @shl, align 8 + %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([8 x i8]* @.str, i64 0, i64 0), i64 %0) nounwind + ret i32 0 +} + +declare i32 @printf(i8* nocapture, ...) nounwind +