xref: /aosp_15_r20/external/skia/site/docs/dev/testing/xsan.md (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1
2---
3title: "MSAN, ASAN, & TSAN"
4linkTitle: "MSAN, ASAN, & TSAN"
5
6---
7
8
9*Testing Skia with memory, address, and thread santizers.*
10
11Compiling Skia with ASAN, UBSAN, or TSAN can be done with the latest version of Clang.
12
13- UBSAN works on Linux, Mac, Android, and Windows, though some checks are platform-specific.
14- ASAN works on Linux, Mac, Android, and Windows.
15- TSAN works on Linux and Mac.
16- MSAN works on Linux[1].
17
18We find that testing sanitizer builds with libc++ uncovers more issues than
19with the system-provided C++ standard library, which is usually libstdc++.
20libc++ proactively hooks into sanitizers to help their analyses.
21We ship a copy of libc++ with our Linux toolchain in /lib.
22
23[1]To compile and run with MSAN, an MSAN-instrumented version of libc++ is needed.
24It's generally easiest to run one of the following 2 steps to build/download a recent version
25of Clang and the instrumented libc++, located in /msan.
26
27Downloading Clang binaries (Googlers Only)
28------------------------------------------
29This requires gsutil, part of the [gcloud sdk](https://cloud.google.com/sdk/downloads).
30
31<!--?prettify lang=sh?-->
32
33    gcloud auth application-default login
34    CLANGDIR="${HOME}/clang"
35    ./bin/sk asset download clang_linux $CLANGDIR
36
37Building Clang binaries from scratch (Other users)
38---------------------------
39
40<!--?prettify lang=sh?-->
41
42    CLANGDIR="${HOME}/clang"
43
44    python3 tools/git-sync-deps
45    CC= CXX= infra/bots/assets/clang_linux/create.py -t "$CLANGDIR"
46
47Configure and Compile Skia with MSAN
48------------------------------------
49
50<!--?prettify lang=sh?-->
51
52    CLANGDIR="${HOME}/clang"
53    mkdir -p out/msan
54    cat > out/msan/args.gn <<- EOF
55        cc = "${CLANGDIR}/bin/clang"
56        cxx = "${CLANGDIR}/bin/clang++"
57        extra_cflags = [ "-B${CLANGDIR}/bin" ]
58        extra_ldflags = [
59            "-B${CLANGDIR}/bin",
60            "-fuse-ld=lld",
61            "-L${CLANGDIR}/msan",
62            "-Wl,-rpath,${CLANGDIR}/msan" ]
63        sanitize = "MSAN"
64        skia_use_fontconfig = false
65    EOF
66    python3 tools/git-sync-deps
67    bin/gn gen out/msan
68    ninja -C out/msan
69
70Configure and Compile Skia with ASAN
71------------------------------------
72
73<!--?prettify lang=sh?-->
74
75    CLANGDIR="${HOME}/clang"
76    mkdir -p out/asan
77    cat > out/asan/args.gn <<- EOF
78        cc = "${CLANGDIR}/bin/clang"
79        cxx = "${CLANGDIR}/bin/clang++"
80        sanitize = "ASAN"
81        extra_ldflags = [ "-fuse-ld=lld", "-Wl,-rpath,${CLANGDIR}/lib/x86_64-unknown-linux-gnu" ]
82    EOF
83    python3 tools/git-sync-deps
84    bin/gn gen out/asan
85    ninja -C out/asan
86
87Configure and Compile Skia with TSAN
88------------------------------------
89
90<!--?prettify lang=sh?-->
91
92    CLANGDIR="${HOME}/clang"
93    mkdir -p out/tsan
94    cat > out/tsan/args.gn <<- EOF
95        cc = "${CLANGDIR}/bin/clang"
96        cxx = "${CLANGDIR}/bin/clang++"
97        sanitize = "TSAN"
98        is_debug = false
99        extra_ldflags = [ "-Wl,-rpath,${CLANGDIR}/lib" ]
100    EOF
101    python3 tools/git-sync-deps
102    bin/gn gen out/tsan
103    ninja -C out/tsan
104
105
106