diff --git a/flake.nix b/flake.nix index 895a081f2..094df9776 100644 --- a/flake.nix +++ b/flake.nix @@ -263,18 +263,46 @@ flatMapAttrs ( { - "" = nixpkgsFor.${system}.native; + # Run all tests with UBSAN enabled. Running both with ubsan and + # without doesn't seem to have much immediate benefit for doubling + # the GHA CI workaround. + # + # TODO: Work toward enabling "address,undefined" if it seems feasible. + # This would maybe require dropping Boost coroutines and ignoring intentional + # memory leaks with detect_leaks=0. + "" = rec { + nixpkgs = nixpkgsFor.${system}.native; + nixComponents = nixpkgs.nixComponents.overrideScope ( + nixCompFinal: nixCompPrev: { + mesonComponentOverrides = _finalAttrs: prevAttrs: { + mesonFlags = + (prevAttrs.mesonFlags or [ ]) + # TODO: Macos builds instrumented with ubsan take very long + # to run functional tests. + ++ lib.optionals (!nixpkgs.stdenv.hostPlatform.isDarwin) [ + (lib.mesonOption "b_sanitize" "undefined") + ]; + }; + } + ); + }; } // lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.hostPlatform.isDarwin) { # TODO: enable static builds for darwin, blocked on: # https://github.com/NixOS/nixpkgs/issues/320448 # TODO: disabled to speed up GHA CI. - #"static-" = nixpkgsFor.${system}.native.pkgsStatic; + # "static-" = { + # nixpkgs = nixpkgsFor.${system}.native.pkgsStatic; + # }; } ) ( - nixpkgsPrefix: nixpkgs: - flatMapAttrs nixpkgs.nixComponents ( + nixpkgsPrefix: + { + nixpkgs, + nixComponents ? nixpkgs.nixComponents, + }: + flatMapAttrs nixComponents ( pkgName: pkg: flatMapAttrs pkg.tests or { } ( testName: test: { @@ -283,7 +311,7 @@ ) ) // lib.optionalAttrs (nixpkgs.stdenv.hostPlatform == nixpkgs.stdenv.buildPlatform) { - "${nixpkgsPrefix}nix-functional-tests" = nixpkgs.nixComponents.nix-functional-tests; + "${nixpkgsPrefix}nix-functional-tests" = nixComponents.nix-functional-tests; } ) // devFlake.checks.${system} or { } diff --git a/src/libutil/strings.cc b/src/libutil/strings.cc index 402b7ae98..785d81797 100644 --- a/src/libutil/strings.cc +++ b/src/libutil/strings.cc @@ -17,8 +17,10 @@ struct view_stringbuf : public std::stringbuf } }; -std::string_view toView(const std::ostringstream & os) +__attribute__((no_sanitize("undefined"))) std::string_view toView(const std::ostringstream & os) { + /* Downcasting like this is very much undefined behavior, so we disable + UBSAN for this function. */ auto buf = static_cast(os.rdbuf()); return buf->toView(); }