为什么 Xcode 在创建经过地址清理的构建时定义 _LIBCPP_HAS_NO_ASAN?

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

Xcode 7 允许使用地址清理器来查找 C/C++ 中的内存问题。

https://github.com/google/sanitizers/wiki/AddressSanitizer

打开地址清理程序会传递编译和链接器标志 -fsanitize=address 并且还会定义 _LIBCPP_HAS_NO_ASAN.

当从命令行构建我的库时,运行 在未定义 _LIBCPP_HAS_NO_ASAN 的情况下对经过清理的构建进行测试时,我看到了不可重复的地址清理程序报告的内存访问问题。像 Xcode 那样定义 _LIBCPP_HAS_NO_ASAN 可以解决消毒剂问题,但我很好奇为什么需要这样做。

为什么我需要使用 AppleClang7 定义 _LIBCPP_HAS_NO_ASAN 以避免在 libcxx 中出现内存访问问题?

根据与 Sean McBride(不在 Whosebug 上)的讨论,在混合检测代码和非检测代码时存在虚假内存越界错误的已知问题:

来自 http://lists.apple.com/archives/xcode-users/2016/Jan/msg00077.html 上的 Anna Zaks:

"Generally, one does not need to rebuild any code that is being linked into sanitized code."

"However, there is one corner case in C++ container overflow checking, where this might not always hold. Specifically, if libc++ containers cross from instrumented (rebuilt with ASan) to non-instrumented code, Address Sanitizer might report container overflow false positives. (Imagine two libraries, both using the same std::vector, only one of them is instrumented. Push_back from the non-instrumented module will not mark the memory for the newly added element as valid. Accessing the element from the instrumented code, would trigger a false positive report.)"

我希望这个问题对其他人有所帮助,因为这个问题占用了我相当多的时间。 Asan 很棒,但是这个信息很难找到。