public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
@ 2014-11-15 15:19 fxcoudert at gcc dot gnu.org
  2014-11-15 15:20 ` [Bug target/63890] " fxcoudert at gcc dot gnu.org
                   ` (24 more replies)
  0 siblings, 25 replies; 26+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2014-11-15 15:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

            Bug ID: 63890
           Summary: [4.9/5.0 regression] Compiling trivial program with -O
                    -p leads to misaligned stack
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fxcoudert at gcc dot gnu.org

Created attachment 33985
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33985&action=edit
Assembler generated by trunk compiler with "-m32 -O -p"

Compile the following trivial program with trunk (rev. 217599) or the released
4.9.2 gcc leads to runtime segfault, on x86_64-apple-darwin14:

$ cat a.c
int main (void) { __builtin_exit (0); }
$ ./bin/gcc -m32 -O -p a.c && ./a.out
zsh: segmentation fault  ./a.out

This shows up as a failure of gcc.dg/20021014-1.c in the testsuite results
(https://gcc.gnu.org/ml/gcc-testresults/2014-11/msg01533.html).

Removing -p, or -O, or compiling for 64-bit doesn't trigger the bug. The
backtrace is:

  * frame #0: 0x9036f440 libdyld.dylib`misaligned_stack_error_
    frame #1: 0x00001f75 a.out`main + 17
    frame #2: 0x903716d9 libdyld.dylib`start + 1

Comparing the generated assembly by the trunk compiler (bad-trunk.s) with that
generated by the 4.8.3 compiler (ok-48.s) shows the difference is simple:

--- ok-48.s    2014-11-15 16:17:55.000000000 +0100
+++ bad-trunk.s    2014-11-15 16:17:44.000000000 +0100
@@ -1,4 +1,4 @@
-    .text
+    .section __TEXT,__text_startup,regular,pure_instructions
     .globl _main
 _main:
 LFB0:
@@ -7,12 +7,12 @@ LCFI0:
     movl    %esp, %ebp
 LCFI1:
     pushl    %ebx
-    subl    $20, %esp
+    subl    $16, %esp
 LCFI2:
     call    ___x86.get_pc_thunk.bx
 L1$pb:
     call mcount
-    movl    $0, (%esp)
+    pushl    $0
     call    _exit
 LFE0:
     .section __TEXT,__textcoal_nt,coalesced,pure_instructions


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
@ 2014-11-15 15:20 ` fxcoudert at gcc dot gnu.org
  2014-11-15 15:45 ` fxcoudert at gcc dot gnu.org
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2014-11-15 15:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Target|                            |x86_64-apple-darwin14
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-11-15
               Host|                            |x86_64-apple-darwin14
     Ever confirmed|0                           |1
              Build|                            |x86_64-apple-darwin14


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
  2014-11-15 15:20 ` [Bug target/63890] " fxcoudert at gcc dot gnu.org
@ 2014-11-15 15:45 ` fxcoudert at gcc dot gnu.org
  2014-11-15 16:01 ` iains at gcc dot gnu.org
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2014-11-15 15:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |iains at gcc dot gnu.org,
                   |                            |mikestump at comcast dot net

--- Comment #1 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
Also failing due to the same bug: gcc.dg/pr43643.c


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
  2014-11-15 15:20 ` [Bug target/63890] " fxcoudert at gcc dot gnu.org
  2014-11-15 15:45 ` fxcoudert at gcc dot gnu.org
@ 2014-11-15 16:01 ` iains at gcc dot gnu.org
  2014-11-15 16:24 ` dominiq at lps dot ens.fr
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: iains at gcc dot gnu.org @ 2014-11-15 16:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

Iain Sandoe <iains at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |evstupac at gmail dot com

--- Comment #2 from Iain Sandoe <iains at gcc dot gnu.org> ---
confirmed on x86_64-darwin12 (217256 gcc04.9 and recent trunk).

this would presumably affect targets other than darwin, too.

looks like the call to the pic base is both (a) unnecessary and (b) hoisted too
early in the routine.  Having said that, the call to mvount would fail if the
thunk call was dropped.

possibly? more fallout from the EBX changes? (maybe not, but worth a look).


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2014-11-15 16:01 ` iains at gcc dot gnu.org
@ 2014-11-15 16:24 ` dominiq at lps dot ens.fr
  2014-11-15 16:42 ` dominiq at lps dot ens.fr
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-11-15 16:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #3 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> possibly? more fallout from the EBX changes? (maybe not, but worth a look).

I doubt it: r203168 (2013-10-03) is OK, r203190 (2013-10-03) is not.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2014-11-15 16:24 ` dominiq at lps dot ens.fr
@ 2014-11-15 16:42 ` dominiq at lps dot ens.fr
  2014-11-15 16:46 ` iains at gcc dot gnu.org
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-11-15 16:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #4 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
>From archives on x86_64-apple-darwin10, the problem was already there at
r203176.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-11-15 16:42 ` dominiq at lps dot ens.fr
@ 2014-11-15 16:46 ` iains at gcc dot gnu.org
  2014-11-15 18:11 ` iains at gcc dot gnu.org
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: iains at gcc dot gnu.org @ 2014-11-15 16:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #5 from Iain Sandoe <iains at gcc dot gnu.org> ---

recent trunk on linux -m32 -O -p doesn't segv 
- but the stack looks odd at the mcount call.

    .file    "t.c"
    .text
    .globl    main
    .type    main, @function
main:
.LFB0:
    .cfi_startproc
    leal    4(%esp), %ecx
    .cfi_def_cfa 1, 0
    andl    $-16, %esp
    pushl    -4(%ecx)
    pushl    %ebp
    .cfi_escape 0x10,0x5,0x2,0x75,0
    movl    %esp, %ebp
    pushl    %ecx
    .cfi_escape 0xf,0x3,0x75,0x7c,0x6
    subl    $16, %esp
1:    call    mcount
    pushl    $0
    call    exit
    .cfi_endproc
.LFE0:
    .size    main, .-main
    .ident    "GCC: (GNU) 5.0.0 20141112 (experimental) [trunk revision
217427]"
    .section    .note.GNU-stack,"",@progbits


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2014-11-15 16:46 ` iains at gcc dot gnu.org
@ 2014-11-15 18:11 ` iains at gcc dot gnu.org
  2014-11-17  9:32 ` rguenth at gcc dot gnu.org
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: iains at gcc dot gnu.org @ 2014-11-15 18:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

Iain Sandoe <iains at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at ucw dot cz, jh at suse dot cz

--- Comment #6 from Iain Sandoe <iains at gcc dot gnu.org> ---
(In reply to Dominique d'Humieres from comment #4)
> From archives on x86_64-apple-darwin10, the problem was already there at
> r203176.

yup - looks like 203171 or 203172.

Honza, all yours :)


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2014-11-15 18:11 ` iains at gcc dot gnu.org
@ 2014-11-17  9:32 ` rguenth at gcc dot gnu.org
  2014-11-24 16:58 ` rguenth at gcc dot gnu.org
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-17  9:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.9.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2014-11-17  9:32 ` rguenth at gcc dot gnu.org
@ 2014-11-24 16:58 ` rguenth at gcc dot gnu.org
  2015-02-24 22:41 ` [Bug target/63890] [4.9/5 " mrs at gcc dot gnu.org
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-24 16:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
      Known to work|                            |4.8.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2014-11-24 16:58 ` rguenth at gcc dot gnu.org
