Skip to content

Commit 5d57bb4

Browse files
committed
Improve thread sanitizer and c# loader over all.
1 parent 5a58da1 commit 5d57bb4

22 files changed

Lines changed: 142 additions & 346 deletions

File tree

source/benchmarks/metacall_cs_call_bench/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ target_link_options(${target}
118118
# Define test
119119
#
120120

121-
if(OPTION_BUILD_ADDRESS_SANITIZER OR OPTION_BUILD_THREAD_SANITIZER)
122-
# TODO: This test fails when run with sanitizers:
123-
# Tracer caught signal 11: addr=0x5000002b0 pc=0x7f614774a0f0 sp=0x7f609fb40d10
124-
# LeakSanitizer has encountered a fatal error.
125-
# HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1
126-
# HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)
127-
#
128-
# For solving this, we should enable C# support for sanitizers and debug it properly
129-
return()
121+
if(OPTION_BUILD_THREAD_SANITIZER)
122+
find_package(DotNET)
123+
check_tsan_executable("${DOTNET_CORE_LIBRARY}" DotNET_TSAN)
124+
if(NOT DotNET_TSAN)
125+
# This test fails when run with thread sanitizer due to C# when CoreCLR is not compiled with TSAN:
126+
# coreclr_initialize status (0x8007ff0b)
127+
# For solving this, we should enable C# support for sanitizers and debug it properly
128+
return()
129+
endif()
130130
endif()
131131

132132
add_test(NAME ${target}

source/benchmarks/metacall_rb_call_bench/CMakeLists.txt

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,30 +118,15 @@ target_link_options(${target}
118118
# Define test
119119
#
120120

121-
if(OPTION_BUILD_ADDRESS_SANITIZER OR OPTION_BUILD_THREAD_SANITIZER)
122-
# TODO: This test fails when run with sanitizers:
123-
#
124-
# Address Sanitizer:
125-
# ERROR: AddressSanitizer: heap-use-after-free on address 0x629000003a50 at pc 0x7fb5059be061 bp 0x6290000032d0 sp 0x629000002a80
126-
# WRITE of size 22 at 0x629000003a50 thread T0
127-
#
128-
# Thread Sanitizer:
129-
# WARNING: ThreadSanitizer: signal-unsafe call inside of a signal (pid=14308)
130-
# #0 malloc ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:647 (libtsan.so.2+0x3ebb8)
131-
# #1 <null> <null> (ld-linux-x86-64.so.2+0x28df)
132-
# #2 <null> <null> (libruby-2.7.so.2.7+0x237879)
133-
# #3 loader_impl_initialize /usr/local/metacall/source/loader/source/loader_impl.c:367 (libmetacalld.so+0x30673)
134-
# #4 loader_impl_load_from_memory /usr/local/metacall/source/loader/source/loader_impl.c:945 (libmetacalld.so+0x30df1)
135-
# #5 loader_load_from_memory /usr/local/metacall/source/loader/source/loader.c:327 (libmetacalld.so+0x2e1d1)
136-
# #6 metacall_load_from_memory /usr/local/metacall/source/metacall/source/metacall.c:357 (libmetacalld.so+0x32c00)
137-
# #7 metacall_rb_call_bench::SetUp(benchmark::State&) /usr/local/metacall/source/benchmarks/metacall_rb_call_bench/source/metacall_rb_call_bench.cpp:51 (metacall-rb-call-benchd+0x1a420)
138-
# #8 benchmark::internal::BenchmarkInstance::Run(unsigned long, int, benchmark::internal::ThreadTimer*, benchmark::internal::ThreadManager*, benchmark::internal::PerfCountersMeasurement*) const <null> (metacall-rb-call-benchd+0x5f41f)
139-
# #9 <null> <null> (libc.so.6+0x29209)
140-
#
141-
# SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal (/lib64/ld-linux-x86-64.so.2+0x28df)
142-
#
143-
# For solving this, we should enable Ruby support for sanitizers and debug it properly
144-
return()
121+
if(OPTION_BUILD_THREAD_SANITIZER AND OPTION_BUILD_LOADERS_CS)
122+
find_package(DotNET)
123+
check_tsan_executable("${DOTNET_CORE_LIBRARY}" DotNET_TSAN)
124+
if(NOT DotNET_TSAN)
125+
# This test fails when run with thread sanitizer due to C# when CoreCLR is not compiled with TSAN:
126+
# coreclr_initialize status (0x8007ff0b)
127+
# For solving this, we should enable C# support for sanitizers and debug it properly
128+
return()
129+
endif()
145130
endif()
146131

147132
add_test(NAME ${target}

source/cli/metacallcli/CMakeLists.txt

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -457,27 +457,14 @@ if(OPTION_BUILD_LOADERS AND OPTION_BUILD_LOADERS_TS AND OPTION_BUILD_SCRIPTS AND
457457
${TESTS_ENVIRONMENT_VARIABLES}
458458
)
459459

460-
if(NOT (OPTION_BUILD_THREAD_SANITIZER AND OPTION_BUILD_LOADERS_CS))
461-
# TODO: This test fails when run with thread sanitizer (this happens when C# loader is enabled):
462-
#
463-
# WARNING: ThreadSanitizer: signal-unsafe call inside of a signal (pid=14459)
464-
# #0 malloc ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:647 (libtsan.so.2+0x3ebb8)
465-
# #1 <null> <null> (ld-linux-x86-64.so.2+0x28df)
466-
# #2 <null> <null> (libruby-2.7.so.2.7+0x237879)
467-
# #3 simple_netcore_create /usr/local/metacall/source/loaders/cs_loader/source/simple_netcore.cpp:42 (libcs_loaderd.so+0x108de)
468-
# #4 cs_loader_impl_initialize /usr/local/metacall/source/loaders/cs_loader/source/cs_loader_impl.c:236 (libcs_loaderd.so+0xf5fe)
469-
# #5 loader_impl_initialize /usr/local/metacall/source/loader/source/loader_impl.c:367 (libmetacalld.so+0x30673)
470-
# #6 loader_impl_load_from_file /usr/local/metacall/source/loader/source/loader_impl.c:822 (libmetacalld.so+0x30888)
471-
# #7 loader_load_from_file /usr/local/metacall/source/loader/source/loader.c:307 (libmetacalld.so+0x2e0d1)
472-
# #8 metacall_load_from_file /usr/local/metacall/source/metacall/source/metacall.c:348 (libmetacalld.so+0x32bbf)
473-
# #9 node_loader_port_load_from_file_export(napi_env__*, napi_callback_info__*) /usr/local/metacall/source/loaders/node_loader/source/node_loader_port.cpp:395 (libnode_loaderd.so+0x113c5)
474-
# #10 <null> <null> (libnode.so.72+0x7b6344)
475-
# #11 node_loader_impl_async_func_call_safe /usr/local/metacall/source/loaders/node_loader/source/node_loader_impl.cpp:2040 (libnode_loaderd.so+0xe2e8)
476-
# #12 <null> <null> (libnode.so.72+0x7b6344)
477-
#
478-
# SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal (/lib64/ld-linux-x86-64.so.2+0x28df)
479-
#
480-
#
460+
if(OPTION_BUILD_THREAD_SANITIZER AND OPTION_BUILD_LOADERS_CS)
461+
find_package(DotNET)
462+
check_tsan_executable("${DOTNET_CORE_LIBRARY}" DotNET_TSAN)
463+
endif()
464+
465+
if(NOT (OPTION_BUILD_THREAD_SANITIZER AND OPTION_BUILD_LOADERS_CS AND NOT DotNET_TSAN))
466+
# This test fails when run with thread sanitizer due to C# when CoreCLR is not compiled with TSAN:
467+
# coreclr_initialize status (0x8007ff0b)
481468
# For solving this, we should enable C# support for sanitizers and debug it properly
482469
add_test(NAME ${target}-tsx-loop-fail
483470
COMMAND $<TARGET_FILE:${target}> loopfail.tsx

source/loaders/cs_loader/include/cs_loader/netcore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class netcore
4545
int functions_count;
4646
char *dotnet_root;
4747
char *dotnet_loader_assembly_path;
48+
bool initialized;
4849

4950
public:
5051
execution_path_w *core_execution_path_w;

source/loaders/cs_loader/source/netcore.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424

2525
#include <exception>
2626

27-
netcore::netcore(char *dotnet_root, char *dotnet_loader_assembly_path)
27+
netcore::netcore(char *dotnet_root, char *dotnet_loader_assembly_path) :
28+
dotnet_root(dotnet_root), dotnet_loader_assembly_path(dotnet_loader_assembly_path), initialized(false)
2829
{
29-
this->dotnet_root = dotnet_root;
30-
this->dotnet_loader_assembly_path = dotnet_loader_assembly_path;
3130
}
3231

3332
netcore::~netcore()

source/loaders/cs_loader/source/netcore_linux.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,22 @@ bool netcore_linux::start()
259259
return false;
260260
}
261261

262+
this->initialized = true;
263+
262264
return true;
263265
}
264266

265267
void netcore_linux::stop()
266268
{
267-
int status = (*this->coreclr_shutdown)(this->hostHandle, this->domainId);
268-
269-
if (status != 0)
269+
if (this->initialized)
270270
{
271-
log_write("metacall", LOG_LEVEL_ERROR, "Stop status (0x%08x)", status);
271+
int status = (*this->coreclr_shutdown)(this->hostHandle, this->domainId);
272+
273+
if (status != 0)
274+
{
275+
log_write("metacall", LOG_LEVEL_ERROR, "Stop status (0x%08x)", status);
276+
}
277+
278+
this->initialized = false;
272279
}
273280
}

source/loaders/cs_loader/source/netcore_win.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ netcore_win::~netcore_win()
2727

2828
void netcore_win::stop()
2929
{
30+
if (!this->initialized)
31+
{
32+
return;
33+
}
34+
3035
HRESULT hr;
3136

3237
log_write("metacall", LOG_LEVEL_DEBUG, "Unloading the AppDomain");
@@ -55,6 +60,8 @@ void netcore_win::stop()
5560
log_write("metacall", LOG_LEVEL_DEBUG, "Releasing ICLRRuntimeHost2");
5661

5762
this->host->Release();
63+
64+
this->initialized = false;
5865
}
5966

6067
bool netcore_win::start()
@@ -81,6 +88,8 @@ bool netcore_win::start()
8188
return false;
8289
}
8390

91+
this->initialized = true;
92+
8493
return true;
8594
}
8695

source/loaders/cs_loader/source/simple_netcore.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030
netcore_handle simple_netcore_create(char *dotnet_root, char *dotnet_loader_assembly_path)
3131
{
3232
#if defined(__linux) | defined(linux)
33-
netcore_linux *netcore_impl = new netcore_linux(dotnet_root, dotnet_loader_assembly_path);
33+
netcore *core = new netcore_linux(dotnet_root, dotnet_loader_assembly_path);
3434
#else
35-
netcore_win *netcore_impl = new netcore_win(dotnet_root, dotnet_loader_assembly_path);
35+
netcore *core = new netcore_win(dotnet_root, dotnet_loader_assembly_path);
3636
#endif
3737

38-
bool result = netcore_impl->start();
38+
bool result = core->start();
3939

4040
if (result == false)
4141
{
42-
delete netcore_impl;
42+
delete core;
4343

4444
return (netcore_handle)NULL;
4545
}
4646

47-
return (netcore_handle)netcore_impl;
47+
return (netcore_handle)core;
4848
}
4949

5050
reflect_function *simple_netcore_get_functions(netcore_handle handle, int *count)

source/ports/node_port/CMakeLists.txt

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,14 @@ if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_NODE OR NOT OPTION_BUILD
9494
endif()
9595

9696
if(OPTION_BUILD_THREAD_SANITIZER AND OPTION_BUILD_LOADERS_CS)
97-
# TODO: This test fails when run with thread sanitizer:
98-
#
99-
# WARNING: ThreadSanitizer: signal-unsafe call inside of a signal (pid=13328)
100-
# #0 free ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:706 (libtsan.so.2+0x47e82)
101-
# #1 _IO_setb <null> (libc.so.6+0x818a4)
102-
# #2 <null> <null> (libruby-2.7.so.2.7+0x237b64)
103-
# #3 simple_netcore_create /usr/local/metacall/source/loaders/cs_loader/source/simple_netcore.cpp:42 (libcs_loaderd.so+0x108de)
104-
# #4 cs_loader_impl_initialize /usr/local/metacall/source/loaders/cs_loader/source/cs_loader_impl.c:236 (libcs_loaderd.so+0xf5fe)
105-
# #5 loader_impl_initialize /usr/local/metacall/source/loader/source/loader_impl.c:367 (libmetacalld.so+0x306a3)
106-
# #6 loader_impl_load_from_file /usr/local/metacall/source/loader/source/loader_impl.c:822 (libmetacalld.so+0x308b8)
107-
# #7 loader_load_from_file /usr/local/metacall/source/loader/source/loader.c:307 (libmetacalld.so+0x2e101)
108-
# #8 metacall_load_from_file /usr/local/metacall/source/metacall/source/metacall.c:348 (libmetacalld.so+0x32bef)
109-
# #9 node_loader_port_load_from_file_export(napi_env__*, napi_callback_info__*) /usr/local/metacall/source/loaders/node_loader/source/node_loader_port.cpp:395 (libnode_loaderd.so+0x113c5)
110-
# #10 <null> <null> (libnode.so.72+0x7b6344)
111-
#
112-
# SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal (/lib/x86_64-linux-gnu/libc.so.6+0x818a4) in _IO_setb
113-
#
114-
# For solving this, we should enable C# support for sanitizers and debug it properly
115-
return()
97+
find_package(DotNET)
98+
check_tsan_executable("${DOTNET_CORE_LIBRARY}" DotNET_TSAN)
99+
if(NOT DotNET_TSAN)
100+
# This test fails when run with thread sanitizer due to C# when CoreCLR is not compiled with TSAN:
101+
# coreclr_initialize status (0x8007ff0b)
102+
# For solving this, we should enable C# support for sanitizers and debug it properly
103+
return()
104+
endif()
116105
endif()
117106

118107
#

source/tests/metacall_cs_test/CMakeLists.txt

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -144,35 +144,13 @@ add_dependencies(${target}
144144
#
145145

146146
if(OPTION_BUILD_THREAD_SANITIZER)
147-
# TODO: This test fails when run with thread sanitizer:
148-
#
149-
# WARNING: ThreadSanitizer: signal-unsafe call inside of a signal (pid=13983)
150-
# #0 operator new(unsigned long) ../../../../src/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.2+0x87323)
151-
# #1 std::__new_allocator<void*>::allocate(unsigned long, void const*) /usr/include/c++/12/bits/new_allocator.h:137 (libbacktrace_plugind.so+0x7096)
152-
# #2 std::allocator_traits<std::allocator<void*> >::allocate(std::allocator<void*>&, unsigned long) /usr/include/c++/12/bits/alloc_traits.h:464 (libbacktrace_plugind.so+0x7096)
153-
# #3 std::_Vector_base<void*, std::allocator<void*> >::_M_allocate(unsigned long) /usr/include/c++/12/bits/stl_vector.h:378 (libbacktrace_plugind.so+0x7096)
154-
# #4 std::vector<void*, std::allocator<void*> >::_M_default_append(unsigned long) /usr/include/c++/12/bits/vector.tcc:650 (libbacktrace_plugind.so+0x7096)
155-
# #5 std::vector<void*, std::allocator<void*> >::resize(unsigned long) /usr/include/c++/12/bits/stl_vector.h:1011 (libbacktrace_plugind.so+0x7453)
156-
# #6 backward::StackTraceImpl<backward::system_tag::linux_tag>::load_here(unsigned long, void*, void*) /usr/local/metacall/build/_deps/backwardcpp-src/backward.hpp:879 (libbacktrace_plugind.so+0x7453)
157-
# #7 backward::StackTraceImpl<backward::system_tag::linux_tag>::load_from(void*, unsigned long, void*, void*) /usr/local/metacall/build/_deps/backwardcpp-src/backward.hpp:887 (libbacktrace_plugind.so+0xe4da)
158-
# #8 backward::SignalHandling::handleSignal(int, siginfo_t*, void*) /usr/local/metacall/build/_deps/backwardcpp-src/backward.hpp:4249 (libbacktrace_plugind.so+0xe4da)
159-
# #9 backward::SignalHandling::sig_handler(int, siginfo_t*, void*) /usr/local/metacall/build/_deps/backwardcpp-src/backward.hpp:4276 (libbacktrace_plugind.so+0xfff0)
160-
# #10 <null> <null> (libcoreclr.so+0x4afbdc)
161-
# #11 simple_netcore_create /usr/local/metacall/source/loaders/cs_loader/source/simple_netcore.cpp:42 (libcs_loaderd.so+0x108de)
162-
# #12 cs_loader_impl_initialize /usr/local/metacall/source/loaders/cs_loader/source/cs_loader_impl.c:236 (libcs_loaderd.so+0xf5fe)
163-
# #13 loader_impl_initialize /usr/local/metacall/source/loader/source/loader_impl.c:367 (libmetacalld.so+0x30673)
164-
# #14 loader_impl_load_from_file /usr/local/metacall/source/loader/source/loader_impl.c:822 (libmetacalld.so+0x30888)
165-
# #15 loader_load_from_file /usr/local/metacall/source/loader/source/loader.c:307 (libmetacalld.so+0x2e0d1)
166-
# #16 metacall_load_from_file /usr/local/metacall/source/metacall/source/metacall.c:348 (libmetacalld.so+0x32bbf)
167-
# #17 environment::SetUp() /usr/local/metacall/source/tests/metacall_cs_test/source/environment.cpp:38 (metacall-cs-testd+0x21968)
168-
# #18 testing::internal::UnitTestImpl::RunAllTests() <null> (metacall-cs-testd+0x483c1)
169-
# #19 <null> <null> (libc.so.6+0x29209)
170-
#
171-
# SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal ../../../../src/libsanitizer/tsan/tsan_new_delete.cpp:64 in operator new(unsigned long)
172-
#
173-
#
174-
# For solving this, we should enable C# support for sanitizers and debug it properly
175-
return()
147+
check_tsan_executable("${DOTNET_CORE_LIBRARY}" DotNET_TSAN)
148+
if(NOT DotNET_TSAN)
149+
# This test fails when run with thread sanitizer due to C# when CoreCLR is not compiled with TSAN:
150+
# coreclr_initialize status (0x8007ff0b)
151+
# For solving this, we should enable C# support for sanitizers and debug it properly
152+
return()
153+
endif()
176154
endif()
177155

178156
add_test(NAME ${target}

0 commit comments

Comments
 (0)