The Kernel Address Sanitizer (KASAN)

To build with KASAN enabled, add the --kasan flag. Example:

$ tools/bazel build --kasan //common:kernel_aarch64

Kasan builds automatically disable LTO by setting its value to none. If --lto is explicitly specified, it must be set to none. Otherwise the build fails.

Interaction with --config=fast

--config=fast specifies --lto=thin, which is not allowed by --kasan. If you want to disable some sandboxes to make incremental build faster, use --config=local instead. For example:

$ tools/bazel build --kasan --config=local //common:kernel_aarch64

Confirming the value of --kasan

You may build the following to confirm the value of kasan setting:

$ tools/bazel build [flags] //build/kernel/kleaf:print_flags

Note: the value of --lto reflects the value specified on the command line, which may show default or none. However, if --kasan is specified, --lto is coerced into none, no matter if it is specified on the command line.

See also

LTO

Sandboxing