On Mon, Jul 20, 2026 at 09:34:29PM +0000, Taylor R Campbell wrote:
> I propose to enable -ftrivial-auto-var-init for all libraries and
> utilities in userland by default (under gcc and clang), and
> specifically to zero-initialize local variables in release builds and
> to nonzero-initialize them in current builds.
>
> See https://mail-index.netbsd.org/tech-kern/2026/07/20/msg031158.html
> for background. If there's any userland-specific considerations to
> discuss, we can discuss in this thread here.
The one mostly userland-specific issue I know of it is that the original
implementation would unconditionally zero all stack variables, even
ones used only in branches. One of the SPEC2006 benchmarks has code
along the lines of:
rettype
frequently_called_function(args)
{
/* reasonable set of stack variables */
char error_buffer [4000];
...
if (error) {
snprintf(error_buffer, sizeof(error_buffer), ...);
...
}
}
The compiler would always zero error_buffer even in paths were it wasn't
touched and didn't escape. The result was a significant performace
degredation. Such cases aren't common (and mostly don't exist in the
kernel where we have better stack discipline), but it's something to be
aware of. I belive modern version of LLVM have dealt with the worse of
these mis-optimizations.
-- Brooks