Page MenuHomeFreeBSD

Add support for initializing stack variables on entry.
ClosedPublic

Authored by brooks on Nov 7 2020, 12:26 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 14 2024, 1:45 AM
Unknown Object (File)
Feb 23 2024, 1:25 PM
Unknown Object (File)
Feb 23 2024, 1:25 PM
Unknown Object (File)
Feb 23 2024, 1:24 PM
Unknown Object (File)
Feb 23 2024, 1:11 PM
Unknown Object (File)
Jan 3 2024, 10:35 PM
Unknown Object (File)
Dec 22 2023, 11:30 PM
Unknown Object (File)
Nov 10 2023, 10:36 PM
Subscribers

Details

Summary

There are two options:

  • WITH_INIT_ALL_ZERO: Zero all variables on the stack.
  • WITH_INIT_ALL_PATTERN: Initialize variables with well-defined patterns. The exact pattern are a compiler implementation detail and vary by type. They are somewhat documented in the LLVM commit message: https://reviews.llvm.org/rL349442

I've used WITH_INIT_ALL_* to match Microsoft's InitAll feature rather
than naming them after the LLVM specific compiler flags.

In a range of consumer products, options like these are used in
both debug and production builds with debugs builds using patterns
(intended to provoke crashes on use of uninitialized values) and
production using zeros (deemed more likely to lead to harmless
misbehavior or NULL-pointer dereferences).

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

We've tested this extensively in CheriBSD on RISC-V.

Despite the silly compiler flag, the zeroing option isn't going away in practice as Apple, Microsoft, and Google all ship with this feature in some of their products.

emaste added inline comments.
share/mk/bsd.prog.mk
63–80 ↗(On Diff #79291)

would be nice if we could share this somehow

This revision is now accepted and ready to land.Nov 10 2020, 5:34 PM

CI build (which isn't very interesting) https://github.com/brooksdavis/freebsd/tree/init-all

share/mk/bsd.prog.mk
63–80 ↗(On Diff #79291)

It would be easy enough to add a src.init_all.mk (although I sort of feel like we should have a share/mk/include for things that should never be included directly if we do that)