This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[tsan] ThreadSanitizer instrumentation part


Hi,

The patch is about ThreadSanitizer. ThreadSanitizer is a data race
detector for C/C++ programs. It contains two parts: instrumentation
and runtime library. This patch is the first part, and runtime will be
included in the second part. Dmitry(dvyukov@google.com) is the author
of this part, and I try to migrate it to trunk. Ok for trunk?

gcc/ChangeLog:
2012-10-31  Wei Mi  <wmi@gmail.com>

        * Makefile.in (tsan.o): New
        * passes.c (init_optimization_passes): Add tsan passes
        * tree-pass.h (register_pass_info): Ditto
        * cfghooks.h (GCC_CFGHOOKS_H): Avoid including duplicate headers
        * doc/invoke.texi: Document tsan related options
        * toplev.c (compile_file): Add tsan pass in driver
        * gcc.c (LINK_COMMAND_SPEC): Add -lasan in link command if there
        -ftsan is on.
        * tsan.c: New file about tsan
        * tsan.h: Ditto

Please check the following links for background:
http://code.google.com/p/data-race-test
http://gcc.gnu.org/wiki/cauldron2012?action=AttachFile&do=get&target=kcc.pdf
(the second half is about ThreadSanitizer).

A small testcase race_on_heap.cc is attached to show its
functionality. Run the small testcase with -ftsan produce the
following warning:

WARNING: ThreadSanitizer: data race (pid=5978)
  Write of size 4 at 0x7d0600039040 by thread 3:
    #0 Thread2(void*) ??:0 (exe+0x0000000052c0)

  Previous write of size 4 at 0x7d0600039040 by thread 2:
    #0 Thread1(void*) ??:0 (exe+0x00000000527d)

  Location is heap block of size 99 at 0x7d0600039030 allocated by thread 1:
    #0 malloc /usr/local/google/home/wmi/Work/llvm-main/trunk/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:293
(exe+0x00000000e9ce)
    #1 alloc() ??:0 (exe+0x0000000052fc)
    #2 AllocThread(void*) ??:0 (exe+0x00000000532c)

  Thread 3 (tid=5981, running) created at:
    #0 pthread_create
/usr/local/google/home/wmi/Work/llvm-main/trunk/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:645
(exe+0x00000000bf1d)
    #1 main ??:0 (exe+0x000000005433)

  Thread 2 (tid=5980, finished) created at:
    #0 pthread_create
/usr/local/google/home/wmi/Work/llvm-main/trunk/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:645
(exe+0x00000000bf1d)
    #1 main ??:0 (exe+0x000000005400)

  Thread 1 (tid=5979, finished) created at:
    #0 pthread_create
/usr/local/google/home/wmi/Work/llvm-main/trunk/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:645
(exe+0x00000000bf1d)
    #1 main ??:0 (exe+0x000000005384)

Thanks,
Wei.

Attachment: patch.txt
Description: Text document

Attachment: race_on_heap.cc
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]