diff --git a/cmake/CSources.txt b/cmake/CSources.txt index 67bf951f15..adbab642c8 100644 --- a/cmake/CSources.txt +++ b/cmake/CSources.txt @@ -8,4 +8,5 @@ packages/bun-usockets/src/quic.c packages/bun-usockets/src/socket.c packages/bun-usockets/src/udp.c src/bun.js/bindings/uv-posix-polyfills.c -src/bun.js/bindings/uv-posix-stubs.c \ No newline at end of file +src/bun.js/bindings/uv-posix-stubs.c +src/asan-config.c diff --git a/cmake/targets/BuildMimalloc.cmake b/cmake/targets/BuildMimalloc.cmake index 3ce366a03a..f406d7e36b 100644 --- a/cmake/targets/BuildMimalloc.cmake +++ b/cmake/targets/BuildMimalloc.cmake @@ -38,7 +38,11 @@ if(WIN32) set(MIMALLOC_LIBRARY mimalloc-static) endif() elseif(DEBUG) - set(MIMALLOC_LIBRARY mimalloc-debug) + if (ENABLE_ASAN) + set(MIMALLOC_LIBRARY mimalloc-asan-debug) + else() + set(MIMALLOC_LIBRARY mimalloc-debug) + endif() else() set(MIMALLOC_LIBRARY mimalloc) endif() diff --git a/cmake/tools/SetupWebKit.cmake b/cmake/tools/SetupWebKit.cmake index 421b28aae5..ad92845801 100644 --- a/cmake/tools/SetupWebKit.cmake +++ b/cmake/tools/SetupWebKit.cmake @@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use") option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading") if(NOT WEBKIT_VERSION) - set(WEBKIT_VERSION 017930ebf915121f8f593bef61cbbca82d78132d) + set(WEBKIT_VERSION eda8b0fb4fb1aa23db9c2b00933df8b58bcdd289) endif() string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX) @@ -79,7 +79,10 @@ else() set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}") endif() -if(ENABLE_ASAN AND ((APPLE AND DEBUG AND ARCH STREQUAL "aarch64") OR (LINUX AND RELEASE))) +if(ENABLE_ASAN) + # We cannot mix and match ASan Bun + non-ASan WebKit, or vice versa, because some WebKit classes + # change their layout according to whether ASan is used, for example: + # https://github.com/oven-sh/WebKit/blob/eda8b0fb4fb1aa23db9c2b00933df8b58bcdd289/Source/WTF/wtf/Vector.h#L682 set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}-asan") endif() diff --git a/package.json b/package.json index 68e4a425ca..0881238bd7 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "watch-windows": "zig build check-windows --watch -fincremental --prominent-compile-errors --global-cache-dir build/debug/zig-check-cache --zig-lib-dir vendor/zig/lib", "bd": "(bun run --silent build:debug &> /tmp/bun.debug.build.log || (cat /tmp/bun.debug.build.log && rm -rf /tmp/bun.debug.build.log && exit 1)) && rm -f /tmp/bun.debug.build.log && ./build/debug/bun-debug", "build:debug": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -B build/debug", + "build:debug:asan": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON -B build/debug-asan", "build:valgrind": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_BASELINE=ON -ENABLE_VALGRIND=ON -B build/debug-valgrind", "build:release": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Release -B build/release", "build:ci": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCI=true -B build/release-ci --verbose --fresh", diff --git a/src/asan-config.c b/src/asan-config.c new file mode 100644 index 0000000000..45cec7748d --- /dev/null +++ b/src/asan-config.c @@ -0,0 +1,12 @@ +#include "wtf/Compiler.h" + +#if ASAN_ENABLED +const char* __asan_default_options(void) +{ + // detect_stack_use_after_return causes some stack allocations to be made on the heap instead, + // which breaks some JSC classes that have to be on the stack: + // ASSERTION FAILED: Thread::currentSingleton().stack().contains(this) + // cache/webkit-eda8b0fb4fb1aa23/include/JavaScriptCore/JSGlobalObjectInlines.h(63) : JSC::JSGlobalObject::GlobalPropertyInfo::GlobalPropertyInfo(const Identifier &, JSValue, unsigned int) + return "detect_stack_use_after_return=0"; +} +#endif