Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable C++ Sanitizers for Nix #10969

Open
roberth opened this issue Jun 26, 2024 · 3 comments
Open

Enable C++ Sanitizers for Nix #10969

roberth opened this issue Jun 26, 2024 · 3 comments
Labels
bug feature Feature request or proposal

Comments

@roberth
Copy link
Member

roberth commented Jun 26, 2024

Is your feature request related to a problem? Please describe.
I'm always frustrated when debugging subtle and hard-to-diagnose issues in Nix due to undefined behavior and memory errors in the C++ codebase. These errors can cause unpredictable behavior and are difficult to trace and fix.

Describe the solution you'd like
I would like the Nix build process to include C++ sanitizers such as AddressSanitizer, UndefinedBehaviorSanitizer, and ThreadSanitizer. Enabling these sanitizers during the build can help detect and report errors related to memory usage, undefined behavior, and threading issues, making the code more robust and easier to maintain.

Describe alternatives you've considered

  • Running sanitizers manually on specific tests and components, but this is not as thorough or automated as including them in the build process.
  • Relying on static analysis tools, which are helpful but do not catch all runtime issues that sanitizers can detect.
  • Incorporating sanitizers only in a separate debugging build configuration, but this would still require additional maintenance and might be overlooked.

Additional context
Including sanitizers in the build process can be controlled via build options or environment variables, ensuring they are only enabled during development and testing phases, not in production builds. This would allow developers to benefit from the enhanced error detection without affecting production performance.

Priorities

Add 👍 to issues you find important.

@roberth roberth added bug feature Feature request or proposal labels Jun 26, 2024
@Ericson2314
Copy link
Member

I think Meson might just have some stuff for this.

@lf-
Copy link
Member

lf- commented Jun 26, 2024

it does. there's a couple of flags you need to get UBSan to work properly on clang however, see lix meson.build. ASan is likely impossible without getting rid of Boost coroutines because even if you do the stuff they claim to make it work, the memory crimes it does still cause ASan to crash.

I've nonetheless found actual bugs with ASan outside of the region using boost coroutines, it's just there's false positives I've not managed to mark as ignored.

Another thing Lix did that you could absolutely take is the fact that our production builds ban signed overflow completely at no measurable performance cost. See our meson.build for that as well.

@Ericson2314
Copy link
Member

it does. there's a couple of flags you need to get UBSan to work properly on clang however, see lix meson.build

OK We'll look!

ASan is likely impossible without getting rid of Boost coroutines because even if you do the stuff they claim to make it work, the memory crimes it does still cause ASan to crash.

Certainly a good reason to reconsider using them! (I am also apprehensive how they will behave on Windows. Or with "anti virus" software.)

Another thing Lix did that you could absolutely take is the fact that our production builds ban signed overflow completely at no measurable performance cost. See our meson.build for that as well.

Per https://discourse.nixos.org/t/2024-06-26-nix-team-meeting-minutes-156/47740 yes we very much do want it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

3 participants