Building WebKit and libsoup with AddressSanitizer (ASan)
I built libsoup and WebKit with ASan today. It works almost out of the box. I used Clang. GCC also supports ASan, but WebKit has a problem with it. WebKit Container SDK is based on Ubuntu 20.04 LTS at the moment. It contains clang 18 by default.
Installed required packages.
sudo apt install libclang-rt-18-dev llvm-18-dev
Set env vars.
export CC=clang CXX=clang++
Passed some flags to libsoup.
--- /jhbuild/webkit-sdk-deps.modules.orig
+++ /jhbuild/webkit-sdk-deps.modules
@@ -149,7 +149,7 @@
</dependencies>
</meson>
- <meson id="libsoup" mesonargs="-Dtests=false">
+ <meson id="libsoup" mesonargs="-Dtests=false -Db_sanitize=address -Db_lundef=false">
<branch repo="github.com"
checkoutdir="libsoup"
module="GNOME/libsoup.git" tag="3.6.6"/>
Then, build and install libsoup.
jhbuild buildone -f libsoup
Then, build WebKit with ASan.
./Tools/Scripts/build-webkit --gtk --release --cmakeargs=-DENABLE_SANITIZERS=address
WebKit has a lot of memory leaks by design. Don’t detect leaks.
export ASAN_OPTIONS=detect_leaks=0
For run-webkit-tests, I had to modify a script a bit.
diff --git a/Tools/Scripts/webkitpy/port/driver.py b/Tools/Scripts/webkitpy/port/driver.py
index eb12801a455b..c9f74eeab4e2 100644
--- a/Tools/Scripts/webkitpy/port/driver.py
+++ b/Tools/Scripts/webkitpy/port/driver.py
@@ -482,7 +482,7 @@ class Driver(object):
else:
environment['DUMPRENDERTREE_TEMP'] = str(self._driver_tempdir)
environment['LOCAL_RESOURCE_ROOT'] = str(self._port.layout_tests_dir())
- environment['ASAN_OPTIONS'] = "allocator_may_return_null=1"
+ environment['ASAN_OPTIONS'] = "allocator_may_return_null=1:detect_leaks=0"
environment['__XPC_ASAN_OPTIONS'] = environment['ASAN_OPTIONS']
# Disable vnode-guard related simulated crashes for WKTR / DRT (rdar://problem/40674034).
That’s it. Enjoy.