• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1MSAN, ASAN, & TSAN
2==================
3
4*Testing Skia with memory, address, and thread santizers.*
5
6Compiling 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
13We find that testing sanitizer builds with libc++ uncovers more issues than
14with the system-provided C++ standard library, which is usually libstdc++.
15libc++ proactively hooks into sanitizers to help their analyses.
16We 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.
19It's generally easiest to run one of the following 2 steps to build/download a recent version
20of Clang and the instrumented libc++, located in /msan.
21
22Downloading Clang binaries (Googlers Only)
23------------------------------------------
24This requires gsutil, part of the [gcloud sdk](https://cloud.google.com/sdk/downloads).
25
26<!--?prettify lang=sh?-->
27
28    CLANGDIR="${HOME}/clang"
29    python2 infra/bots/assets/clang_linux/download.py -t $CLANGDIR
30
31Building Clang binaries from scratch (Other users)
32---------------------------
33
34<!--?prettify lang=sh?-->
35
36    CLANGDIR="${HOME}/clang"
37
38    python2 tools/git-sync-deps
39    CC= CXX= infra/bots/assets/clang_linux/create.py -t "$CLANGDIR"
40
41Configure and Compile Skia with MSAN
42------------------------------------
43
44<!--?prettify lang=sh?-->
45
46    CLANGDIR="${HOME}/clang"
47    mkdir -p out/msan
48    cat > out/msan/args.gn <<- EOF
49        cc = "${CLANGDIR}/bin/clang"
50        cxx = "${CLANGDIR}/bin/clang++"
51        extra_cflags = [ "-B${CLANGDIR}/bin" ]
52        extra_ldflags = [
53            "-B${CLANGDIR}/bin",
54            "-fuse-ld=lld",
55            "-L${CLANGDIR}/msan",
56            "-Wl,-rpath,${CLANGDIR}/msan" ]
57        sanitize = "MSAN"
58        skia_use_fontconfig = false
59    EOF
60    python2 tools/git-sync-deps
61    bin/gn gen out/msan
62    ninja -C out/msan
63
64Configure and Compile Skia with ASAN
65------------------------------------
66
67<!--?prettify lang=sh?-->
68
69    CLANGDIR="${HOME}/clang"
70    mkdir -p out/asan
71    cat > out/asan/args.gn <<- EOF
72        cc = "${CLANGDIR}/bin/clang"
73        cxx = "${CLANGDIR}/bin/clang++"
74        sanitize = "ASAN"
75        extra_ldflags = [ "-fuse-ld=lld", "-Wl,-rpath,${CLANGDIR}/lib" ]
76    EOF
77    python2 tools/git-sync-deps
78    bin/gn gen out/asan
79    ninja -C out/asan
80
81Configure and Compile Skia with TSAN
82------------------------------------
83
84<!--?prettify lang=sh?-->
85
86    CLANGDIR="${HOME}/clang"
87    mkdir -p out/tsan
88    cat > out/tsan/args.gn <<- EOF
89        cc = "${CLANGDIR}/bin/clang"
90        cxx = "${CLANGDIR}/bin/clang++"
91        sanitize = "TSAN"
92        is_debug = false
93        extra_ldflags = [ "-Wl,-rpath,${CLANGDIR}/lib" ]
94    EOF
95    python2 tools/git-sync-deps
96    bin/gn gen out/tsan
97    ninja -C out/tsan
98
99