Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Feb 2015 18:38:46 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        src-committers@freebsd.org, Ian Lepore <ian@freebsd.org>, svn-src-all@freebsd.org, Pedro Giffuni <pfg@freebsd.org>, Gleb Smirnoff <glebius@freebsd.org>, svn-src-head@freebsd.org
Subject:   Re: svn commit: r278737 - head/usr.sbin/flowctl
Message-ID:  <20150215182110.C1367@besplex.bde.org>
In-Reply-To: <20150215162553.L977@besplex.bde.org>
References:  <201502132357.t1DNvKda075915@svn.freebsd.org>  <20150214193210.N945@besplex.bde.org> <20150214181508.GL15484@FreeBSD.org> <1423938828.80968.148.camel@freebsd.org> <54DFA7CC.20305@FreeBSD.org> <20150215162553.L977@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 15 Feb 2015, Bruce Evans wrote:

> On Sat, 14 Feb 2015, Pedro Giffuni wrote:
>> _____
>> ...
>> BUGS
>> The alloca() function is machine and compiler dependent; its use is dis-
>> couraged.
>
> This became out of date with VLAs in C99.  Except for scopes, compilers
> must have slightly more complications to support VLAs than alloca().
> They might still not support alloca().  But FreeBSD never used ones that
> don't.  That it would never use them was not so clear when this man page
> was written.

I found this interesting related problem on the web: inline functions
with alloca() in them may blow out the stack.

But this is only with broken compilers.  For inline functions to work,
they must have the same semantics as when they aren't inlined,
especially when they are automatically inlined.  This means that any
alloca()'ed space in an inline function must be freed at the end of
that function, not at the end of its caller.

clang handles this correctly by doing requested inlining, and freeing
in the right place.  gcc documents the problem and normally refuse to
do requested inlining in functions that call alloca().  However, gcc
can be broken by forcing the inlining using __always_inline.  gcc-4.2
silently produces the stack-blowing code.  gcc-4.8 warns that the
forced inlining might be wrong.

alloca() in any macro would have this problem, unlike a [VL]A in a
compound statement in a macro.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150215182110.C1367>