coolxv/cpp-stub

Thread Sanitizer crashes when running `REPLCE_NEAR`

jiridanek opened this issue · 5 comments

I am using void Stub::set to install my stub. The program crashes when compiled in GCC with Thread Sanitizer.

ThreadSanitizer:DEADLYSIGNAL
==4759==ERROR: ThreadSanitizer: SEGV on unknown address 0x000000001297 (pc 0x7f5971a10868 bp 0x1000010d4a00 sp 0x7ffff03b4e90 T4759)
==4759==The signal is caused by a WRITE memory access.
    #0 __tsan_write1 <null> (libtsan.so.0+0x91868)
    #1 void Stub::set<int (*)(char*, unsigned long, char const*, __va_list_tag*), int (*)(char*, unsigned long, char const*, ...)>(int (*)(char*, unsigned long, char const*, __va_list_tag*), int (*)(char*, unsigned long, char const*, ...)) /home/runner/work/qpid-dispatch/qpid-dispatch/qpid-dispatch/tests/cpp-stub/cpp_stub.h:247 (c_unittests+0x490ea4)
    #2 _DOCTEST_ANON_FUNC_2 /home/runner/work/qpid-dispatch/qpid-dispatch/qpid-dispatch/tests/c_unittests/test_terminus.cpp:88 (c_unittests+0x490ea4)
    #3 doctest::Context::run() /home/runner/work/qpid-dispatch/qpid-dispatch/qpid-dispatch/tests/c_unittests/doctest.h:6486 (c_unittests+0x458747)
    #4 main /home/runner/work/qpid-dispatch/qpid-dispatch/qpid-dispatch/tests/c_unittests/doctest.h:6571 (c_unittests+0x43b762)
    #5 __libc_start_call_main <null> (libc.so.6+0x2d55f)
    #6 __libc_start_main_impl <null> (libc.so.6+0x2d60b)
    #7 _start <null> (c_unittests+0x43c8e4)

My guess is that the address is not instrumented correctly by TSan and that therefore it is correct to resolve this by disabling TSan instrumentation for Stub::set. The Address Sanitizer tool is not complaining, given the exactly same code.

stub-cpp is not optimized for Sanitizer.
This is only used in unit test scenarios.

@coolxv I use Thread Sanitizer for unit tests. I think that putting __attribute__((no_sanitize("thread"))) on Stub::set is reasonable. I am also thinking that maybe the Sanitizer error is actually a sanitizer bug. I'll consider reporting it there.

Sanitizer is the compiler that has done special processing and inserted some special statements.

@jiridanek Unit tests do not need to be compiled with the sanitizer option.

I'm on my machine and use attribute((no_sanitize("thread"))) on Stub::set is correct.

gcc version 10.2.0 (Ubuntu 10.2.0-5ubuntu1~20.04)