1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-30 19:57:59 +02:00

Merge pull request #12615 from xokdvium/ubsan-checks

flake: Enable UBSAN for checks
This commit is contained in:
Jörg Thalheim 2025-03-11 14:22:20 +01:00 committed by GitHub
commit 8e8edb5bf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 6 deletions

View file

@ -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 { }

View file

@ -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<view_stringbuf *>(os.rdbuf());
return buf->toView();
}