[compiler-rt] Revert "[safestack] Various Solaris fixes" (PR #98541)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 21:04:23 PDT 2024
vitalybuka wrote:
How that's possi
> Dealing with `__sanitizer_internal_memset` turns out to be more involved than I hoped: when I added stub versions of `__sanitizer_internal_mem*` to `safestack.cpp`, testing went fine on all of Solaris/sparcv9, Solaris/amd64, and Linux/x86_64 (32 and 64-bit each). However, Linux/sparc64 was different: while 64-bit was ok as well, 32-bit aborted in a call to `__sanitizer_internal_memset` in the `pthread_create` interceptor. Here's what I found:
>
> * `safestack.cpp` is compiled with `-ftrivial-auto-var-init=pattern` (which isn't documented in the clang manual AFAICT).
> * This causes `tmpattr` in the `pthread_create` interceptor to be initialized to `-1`. On most targets, this is done inline: Solaris `pthread_attr_init` is `sizeof(void *)` so this is trivial, while on Linux it's way larger (36 bytes for 32-bit, 56-bytes for 64-bit). Only on 32-bit Linux/sparc, this is done with a call to `memset` which ultimately results in the failing call to `__sanitizer_internal_memset`.
I believe just defining `#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS` before including #include "sanitizer_common/sanitizer_platform.h" in `compiler-rt/lib/safestack/safestack_platform.h` is enough.
`-ftrivial-auto-var-init=pattern` is optional for compiler-rt, most helps to reduce false negative with lsan.
`__sanitizer_internal_mem` is from sanitizer_redefine_builtins.h which suppose to avoid libc mem* calls from sanitizers with mem* interceptors. Luckly for us safe stack does not have them, so SANITIZER_COMMON_NO_REDEFINE_BUILTINS is appropriate.
>
> It seems the safestack developers have just been lucky (or lazy) here.
Both: `-ftrivial-auto-var-init=pattern` SANITIZER_COMMON_NO_REDEFINE_BUILTINS were added after safestack implementation. So this "sanitizer_common/sanitizer_platform.h" from safestack is unfortunate, we missed that adding pattern and REDEFINE for others sanitizers. Note iterception also use that header.
https://github.com/llvm/llvm-project/pull/98541
More information about the llvm-commits
mailing list