@ 2015-02-24 22:41 ` mrs at gcc dot gnu.org
  2015-02-25  2:16 ` mrs at gcc dot gnu.org
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: mrs at gcc dot gnu.org @ 2015-02-24 22:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

mrs at gcc dot gnu.org <mrs at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrs at gcc dot gnu.org

--- Comment #8 from mrs at gcc dot gnu.org <mrs at gcc dot gnu.org> ---
Yes, the stack must be suitably aligned before the call to mcount.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2015-02-24 22:41 ` [Bug target/63890] [4.9/5 " mrs at gcc dot gnu.org
@ 2015-02-25  2:16 ` mrs at gcc dot gnu.org
  2015-02-25  4:24 ` mrs at gcc dot gnu.org
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: mrs at gcc dot gnu.org @ 2015-02-25  2:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #9 from mrs at gcc dot gnu.org <mrs at gcc dot gnu.org> ---
This is caused by:

--- ChangeLog   (revision 203170)
+++ ChangeLog   (revision 203171)
@@ -1,3 +1,8 @@
+2013-10-03  Jan Hubicka  <jh@suse.cz>
+
+       * i386.c (ix86_option_override_internal): Do not enable
+       accumulate-outgoing-args when producing unwind info.


Without saying if this is the right approach, I can just note that it works.

Index: config/i386/i386.h
===================================================================
--- config/i386/i386.h    (revision 220946)
+++ config/i386/i386.h    (working copy)
@@ -1606,7 +1606,7 @@ enum reg_class

 #define ACCUMULATE_OUTGOING_ARGS \
   ((TARGET_ACCUMULATE_OUTGOING_ARGS && optimize_function_for_speed_p (cfun)) \
-   || TARGET_STACK_PROBE || TARGET_64BIT_MS_ABI)
+   || TARGET_STACK_PROBE || TARGET_64BIT_MS_ABI || crtl->profile)

 /* If defined, a C expression whose value is nonzero when we want to use PUSH
    instructions to pass outgoing arguments.  */

The idea is, if mcount requires alignment of the stack, and outgoing arguments
is the only way to get that, then it would makes sense to have -p imply
outgoing arguments.

Previously on darwin we had flag_asynchronous_unwind_tables which turned on
target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS, which ensured that
TARGET_ACCUMULATE_OUTGOING_ARGS was true which was enough to ensure that
ACCUMULATE_OUTGOING_ARGS was true.

If linux and all other x86 ports also needs stack alignment in mcount, then the
above should be correct.  If not, then darwin needs to ask specially, since no
one else does.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2015-02-25  2:16 ` mrs at gcc dot gnu.org
@ 2015-02-25  4:24 ` mrs at gcc dot gnu.org
  2015-02-25  6:46 ` hubicka at ucw dot cz
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: mrs at gcc dot gnu.org @ 2015-02-25  4:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

