abseil / abseil-cpp

Abseil Common Libraries (C++)

Home Page:https://abseil.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sanitiser options detection in headers

whoozle opened this issue · comments

Detecting sanitiser presence in headers makes using sanitiser in large projects very complicated and can lead to the hard to catch errors.

Let's say we have a project that depends on other project which is also using absl (like re2).
And we want to use sanitiser without rebuilding all deps (also it's painful to thread copts through all subprojects, especially if you don't own them)

So if you use some 3rd party non-sanitised library which uses abseil too, we may end up with the following situation:

raw_hash_set<>::clear() is called from sanitised code and poison slots_ internal structure
raw_hash_set<>::insert() is called from non-sanitised code (from any dependency for instance) and it does not know that we use sanitiser, so it crashes with ASAN assertion while accessing slots_.

Maybe it's better to detect/specify sanitiser at abseil build stage. And have Sanitizer(Un)PoisonMemoryRegion in the .cc file, hiding detection/compiler detail, so abseil code won't rely on macro. Then poisoning will happen only if abseil was configured with -fsanitiser=address option. If abseil wasn't configured to use sanitiser, then ignore it completely.

Hope it makes sense,
Thanks

And we want to use sanitiser without rebuilding all deps (also it's painful to thread copts through all subprojects, especially if you don't own them)

This issue is not unique to sanitizers, so we make our position on this clear: do not rely on precompiled libraries. Build everything from source with the same compile options. You are only going to cause yourself pain in the long run if you do not, and this issue is an example.

We don't rely on them, although it's not clear to me how would I pass "global" project wide options for all third party dependencies in bazel.

Even with abseil, I found ABSL_GCC_FLAGS but in order to change them - you have to edit absl/copts/copts.py and I didn't find another way to do it.

Bazel makes this easy. Use the --copt flag.

bazel build --copt=-fsanitize=address ...

ABSL_GCC_FLAGS is not for users to edit. These are for our build warnings that do not effect ABI.

Correct me if I wrong, If you pass it for Tensorflow (for instance), no -fsanitize=address appears while building third_party/absl repo for some reason.

You can try this yourself by passing --subcommands to bazel and observing the actual build steps. If the flag isn't making it to all dependencies, the dependencies are not setup correctly.