@@ -628,20 +628,38 @@ Building and Testing with TSan
628
628
It is possible to build and test with TSan, with a few additional steps.
629
629
These steps are normally done automatically in the docker.
630
630
631
- There is a one time patch needed in clang-9 or clang-10 at this time:
631
+ TSan is supported for clang and gcc.
632
+ One particularity of sanitizers is that all the code, including shared objects
633
+ dependencies, should be built with it.
634
+ In the case of TSan, any synchronization primitive from glib (GMutex for
635
+ instance) will not be recognized, and will lead to false positives.
636
+
637
+ To build a tsan version of glib:
632
638
633
639
.. code ::
634
640
635
- sed -i 's/^const/static const/g' \
636
- /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h
641
+ $ git clone --depth=1 --branch=2.81.0 https://github.com/GNOME/glib.git
642
+ $ cd glib
643
+ $ CFLAGS="-O2 -g -fsanitize=thread" meson build
644
+ $ ninja -C build
637
645
638
646
To configure the build for TSan:
639
647
640
648
.. code ::
641
649
642
- ../configure --enable-tsan --cc=clang-10 --cxx=clang++-10 \
650
+ ../configure --enable-tsan \
643
651
--disable-werror --extra-cflags="-O0"
644
652
653
+ When executing qemu, don't forget to point to tsan glib:
654
+
655
+ .. code ::
656
+
657
+ $ glib_dir=/path/to/glib
658
+ $ export LD_LIBRARY_PATH=$glib_dir/build/gio:$glib_dir/build/glib:$glib_dir/build/gmodule:$glib_dir/build/gobject:$glib_dir/build/gthread
659
+ # check correct version is used
660
+ $ ldd build/qemu-x86_64 | grep glib
661
+ $ qemu-system-x86_64 ...
662
+
645
663
The runtime behavior of TSAN is controlled by the TSAN_OPTIONS environment
646
664
variable.
647
665
0 commit comments