Search code examples
multithreadingnullthread-sanitizer

TSan doesn't sybmolize dynamically linked SO


I've got the following problem with TSAN (g++ 9.4.0) on Ubuntu 20.04.2 - it doesn't symbolize symbols from dynamically loaded SOs (while does for the executed binary itself):

WARNING: ThreadSanitizer: data race (pid=58921)
  Read of size 8 at 0x7b4000000800 by thread T1:
    #0 memchr ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:915 (libtsan.so.0+0x36f6f)
    #1 memchr ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:911 (libtsan.so.0+0x36f6f)
    #2 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char const*, unsigned long, unsigned long) const <null> (libstdc++.so.6+0x144f44)

  Previous write of size 8 at 0x7b4000000800 by main thread (mutexes: write M17):
    #0 operator new(unsigned long) ../../../../src/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x8c032)
    #1 void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) /usr/include/c++/9/bits/basic_string.tcc:219 (libcyber_Scommon_Slibfile.so+0x709d)
    #2 <null> <null> (libplanner_common.so+0x70e340)
    #3 <null> <null> (libplanner_runner.so+0x38b3b2)
    #4 <null> <null> (libplanner_component.so+0x4d40e)
    #5 <null> <null> (libplanner_component.so+0x98f4f)
    #6 apollo::cyber::TimerComponent::Initialize(apollo::cyber::proto::TimerComponentConfig const&) cyber/component/timer_component.cc:42 (libcyber_Scomponent_Slibtimer_Ucomponent.so+0x3e78)

I found the same problem in my search https://groups.google.com/g/thread-sanitizer/c/OsLLKNGxNUA, but unfortunately this person doesn't have a good solution. I want to get the stack information in TSAN warning. Hava a good day:D


Solution

  • We need to import dynamic libraries that are not displayed in advance. Please refer to the following instructions:

    export LD_PRELOAD=$LD_PRELOAD:/lib/x86_64-linux-gnu/libtsan.so.0:/integration/lib/libplanner_runner.so:/integration/lib/libplanner_common.so

    notice:

    If dynamic libraries need to be imported after program startup, the above instructions will cause errors. There is currently no solution for such dynamic libraries, such as the libplanner_component.so in my question here.

    if you have some good solutions for it, please tell me, have a good day, everyone:D