mrs at gcc dot gnu.org <mrs at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major

--- Comment #10 from mrs at gcc dot gnu.org <mrs at gcc dot gnu.org> ---
Bump priority to RMs can make informed decisions.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (11 preceding siblings ...)
  2015-02-25  4:24 ` mrs at gcc dot gnu.org
@ 2015-02-25  6:46 ` hubicka at ucw dot cz
       [not found] ` <bug-63890-4-n8faGCUNTz@http.gcc.gnu.org/bugzilla/>
                   ` (11 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: hubicka at ucw dot cz @ 2015-02-25  6:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #11 from Jan Hubicka <hubicka at ucw dot cz> ---
> 
> Index: config/i386/i386.h
> ===================================================================
> --- config/i386/i386.h    (revision 220946)
> +++ config/i386/i386.h    (working copy)
> @@ -1606,7 +1606,7 @@ enum reg_class
> 
>  #define ACCUMULATE_OUTGOING_ARGS \
>    ((TARGET_ACCUMULATE_OUTGOING_ARGS && optimize_function_for_speed_p (cfun)) \
> -   || TARGET_STACK_PROBE || TARGET_64BIT_MS_ABI)
> +   || TARGET_STACK_PROBE || TARGET_64BIT_MS_ABI || crtl->profile)

I do not see how ACCUMULATE_OUTGOING_ARGS is going to ensure mcount stack
alignment.
the calls are output into assembly code by:
/* Output assembler code to FILE to increment profiler label # LABELNO          
   for profiling a function entry.  */                                          
void                                                                            
x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)                
{                                                                               
  const char *mcount_name = (flag_fentry ? MCOUNT_NAME_BEFORE_PROLOGUE          
                                         : MCOUNT_NAME);                        
  if (TARGET_64BIT)                                                             
    {                                                                           
#ifndef NO_PROFILE_COUNTERS                                                     
      fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno);         
#endif                                                                          

      if (!TARGET_PECOFF && flag_pic)                                           
        fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);         
      else                                                                      
        x86_print_call_or_nop (file, mcount_name);                              
    }                                                                           

that does not care about ACCUMULATE_OUTGOING_ARGS.  We basically get alignment
by accident because we push RBP.  

My guess is that you want to bump crtl->stack_alignment_needed to 64bits for
every function with crtl->profile


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
       [not found] ` <bug-63890-4-n8faGCUNTz@http.gcc.gnu.org/bugzilla/>
@ 2015-02-27  8:29   ` Jan Hubicka
  0 siblings, 0 replies; 26+ messages in thread
From: Jan Hubicka @ 2015-02-27  8:29 UTC (permalink / raw)
  To: jakub at gcc dot gnu.org; +Cc: gcc-bugs

Hi,
the problem is that darwin output profiler after prologue.
With ACCUMULATE_OUTGOING_ARGS we leave stack pointer aligned to boundary - 4
(for return pointer) without we leave it aligned.
I guess it is possible to compensate this in FUNCTION_PROFILER, but I am not
convinced this will work reliably. Probably disabling combine-stack-adjustments
would be needed, too.
(I do not think it is reliable with ACCUMULATE_OUTGOING_ARGS either)

