For some targets uptr is mapped to unsigned int and size_t to unsigned
long and sizeof(int)==sizeof(long) holds. Still, these are distinct
types and type checking may fail. Therefore, replace uptr by
usize/SIZE_T wherever a size_t is expected.
Part of #116957
Fixes asan, msan crash on check added in #108684.
The #108684 includes reproducer of the issue.
Change interface of `GetThreadStackAndTls` to
set `tls_begin` and `tls_end` at the same time.
* The performance is better than the glibc allocator.
* Allocator interface functions, sanitizer allocator options, and
MallocHooks/FreeHooks are supported.
* Shadow memory has specific memory layout requirement. Using libc
allocator could lead to conflicts.
* When we add a mmap interceptor for reliability (the VMA could reuse a
previously released VMA that is poisoned): glibc may invoke an
internal system call to call unmmap, which cannot be intercepted. We
will not be able to return the shadow memory to the OS.
Similar to dfsan https://reviews.llvm.org/D101204 . Also intercept
operator new/delete to be similar to other sanitizers using the
sanitizer allocator. The align_val_t overload of operator new has
slightly less overhead.
Pull Request: https://github.com/llvm/llvm-project/pull/102764
On thread creation, asan/hwasan/msan/tsan unpoison the thread stack and
static TLS blocks in case the blocks reuse previously freed memory that
is possibly poisoned. glibc nptl/allocatestack.c allocates thread stack
using a hidden, non-interceptable function.
nsan is similar: the shadow types for the thread stack and static TLS
blocks should be set to unknown, otherwise if the static TLS blocks
reuse previous shadow memory, and `*p += x` instead of `*p = x` is used
for the first assignment, the mismatching user and shadow memory could
lead to false positives.
NsanThread is also needed by the next patch to use the sanitizer
allocator.
Pull Request: https://github.com/llvm/llvm-project/pull/102718
Fixes a build failure on 19.1.0-rc1 when building on linux with musl as
the libc
musl does not provide mallopt, whereas glibc does. mallopt has
portability issues with other libc implementations. Just remove the use.
Co-authored-by: Daniel Martinez <danielmartinez@cock.li>
As previously noted in nsan.cpp we can implement
optimized variants of `__nsan_copy_values` and
`__nsan_set_value_unknown` if a memory operation
size is known.
Now the instrumentation creates calls to optimized functions if there is
4, 8 or 16-byte memory operation like
`memset(X, value, 4/8/16)` or `memcpy(dst, src, 4/8/16)`
nsan.cpp provides definitions of the optimized functions.
Disable core dump creation.
If NSAN_OPTIONS includes abort_on_error=1,
the process may hang as the kernel attempts
to create an excessively large core file.
Fix#98806
Currently NSAN prints reports that are entirely red and the terminal
prompt after the program exits is red too. With this change we make red
only `WARNING` summary and the rest of the report isn't colored.
This behavior is similar to the behavior of other sanitizers.
#94322 defines .preinit_array to initialize nsan early.
DT_PREINIT_ARRAY can only be used with the main executable. GNU ld would
complain when a DSO has .preinit_array. Therefore,
nsan_preinit.cpp cannot be linked into `libclang_rt.nsan.so` (#98415).
Working with @alexander-shaposhnikov, we noticed that `Nsan-x86_64-Test
--gtest_output=json` without `.preinit_array` will sigsegv. This is
because googletest with the JSON output calls `localtime_r` , which
calls `free(0)` and fails when `REAL(free)` remains uninitialized
(nullptr). This is benign with the default output because malloc/free
are all paired and `REAL(free)(ptr)` is not called.
To fix the unittest failure, `__nsan_init` needs to be called early
(.preinit_array).
`asan/tests/CMakeLists.txt:ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS` ues
`-fsanitize=address` to ensure `asan_preinit.cpp.o` is linked into the
unittest executable. Port the approach and remove
`NSAN_TEST_RUNTIME_OBJECTS`.
Fix#98523
Pull Request: https://github.com/llvm/llvm-project/pull/98564
#94322 defines .preinit_array to initialize nsan early.
DT_PREINIT_ARRAY can only be used with the main executable. GNU ld would
complain when a DSO has .preinit_array .
so that `clang -fsanitize=numerical -shared-libsan` will use
`libclang_rt.nsan.so` on Linux.
Shared runtime is preferred for some platforms (Android, Apple, Fuchsia;
though they are not supported yet) and helps plugin use cases (#98302).
* Update `ninja nsan` to build `libclang_rt.nsan.so`
* Fix `nsan.syms.extra`: `nsan_*` is unneeded. Add `__ubsan_*` so that
`-fsanitize=numerical,undefined -shared-libsan` works.
* Move allocation functions to `nsan_malloc_linux.cpp`. While Apple
platforms aren't supported yet, this separation makes it easier to add
Apple support.
* Delete interceptors for very obsoleted pvalloc/valloc but retain
memalign.
* Replace `HandleEarlyAlloc` with `DlsymAlloc`.
Pull Request: https://github.com/llvm/llvm-project/pull/98415
They are checked in the parent CMakeLists in
`compiler_rt_build_runtime` and `compiler_rt_test_runtime`.
There are non-redundant checks when a sanitizer checks
for the presense of another one. They should not be removed.
This diff contains the compiler-rt changes / preparations for nsan.
Test plan:
1. cd build/runtimes/runtimes-bins && ninja check-nsan
2. ninja check-all