public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/32577]  New: [SH] static inline attribute causes stack overflow
@ 2007-07-02  2:52 saito at densan dot co dot jp
  2007-07-02 14:21 ` [Bug target/32577] " kkojima at gcc dot gnu dot org
  2007-07-23  1:23 ` saito at densan dot co dot jp
  0 siblings, 2 replies; 3+ messages in thread
From: saito at densan dot co dot jp @ 2007-07-02  2:52 UTC (permalink / raw)
  To: gcc-bugs

When I use static inline attribute without any optimization as follows, stack
space is stacked. As a result, a stack overflow is caused. This problem came
from using gcc-4.2.0 for linux kernel which uses many inlines.

-compile options---------------------
sh4-linux-gcc -S test.c

-testcase #1-----------------------
static inline __attribute__((always_inline)) int add(int x, int y)
{
    return x + y;
}

int x, y;

main(int ac, char** av)
{
    x = add(x, y);
    return x;
}

-testcase #2-----------------------
static inline __attribute__((always_inline)) int add(int x, int y)
{
    return x + y;
}

int x, y;

main(int ac, char** av)
{
    x = add(x, y);
    x = add(x, y);
    return x;
}

-assembled code for testcase #1---------------------------
        .global main
        .type   main, @function
main:
        mov.l   r14,@-r15
        add     #-16,r15
        mov     r15,r14
        mov     r14,r1
        add     #-48,r1
        mov.l   r4,@(52,r1)
        ...

-assembled code for testcase #2---------------------------
        .global main
        .type   main, @function
main:
        mov.l   r14,@-r15
        add     #-24,r15     <-- stack grows down
        mov     r15,r14
        mov     r14,r1
        add     #-40,r1
        mov.l   r4,@(44,r1)
        ...


-- 
           Summary: [SH] static inline attribute causes stack overflow
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: saito at densan dot co dot jp
 GCC build triplet: sh4-linux
  GCC host triplet: sh4-linux
GCC target triplet: sh4-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32577


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

* [Bug target/32577] [SH] static inline attribute causes stack overflow
  2007-07-02  2:52 [Bug target/32577] New: [SH] static inline attribute causes stack overflow saito at densan dot co dot jp
@ 2007-07-02 14:21 ` kkojima at gcc dot gnu dot org
  2007-07-23  1:23 ` saito at densan dot co dot jp
  1 sibling, 0 replies; 3+ messages in thread
From: kkojima at gcc dot gnu dot org @ 2007-07-02 14:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from kkojima at gcc dot gnu dot org  2007-07-02 14:21 -------
I don't think that this is a bug.  Without optimization, all
intermediate variables can be allocated on stack.  It's the case
even on other architectures.  The test case #2 is compiled to

        pushl   %ebp
        movl    %esp, %ebp
        subl    $16, %esp
        movl    y, %edx
        movl    x, %eax
        movl    %eax, -12(%ebp)

on x86 with -O0 and if you added two more x = add(x,y); lines to
#2, you got

        pushl   %ebp
        movl    %esp, %ebp
        subl    $32, %esp
        movl    y, %edx
        movl    x, %eax
        movl    %eax, -28(%ebp)

i.e. more invocations of inline functions requires more intermediate
variables and stack area.  Reducing the number of such variables or
using hardware registers for them if possible is already an optimization
and is not expected with -O0.


-- 

kkojima at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32577


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

* [Bug target/32577] [SH] static inline attribute causes stack overflow
  2007-07-02  2:52 [Bug target/32577] New: [SH] static inline attribute causes stack overflow saito at densan dot co dot jp
  2007-07-02 14:21 ` [Bug target/32577] " kkojima at gcc dot gnu dot org
@ 2007-07-23  1:23 ` saito at densan dot co dot jp
  1 sibling, 0 replies; 3+ messages in thread
From: saito at densan dot co dot jp @ 2007-07-23  1:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from saito at densan dot co dot jp  2007-07-23 01:23 -------
How about following testcase. 

I list the value which moves current sp as to some architectures.
In the following case, listed value is 24.

>         add     #-24,r15     <-- stack grows down

With the result that only gcc-4.2.0 for sh4 accumulates the stack space for
inlined variables. Actually, I need to spread the stack size for sh-linux's
kernel-thread from 0x2000 byte to 0x4000 byte, although I specify optimization
option(-O2). Gcc-4.1.2 does not have this problem.

-testcase--------------------------------------------------
struct xxx {
    int x;
    int y;
};

static inline __attribute__((always_inline)) int add(int x, int y)
{
    struct xxx xxx;
    xxx.x = x;
    xxx.y = y;
    dummy(&xxx);
    return x + y;
}

int x, y;

main(int ac, char** av)
{
    x = add(x, y);      /* count of add is one */
    return x;
}
-end testcase----------------------------------------------

compiling options: gcc test.c -O2 -S

case of gcc-4.2.0
-----------------------------------------------------------
count of add     |      1      2      4      8     16
-------------------------------------------------------------
the value    sh4 |      8     16     24     40     68
             ppc |     48     64     64     64     64
            i686 |     16     16     16     16     16

case of gcc-4.1.2
-----------------------------------------------------------
the value    sh4 |      8      8      8      8      8


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32577


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

end of thread, other threads:[~2007-07-23  1:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-02  2:52 [Bug target/32577] New: [SH] static inline attribute causes stack overflow saito at densan dot co dot jp
2007-07-02 14:21 ` [Bug target/32577] " kkojima at gcc dot gnu dot org
2007-07-23  1:23 ` saito at densan dot co dot jp

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).