Subject: Re: port-i386/1974: Large static structures cause program to segmentation fault upon execution
To: None <netbsd-bugs@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 01/25/1996 11:30:47
> >Synopsis:       Large static structures cause program to segmentation fault upon execution

> 	Declaring and instance of a large strucuture in the main
> 	program causes the program to segmentation fault

> typedef struct Graph {
> [...aproximately 513K...]
> } Graph;
> 
> int main() {
>   Graph g;
>   int i, j;

Um, that isn't a "[l]arge static structure"; it's a large _automatic_
structure.  This is a significant difference.  You are almost certainly
running into the wild-stack-pointer problem.

The stack is grown automatically whenever the process refers to
addresses that are within a certain zone past the end of the stack
segment.  But when you declare a huge automatic object (like g, above,
or "char foo[525000];"), the process ends up trying to grow the stack
by an enormous amount in one leap.  If the step is too big, the
reference appears to the kernel as a reference to a random (illegal)
address, rather than an attempt to grow the stack.  A proper kernel
will base its checks solely on the stacksize limit, so that a huge jump
like this will fail only when it would fail to do the same growth in
many little pieces.

I have not looked at the NetBSD code for this to see how it does it.
But I did check, and on "my" NetBSD/sparc machine, the default
stacksize limit is 512K, which you are exceeding.  Check your stacksize
limit, and if it's under about 514K or so, try raising it in your
shell, before running the program, and see if that helps.

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu