What's the correct way to suppress errors of MSan using bazel?
06:29 04 Jan 2026

I'm working on a downstream project of openxla, whose build system is bazel. And now, I'd like to enable MSan for our source tree.

It's quite easy to enable the MSan using the following bazelrc,

build:msan --copt=-fsanitize=memory
build:msan --copt=-fno-omit-frame-pointer
build:msan --copt=-g
build:msan --linkopt=-fsanitize=memory
build:msan --linkopt=-g
test:msan --test_env=MSAN_SYMBOLIZER_PATH=/path/to/llvm-symbolizer

// run bazel with `bazel build/test --config msan ...`

However, MSan reports some errors in 3rd-party libraries such as google protobuf and gtest, which I'd like to suppress.

The only way I can find to suppress MSan errors is writing an ignore-list file, and pass the file to clang using -fsanitize-ignorelist= . However, with bazel, such a simple thing becomes extremely painful, as the ignore-list file is not a data/dependency of any bazel target, and cannot be used during compilation.

ChatGPT and Gemini suggests several ways,

  • a) adding the ignore-list file as dependency/data for each cc_* target; or

  • b) creating a custom toolchain which takes the list file as a part of compiler_files; or

  • c) writing a clang-wrapper, which invoke clang with hard-coded -fsanitize-ignorelist=;

a) is not acceptable as I need to update all cc_* for the whole project, and even I write my_msan_cc_* wrappers, I still need to change all lines of cc_*.

c) is a bit dirty, and I cannot determine the correct path of clang in the wrapper;

I tried b) but found it's not easy -- with the help of Gemini and ChatGPT, and tried various ways writing bazel script, I still cannot make my custom toolchain work -- bazel keeps reporting errors which ChatGPT and I cannot understand.

So I'm wondering if there's a simple way to suppress msan errors using bazel? Is there any existing project successfully achieving so, which I can take as a reference?

P.S., my conversation (in Chinese) with

bazel bazel-cpp msan