X86 backend converts calls to constant addresses to indirect calls.
| Bugzilla Link | 3666 |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @asl,@sunfishcode,@darkbuck,@nlewycky |
Extended Description
The following llvm code:
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i386-pc-linux-gnu"
define i32 @main() nounwind {
entry:
%0 = call i32 inttoptr (i32 12345678 to i32 (i32)*)(i32 0) nounwind ; <i32> [#uses=1]
ret i32 %0
}
Produces the following assembler (with directives removed)
main:
subl $4, %esp
movl $0, (%esp)
movl $12345678, %eax
call *%eax
addl $4, %esp
ret
Whereas it should produce this code:
main:
subl $4, %esp
movl $0, (%esp)
call *12345678
addl $4, %esp
ret
This is important since all calls in JIT compiled code, will be in the above form.
with the latest trunk, this one works.
When upgrading from 2.5 to 2.6 this patch seems to break stuff:
llvm 2.5 outputs the following assembly: movl $12345678, %eax call *%eax this is correct, but indirect, as documented in the initial comment.
the initial comment says that llvm 2.6 should output: call *12345678 the above assembly calls the function pointer stored at address 12345678. this is not the same as calling the function at address 12345678, which is what the IR would like to do.
actually llvm 2.6 outputs the following assembly: call 12345678 the above assembly calls the function pointer relative to the current program counter (IPC+12345678 -> crash). this is not the same as calling the function at the absolute address 12345678, which is what the IR would like to do.
perhaps someone with good x86 at&t assembly knowledge can shed some light on it. I have already tried: call 12345678 - . - 1 this works but I don't know if it is fully relocatable when linked as a shared library.
This is now fixed. http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090309/075148.html
66024 was reverted.
Fixed. Revision 66024.
The PPC backend gets this right, it mattered for the "fast objc dispatch" codepath.
Comments say fixed