Honza

Index: config/i386/darwin.h
===================================================================
--- config/i386/darwin.h	(revision 221034)
+++ config/i386/darwin.h	(working copy)
@@ -210,6 +210,8 @@ extern int darwin_emit_branch_islands;
 #undef FUNCTION_PROFILER
 #define FUNCTION_PROFILER(FILE, LABELNO)				\
     do {								\
+      if (!ACCUMULATE_OUTGOING_ARGS)					\
+        fprintf (FILE, "\tpushl %%ebx\n");  /*  Align stack  */		\
       if (TARGET_MACHO_BRANCH_ISLANDS 					\
 	   && MACHOPIC_INDIRECT && !TARGET_64BIT)			\
 	{								\
@@ -218,6 +220,8 @@ extern int darwin_emit_branch_islands;
 	  machopic_validate_stub_or_non_lazy_ptr (name);		\
 	}								\
       else fprintf (FILE, "\tcall mcount\n");				\
+      if (!ACCUMULATE_OUTGOING_ARGS)					\
+       fprintf (FILE, "\tpopl %%ebx\n");  /*  Align stack  */		\
     } while (0)
 
 #define C_COMMON_OVERRIDE_OPTIONS					\
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 221034)
+++ config/i386/i386.c	(working copy)
@@ -10061,6 +10061,13 @@ ix86_compute_frame_layout (struct ix86_f
       if (crtl->stack_alignment_needed < PREFERRED_STACK_BOUNDARY)
 	crtl->stack_alignment_needed = PREFERRED_STACK_BOUNDARY;
     }
+  /* Be sure we get stack aligned for mcount call.  */
+  else if (crtl->profile && flag_fentry)
+    {
+      crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
+      if (crtl->stack_alignment_needed < PREFERRED_STACK_BOUNDARY)
+	crtl->stack_alignment_needed = PREFERRED_STACK_BOUNDARY;
+    }
 
   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (13 preceding siblings ...)
       [not found] ` <bug-63890-4-n8faGCUNTz@http.gcc.gnu.org/bugzilla/>
@ 2015-02-27  8:38 ` hubicka at ucw dot cz
  2015-03-01 20:42 ` howarth at bromo dot med.uc.edu
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: hubicka at ucw dot cz @ 2015-02-27  8:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #12 from Jan Hubicka <hubicka at ucw dot cz> ---
Hi,
the problem is that darwin output profiler after prologue.
With ACCUMULATE_OUTGOING_ARGS we leave stack pointer aligned to boundary - 4
(for return pointer) without we leave it aligned.
I guess it is possible to compensate this in FUNCTION_PROFILER, but I am not
convinced this will work reliably. Probably disabling combine-stack-adjustments
would be needed, too.
(I do not think it is reliable with ACCUMULATE_OUTGOING_ARGS either)

Honza

Index: config/i386/darwin.h
===================================================================
--- config/i386/darwin.h    (revision 221034)
+++ config/i386/darwin.h    (working copy)
@@ -210,6 +210,8 @@ extern int darwin_emit_branch_islands;
 #undef FUNCTION_PROFILER
 #define FUNCTION_PROFILER(FILE, LABELNO)                \
     do {                                \
+      if (!ACCUMULATE_OUTGOING_ARGS)                    \
+        fprintf (FILE, "\tpushl %%ebx\n");  /*  Align stack  */        \
       if (TARGET_MACHO_BRANCH_ISLANDS                     \
        && MACHOPIC_INDIRECT && !TARGET_64BIT)            \
     {                                \
@@ -218,6 +220,8 @@ extern int darwin_emit_branch_islands;
       machopic_validate_stub_or_non_lazy_ptr (name);        \
     }                                \
       else fprintf (FILE, "\tcall mcount\n");                \
+      if (!ACCUMULATE_OUTGOING_ARGS)                    \
+       fprintf (FILE, "\tpopl %%ebx\n");  /*  Align stack  */        \
     } while (0)

 #define C_COMMON_OVERRIDE_OPTIONS                    \
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c    (revision 221034)
+++ config/i386/i386.c    (working copy)
@@ -10061,6 +10061,13 @@ ix86_compute_frame_layout (struct ix86_f
       if (crtl->stack_alignment_needed < PREFERRED_STACK_BOUNDARY)
     crtl->stack_alignment_needed = PREFERRED_STACK_BOUNDARY;
     }
+  /* Be sure we get stack aligned for mcount call.  */
+  else if (crtl->profile && flag_fentry)
+    {
+      crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
+      if (crtl->stack_alignment_needed < PREFERRED_STACK_BOUNDARY)
+    crtl->stack_alignment_needed = PREFERRED_STACK_BOUNDARY;
+    }

   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (14 preceding siblings ...)
  2015-02-27  8:38 ` hubicka at ucw dot cz
