public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Catching stack overflow errors
@ 2000-08-04 13:42 Earl S. Harris, Jr.
  2000-08-04 14:04 ` David Edelsohn
  0 siblings, 1 reply; 6+ messages in thread
From: Earl S. Harris, Jr. @ 2000-08-04 13:42 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 310 bytes --]

Is there a machine independent way to catch stack overflow errors?

When I build a recursive program, I want to check if there is stack
overflow.
I have some solutions that work in one architecture, but not another.

Enclosed is a file that I use to test for stack overflow problems.

Thank You,
Earl
temp.cc


[-- Attachment #2: temp.cc --]
[-- Type: text/x-c, Size: 830 bytes --]

#include <iostream.h>
#include <stdlib.h>
#include <signal.h>

void signal_handler(int signalValue)
{
  cout << endl << "Interrupt signal (" << signalValue
       << ") received." << endl;
  exit(1);
}

long triangle(long n);

int main()
{
  //signal(EXCEPTION_STACK_OVERFLOW, signal_handler);
  for (unsigned long j = 0; j != 40; j++) signal(j, signal_handler);
  //signal(SIGSEGV, signal_handler);
  //signal(SIGABRT, signal_handler);
  //signal(SIGILL, signal_handler);
  //signal(SIGTERM, signal_handler);
  for (unsigned long i = 0; i != 60; i++) {
    cout << "triangle(" << i << ") = " << triangle(i) << endl;
  }
  //raise(SIGILL);
  cout << "triangle(10000000) = " << triangle(10000000) << endl;
  return 0;
}


long triangle(long n)
{
  return n <= 0ul ? 0ul : n + triangle(n - 1);
}


^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: Catching stack overflow errors
@ 2000-08-13 13:45 Geert Bosch
  0 siblings, 0 replies; 6+ messages in thread
From: Geert Bosch @ 2000-08-13 13:45 UTC (permalink / raw)
  To: Anthony Green, Earl S. Harris, Jr.; +Cc: gcc

On 11 Aug 2000 06:30:07 -0700, Anthony Green wrote:

  It is also important for other languages supported by GCC.  Java
  implementations are required to throw exceptions when a stack is blown
  but gcj currently ignores this.

One of the weaknesses currently in GCC is that under certain
circumstances the fixed portion of the stack frame can get
larger than the amount of storage which is guaranteed to be
available when the function is called (typically 1 page, or 4kB)
Even though there is a warning "stack frame too large, reduce
number of locals", this is not that helpful especially if many
of the locals are temporaries introduced by the compiler during
expansion of certain constructs.

GCC has some hacks that try to allocate anyting big in the dynamic
portion of the frame, but this only masks the problems and leads
to unnecessarily inefficient code.

  -Geert


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

end of thread, other threads:[~2000-08-13 13:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-04 13:42 Catching stack overflow errors Earl S. Harris, Jr.
2000-08-04 14:04 ` David Edelsohn
2000-08-07  5:44   ` Earl S. Harris, Jr.
2000-08-11  6:30     ` Anthony Green
2000-08-11 15:57       ` Geoff Keating
2000-08-13 13:45 Geert Bosch

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