Description
tl;dr:
llvm/Support/Allocator.h transitively uses __has_feature(address_sanitizer) to decide if it uses __msan_* and __asan_* markers and if it should allocate a red zone. This is very problematic when this header is pulled into an LLVM compilation unit but is also made available through some LLVM template to down-stream users.
Extended bug explanation
We observe an ASAN crash in the following setup:
We build LLVM + MLIR without sanitizers enabled, but have a downstream project that we build with ASAN. Due to relying on MLIR's StorageUniquer, which is a templated implementation in a header, we pull in a copy of BumpPtrAllocatorImpl::Allocate. This function changes behavior, depending on ASAN being enabled or not:
llvm-project/llvm/include/llvm/Support/Allocator.h
Lines 156 to 159 in 0e9a102
Additionally, this code contains multiple __msan_* and __asan_* usages.
Unfortunately, other parts of MLIR's StorageUniquer are implemented in a .cpp file, which result in it being compiled without ASAN. This is problematic, due the a non-ASAN build replacing all __msan_* and __asan_* functions with empty macros.
llvm-project/llvm/include/llvm/Support/Compiler.h
Lines 441 to 461 in 2d98d76
Therefore, some of the poison marking is compiled in, while unpoison markings are omitted. This can therefore lead to ASAN violations that are very tricky to hunt down.
CC @ibookstein
Activity