https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68937
Bug ID: 68937
Summary: i686: -fno-plt produces wrong code (maybe only with
tailcall)
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: zsojka at seznam dot cz
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Target: i686-pc-linux-gnu
Created attachment 37047
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37047&action=edit
reduced testcase
Output:
$ i686-pc-linux-gnu-gcc -O2 -fPIC -fno-plt testcase.c
$ ./a.out
Segmentation fault
The wrong code is:
...
foo:
...
call [DWORD PTR bar@GOT[ebx]]
mov DWORD PTR 32[esp], esi
add esp, 20
pop ebx
pop esi
jmp [DWORD PTR bar@GOT[ebx]]
ebx is invalid at this point.
Without -fno-plt, the tailcall optimization is not performed:
--- testcase.s 2015-12-16 12:14:49.061674916 +0100
+++ testcase_broken.s 2015-12-16 12:14:17.541674625 +0100
@@ -30,9 +30,8 @@
mov esi, DWORD PTR 32[esp]
push esi
- call bar@PLT
- mov DWORD PTR [esp], esi
- call bar@PLT
+ call [DWORD PTR bar@GOT[ebx]]
+ mov DWORD PTR 32[esp], esi
add esp, 20
pop ebx
@@ -41,7 +40,7 @@
pop esi
- ret
+ jmp [DWORD PTR bar@GOT[ebx]]
This seems to affect only i686 (powerpc, powerpc64, x86_64, x86_64 x32,
aarch64, armv7 are fine)
Tested revisions:
r231665 - FAIL