[llvm-commits] [llvm] r120006 - in /llvm/trunk: lib/Target/X86/X86MCCodeEmitter.cpp test/MC/ELF/call-abs.ll
Rafael Espindola
rafael.espindola at gmail.com
Mon Nov 22 23:20:12 PST 2010
Author: rafael
Date: Tue Nov 23 01:20:12 2010
New Revision: 120006
URL: http://llvm.org/viewvc/llvm-project?rev=120006&view=rev
Log:
Produce a relocation for pcrel absolute values. Based on a patch by David Meyer.
Added:
llvm/trunk/test/MC/ELF/call-abs.ll
Modified:
llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp
Modified: llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp?rev=120006&r1=120005&r2=120006&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp Tue Nov 23 01:20:12 2010
@@ -218,18 +218,22 @@
EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
unsigned &CurByte, raw_ostream &OS,
SmallVectorImpl<MCFixup> &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);
Added: llvm/trunk/test/MC/ELF/call-abs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/call-abs.ll?rev=120006&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/call-abs.ll (added)
+++ llvm/trunk/test/MC/ELF/call-abs.ll Tue Nov 23 01:20:12 2010
@@ -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: ])
More information about the llvm-commits
mailing list