Search code examples
c++libc++address-sanitizer

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?


Solution

  • "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?