How to use thread-sanitizer of gcc v4.8.1?

让人想犯罪 __ 提交于 2019-12-20 12:48:20

问题


gcc v4.8.x add options for debugging your program:

-fsanitize=thread

Enable ThreadSanitizer, a fast data race detector. Memory access instructions will be instrumented to detect data race bugs. See http://code.google.com/p/data-race-test/wiki/ThreadSanitizer for more details.

My gcc version on Fedora 19:

gcc version 4.8.1 20130603 (Red Hat 4.8.1-1) (GCC)

Link my program with below command (output of CMake):

Linking C executable bin/ftu
/usr/bin/cmake -E cmake_link_script CMakeFiles/ftu.dir/link.txt --verbose=1
/usr/bin/cc  -g -g -O0 -Wall -D_REENTRANT  -rdynamic -fsanitize=thread -fPIE -pie    CMakeFiles/ftu.dir/src/main/main.c.o  -o bin/ftu  -L/home/hl/ftu/arm/src/libapp/pc -rdynamic ../libapp/pc/libbase.a ../libapp/pc/libstbl.a ../libapp/pc/libstbl_utest.a ../libapp/pc/libbase_utest.a ../libapp/pc/libmem_utest.a ../libapp/pc/libmemspy_utest.a ../libapp/pc/libos_utest.a ../libapp/pc/libmain_utest.a ../libapp/pc/liblog_utest.a ../libapp/pc/libini_utest.a ../libapp/pc/libdsp_utest.a ../libapp/pc/libmstation_utest.a ../libapp/pc/libflist_utest.a ../libapp/pc/libdc_utest.a ../libapp/pc/libflist.a ../libapp/pc/libdsp.a ../libapp/pc/liblog.a ../libapp/pc/libini.a ../libapp/pc/libmstation.a ../libapp/pc/libdc.a ../libapp/pc/libmemspy.a ../libapp/pc/libmem.a ../libapp/pc/libos.a ../libapp/pc/libbase.a -lrt -lpopt -lpthread -Wl,-rpath,/home/hl/ftu/arm/src/libapp/pc

/usr/bin/ld: cannot find -ltsan

collect2: error: ld returned 1 exit status

Gcc says "cannot find -ltsan". Where is libtsan exist?

I found something on http://gcc.gnu.org/gcc-4.8/changes.html:

ThreadSanitizer has been added and can be enabled via -fsanitize=thread. Instructions will be instrumented to detect data races. The ThreadSanitizer is available on x86-64 GNU/Linux.

-fsanitize=thread is only support on 64bit CPU. My linux uname -a output is:

Linux hl.zy 3.9.8-300.fc19.i686 #1 SMP Thu Jun 27 19:40:39 UTC 2013 i686 i686 i386 GNU/Linux

My cpu is 32bit, It's not support! Am I right?


回答1:


I did some exploration:

  1. I found the following on http://gcc.gnu.org/gcc-4.8/changes.html:

ThreadSanitizer has been added and can be enabled via -fsanitize=thread. Instructions will be instrumented to detect data races. The ThreadSanitizer is available on x86-64 GNU/Linux.

-fsanitize=thread is only supported on 64 bit CPU. My linux uname -a outputs:

Linux hl.zy 3.9.8-300.fc19.i686 #1 SMP Thu Jun 27 19:40:39 UTC 2013 i686 i686 i386 GNU/Linux

My CPU is 32 bit, It's not supported!

  1. I checked the compiler configuration, as Jonathan Leffler said

below is output of "gcc -dumpspecs | grep tsan":

%{fsanitize=thread:%{static-libtsan:%{!shared:-Bstatic --whole-archive \
  -ltsan --no-whole-archive -Bdynamic}}%{!static-libtsan:-ltsan}}}} %o 

But I don't understand the output.

  1. I have install Fedora 19 64 bit, you can install libtsan:

    sudo yum install libtsan.x86_64
    

Concusion:

-fsanitize=thread is only supported on 64 bit gcc now.



来源:https://stackoverflow.com/questions/17517824/how-to-use-thread-sanitizer-of-gcc-v4-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!