AddressSanitizer (ASAN) is a fast memory error detector based on compiler instrumentation (LLVM).
It is fully usable for Chrome on Linux and Mac. If you're working on Windows you can use SyzyASan.
Additional info on the tool itself is available at http://clang.llvm.org/docs/AddressSanitizer.html.
See also: LeakSanitizer.
The Chromium Memory waterfall (not to be confused with the Memory FYI waterfall) contains buildbots running Chromium tests under ASan on Linux (Linux ASan bots for the regular Linux build, Linux Chromium OS ASan for the chromeos=1 build running on Linux), OS X (both 32 and 64 bits), Chromium OS (x86 and amd64 builds running inside VMs).
The trybots running Chromium tests on Linux and OSX are: linux_asan (everything except browser_tests and content_browsertests), linux_browser_asan (browser_tests and content_browsertests), mac_asan (many tests including browser_tests and content_browsertests), linux_chromeos_asan (the chromeos=1 build running on a Linux machine, many tests including browser_tests and content_browsertests).
You can grab fresh Chrome binaries for Linux built with ASAN here.
If you're on mac or linux64, building with Asan is easy:
Make sure you've run tools/clang/scripts/update.sh (see https://code.google.com/p/chromium/wiki/Clang for details).
Start with base_unittests and verify your build is working (see below). Then you can ninja ... chrome or ninja ... browser_tests.
ninja -C out/Release base_unittests
Mac 64-bit build:
GYP_DEFINES='asan=1 target_arch=x64 host_arch=x64' ./build/gyp_chromium
ninja -C out/Release base_unittests
On both Linux64 and Mac, building with ninja instead of make should just work. Make sure to do a release build.
Please refer to https://groups.google.com/a/google.com/forum/#!topic/goma-users/xDDxSmfxzuY. Note that the argument -fasan is obsolete; use -fsanitize=address instead.
If you want your stack traces to be precise, you will have to disable inlining:
Now, check that the tool works. Run the following:
The test will crash with the following error report:
==26552== ERROR: AddressSanitizer stack-buffer-overflow on address 0x7fff338adb14 at pc 0xac20a7 bp 0x7fff338adad0 sp 0x7fff338adac8
WRITE of size 4 at 0x7fff338adb14 thread T0
#0 0xac20a7 in base::ToolsSanityTest_DISABLED_AddressSanitizerLocalOOBCrashTest_Test::TestBody() ???:0
#1 0xcddbd6 in testing::Test::Run() testing/gtest/src/gtest.cc:2161
#2 0xcdf63b in testing::TestInfo::Run() testing/gtest/src/gtest.cc:2338
Address 0x7fff338adb14 is located at offset 52 in frame <base::ToolsSanityTest_DISABLED_AddressSanitizerLocalOOBCrashTest_Test::TestBody()> of T0's stack:
This frame has 2 object(s):
[32, 52) 'array'
[96, 104) 'access'
Congrats, you have a working ASan build! :-)
Run chrome under ASan
And finally, have fun with the out/Release/chrome binary. The filter script tools/valgrind/asan/asan_symbolize.py (and, optionally, c++filt) should be used to symbolize the output.
(Note that asan_symbolize.py is absolutely necessary if you need the symbols - there is no built-in symbolizer for ASan in Chrome).
ASan should perfectly work with Chrome's sandbox. You should only need to run with --no-sandbox on Linux if you're debugging ASan.
You may need to run with --disable-gpu on Linux with NVIDIA driver older than 295.20.
You will likely need to define environment variable G_SLICE=always-malloc to avoid crashes inside gtk.
NSS_DISABLE_ARENA_FREE_LIST=1 and NSS_DISABLE_UNLOAD=1 are required as well.
When filing a bug found by AddressSanitizer, please add a label Stability-AddressSanitizer.
On Linux (and soon on Mac) you can build and run Chromium with NaCl under ASan. Untrusted code (nexe) itself is not instrumented with ASan in this mode, but everything else is.
To do this, remove
Pipe chromium output (stderr) through
If you're seeing crashes within nacl_helper_bootstrap, try deleting out/Release/nacl_helper.
It's possible to build and run Chrome tests for iOS simulator (which are x86 binaries essentially) under ASan. Note that you'll need a Chrome iOS checkout for that. It isn't currently possible to build iOS binaries targeting ARM.
Fix chromium.gyp_env to use ASan.
Now build the test binary and run it:Then update Clang and prepare the build env:
You'll see the same report as shown above (see the "Verify the ASan tool works" section), with a number of iOS-specific frames.
If for some reason you need to build a 32-bit Chrome binary, you'll need to do some magic. The same command is needed to use a custom compiler binary: