skia2/site/dev/testing/xsan.md
Hal Canary 71cf6292db Documentation: more updates to site/dev/testing/xsan.md
No-Try: true
Docs-Preview: https://skia.org/dev/testing/xsan?cl=167393
Change-Id: I5b2a992c762221e45ea3e9dcfb97cc06a86e9bc5
Reviewed-on: https://skia-review.googlesource.com/c/167393
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
2018-11-05 18:23:02 +00:00

2.9 KiB

MSAN, ASAN, & TSAN

Testing Skia with memory, address, and thread santizers.

Compiling Skia with ASAN, UBSAN, or TSAN can be done with the latest version of Clang.

  • UBSAN works on Linux, Mac, Android, and Windows, though some checks are platform-specific.
  • ASAN works on Linux, Mac, Android.
  • TSAN works on Linux and Mac.
  • MSAN works on Linux[1].

We find that testing sanitizer builds with libc++ uncovers more issues than with the system-provided C++ standard library, which is usually libstdc++. libc++ proactively hooks into sanitizers to help their analyses. We ship a copy of libc++ with our Linux toolchain in /lib.

[1]To compile and run with MSAN, an MSAN-instrumented version of libc++ is needed. It's generally easiest to run one of the following 2 steps to build/download a recent version of Clang and the instrumented libc++, located in /msan.

Downloading Clang binaries (Googlers Only)

This requires gsutil, part of the gcloud sdk.

CLANGDIR="${HOME}/clang"
python infra/bots/assets/clang_linux/download.py -t $CLANGDIR

Building Clang binaries from scratch (Other users)

CLANGDIR="${HOME}/clang"

python tools/git-sync-deps
CC= CXX= infra/bots/assets/clang_linux/create.py -t "$CLANGDIR"

Configure and Compile Skia with MSAN

CLANGDIR="${HOME}/clang"
mkdir -p out/msan
cat > out/msan/args.gn <<- EOF
    cc = "${CLANGDIR}/bin/clang"
    cxx = "${CLANGDIR}/bin/clang++"
    extra_cflags = [ "-B${CLANGDIR}/bin" ]
    extra_ldflags = [
        "-B${CLANGDIR}/bin",
        "-fuse-ld=lld",
        "-L${CLANGDIR}/msan",
        "-Wl,-rpath,${CLANGDIR}/msan" ]
    sanitize = "MSAN"
    skia_use_fontconfig = false
EOF
python tools/git-sync-deps
bin/gn gen out/msan
ninja -C out/msan

Configure and Compile Skia with ASAN

CLANGDIR="${HOME}/clang"
mkdir -p out/asan
cat > out/asan/args.gn <<- EOF
    cc = "${CLANGDIR}/bin/clang"
    cxx = "${CLANGDIR}/bin/clang++"
    sanitize = "ASAN"
    extra_ldflags = [ "-fuse-ld=lld", "-Wl,-rpath,${CLANGDIR}/lib" ]
EOF
python tools/git-sync-deps
bin/gn gen out/asan
ninja -C out/asan

Configure and Compile Skia with TSAN

CLANGDIR="${HOME}/clang"
mkdir -p out/tsan
cat > out/tsan/args.gn <<- EOF
    cc = "${CLANGDIR}/bin/clang"
    cxx = "${CLANGDIR}/bin/clang++"
    sanitize = "TSAN"
    is_debug = false
    extra_ldflags = [ "-Wl,-rpath,${CLANGDIR}/lib" ]
EOF
python tools/git-sync-deps
bin/gn gen out/tsan
ninja -C out/tsan