[U-Boot] C99 and dynamic arrays
Steve Strobel
steve.strobel at link-comm.com
Wed Mar 20 03:24:38 CET 2013
On Wed, Mar 13, 2013 at 1:55 PM, Måns Rullgård <mans at mansr.com> wrote:
> >>> I suppose we could check the available stack space.
> >> There is no way to check stack usage from C.
> > Well there is an architecture-specific way. A function can generally
> > find its own stack pointer by taking the address of a local variable,
> > so it is possible to write a function to check for stack overflow.
>
> Performing such checks without getting into undefined behaviours is
> tricky if not impossible, and modern compilers are quite effective at
> exploiting these, rendering such checks useless. Remember the deleted
> null checks in the kernel a while back?
>
If possible, it is much nicer to use a compiler option rather than
something in the application itself to check for stack overflow. On the
Blackfin gcc there is a -mstack-check-l1 option to do this. It has a
little overhead, but has saved my bacon. Note that the libraries also need
to be compiled with that option if stack overflows within those libraries
are to be detected.
Steve
--
Steve Strobel
Link Communications, Inc.
1035 Cerise Rd
Billings, MT 59101-7378
(406) 245-5002 ext 102
(406) 245-4889 (fax)
WWW: http://www.link-comm.com
MailTo:steve.strobel at link-comm.com
More information about the U-Boot
mailing list