jbcoe jbcoe - 1 month ago 9
C++ Question

Why does an address sanitized build of a C++ library give non-reproducible ASAN issues in libcxx classes?

When building with -fsanitize=address I sometimes see bad memory access issues from libc++ classes.

The errors do not appear to be repeatable from run-to-run and sometimes do not happen at all.

What is happening? How can I prevent this?

Answer

"If libc++ containers cross from instrumented (rebuilt with ASan) to non-instrumented code, Address Sanitizer might report container overflow false positives."

If your program is linking with libraries built with libc++ without ASAN then you need to define _LIBCXX_HAS_NO_ASAN when building.

See Why does Xcode define _LIBCPP_HAS_NO_ASAN when creating an address-sanitized build?