[PATCH] Fix for PR15086

Dimitry Andric dimitry at andric.com
Sat Oct 19 11:28:42 PDT 2013


Hi,

There finally was a bit of movement again on http://llvm.org/PR15086 , which deals with tail call optimization in GOT PIC mode (used on e.g. Linux and FreeBSD on 32-bit x86 arches).

The basic problem is that mainstream programs such as X.org cannot deal with the way clang optimizes tail calls, as in this example:

int foo(void);
int bar(void) {
  return foo();
}

where the call is transformed to:

	calll	.L0$pb
.L0$pb:
	popl	%eax
.Ltmp0:
	addl	$_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %eax
	movl	foo at GOT(%eax), %eax
	popl	%ebp
	jmpl	*%eax                   # TAILCALL

However, the GOT references must all be resolved at dlopen() time, and so this approach cannot be used with lazy dynamic linking (e.g. using RTLD_LAZY), which usually populates the PLT with stubs that perform the actual resolving.

Therefore, I propose the attached fix, which changes X86TargetLowering::LowerCall() to skip tail call optimization, if the called function is a global or external symbol.  I have also updated the appropriate test cases.  If most people would also like to have a separate test case just for this specific PR, let me know and I will add one.

-Dimitry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-pr15086-1.diff
Type: application/octet-stream
Size: 3564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131019/a8348f1d/attachment.obj>
-------------- next part --------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 203 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131019/a8348f1d/attachment.sig>


More information about the llvm-commits mailing list