Skip to content

Commit 8e8edb5

Browse files
authored
Merge pull request #12615 from xokdvium/ubsan-checks
flake: Enable UBSAN for checks
2 parents 341628a + 8745875 commit 8e8edb5

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

flake.nix

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,46 @@
263263
flatMapAttrs
264264
(
265265
{
266-
"" = nixpkgsFor.${system}.native;
266+
# Run all tests with UBSAN enabled. Running both with ubsan and
267+
# without doesn't seem to have much immediate benefit for doubling
268+
# the GHA CI workaround.
269+
#
270+
# TODO: Work toward enabling "address,undefined" if it seems feasible.
271+
# This would maybe require dropping Boost coroutines and ignoring intentional
272+
# memory leaks with detect_leaks=0.
273+
"" = rec {
274+
nixpkgs = nixpkgsFor.${system}.native;
275+
nixComponents = nixpkgs.nixComponents.overrideScope (
276+
nixCompFinal: nixCompPrev: {
277+
mesonComponentOverrides = _finalAttrs: prevAttrs: {
278+
mesonFlags =
279+
(prevAttrs.mesonFlags or [ ])
280+
# TODO: Macos builds instrumented with ubsan take very long
281+
# to run functional tests.
282+
++ lib.optionals (!nixpkgs.stdenv.hostPlatform.isDarwin) [
283+
(lib.mesonOption "b_sanitize" "undefined")
284+
];
285+
};
286+
}
287+
);
288+
};
267289
}
268290
// lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.hostPlatform.isDarwin) {
269291
# TODO: enable static builds for darwin, blocked on:
270292
# https://github.com/NixOS/nixpkgs/issues/320448
271293
# TODO: disabled to speed up GHA CI.
272-
#"static-" = nixpkgsFor.${system}.native.pkgsStatic;
294+
# "static-" = {
295+
# nixpkgs = nixpkgsFor.${system}.native.pkgsStatic;
296+
# };
273297
}
274298
)
275299
(
276-
nixpkgsPrefix: nixpkgs:
277-
flatMapAttrs nixpkgs.nixComponents (
300+
nixpkgsPrefix:
301+
{
302+
nixpkgs,
303+
nixComponents ? nixpkgs.nixComponents,
304+
}:
305+
flatMapAttrs nixComponents (
278306
pkgName: pkg:
279307
flatMapAttrs pkg.tests or { } (
280308
testName: test: {
@@ -283,7 +311,7 @@
283311
)
284312
)
285313
// lib.optionalAttrs (nixpkgs.stdenv.hostPlatform == nixpkgs.stdenv.buildPlatform) {
286-
"${nixpkgsPrefix}nix-functional-tests" = nixpkgs.nixComponents.nix-functional-tests;
314+
"${nixpkgsPrefix}nix-functional-tests" = nixComponents.nix-functional-tests;
287315
}
288316
)
289317
// devFlake.checks.${system} or { }

src/libutil/strings.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ struct view_stringbuf : public std::stringbuf
1717
}
1818
};
1919

20-
std::string_view toView(const std::ostringstream & os)
20+
__attribute__((no_sanitize("undefined"))) std::string_view toView(const std::ostringstream & os)
2121
{
22+
/* Downcasting like this is very much undefined behavior, so we disable
23+
UBSAN for this function. */
2224
auto buf = static_cast<view_stringbuf *>(os.rdbuf());
2325
return buf->toView();
2426
}

0 commit comments

Comments
 (0)