1

我有一些奇怪的多线程错误,所以我想使用 gcc thread sanitizer 来找到它们。但是,当我-sanitize=thread立即使用以下堆栈跟踪使用生成的二进制段错误进行编译时:

#0  0x0000000000000000 in ?? ()
#1  0x00007ffff5911cee in ?? () from /usr/lib/x86_64-linux-gnu/libtsan.so.0
#2  0x00007ffff593408d in ?? () from /usr/lib/x86_64-linux-gnu/libtsan.so.0
#3  0x00007ffff58eeb98 in ?? () from /usr/lib/x86_64-linux-gnu/libtsan.so.0
#4  0x00007ffff58ef0ce in __interceptor___cxa_atexit ()
   from /usr/lib/x86_64-linux-gnu/libtsan.so.0
#5  0x00007ffff55d1e56 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff7de74ea in call_init (l=<optimised out>, argc=argc@entry=1, 
    argv=argv@entry=0x7fffffffdeb8, env=env@entry=0x7fffffffdec8)
    at dl-init.c:72
#7  0x00007ffff7de75fb in call_init (env=0x7fffffffdec8, argv=0x7fffffffdeb8, 
    argc=1, l=<optimised out>) at dl-init.c:30
#8  _dl_init (main_map=0x7ffff7ffe168, argc=1, argv=0x7fffffffdeb8, 
    env=0x7fffffffdec8) at dl-init.c:120
#9  0x00007ffff7dd7cfa in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#10 0x0000000000000001 in ?? ()
#11 0x00007fffffffe22b in ?? ()
#12 0x0000000000000000 in ?? ()

我尝试添加-static-libtsan属性,但现在我收到以下错误:

FATAL: ThreadSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_allocator.h:1203 "((IsAligned(p, page_size_))) != (0)" (0x0, 0x0)
    #0 __tsan::TsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) <null> (sql+0x0000004aeb53)
    #1 __tsan::TsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) <null> (sql+0x0000004aeb5b)
    #2 __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) <null> (sql+0x0000004b3af3)
    #3 __tsan::user_free(__tsan::ThreadState*, unsigned long, void*, bool) <null> (sql+0x00000049e6fc)
    #4 operator delete(void*) <null> (sql+0x00000045f6ec)
    #5 __static_initialization_and_destruction_0(int, int) [clone .constprop.123] <null> (sql+0x00000044a4ab)
    #6 __libc_csu_init <null> (sql+0x00000254468c)
    #7 __libc_start_main <null> (libc.so.6+0x0000000207be)
    #8 _start <null> (sql+0x000000459e18)

我怎样才能解决这个问题?我在这里做错了什么?

4

2 回答 2

0

我没有使用过带 gcc 的 TSAN,所以在那里帮不上忙,但您可能想尝试一下 clang ( https://clang.llvm.org/ )。由于 TSAN 是 clang 的一部分,因此错误往​​往会首先在那里得到修复。

如果您需要帮助构建 clang,我还写了一篇可能有用的文章:http: //btorpey.github.io/blog/2015/01/02/building-clang/

于 2018-04-18T17:47:46.063 回答
0

在这里找到答案: https ://groups.google.com/forum/#!topic/thread-sanitizer/5cxyhIrl_SE

您不需要提供 -ltsan (至少在使用 clang 时)。您需要在编译和链接时都提供 -fsanitize=thread 。链接时 -fsanitize=thread 将确保链接所有正确的库。

这对 clang 和 gcc 都适用

于 2020-04-17T20:36:52.380 回答