1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-19 23:41:07 +01:00

treewide: Support builds with ASAN, enable in CI

Enables builds with ASAN to catch memory corruption
bugs faster and in CI. This is an incredibly valuable
instrument that must be used as much as possible.

Somewhat based on jade's work from Lix, though there's a lot that
we have to do differently:

19ae87e5ce

Co-authored-by: Jade Lovelace <lix@jade.fyi>
This commit is contained in:
Sergei Zimmerman 2025-09-19 01:33:57 +03:00
parent 3a687eeb4f
commit 94d37e62fc
No known key found for this signature in database
39 changed files with 88 additions and 26 deletions

View file

@ -239,6 +239,12 @@ foreach suite : suites
# Turns, e.g., `tests/functional/flakes/show.sh` into a Meson test target called
# `functional-flakes-show`.
name = fs.replace_suffix(script, '')
asan_options = 'abort_on_error=1:print_summary=1:detect_leaks=0'
# Otherwise ASAN dumps warnings into stderr that make some tests fail on stderr output
# comparisons.
asan_options += ':log_path=@0@'.format(
meson.current_build_dir() / 'asan-log',
)
test(
name,
@ -253,6 +259,7 @@ foreach suite : suites
],
suite : suite_name,
env : {
'ASAN_OPTIONS' : asan_options,
'_NIX_TEST_SOURCE_DIR' : meson.current_source_dir(),
'_NIX_TEST_BUILD_DIR' : meson.current_build_dir(),
'TEST_NAME' : suite_name / name,

View file

@ -5,6 +5,13 @@
using namespace nix;
extern "C" [[gnu::retain]] const char * __asan_default_options()
{
// We leak a bunch of memory knowingly on purpose. It's not worthwhile to
// diagnose that memory being leaked for now.
return "abort_on_error=1:print_summary=1:detect_leaks=0";
}
int main(int argc, char ** argv)
{
try {

View file

@ -1,3 +1,7 @@
cxx = meson.get_compiler('cpp')
subdir('nix-meson-build-support/asan-options')
libstoreconsumer_tester = executable(
'test-libstoreconsumer',
'main.cc',

View file

@ -0,0 +1 @@
../../../nix-meson-build-support