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-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.
  0 siblings, 1 reply; 6+ messages in thread
From: David Edelsohn @ 2000-08-04 14:04 UTC (permalink / raw)
  To: Earl S. Harris, Jr.; +Cc: gcc

>>>>> "Earl S Harris, Jr " writes:

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

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

	Some members of IBM's Tokyo Research Lab have been investigating a
machine-independent change to GCC that would generate code to check for
stack overflow / corruption / smashing.  They currently are judging
community interest to determine if they should try to contribute this code
to GCC.  They have a research report on an external website, but the HTML
generates a server error at the moment.

David

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

* Re: Catching stack overflow errors
  2000-08-04 14:04 ` David Edelsohn
@ 2000-08-07  5:44   ` Earl S. Harris, Jr.
  2000-08-11  6:30     ` Anthony Green
  0 siblings, 1 reply; 6+ messages in thread
From: Earl S. Harris, Jr. @ 2000-08-07  5:44 UTC (permalink / raw)
  To: David Edelsohn; +Cc: gcc

David Edelsohn wrote:
> 
> >>>>> "Earl S Harris, Jr " writes:
> 
> Earl> Is there a machine independent way to catch stack overflow errors?
> 
> Earl> When I build a recursive program, I want to check if there is stack
> Earl> overflow.
> Earl> I have some solutions that work in one architecture, but not another.
> 
>         Some members of IBM's Tokyo Research Lab have been investigating a
> machine-independent change to GCC that would generate code to check for
> stack overflow / corruption / smashing.  They currently are judging
> community interest to determine if they should try to contribute this code

I think this is important if the following conditions hold.

1. A programmer wants to use non tail recursion in his/her C++ program.
2. He/she doesn't want the program to crash inelegantly.

Earl Harris Jr.

> to GCC.  They have a research report on an external website, but the HTML
> generates a server error at the moment.
> 
> David

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

* Re: Catching stack overflow errors
  2000-08-07  5:44   ` Earl S. Harris, Jr.
@ 2000-08-11  6:30     ` Anthony Green
  2000-08-11 15:57       ` Geoff Keating
  0 siblings, 1 reply; 6+ messages in thread
From: Anthony Green @ 2000-08-11  6:30 UTC (permalink / raw)
  To: Earl S. Harris, Jr.; +Cc: gcc

"Earl S. Harris, Jr." <esharris@mitre.org> writes:
> I think this is important if the following conditions hold.
> 
> 1. A programmer wants to use non tail recursion in his/her C++ program.
> 2. He/she doesn't want the program to crash inelegantly.

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.

AG

-- 
Anthony Green                                                        Red Hat
                                                       Sunnyvale, California

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

* Re: Catching stack overflow errors
  2000-08-11  6:30     ` Anthony Green
@ 2000-08-11 15:57       ` Geoff Keating
  0 siblings, 0 replies; 6+ messages in thread
From: Geoff Keating @ 2000-08-11 15:57 UTC (permalink / raw)
  To: Anthony Green; +Cc: Earl S. Harris, Jr., gcc

Anthony Green <green@cygnus.com> writes:

> "Earl S. Harris, Jr." <esharris@mitre.org> writes:
> > I think this is important if the following conditions hold.
> > 
> > 1. A programmer wants to use non tail recursion in his/her C++ program.
> > 2. He/she doesn't want the program to crash inelegantly.
> 
> 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.

There are some features in the development gcc that let you detect
stack overflows, if the usual OS signal-handling isn't robust enough
for you.  Look at the -fstack-limit-* options.  It has to be used in a
processor-specific way, but it does guarantee that you will get a
SIGTRAP _before_ the stack is expanded (rather than after all the
damage is done).  You can then catch the signal and deal with it by,
for instance, calling siglongjmp().
-- 
- Geoffrey Keating <geoffk@cygnus.com>

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