[libcxx-commits] [libcxx] [ASan][libc++] Turn on ASan annotations for short strings (PR #79536)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat May 4 10:23:34 PDT 2024


AdvenamTacet wrote:

Sorry for the delay, I had to focus on other projects and it took me a while to fix the issue and properly test it.

@vitalybuka I believe with those new changes it's ready to be upstreamed.
I have tested with `sanitizers/buildbot_bootstrap_asan.sh`, `sanitizers/buildbot_fast.sh` and with fuzzing a few projects. Didn't notice any problems.

New changes are in a separate commit `[ASan][libc++] Turn on ASan annotations for short strings`.
Changes in the commit:
- Value of `__trivially_relocatable` is set to false when compiling with ASan (nothing changes when compiling without ASan). Short strings make `std::basic_string` to not be trivially relocatable, because memory has to be unpoisoned.
- Added two `_LIBCPP_STRING_INTERNAL_MEMORY_ACCESS`.
- Added a macro `_LIBCPP_ASAN_VOLATILE_WRAPPER`, basically it's your idea of changing pointer into a volatile pointer for a moment. When compiling without ASan, macro is "transparent" as shown below.
```cpp
#define _LIBCPP_ASAN_VOLATILE_WRAPPER(ptr) __asan_volatile_wrapper(ptr)
#else
#define _LIBCPP_ASAN_VOLATILE_WRAPPER(ptr) ptr
#endif
```

I was thinking about a different approach where we rely on compiler optimizations and always call `__asan_volatile_wrapper` instead of the macro. And without ASan volatile code doesn't exist. That would be consistent with other ASan helper functions, but we had problems with it in past, so I took safer approach.

 I can't find a problem with that implementation, so I am happy to upstream it. Hope it won't cause a problem anymore.

https://github.com/llvm/llvm-project/pull/79536


More information about the libcxx-commits mailing list