Operating System - HP-UX
1826314 Members
3775 Online
109692 Solutions
New Discussion

Re: Application receive a SIGSEGV for stack growth failure

 
SOLVED
Go to solution
Ravi Nallappan
New Member

Application receive a SIGSEGV for stack growth failure

Hi,

I came across this rather unusual scenario and wonder why it behave as such:

OS: HPUX 11.11
Application : C
Compiler: HP C/HP-UX Compiler B.11.11.16

One of my application crashes with above error message, upon inspecting core, found that a function used up about 8MiB of stack size.

Here is simple program I wrote to reproduce the issue:

------test.c-------------
#include

struct _a_data {
int x ;
int y ;
int z ;
} ;
typedef struct _a_data *a_data_ptr ;

int func1( void ) {
int i = 0 ;
int num = 1 ;

while ( i < 3000000 ) {
a_data_ptr data[num] ;
int j ;
i++ ;
}
return 0 ;
}

int main( void ) {
printf("Yahoo1\n") ;
func1() ;
printf("Yahoo2\n") ;
return 0 ;
}
-------------------------

Compile and run as follow:
cc -g test2.c
gdb a.out
(gdb) break 28 # -> i++ ;
(gdb) run

Tracing $sp on every loop reveals that it used up additional 64 bytes per loop.

---------------------------
:
25 while ( i < 30000 ) {
(gdb) print $sp
$2 = 2139032080
(gdb) next
:
25 while ( i < 30000 ) {
(gdb) print $sp
$3 = 2139032144

---------------------------

And the stack size does not increase if
"a_data_ptr data[num] ;"
is removed, or use of other data types i.e "int x;" etc

Why such behavior? It is related to PA-RISC 2.0 feature or just a bug in compiler?

Thanks.
3 REPLIES 3
Dennis Handly
Acclaimed Contributor
Solution

Re: Application receive a SIGSEGV for stack growth failure

This works fine on Integrity, where the default is C99.

>Why such behavior? or just a bug in compiler?

It's a bug in the C99 VLA implementation. It doesn't understand block scoping. You should move it out of the loop.

Please contact the Response Center to report this bug.
Dennis Handly
Acclaimed Contributor

Re: Application receive a SIGSEGV for stack growth failure

This also works fine on PA using "aCC -AC99".
Ravi Nallappan
New Member

Re: Application receive a SIGSEGV for stack growth failure

Thanks Dennis, Thats answered my question.