> Date: Mon, 20 Jul 2026 16:37:51 -0700
> From: Jason Thorpe <[email protected]>
>
> > On Jul 20, 2026, at 2:34 PM, Taylor R Campbell <[email protected]> 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.
>
> I think I’d like to see an evaluation of potential code-size
> increase that could impact more constrained platforms.
Looks like overall 1-5% code expansion, in a GENERIC kernel and libc
on sparc and sun2. Curiously, on sparc, -ftrivial-auto-var-init=zero
expanded the code _more_ than -ftrivial-auto-var-init=pattern!
We could obviously make this configurable in mk.conf and have the
default different by port too.
* Kernel
$ size sun2/compile/GENERIC.*/netbsd
text data bss dec hex filename
1382055 77428 78160 1537643 17766b sun2/compile/GENERIC.baseline/netbsd
1404951 77428 78160 1560539 17cfdb sun2/compile/GENERIC.zeroinit/netbsd
1413333 77428 78160 1568921 17f099 sun2/compile/GENERIC.patterninit/netbsd
-> zeroinit: 1.67% code expansion over baseline
-> patterninit: 2.26% code expansion over baseline
$ size sparc/compile/GENERIC.*/netbsd
text data bss dec hex filename
5751146 158640 135720 6045506 5c3f42 sparc/compile/GENERIC.baseline/netbsd
5832326 158640 135720 6126686 5d7c5e sparc/compile/GENERIC.zeroinit/netbsd
5830910 158640 135720 6125270 5d76d6 sparc/compile/GENERIC.patterninit/netbsd
-> zeroinit: 1.41% code expansion over baseline
-> patterninit: 1.39% code expansion over baseline
* Userland
$ size obj.sun2/lib/libc.baseline/libc.a | awk '{t+=$1}END{print t}'
1123171
$ size obj.sun2/lib/libc.zeroinit/libc.a | awk '{t+=$1}END{print t}'
1155625
$ size obj.sun2/lib/libc.patterninit/libc.a | awk '{t+=$1}END{print t}'
1171435
-> zeroinit: 2.89% code expansion over baseline
-> patterninit: 4.28% code expansion over baseline
$ size obj.sparc/lib/libc.*/libc.so
text data bss dec hex filename
2227198 59704 158600 2445502 2550be obj.sparc/lib/libc.baseline/libc.so
2263742 59704 158600 2482046 25df7e obj.sparc/lib/libc.zeroinit/libc.so
2252938 59704 158600 2471242 25b54a obj.sparc/lib/libc.patterninit/libc.so
-> zeroinit: 1.64% code expansion over baseline
-> patterninit: 1.16% code expansion over baseline