File tree Expand file tree Collapse file tree 20 files changed +74
-44
lines changed
nix-meson-build-support/common/asan-options
tests/functional/test-libstoreconsumer Expand file tree Collapse file tree 20 files changed +74
-44
lines changed Original file line number Diff line number Diff line change 2323 packages' = nixFlake . packages . ${ system } ;
2424 stdenv = ( getStdenv pkgs ) ;
2525
26- enableSanitizersLayer = finalAttrs : prevAttrs : {
27- mesonFlags =
28- ( prevAttrs . mesonFlags or [ ] )
29- ++ [ ( lib . mesonOption "b_sanitize" "address,undefined" ) ]
30- ++ ( lib . optionals stdenv . cc . isClang [
31- # https://www.github.com/mesonbuild/meson/issues/764
32- ( lib . mesonBool "b_lundef" false )
33- ] ) ;
34- } ;
35-
3626 collectCoverageLayer = finalAttrs : prevAttrs : {
3727 env =
3828 let
5545 '' ;
5646 } ;
5747
58- componentOverrides =
59- ( lib . optional withSanitizers enableSanitizersLayer )
60- ++ ( lib . optional withCoverage collectCoverageLayer ) ;
48+ componentOverrides = ( lib . optional withCoverage collectCoverageLayer ) ;
6149in
6250
6351rec {
6452 nixComponentsInstrumented = nixComponents . overrideScope (
6553 final : prev : {
54+ withASan = withSanitizers ;
55+ withUBSan = withSanitizers ;
56+
6657 nix-store-tests = prev . nix-store-tests . override { withBenchmarks = true ; } ;
6758 # Boehm is incompatible with ASAN.
6859 nix-expr = prev . nix-expr . override { enableGC = ! withSanitizers ; } ;
Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ pymod = import('python')
1515python = pymod.find_installation(' python3' )
1616
1717nix_env_for_docs = {
18- ' ASAN_OPTIONS' : ' abort_on_error=1:print_summary=1:detect_leaks=0' ,
1918 ' HOME' : ' /dummy' ,
2019 ' NIX_CONF_DIR' : ' /dummy' ,
2120 ' NIX_SSL_CERT_FILE' : ' /dummy/no-ca-bundle.crt' ,
Original file line number Diff line number Diff line change 1+ extern " C" [[gnu::retain, gnu::weak]] const char * __asan_default_options ()
2+ {
3+ // We leak a bunch of memory knowingly on purpose. It's not worthwhile to
4+ // diagnose that memory being leaked for now.
5+ return " abort_on_error=1:print_summary=1:detect_leaks=0:detect_odr_violation=0" ;
6+ }
Original file line number Diff line number Diff line change 1- asan_test_options_env = {
2- ' ASAN_OPTIONS' : ' abort_on_error=1:print_summary=1:detect_leaks=0' ,
3- }
4-
51# Clang gets grumpy about missing libasan symbols if -shared-libasan is not
62# passed when building shared libs, at least on Linux
73if cxx.get_id() == ' clang' and (' address' in get_option (' b_sanitize' ) or ' undefined' in get_option (
@@ -10,3 +6,6 @@ if cxx.get_id() == 'clang' and ('address' in get_option('b_sanitize') or 'undefi
106 add_project_link_arguments (' -shared-libasan' , language : ' cpp' )
117endif
128
9+ if ' address' in get_option (' b_sanitize' )
10+ deps_other += declare_dependency (sources : ' asan-options.cc' )
11+ endif
Original file line number Diff line number Diff line change 204204 mesonFlags = [ ( lib . mesonBool "b_asneeded" false ) ] ++ prevAttrs . mesonFlags or [ ] ;
205205 } ;
206206
207+ enableSanitizersLayer =
208+ finalAttrs : prevAttrs :
209+ let
210+ sanitizers = lib . optional scope . withASan "address" ++ lib . optional scope . withUBSan "undefined" ;
211+ in
212+ {
213+ mesonFlags =
214+ ( prevAttrs . mesonFlags or [ ] )
215+ ++ lib . optionals ( lib . length sanitizers > 0 ) (
216+ [
217+ ( lib . mesonOption "b_sanitize" ( lib . concatStringsSep "," sanitizers ) )
218+ ]
219+ ++ ( lib . optionals stdenv . cc . isClang [
220+ # https://www.github.com/mesonbuild/meson/issues/764
221+ ( lib . mesonBool "b_lundef" false )
222+ ] )
223+ ) ;
224+ } ;
225+
207226 nixDefaultsLayer = finalAttrs : prevAttrs : {
208227 strictDeps = prevAttrs . strictDeps or true ;
209228 enableParallelBuilding = true ;
246265
247266 inherit filesetToSource ;
248267
268+ /**
269+ Whether meson components are built with [AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html).
270+ */
271+ withASan = false ;
272+
273+ /**
274+ Whether meson components are built with [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html).
275+ */
276+ withUBSan = false ;
277+
249278 /**
250279 A user-provided extension function to apply to each component derivation.
251280 */
332361 setVersionLayer
333362 mesonLayer
334363 fixupStaticLayer
364+ enableSanitizersLayer
335365 scope . mesonComponentOverrides
336366 ] ;
337367 mkMesonExecutable = mkPackageBuilder [
342372 mesonLayer
343373 mesonBuildLayer
344374 fixupStaticLayer
375+ enableSanitizersLayer
345376 scope . mesonComponentOverrides
346377 ] ;
347378 mkMesonLibrary = mkPackageBuilder [
353384 mesonBuildLayer
354385 mesonLibraryLayer
355386 fixupStaticLayer
387+ enableSanitizersLayer
356388 scope . mesonComponentOverrides
357389 ] ;
358390
Original file line number Diff line number Diff line change 158158 in
159159 forAllPackages ( pkgName : forAllSystems ( system : components . ${ system } . ${ pkgName } ) ) ;
160160
161+ buildWithSanitizers =
162+ let
163+ components = forAllSystems (
164+ system :
165+ let
166+ pkgs = nixpkgsFor . ${ system } . native ;
167+ in
168+ pkgs . nixComponents2 . overrideScope (
169+ self : super : {
170+ # Boost coroutines fail with ASAN on darwin.
171+ withASan = ! pkgs . stdenv . buildPlatform . isDarwin ;
172+ withUBSan = true ;
173+ nix-expr = super . nix-expr . override { enableGC = false ; } ;
174+ # Unclear how to make Perl bindings work with a dynamically linked ASAN.
175+ nix-perl-bindings = null ;
176+ }
177+ )
178+ ) ;
179+ in
180+ forAllPackages ( pkgName : forAllSystems ( system : components . ${ system } . ${ pkgName } ) ) ;
181+
161182 buildNoTests = forAllSystems ( system : nixpkgsFor . ${ system } . native . nixComponents2 . nix-cli ) ;
162183
163184 # Toggles some settings for better coverage. Windows needs these
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ this_exe = executable(
8282test (
8383 meson .project_name(),
8484 this_exe,
85- env : asan_test_options_env + {
85+ env : {
8686 ' _NIX_TEST_UNIT_DATA' : meson .current_source_dir() / ' data' ,
8787 },
8888 protocol : ' gtest' ,
Original file line number Diff line number Diff line change @@ -62,7 +62,6 @@ mkMesonExecutable (finalAttrs: {
6262 mkdir -p "$HOME"
6363 ''
6464 + ''
65- export ASAN_OPTIONS=abort_on_error=1:print_summary=1:detect_leaks=0
6665 export _NIX_TEST_UNIT_DATA=${ resolvePath ./data }
6766 ${ stdenv . hostPlatform . emulator buildPackages } ${ lib . getExe finalAttrs . finalPackage }
6867 touch $out
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ this_exe = executable(
6363test (
6464 meson .project_name(),
6565 this_exe,
66- env : asan_test_options_env + {
66+ env : {
6767 ' _NIX_TEST_UNIT_DATA' : meson .current_source_dir() / ' data' ,
6868 },
6969 protocol : ' gtest' ,
Original file line number Diff line number Diff line change @@ -61,7 +61,6 @@ mkMesonExecutable (finalAttrs: {
6161 buildInputs = [ writableTmpDirAsHomeHook ] ;
6262 }
6363 ''
64- export ASAN_OPTIONS=abort_on_error=1:print_summary=1:detect_leaks=0
6564 export _NIX_TEST_UNIT_DATA=${ resolvePath ./data }
6665 ${ stdenv . hostPlatform . emulator buildPackages } ${ lib . getExe finalAttrs . finalPackage }
6766 touch $out
You can’t perform that action at this time.
0 commit comments