request for stack advice
Joe Buck
Joe.Buck@synopsys.COM
Mon Apr 26 18:25:00 GMT 2004
On Mon, Apr 26, 2004 at 11:41:10AM -0500, Justin M. Lee wrote:
> I recently inherited some C that crashes when compiled with 3.2-3.3
> compilers on Linux x86. It works on SGI's compiler on Irix and gcc 2.95
> on Linux x86.
>
> This code is a bit strange - it puts huge arrays on the stack. We're
> talking about several megs. In a debugger, it appears that the crash
> happens when it tries to touch something on the stack in a particular
> call. I came to realize that I don't understand how stack allocation
> works. Looking at the assembly code, a function doesn't really request
> more stack -- it just subtracts from esp. How does the OS know to
> allocate pages to the stack area? I saw something about stack space in
> the ld man page, but it didn't know what I was talking about when I tried
> to pass it in via -Xlinker. Is there a default stack space?
This is operating system-dependent. Within a certain size range, the
stack will be automatically grown by the OS, but if this size limit is
exceeded, you'll get faults.
> Some more info: it looks to me like the esp is valid at the point of the
> crash: its about 8 megs less at the point of the crash than at main. The
> reason I even got here was because I thought the stack was getting
> trashed.
8 megs sounds like the typical default stack size. It can be changed with
"ulimit" (or "limit" if you use csh or tcsh).
More information about the Gcc
mailing list