Generate code to detect stack overflow errors at runtime, optionally specifying an action to
be taken when a stack overflow error is detected.
A stack overflow error occurs when a thread's stack pointer is set beyond the thread's
allocated stack bounds. The error may not be detected if the new top of stack address is
writable.
A stack overflow error is detected if a memory access violation occurs as a direct result of
the error, raising an associated signal (usually SIGSEGV). The signal thus raised is said to be
associated with the error.
If -xcheck=stkovf[action] is specified, the
compiler generates code to detect stack overflow errors in cases involving stack frames larger than
the system page size. The code includes a library call to force a memory access violation instead of
setting the stack pointer to an invalid but potentially mapped address (see
_stack_grow(3C)).
The optional action, if specified, must be either
:detect or :diagnose.
If action is :detect, a detected stack overflow
error is handled by executing the signal handler normally associated with the error.
If action is :diagnose, a detected stack
overflow error is handled by catching the associated signal and calling
stack_violation(3C) to diagnose the error. This is the default behavior if no
action is specified.
If a memory access violation is diagnosed as a stack overflow error, the following message is
printed to stderr:
ERROR: stack overflow detected: pc=<inst_addr>, sp=<sp_addr>
where <inst_addr> is the address of the instruction where the
error was detected, and <sp_addr> is the value of the stack pointer at
the time that the error was detected. After checking for stack overflow and printing the above
message if appropriate, control passes to the signal handler normally associated with the
error.
-xcheck=stkovf:detect adds a stack bounds check on entry to routines with
stack frames larger than system page size (see _stack_grow(3C)). The relative
cost of the additional bounds check should be negligible in most applications.
-xcheck=stkovf:diagnose adds a system call to thread creation (see
sigaltstack(2)). The relative cost of the additional system call depends on how
frequently the application creates and destroys new threads.
-xcheck=stkovf is supported only on Oracle Solaris. The C runtime library
on Linux does not support stack overflow detection.
|