[all-commits] [llvm/llvm-project] a853fe: [nsan] Add nsan_preinit.cpp and make it static lib...
Fangrui Song via All-commits
all-commits at lists.llvm.org
Thu Jul 11 18:23:14 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: a853fe25df1cda0117055c0d836e7b107d98c791
https://github.com/llvm/llvm-project/commit/a853fe25df1cda0117055c0d836e7b107d98c791
Author: Fangrui Song <i at maskray.me>
Date: 2024-07-11 (Thu, 11 Jul 2024)
Changed paths:
M compiler-rt/lib/nsan/CMakeLists.txt
M compiler-rt/lib/nsan/nsan.cpp
M compiler-rt/lib/nsan/nsan.h
A compiler-rt/lib/nsan/nsan_preinit.cpp
M compiler-rt/lib/nsan/tests/CMakeLists.txt
Log Message:
-----------
[nsan] Add nsan_preinit.cpp and make it static library only
#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
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list