Search code examples
c++clangaddress-sanitizer

clang address sanitizer: stacktrace seems to be truncated


I compiled my c++ program in debug mode with the options -fsanitize=address -fno-optimize-sibling-calls. At the very end of the program, I got the following error:

==3985624==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 792 byte(s) in 3 object(s) allocated from:
    #0 0x7fecc2078608 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:98
    #1 0x7feca17525e2 in tbb::internal::task_stream<3>::initialize(unsigned int) (/calculate/dealii-9.3.2/opt/spack/linux-ubuntu22.04-skylake/gcc-12.1.0/intel-tbb-2020.3-ulfjl2ollhdkou6aoriwp27nlydyzuvj/lib/libtbb_debug.so.2+0x415e2)
    #2 0x7feca174daf0 in tbb::internal::arena::arena(tbb::internal::market&, unsigned int, unsigned int) ../../src/tbb/arena.cpp:270
    #3 0x7feca174dc64 in tbb::internal::arena::allocate_arena(tbb::internal::market&, unsigned int, unsigned int) ../../src/tbb/arena.cpp:293
    #4 0x7feca1749a68 in tbb::internal::market::create_arena(int, int, unsigned long) ../../src/tbb/market.cpp:314
    #5 0x7feca1747980 in tbb::internal::governor::init_scheduler(int, unsigned long, bool) ../../src/tbb/governor.cpp:197
    #6 0x7feca174845a in tbb::task_scheduler_init::initialize(int, unsigned long) ../../src/tbb/governor.cpp:490
    #7 0x7feca17483a8 in tbb::task_scheduler_init::initialize(int) ../../src/tbb/governor.cpp:478
    #8 0x7fecb5ea073f in dealii::MultithreadInfo::set_thread_limit(unsigned int) /calculate/temp/ltmadmin/spack-stage-dealii-9.3.2-fpaxcn6bqnnmqjyg5nnmil5csgbvxate/spack-src/source/base/multithread_info.cc:93
    #9 0x7fecb5ea0ada in dealii::MultithreadInfo::initialize_multithreading() /calculate/temp/ltmadmin/spack-stage-dealii-9.3.2-fpaxcn6bqnnmqjyg5nnmil5csgbvxate/spack-src/source/base/multithread_info.cc:132
    #10 0x7fecb5ea0af8 in DoOnce /calculate/temp/ltmadmin/spack-stage-dealii-9.3.2-fpaxcn6bqnnmqjyg5nnmil5csgbvxate/spack-src/source/base/multithread_info.cc:147
    #11 0x7fecb5ea4297 in __static_initialization_and_destruction_0 /calculate/temp/ltmadmin/spack-stage-dealii-9.3.2-fpaxcn6bqnnmqjyg5nnmil5csgbvxate/spack-src/source/base/multithread_info.cc:149
    #12 0x7fecb5ea42b1 in _GLOBAL__sub_I_multithread_info.cc /calculate/temp/ltmadmin/spack-stage-dealii-9.3.2-fpaxcn6bqnnmqjyg5nnmil5csgbvxate/spack-src/source/base/multithread_info.cc:152
    #13 0x7fecc269347d in call_init elf/dl-init.c:70

Direct leak of 544 byte(s) in 1 object(s) allocated from:
    #0 0x7fecc2078608 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:98
    #1 0x7fec98529fb3  (/calculate/dealii-9.3.2/opt/spack/linux-ubuntu22.04-skylake/gcc-12.1.0/oce-0.18.3-ecsmaa46gxbflztayfsqannu7m66vwcb/lib/libTKernel.so.11+0xa3fb3)

How can I get the full stack trace starting from the main function of my program? What I see here is not really helpful to me.

I also tried the option -fno-omit-frame-pointer but this also gives me not the full stacktrace. The ASAN_SYMBOLIZER_PATH environment variable is set.


Solution

  • By default Asan/Lsan collect malloc stacktraces by following chain of frame pointers. If particular library is compiled without FP support (i.e. with -fomit-frame-pointer) the chain gets broken along the way which is exactly what you experience here.

    You could instead use a more reliable (but also much slower) stacktrace collection via export ASAN_OPTIONS=fast_unwind_on_malloc=false