View topic - detecting stack overflow during compile time?

detecting stack overflow during compile time?

anything that doesn't fit to other groups.

detecting stack overflow during compile time?

Postby jinma » Wed Feb 24, 2010 1:14 am

how can I do this? anyone used -fstack-check option with gcc? How does it work? Any idea on checking the state of the stack during run time?
Thanks in advance.
jinma
Senior Member
 
Posts: 428
Joined: Thu Oct 28, 2004 10:13 pm

RE: detecting stack overflow during compile time?

Postby jinma » Fri Feb 26, 2010 6:24 pm

Am I asking a dumb question here? or too generic?
jinma
Senior Member
 
Posts: 428
Joined: Thu Oct 28, 2004 10:13 pm

Postby Tim » Fri Feb 26, 2010 7:04 pm

Jinma,

I'd say your asking a question that is better asked (or googled) in a gcc forum than a QNX one since this is a compiler specific option.

Tim
Tim
Senior Member
 
Posts: 1466
Joined: Wed Mar 10, 2004 12:28 am

Postby mario » Fri Feb 26, 2010 7:46 pm

If the stack grow to big you'll get a SIGSEGV, not sure the fstack-check is relevant under QNX6?
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby jinma » Fri Feb 26, 2010 8:59 pm

I just wanted to try here first to see if there were any QNX users who tried such option.
I do handle the SIGSEGV in my code when it happens, but I just wanted to capture obvious stack overflow during compile time.
jinma
Senior Member
 
Posts: 428
Joined: Thu Oct 28, 2004 10:13 pm

Postby jinma » Mon Mar 01, 2010 11:40 pm

I think I found the answer from the QNX documentation, it seems like -f stack-check option is not available in QNX. Below is the text from the documentation under the title "Heap Analysis: Making Memory Errors a Thing of the Past"

-------------------------------
Bounds checking GCC

Bounds checking GCC is a variant of GCC that allows individual modules to be compiled with bounds checking enabled. When a heap buffer is allocated within a checked module, information about the buffer is added to the runtime information about the memory space kept on behalf of the compiler. Attempts to dereference or update the pointer in checked modules invokes intrinsic functions that obtain information about the bounds of the object -- it may be stack, heap or an object in the data segment -- and checks to see that the reference is in bounds. When an access is out of bounds, the runtime environment generates an error.

The bounds checking variant of GCC hasn't been ported to the Neutrino environment. In order to check objects that are kept within the data segment of the application, the compiler runtime environment requires some Unix functions that aren't provided by Neutrino. The intrinsics would have to be modified to work in the Neutrino environment.

The model for obtaining information about heap buffers with this compiler is also slightly different than the model employed by the malloc library. Instead of this, the compiler includes an alternative malloc implementation that registers checked heap buffers with a tree data structure outside of the program's control. This tree is used for searches made by the intrinsics to obtain information about checked objects. This technique may take more time than the malloc mechanism for some programs, and is incompatible with the checking and memory leak detection provided by the malloc library. Rather than performing multiple test runs, a port which reimplemented the compiler intrinsics to obtain heap buffer information from the malloc library would be desirable.
jinma
Senior Member
 
Posts: 428
Joined: Thu Oct 28, 2004 10:13 pm

Postby mario » Tue Mar 02, 2010 2:30 pm

You might want to look at pclint ( www.gimple.com )
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby maschoen » Tue Mar 02, 2010 4:27 pm

Bounds checking comes with an obvious overhead price. I think that you can do the same thing with C++ without needing a special implementation of GCC.

The gimple.com link seems to be broken Mario. At least it is right now.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Postby jinma » Tue Mar 02, 2010 5:54 pm

how can I do this in C++?
jinma
Senior Member
 
Posts: 428
Joined: Thu Oct 28, 2004 10:13 pm

Postby mario » Tue Mar 02, 2010 7:27 pm

maschoen wrote:Bounds checking comes with an obvious overhead price. I think that you can do the same thing with C++ without needing a special implementation of GCC.

The gimple.com link seems to be broken Mario. At least it is right now.


Woops my bad http://www.gimpel.com/
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby mario » Tue Mar 02, 2010 7:27 pm

jinma wrote:how can I do this in C++?


You could use std::vector in combinaison with at(). For standard array (allocated on the stack) you can use boost::array ( you need boost for that ).

But this is at run time, not at compile time.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby maschoen » Tue Mar 02, 2010 7:44 pm

jinma wrote:how can I do this in C++?

Instead of an array you could create your own array like object.
Your accessors do the bounds checking.

There are probably standard objects that do this already.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Postby mario » Wed Mar 03, 2010 5:07 pm

The new gcc (4.4.2) that will be coming out with 6.5.0 support a new -Wframe-larger-than=NUMBER option

The new -Wframe-larger-than=NUMBER option directs GCC to emit a warning if any stack frame is larger than NUMBER bytes. This may be used to help ensure that code fits within a limited amount of stack space.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby jinma » Wed Mar 03, 2010 8:02 pm

thanks a bunch for all your input, it was helpful.
jinma
Senior Member
 
Posts: 428
Joined: Thu Oct 28, 2004 10:13 pm


Return to General Programming

Who is online

Users browsing this forum: No registered users and 2 guests