@ 2015-03-01 20:42 ` howarth at bromo dot med.uc.edu
  2015-03-01 22:02 ` hubicka at gcc dot gnu.org
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: howarth at bromo dot med.uc.edu @ 2015-03-01 20:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

howarth at bromo dot med.uc.edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |howarth at bromo dot med.uc.edu

--- Comment #13 from howarth at bromo dot med.uc.edu ---
Is the change in Comment 12 awaiting a darwin maintainer review?


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (15 preceding siblings ...)
  2015-03-01 20:42 ` howarth at bromo dot med.uc.edu
@ 2015-03-01 22:02 ` hubicka at gcc dot gnu.org
  2015-03-01 23:19 ` mrs at gcc dot gnu.org
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: hubicka at gcc dot gnu.org @ 2015-03-01 22:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org

--- Comment #14 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
It needs testing on something larger first and investigation how this interfere
with combine-stack-adjustments.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (16 preceding siblings ...)
  2015-03-01 22:02 ` hubicka at gcc dot gnu.org
@ 2015-03-01 23:19 ` mrs at gcc dot gnu.org
  2015-03-01 23:26 ` hubicka at ucw dot cz
                   ` (6 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: mrs at gcc dot gnu.org @ 2015-03-01 23:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #15 from mrs at gcc dot gnu.org <mrs at gcc dot gnu.org> ---
Substantially changing code gen 2 days before release with inadequate testing
is slightly dangerous; seem more appropriate for stage 1.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (17 preceding siblings ...)
  2015-03-01 23:19 ` mrs at gcc dot gnu.org
@ 2015-03-01 23:26 ` hubicka at ucw dot cz
  2015-03-01 23:49 ` mrs at gcc dot gnu.org
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: hubicka at ucw dot cz @ 2015-03-01 23:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #16 from Jan Hubicka <hubicka at ucw dot cz> ---
> Substantially changing code gen 2 days before release with inadequate testing
> is slightly dangerous; seem more appropriate for stage 1.
What release you have in mind?
Honza


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (18 preceding siblings ...)
  2015-03-01 23:26 ` hubicka at ucw dot cz
@ 2015-03-01 23:49 ` mrs at gcc dot gnu.org
  2015-03-02  0:29 ` hubicka at ucw dot cz
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: mrs at gcc dot gnu.org @ 2015-03-01 23:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #17 from mrs at gcc dot gnu.org <mrs at gcc dot gnu.org> ---
I'm happy to defer the question to the person that reviews the patch for the
tree.  I'd like a codegen type person that understands the proposed change to
review it.  They may feel perfectly comfortable approving it for the tree now.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (19 preceding siblings ...)
  2015-03-01 23:49 ` mrs at gcc dot gnu.org
@ 2015-03-02  0:29 ` hubicka at ucw dot cz
  2015-03-30 13:17 ` iains at gcc dot gnu.org
                   ` (3 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: hubicka at ucw dot cz @ 2015-03-02  0:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #18 from Jan Hubicka <hubicka at ucw dot cz> ---
> I'm happy to defer the question to the person that reviews the patch for the
> tree.  I'd like a codegen type person that understands the proposed change to
> review it.  They may feel perfectly comfortable approving it for the tree now.

Well, I think the patch is in area I can review (though I would welcome second
opinion as I am nothappy about solution at all).

The way the call is output is broken by design.  final.c is outputting
optimized function body and after seeing NOTE_INSN_PROLOGUE_END it calls a hook
that output assembler blob in there. This made sense in early 90's but not much
today when prologues are optimized into rest of the code.  We make no promises
about stack alignment at the place NOTE_INSN_PROLOGUE_END is inserted.

So either someone needs to step forward and implement profile_before_prologue
version or we can go with a hack.  I do not have darwin setup to test either.

My understanding is that currently profiling is completely broken (segfaults
on empty propgram). If the patch helps profiling to be resonably working,
and lacking better altenatives I would go for it.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (20 preceding siblings ...)
  2015-03-02  0:29 ` hubicka at ucw dot cz
