8750 – Cygwin prolog generation erroneously emitting __alloca as regular function call (original) (raw)
| (Note: please ignore my prior email to gcc-bugs@gcc.gnu.org as this bug report replaces it. The .zip file included in my priot email didn't include the -save-temps .i output, whereas the .zip file attached to this report does) Dr. Ulrich Weigand (weigand@informatik.uni-erlangen.de) has analyzed this bug as follows: "This would appear to be a gcc bug. Specifically, what appears to happen here is that instruction scheduling moves the leal across the call to __alloca. This in turn is caused by a bug in the cygwin prolog generation code that emits the __alloca call as a regular function call." "As regular function calls do not change the stack pointer, the instruction scheduling pass concluded that it was safe to move the leal 16(%esp),%edi across the call (%edi is preserved across calls as well)." "Instead, the __alloca call should have been annotated to express the fact that it changes %esp in a special way. How to best fix this I'd leave to the i386 backend maintainers; please report this bug (with testcase and explanation) to the gcc bug-tracking system." "(From what I can see, the same bug exists unchanged in gcc 3.2.1 and the current pre-3.3 sources. As this particular code path is only used for cygwin, it probably wasn't noticed earlier ...)" Release: gcc version 3.2 20020927 (prerelease) Environment: PIII 800MHz Windows 2000 Pro SP3 Cygwin 1.3.16-1 gcc 3.2-3 $ uname -a CYGWIN_NT-5.0 (censored) 1.3.16(0.65/3/2) 2002-11-22 22:18 i686 unknown How-To-Repeat: fish@foobar ~/fishtest $ cat fish.c #include <stdio.h> #include <string.h> void foo () { char a[15000]; a[0]=0; printf("String length=%d\n",strlen(a)); memset( &a[0], 0xCD, 13371 ); a[13371]=0; printf("String length=%d\n",strlen(a)); } int main ( int argc, char* argv[] ) { foo(); return 0; } fish@foobar ~/fishtest $ gcc -march=i686 -g -O2 -fomit-frame-pointer -c fish.c -Wa,-adhln=fish.c.listing.txt fish@foobar ~/fishtest $ gcc -march=i686 -g -O2 -fomit-frame-pointer -o fish.exe fish.o fish@foobar ~/fishtest $ fish String length=2 Comment 1 fish 2002-11-28 13:26:00 UTC Fix: 1. -O0 or -O1, or... 2. -fno-omit-frame-pointer, or... 3. use memset len < 13371, or... 4. don't use largish local stack vars so as to prevent __alloca from being called/used. Comment 2 danny_r_smith_2001 2002-12-20 06:06:43 UTC From: =?iso-8859-1?q?Danny=20Smith?= <danny_r_smith_2001@yahoo.co.nz> To: hercules-390@yahoogroups.com, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, zHercules@yahoogroups.com, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org, fish@infidels.org Cc: Subject: Re: optimization/8750: Cygwin prolog generation erroneously emitting __alloca as regular function call Date: Fri, 20 Dec 2002 06:06:43 +1100 (EST) http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8750 The followin fixes PR optimization/8750, a serious regression from 2.95 on W32 targets (which set TARGET_STACK_PROBE) Tested on 3.2 and 3.3 branches with i386-pc-mingw32. Can someone with more knowledge of 1386 backend please review and perhaps suggest less naive fix. ChangeLog 2002-12-19 Danny Smith <dannysmith@users.sourceforge.net> PR optimization/8750 * config/i386/i386.c (ix86_expand_prologue): Don't allow scheduling pass to move insns across __alloca call. Index: i386.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v retrieving revision 1.495 diff -c -3 -p -r1.495 i386.c *** i386.c 9 Dec 2002 23:53:59 -0000 1.495 --- i386.c 19 Dec 2002 10:44:08 -0000 *************** ix86_expand_prologue () *** 4516,4521 **** --- 4516,4525 ---- CALL_INSN_FUNCTION_USAGE (insn) = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, arg0), CALL_INSN_FUNCTION_USAGE (insn)); + + /* Don't allow scheduling pass to move insns across __alloca + call. */ + emit_insn (gen_blockage (const0_rtx)); } if (use_mov) { http://greetings.yahoo.com.au - Yahoo! Greetings - Send your seasons greetings online this year! Comment 6 Eric Botcazou 2003-02-18 13:48:54 UTC Responsible-Changed-From-To: unassigned->dannysmith Responsible-Changed-Why: Submitter of the fix. Comment 7 Eric Botcazou 2003-02-18 13:48:54 UTC State-Changed-From-To: open->analyzed State-Changed-Why: Do you plan to backport the patch to the 3.2 branch? If no, please close the bug. Comment 9 Danny Smith 2003-04-29 00:50:47 UTC State-Changed-From-To: analyzed->closed State-Changed-Why: Fixed in 3.3 Comment 10 Drea Pinski 2003-05-28 13:07:30 UTC *** Bug 9185 has been marked as a duplicate of this bug. *** Comment 11 Drea Pinski 2003-05-28 13:12:46 UTC *** Bug 8437 has been marked as a duplicate of this bug. *** | | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |