llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

X86 backend converts calls to constant addresses to indirect calls.

Open llvmbot opened this issue 17 years ago • 7 comments

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.

llvmbot avatar Feb 25 '09 14:02 llvmbot

with the latest trunk, this one works.

darkbuck avatar Jul 20 '12 06:07 darkbuck

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.

llvmbot avatar Nov 16 '09 11:11 llvmbot

This is now fixed. http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090309/075148.html

sunfishcode avatar Mar 13 '09 01:03 sunfishcode

66024 was reverted.

sunfishcode avatar Mar 12 '09 01:03 sunfishcode

Fixed. Revision 66024.

llvmbot avatar Mar 04 '09 08:03 llvmbot

The PPC backend gets this right, it mattered for the "fast objc dispatch" codepath.

lattner avatar Feb 25 '09 20:02 lattner

Comments say fixed

arsenm avatar Aug 05 '23 21:08 arsenm