@ 2015-03-30 13:17 ` iains at gcc dot gnu.org
  2015-04-02  9:15 ` dominiq at lps dot ens.fr
                   ` (2 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: iains at gcc dot gnu.org @ 2015-03-30 13:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #19 from Iain Sandoe <iains at gcc dot gnu.org> ---
also failing from the same bug, gcc.dg/aru-2.c


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (21 preceding siblings ...)
  2015-03-30 13:17 ` iains at gcc dot gnu.org
@ 2015-04-02  9:15 ` dominiq at lps dot ens.fr
  2015-06-26 20:07 ` [Bug target/63890] [4.9/5/6 " jakub at gcc dot gnu.org
  2015-06-26 20:36 ` jakub at gcc dot gnu.org
  24 siblings, 0 replies; 26+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-04-02  9:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #20 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> also failing from the same bug, gcc.dg/aru-2.c

and likely gcc.dg/20021014-1.c.

The patch in comment 12 fixes

FAIL: gcc.dg/20021014-1.c execution test
FAIL: gcc.dg/aru-2.c execution test
FAIL: gcc.dg/pr43643.c execution test

but causes the following regressions

FAIL: g++.old-deja/g++.law/profile1.C  -std=gnu++11 execution test
FAIL: g++.old-deja/g++.law/profile1.C  -std=gnu++14 execution test
FAIL: g++.old-deja/g++.law/profile1.C  -std=gnu++98 execution test
FAIL: gcc.dg/nest.c execution test
FAIL: gcc.dg/nested-func-4.c execution test
FAIL: gcc.dg/pr32450.c execution test
FAIL: gcc.target/i386/mcount_pic.c execution test

(all with -m32).


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5/6 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (22 preceding siblings ...)
  2015-04-02  9:15 ` dominiq at lps dot ens.fr
@ 2015-06-26 20:07 ` jakub at gcc dot gnu.org
  2015-06-26 20:36 ` jakub at gcc dot gnu.org
  24 siblings, 0 replies; 26+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-26 20:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

--- Comment #21 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.9.3 has been released.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug target/63890] [4.9/5/6 regression] Compiling trivial program with -O -p leads to misaligned stack
  2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
                   ` (23 preceding siblings ...)
  2015-06-26 20:07 ` [Bug target/63890] [4.9/5/6 " jakub at gcc dot gnu.org
@ 2015-06-26 20:36 ` jakub at gcc dot gnu.org
  24 siblings, 0 replies; 26+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-06-26 20:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63890

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.3                       |4.9.4


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-06-26 20:35 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-15 15:19 [Bug target/63890] New: [4.9/5.0 regression] Compiling trivial program with -O -p leads to misaligned stack fxcoudert at gcc dot gnu.org
2014-11-15 15:20 ` [Bug target/63890] " fxcoudert at gcc dot gnu.org
2014-11-15 15:45 ` fxcoudert at gcc dot gnu.org
2014-11-15 16:01 ` iains at gcc dot gnu.org
2014-11-15 16:24 ` dominiq at lps dot ens.fr
2014-11-15 16:42 ` dominiq at lps dot ens.fr
2014-11-15 16:46 ` iains at gcc dot gnu.org
2014-11-15 18:11 ` iains at gcc dot gnu.org
2014-11-17  9:32 ` rguenth at gcc dot gnu.org
2014-11-24 16:58 ` rguenth at gcc dot gnu.org
2015-02-24 22:41 ` [Bug target/63890] [4.9/5 " mrs at gcc dot gnu.org
2015-02-25  2:16 ` mrs at gcc dot gnu.org
2015-02-25  4:24 ` mrs at gcc dot gnu.org
2015-02-25  6:46 ` hubicka at ucw dot cz
     [not found] ` <bug-63890-4-n8faGCUNTz@http.gcc.gnu.org/bugzilla/>
2015-02-27  8:29   ` Jan Hubicka
2015-02-27  8:38 ` hubicka at ucw dot cz
2015-03-01 20:42 ` howarth at bromo dot med.uc.edu
2015-03-01 22:02 ` hubicka at gcc dot gnu.org
2015-03-01 23:19 ` mrs at gcc dot gnu.org
2015-03-01 23:26 ` hubicka at ucw dot cz
2015-03-01 23:49 ` mrs at gcc dot gnu.org
2015-03-02  0:29 ` hubicka at ucw dot cz
2015-03-30 13:17 ` iains at gcc dot gnu.org
2015-04-02  9:15 ` dominiq at lps dot ens.fr
2015-06-26 20:07 ` [Bug target/63890] [4.9/5/6 " jakub at gcc dot gnu.org
2015-06-26 20:36 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).