File tree Expand file tree Collapse file tree 4 files changed +34
-7
lines changed Expand file tree Collapse file tree 4 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ set(NSAN_SOURCES
1111 nsan_suppressions.cpp
1212)
1313
14+ set (NSAN_PREINIT_SOURCES
15+ nsan_preinit.cpp)
16+
1417set (NSAN_HEADERS
1518 nsan.h
1619 nsan_flags.h
@@ -61,6 +64,12 @@ if(NOT APPLE)
6164 ADDITIONAL_HEADERS ${NSAN_HEADERS}
6265 CFLAGS ${NSAN_CFLAGS} )
6366
67+ add_compiler_rt_object_libraries(RTNsan_preinit
68+ ARCHS ${NSAN_SUPPORTED_ARCH}
69+ SOURCES ${NSAN_PREINIT_SOURCES}
70+ ADDITIONAL_HEADERS ${NSAN_HEADERS}
71+ CFLAGS ${NSAN_CFLAGS} )
72+
6473 file (WRITE ${CMAKE_CURRENT_BINARY_DIR} /dummy.cpp "" )
6574 add_compiler_rt_object_libraries(RTNsan_dynamic_version_script_dummy
6675 ARCHS ${NSAN_SUPPORTED_ARCH}
@@ -72,7 +81,7 @@ add_compiler_rt_runtime(
7281 clang_rt.nsan
7382 STATIC
7483 ARCHS ${NSAN_SUPPORTED_ARCH}
75- OBJECT_LIBS RTNsan
84+ OBJECT_LIBS RTNsan_preinit RTNsan
7685 ${NSAN_COMMON_RUNTIME_OBJECT_LIBS}
7786 CFLAGS ${NSAN_CFLAGS}
7887 PARENT_TARGET nsan)
Original file line number Diff line number Diff line change @@ -779,7 +779,7 @@ extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_dump_shadow_args() {
779779bool __nsan::nsan_initialized;
780780bool __nsan::nsan_init_is_running;
781781
782- extern " C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_init () {
782+ extern " C" void __nsan_init () {
783783 CHECK (!nsan_init_is_running);
784784 if (nsan_initialized)
785785 return ;
@@ -801,8 +801,3 @@ extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_init() {
801801 nsan_init_is_running = false ;
802802 nsan_initialized = true ;
803803}
804-
805- #if SANITIZER_CAN_USE_PREINIT_ARRAY
806- __attribute__ ((section(" .preinit_array" ),
807- used)) static void (*nsan_init_ptr)() = __nsan_init;
808- #endif
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ using __sanitizer::uptr;
3232// Private nsan interface. Used e.g. by interceptors.
3333extern " C" {
3434
35+ void __nsan_init ();
36+
3537// This marks the shadow type of the given block of application memory as
3638// unknown.
3739// printf-free (see comment in nsan_interceptors.cc).
Original file line number Diff line number Diff line change 1+ // ===- nsan_preinit.cpp ---------------------------------------------------===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+ //
9+ // Call __nsan_init early using ELF DT_PREINIT_ARRAY.
10+ //
11+ // ===----------------------------------------------------------------------===//
12+
13+ #include " nsan/nsan.h"
14+ #include " sanitizer_common/sanitizer_internal_defs.h"
15+
16+ #if SANITIZER_CAN_USE_PREINIT_ARRAY
17+
18+ __attribute__ ((section(" .preinit_array" ), used)) static auto nsan_preinit =
19+ __nsan_init;
20+
21+ #endif
You can’t perform that action at this time.
0 commit comments