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

1

14

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?

Howl answered 8/7, 2013 at 0:45 Comment(3)
Since it isn't mentioned in the link command line but is complained about by the linker, the chances are high that your installation is in some way defective. Either the compiler should not be accepting the -fsanitize=thread option or the library should have been installed when the rest of GCC was installed. Have you looked at the release notes? Have you checked the compiler configuration (gcc -dumpspecs, etc)?Mossy
I'm not familiar with gcc, below is output of "gcc -dumpspecs | grep tsan": %{fsanitize=thread:%{static-libtsan:%{!shared:-Bstatic --whole-archive -ltsan --no-whole-archive -Bdynamic}}%{!static-libtsan:-ltsan}}}} %oHowl
@JonathanLeffler, you're assuming someone will have implemented a check to fail nicely when tsan isn't supported ... I'm not sure that's true :)Defeat
H
15

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.

Howl answered 9/7, 2013 at 7:0 Comment(1)
Just to clarify, you guys make it sound like you need a x86_64 CPU, versus ARM for example. Do you really mean tsan will only work for 64-bit builds?Finney

© 2022 - 2024 — McMap. All rights reserved.