|
17 | 17 | # pragma GCC system_header |
18 | 18 | #endif |
19 | 19 |
|
20 | | -// _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS determines whether the containers should provide ASAN container |
21 | | -// overflow checks. Some containers like std::string need stricter requirements in order to enable these |
22 | | -// checks and also need to check that the library was built with sanitizer support (_LIBCPP_INSTRUMENTED_WITH_ASAN). |
| 20 | +// Within libc++, _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS determines whether the containers should |
| 21 | +// provide ASAN container overflow checks. That setting attempts to honour ASAN's documented option |
| 22 | +// __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ which can be defined by users to disable container overflow |
| 23 | +// checks. |
| 24 | +// |
| 25 | +// However, since parts of some containers (e.g. std::string) are compiled separately into the built |
| 26 | +// library, there are caveats: |
| 27 | +// - __SANITIZER_DISABLE_CONTAINER_OVERFLOW__ can't always be honoured, i.e. if the built library |
| 28 | +// was compiled with ASAN container checks, it's impossible to turn them off afterwards. We diagnose |
| 29 | +// this with an error to avoid the proliferation of invalid configurations that appear to work. |
| 30 | +// |
| 31 | +// - The container overflow checks themselves are not always available even when the user is compiling |
| 32 | +// with -fsanitize=address. If a container is compiled separately like std::string, it can't provide |
| 33 | +// container checks unless the separately compiled code was built with container checks enabled. These |
| 34 | +// containers need to also conditionalize whether they provide overflow checks on `_LIBCPP_INSTRUMENTED_WITH_ASAN`. |
23 | 35 | #if __has_feature(address_sanitizer) && !defined(__SANITIZER_DISABLE_CONTAINER_OVERFLOW__) |
24 | 36 | # define _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS 1 |
25 | 37 | #else |
26 | 38 | # define _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS 0 |
27 | 39 | #endif |
28 | 40 |
|
| 41 | +#if _LIBCPP_INSTRUMENTED_WITH_ASAN && !_LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS |
| 42 | +# error "We can't disable ASAN container checks when libc++ has been built with these checks enabled" |
| 43 | +#endif |
| 44 | + |
29 | 45 | #if _LIBCPP_ENABLE_ASAN_CONTAINER_CHECKS |
30 | 46 |
|
31 | 47 | extern "C" { |
|
0 commit comments