Home | History | Annotate | Download | only in testing
      1 MSAN, ASAN, & TSAN
      2 ==================
      3 
      4 *Testing Skia with memory, address, and thread santizers.*
      5 
      6 Compiling Skia with ASAN, UBSAN, or TSAN can be done with the latest version of Clang.
      7 
      8 - UBSAN works on Linux, Mac, Android, and Windows, though some checks are platform-specific.
      9 - ASAN works on Linux, Mac, Android.
     10 - TSAN works on Linux and Mac.
     11 - MSAN works on Linux[1].
     12 
     13 We find that testing sanitizer builds with libc++ uncovers more issues than
     14 with the system-provided C++ standard library, which is usually libstdc++.
     15 libc++ proactively hooks into sanitizers to help their analyses.
     16 We ship a copy of libc++ with our Linux toolchain in /lib.
     17 
     18 [1]To compile and run with MSAN, an MSAN-instrumented version of libc++ is needed.
     19 It's generally easiest to run one of the following 2 steps to build/download a recent version
     20 of Clang and the instrumented libc++, located in /msan.
     21 
     22 Downloading Clang binaries (Googlers Only)
     23 ------------------------------------------
     24 
     25     CLANGDIR="${HOME}/clang"
     26     python infra/bots/assets/clang_linux/download.py -t $CLANGDIR
     27 
     28 Building Clang binaries from scratch (Other users)
     29 ---------------------------
     30 
     31     CLANGDIR="${HOME}/clang"
     32 
     33     python tools/git-sync-deps
     34     CC= CXX= infra/bots/assets/clang_linux/create.py -t "$CLANGDIR"
     35 
     36 Configure and Compile Skia with MSAN
     37 ------------------------------------
     38 
     39     CLANGDIR="${HOME}/clang"
     40     mkdir -p out/msan
     41     cat > out/msan/args.gn <<- EOF
     42         cc = "${CLANGDIR}/bin/clang"
     43         cxx = "${CLANGDIR}/bin/clang++"
     44         extra_cflags = [ "-B${CLANGDIR}/bin" ]
     45         extra_ldflags = [ "-B${CLANGDIR}/bin", "-fuse-ld=lld", "-L${CLANGDIR}/msan" ]
     46         sanitize = "MSAN"
     47         skia_use_fontconfig = false
     48     EOF
     49     python tools/git-sync-deps
     50     bin/gn gen out/msan
     51     ninja -C out/msan
     52 
     53 When you run a binary built with MSAN, make sure you force it to use our
     54 MSAN-instrumented libc++:
     55 
     56     env LD_LIBRARY_PATH=$CLANGDIR/msan out/dm ...
     57 
     58 Configure and Compile Skia with ASAN
     59 ------------------------------------
     60 
     61     CLANGDIR="${HOME}/clang"
     62     mkdir -p out/asan
     63     cat > out/asan/args.gn <<- EOF
     64         cc = "${CLANGDIR}/bin/clang"
     65         cxx = "${CLANGDIR}/bin/clang++"
     66         sanitize = "ASAN"
     67     EOF
     68     python tools/git-sync-deps
     69     bin/gn gen out/asan
     70     ninja -C out/asan
     71 
     72 
     73 To use the libc++ that comes with the above Clang asset:
     74 
     75     env LD_LIBRARY_PATH=$CLANGDIR/lib out/dm ...
     76 
     77 Configure and Compile Skia with TSAN
     78 ------------------------------------
     79 
     80     CLANGDIR="${HOME}/clang"
     81     mkdir -p out/tsan
     82     cat > out/tsan/args.gn <<- EOF
     83         cc = "${CLANGDIR}/bin/clang"
     84         cxx = "${CLANGDIR}/bin/clang++"
     85         sanitize = "TSAN"
     86         is_debug = false
     87     EOF
     88     python tools/git-sync-deps
     89     bin/gn gen out/tsan
     90     ninja -C out/tsan
     91 
     92 
     93