Bug 28621 - [4.1 Regression] SIGSEGV in set_fast_math () at -Os
Summary: [4.1 Regression] SIGSEGV in set_fast_math () at -Os
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.1.1
: P1 blocker
Target Milestone: 4.1.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 13685 33721
Blocks:
  Show dependency treegraph
 
Reported: 2006-08-06 17:08 UTC by Marco Aurélio Graciotto Silva
Modified: 2007-10-10 04:12 UTC (History)
4 users (show)

See Also:
Host:
Target: ix86-*-*
Build:
Known to work: 4.2.0 4.1.2 4.0.0
Known to fail:
Last reconfirmed: 2006-08-08 00:29:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Aurélio Graciotto Silva 2006-08-06 17:08:04 UTC
After build a new version of procps using the "-Os" flag for gcc, all its (procps) software (ps, top, etc) were failing due to a segmentation fault. I couldn't find a report about that at Bugzilla, but I did find one at "http://www.netdomination.org/~stkn/index.php?/archives/24-Anatomy-of-a-segfault....html". Although the author of that report was using ulibc (and I glibc), it applied perfectly to my case. After I removed the "-ffast-math" from the procps compile command, everything worked fine again.
Comment 2 H.J. Lu 2006-08-06 18:29:13 UTC
The main problem is bug 27537. That is -Os aligns stack at 4 bytes and the other
part of i386 backend assumes stack aliged at 16byte. We can word around this by

1. Don't include crtfastmath.o for -m32.
2. Make crtfastmath.o dummy for -m32.
3. Use a static variable to align at 16byte.
4. Compile crtfastmath.o with -mstackrealign. Need to backport -mstackrealign to
4.1?
5. Fix i386 backend only to assume 4byte stack alignment.

The easiest one is #2 or #3. The idel one is #5.
Comment 3 Jan Hubicka 2006-08-07 10:18:50 UTC
Hi,
because of quite serve register pressure issues, I don't like much idea of GCC realocating stack transparently (it is also dificult to teach reload to decide when alignment is needed).  Safe bugfix for 4.2 seems to be this:
	PR target/28621
	* crtfastmath.c (force_align_arg_pointer): Force stack alignment.
Index: config/i386/crtfastmath.c
===================================================================
-u -L config/i386/crtfastmath.c	(revision 115987) -L config/i386/crtfastmath.c	(working copy) config/i386/.svn/text-base/crtfastmath.c.svn-base config/i386/crtfastmath.c
--- config/i386/crtfastmath.c	(revision 115987)
+++ config/i386/crtfastmath.c	(working copy)
@@ -38,6 +38,9 @@
 #define SSE	(1 << 25)
 
 static void __attribute__((constructor))
+#ifndef __x86_64__
+__attribute__ ((force_align_arg_pointer))
+#endif
 set_fast_math (void)
 {
 #ifndef __x86_64__

Does it help?
Honza
Comment 4 Marco Aurélio Graciotto Silva 2006-08-11 13:27:22 UTC
(In reply to comment #3)
> --- config/i386/crtfastmath.c   (revision 115987)
> +++ config/i386/crtfastmath.c   (working copy)
> @@ -38,6 +38,9 @@
>  #define SSE    (1 << 25)
> 
>  static void __attribute__((constructor))
> +#ifndef __x86_64__
> +__attribute__ ((force_align_arg_pointer))
> +#endif
>  set_fast_math (void)
>  {
>  #ifndef __x86_64__
> 
> Does it help?

I applied this patch against the gcc 4.1.1, but the bug is still there (at least procps keeps segfaulting).
Comment 5 Andrew Pinski 2006-08-18 04:34:41 UTC
(In reply to comment #4)
> I applied this patch against the gcc 4.1.1, but the bug is still there (at
> least procps keeps segfaulting).

4.1.1 did not have the force_align_arg_pointer attribute so what do you expect.
Comment 6 Marco Aurélio Graciotto Silva 2006-08-18 07:16:23 UTC
Sorry, but I didn't know that. I reported the bug against GCC 4.1.1 and the target milestone set for it is GCC 4.1.2. So, I expected that patch to work with gcc 4.1.x. The 'force_align_arg_pointer' attribute is available at GCC 4.1.2 or just GCC 4.2.x?
Comment 7 Andrew Pinski 2006-08-18 11:42:55 UTC
(In reply to comment #6)
> Sorry, but I didn't know that. I reported the bug against GCC 4.1.1 and the
> target milestone set for it is GCC 4.1.2. So, I expected that patch to work
> with gcc 4.1.x. The 'force_align_arg_pointer' attribute is available at GCC
> 4.1.2 or just GCC 4.2.x?

Just 4.2.0 which right now the trunk (aka mainline) of the svn.
Comment 8 Paul Brook 2006-08-25 20:40:22 UTC
Subject: Bug 28621

Author: pbrook
Date: Fri Aug 25 20:39:48 2006
New Revision: 116431

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116431
Log:
2006-08-25  Jan Hubicka  <jh@suse.cz>

	PR target/28621
	* config/i386/crtfastmath.c (set_fast_math): Force stack alignment.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/crtfastmath.c

Comment 9 H.J. Lu 2006-09-08 00:51:04 UTC
Fix for PR 13685 should also fix this bug. In fact, we can back out the
change in comment #3.

Comment 10 H.J. Lu 2006-09-08 00:52:52 UTC
We can even back out the patch and close it as a dup for PR 13685.
Comment 11 Andrew Pinski 2006-09-08 01:18:47 UTC
(In reply to comment #10)
> We can even back out the patch and close it as a dup for PR 13685.
Not really and here is why:
-Os on the file containing main will still crash.  -Os -msse on the file with main will not crash.
Comment 12 hjl@gcc.gnu.org 2006-09-11 21:34:17 UTC
Subject: Bug 28621

Author: hjl
Date: Mon Sep 11 21:34:06 2006
New Revision: 116860

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116860
Log:
gcc/

2006-09-11  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/13685
	PR target/27537
	PR target/28621
	* config/i386/i386.c (override_options): Always default to 16
	byte stack boundary.

gcc/testsuite/

2006-09-11  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/13685
	* gcc.target/i386/pr13685.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr13685.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/testsuite/ChangeLog

Comment 13 hjl@gcc.gnu.org 2006-09-12 02:54:58 UTC
Subject: Bug 28621

Author: hjl
Date: Tue Sep 12 02:54:42 2006
New Revision: 116870

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116870
Log:
gcc/

2006-09-11  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/13685
	PR target/27537
	PR target/28621
	* config/i386/i386.c (override_options): Always default to 16
	byte stack boundary.

gcc/testsuite/

2006-09-11  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/13685
	* gcc.target/i386/pr13685.c: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.target/i386/pr13685.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/config/i386/i386.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 14 H.J. Lu 2006-09-12 05:34:37 UTC
Fixed.