File tree 4 files changed +34
-7
lines changed 4 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ set(NSAN_SOURCES
11
11
nsan_suppressions.cpp
12
12
)
13
13
14
+ set (NSAN_PREINIT_SOURCES
15
+ nsan_preinit.cpp)
16
+
14
17
set (NSAN_HEADERS
15
18
nsan.h
16
19
nsan_flags.h
@@ -61,6 +64,12 @@ if(NOT APPLE)
61
64
ADDITIONAL_HEADERS ${NSAN_HEADERS}
62
65
CFLAGS ${NSAN_CFLAGS} )
63
66
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
+
64
73
file (WRITE ${CMAKE_CURRENT_BINARY_DIR} /dummy.cpp "" )
65
74
add_compiler_rt_object_libraries(RTNsan_dynamic_version_script_dummy
66
75
ARCHS ${NSAN_SUPPORTED_ARCH}
@@ -72,7 +81,7 @@ add_compiler_rt_runtime(
72
81
clang_rt.nsan
73
82
STATIC
74
83
ARCHS ${NSAN_SUPPORTED_ARCH}
75
- OBJECT_LIBS RTNsan
84
+ OBJECT_LIBS RTNsan_preinit RTNsan
76
85
${NSAN_COMMON_RUNTIME_OBJECT_LIBS}
77
86
CFLAGS ${NSAN_CFLAGS}
78
87
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() {
779
779
bool __nsan::nsan_initialized;
780
780
bool __nsan::nsan_init_is_running;
781
781
782
- extern " C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_init () {
782
+ extern " C" void __nsan_init () {
783
783
CHECK (!nsan_init_is_running);
784
784
if (nsan_initialized)
785
785
return ;
@@ -801,8 +801,3 @@ extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __nsan_init() {
801
801
nsan_init_is_running = false ;
802
802
nsan_initialized = true ;
803
803
}
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;
32
32
// Private nsan interface. Used e.g. by interceptors.
33
33
extern " C" {
34
34
35
+ void __nsan_init ();
36
+
35
37
// This marks the shadow type of the given block of application memory as
36
38
// unknown.
37
39
// 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