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

Augment bazelrc to support asan & ubsan #2197

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

fzakaria
Copy link
Contributor

A prior failure in the google3 internal codebase showed that we were not executing the sanitizers like we thought we were.

This change augments bazelrc to do asan and ubsan via config. It leverages the default feature set offered by bazelrc.

I tested the commit priot to 474caa8 to validate that the bug was exhibited.

I've added the sanitizers to the default Bazel build which also builds debug builds.
This may come at an increase cost. If undesirable we can split the job out.

A prior failure in the google3 internal codebase showed that we were not
executing the sanitizers like we thought we were.

This change augments bazelrc to do asan and ubsan via config.
It leverages the default feature set offered by bazelrc.

I tested the commit priot to 474caa8 to
validate that the bug was exhibited.
Copy link
Contributor

@mlevesquedion mlevesquedion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool! A few high-level comments/questions:

  • Consider adding a link to the documentation for sanitizers somewhere.
  • Do we want msan as well?
  • I thought we ran sanitizers in our CMake build? Any insight on why that didn't catch the issues?
  • From the CI on this PR, it does look like this makes the bazel build a lot slower. Also, it seems to be producing some errors, is that expected?

@@ -14,6 +14,11 @@

build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17
# llvm builds typically without rtti
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider linking to a reference for this, would be helpful for context and in case we need to adjust this in the future.

.bazelrc Show resolved Hide resolved
.bazelrc Outdated
Comment on lines 30 to 35
# turn on fission https://gcc.gnu.org/wiki/DebugFission
# this separates the debug information and can improve link times
build --fission=yes

build:dbg --compilation_mode=dbg
build:opt --compilation_mode=opt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines look like they belong in a separate change? Not a huge deal, but consider splitting this out into its own PR and/or calling this out in the commit message/PR description.

(--fission seems like general QOL, --opt seems unused, and --dbg is used, but I only see it used once below, so it could be inlined.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them for now and turned on fission only for dbg.
This should bring the code size back down to normal?

@@ -22,5 +22,5 @@ if [[ $# -ne 0 ]] ; then
fi

# Build and Test StableHLO
bazel build --lockfile_mode=error //...
bazel test //...
bazel build --lockfile_mode=error //... --config=asan --config=ubsan
Copy link
Contributor

@mlevesquedion mlevesquedion Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a separate config that wraps these two, e.g. build:san --config=asan --config=ubsan and then you can do --config=san here.

@fzakaria
Copy link
Contributor Author

I thought we ran sanitizers in our CMake build? Any insight on why that didn't catch the issues?
From the CI on this PR, it does look like this makes the bazel build a lot slower. Also, it seems to be producing some errors, is that expected?

I am looking into having it run non debug.

@fzakaria
Copy link
Contributor Author

If this builds and passes, I'll augment the README with a little section on how to build with Bazel & the sanitizers
(+ running with dbg)

TODO remains to look at our CMake :S

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants