From d93ceeb125c11a96eb85618bb9a8a7d664a1d8f4 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 23 Nov 2010 07:20:12 +0000 Subject: [PATCH] Produce a relocation for pcrel absolute values. Based on a patch by David Meyer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120006 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86MCCodeEmitter.cpp | 20 ++++++++++++-------- test/MC/ELF/call-abs.ll | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 test/MC/ELF/call-abs.ll diff --git a/lib/Target/X86/X86MCCodeEmitter.cpp b/lib/Target/X86/X86MCCodeEmitter.cpp index fea37f85a74..586216d774b 100644 --- a/lib/Target/X86/X86MCCodeEmitter.cpp +++ b/lib/Target/X86/X86MCCodeEmitter.cpp @@ -218,18 +218,22 @@ void X86MCCodeEmitter:: EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind, unsigned &CurByte, raw_ostream &OS, SmallVectorImpl &Fixups, int ImmOffset) const { - // If this is a simple integer displacement that doesn't require a relocation, - // emit it now. + const MCExpr *Expr = NULL; if (DispOp.isImm()) { - // FIXME: is this right for pc-rel encoding?? Probably need to emit this as - // a fixup if so. - EmitConstant(DispOp.getImm()+ImmOffset, Size, CurByte, OS); - return; + // If this is a simple integer displacement that doesn't require a relocation, + // emit it now. + if (FixupKind != MCFixupKind(X86::reloc_pcrel_1byte) && + FixupKind != MCFixupKind(X86::reloc_pcrel_2byte) && + FixupKind != MCFixupKind(X86::reloc_pcrel_4byte)) { + EmitConstant(DispOp.getImm()+ImmOffset, Size, CurByte, OS); + return; + } + Expr = MCConstantExpr::Create(DispOp.getImm(), Ctx); + } else { + Expr = DispOp.getExpr(); } // If we have an immoffset, add it to the expression. - const MCExpr *Expr = DispOp.getExpr(); - if (FixupKind == FK_Data_4 && StartsWithGlobalOffsetTable(Expr)) { assert(ImmOffset == 0); diff --git a/test/MC/ELF/call-abs.ll b/test/MC/ELF/call-abs.ll new file mode 100644 index 00000000000..6ebd17f30cf --- /dev/null +++ b/test/MC/ELF/call-abs.ll @@ -0,0 +1,16 @@ +; RUN: llc -filetype=obj -mtriple i686-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +define i32 @f() nounwind optsize ssp { +entry: + %call = tail call i32 inttoptr (i64 42 to i32 ()*)() nounwind optsize + %add = add nsw i32 %call, 1 + ret i32 %add +} + +; CHECK: ('_relocations', [ +; CHECK-NEXT: # Relocation 0x00000000 +; CHECK-NEXT: (('r_offset', 0x00000004) +; CHECK-NEXT: ('r_sym', 0x00000000) +; CHECK-NEXT: ('r_type', 0x00000002) +; CHECK-NEXT: ), +; CHECK-NEXT: ]) -- 2.34.1