From 285691cd192544018185e5b27873482662794b79 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 8 Jun 2026 22:14:10 -0600 Subject: [PATCH 1/4] Add -debug-asan presets with AddressSanitizer --- CMakeLists.txt | 30 ++++++++++++++++++ CMakePresets.json | 70 +++++++++++++++++++++++++++++++++++++++++ docs/building.md | 4 +++ src/dusk/asan_options.c | 3 ++ 4 files changed, 107 insertions(+) create mode 100644 src/dusk/asan_options.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e52e841ec5..8954e9357a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,6 +126,33 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "_cmake") +option(ENABLE_ASAN "Enable AddressSanitizer" OFF) +if (ENABLE_ASAN) + if (CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC" AND + CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") + add_compile_options($<$:/fsanitize=address>) + add_link_options(/fsanitize=address /INCREMENTAL:NO) + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "ProgramDatabase") + foreach (_lang C CXX) + foreach (_rtc_flag /RTC1 /RTCc /RTCs /RTCu) + string(REPLACE "${_rtc_flag}" "" CMAKE_${_lang}_FLAGS_DEBUG "${CMAKE_${_lang}_FLAGS_DEBUG}") + endforeach () + endforeach () + elseif (CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "GNU" AND + CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU") + add_compile_options( + $<$:-fsanitize=address> + $<$:-fno-omit-frame-pointer> + ) + add_link_options(-fsanitize=address) + else () + message(FATAL_ERROR "ENABLE_ASAN requires GNU-like or MSVC-like C/C++ compiler frontends") + endif () + + add_compile_definitions(NDEBUG_SANITIZER) # Avoids absl issue with SwissTable debug code + message(STATUS "dusklight: Enabled AddressSanitizer") +endif () + if (CMAKE_SYSTEM_NAME STREQUAL Linux) set(DAWN_USE_WAYLAND ON CACHE BOOL "Enable support for Wayland surface" FORCE) endif () @@ -491,6 +518,9 @@ if(ANDROID) else () add_executable(dusklight ${DUSK_FILES}) endif () +if (ENABLE_ASAN) + target_sources(dusklight PRIVATE src/dusk/asan_options.c) +endif () target_compile_definitions(dusklight PRIVATE ${GAME_COMPILE_DEFS}) target_include_directories(dusklight PRIVATE ${GAME_INCLUDE_DIRS}) diff --git a/CMakePresets.json b/CMakePresets.json index 6c3a2c46ef..461e751296 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -52,6 +52,16 @@ } } }, + { + "name": "asan", + "hidden": true, + "cacheVariables": { + "ENABLE_ASAN": { + "type": "BOOL", + "value": true + } + } + }, { "name": "linux-default", "displayName": "Linux (default)", @@ -83,6 +93,15 @@ "linux-default" ] }, + { + "name": "linux-default-debug-asan", + "displayName": "Linux (default) Debug ASan", + "inherits": [ + "debug", + "linux-default", + "asan" + ] + }, { "name": "linux-default-relwithdebinfo", "displayName": "Linux (default) RelWithDebInfo", @@ -110,6 +129,15 @@ "linux-clang" ] }, + { + "name": "linux-clang-debug-asan", + "displayName": "Linux (Clang) Debug ASan", + "inherits": [ + "debug", + "linux-clang", + "asan" + ] + }, { "name": "linux-clang-relwithdebinfo", "displayName": "Linux (Clang) RelWithDebInfo", @@ -148,6 +176,15 @@ "windows-msvc" ] }, + { + "name": "windows-msvc-debug-asan", + "displayName": "Windows (MSVC) Debug ASan", + "inherits": [ + "debug", + "windows-msvc", + "asan" + ] + }, { "name": "windows-msvc-relwithdebinfo", "displayName": "Windows (MSVC) RelWithDebInfo", @@ -239,6 +276,15 @@ "macos-default" ] }, + { + "name": "macos-default-debug-asan", + "displayName": "macOS (default) Debug ASan", + "inherits": [ + "debug", + "macos-default", + "asan" + ] + }, { "name": "macos-default-relwithdebinfo", "displayName": "macOS (default) RelWithDebInfo", @@ -529,6 +575,12 @@ "description": "Linux (default) debug build", "displayName": "Linux (default) Debug" }, + { + "name": "linux-default-debug-asan", + "configurePreset": "linux-default-debug-asan", + "description": "Linux (default) debug build with AddressSanitizer", + "displayName": "Linux (default) Debug ASan" + }, { "name": "linux-default-relwithdebinfo", "configurePreset": "linux-default-relwithdebinfo", @@ -541,6 +593,12 @@ "description": "Linux (Clang) debug build", "displayName": "Linux (Clang) Debug" }, + { + "name": "linux-clang-debug-asan", + "configurePreset": "linux-clang-debug-asan", + "description": "Linux (Clang) debug build with AddressSanitizer", + "displayName": "Linux (Clang) Debug ASan" + }, { "name": "linux-clang-relwithdebinfo", "configurePreset": "linux-clang-relwithdebinfo", @@ -553,6 +611,12 @@ "description": "macOS debug build", "displayName": "macOS Debug" }, + { + "name": "macos-default-debug-asan", + "configurePreset": "macos-default-debug-asan", + "description": "macOS debug build with AddressSanitizer", + "displayName": "macOS Debug ASan" + }, { "name": "macos-default-relwithdebinfo", "configurePreset": "macos-default-relwithdebinfo", @@ -610,6 +674,12 @@ "description": "Windows (MSVC) debug build", "displayName": "Windows (MSVC) Debug" }, + { + "name": "windows-msvc-debug-asan", + "configurePreset": "windows-msvc-debug-asan", + "description": "Windows (MSVC) debug build with AddressSanitizer", + "displayName": "Windows (MSVC) Debug ASan" + }, { "name": "windows-msvc-relwithdebinfo", "configurePreset": "windows-msvc-relwithdebinfo", diff --git a/docs/building.md b/docs/building.md index 9f7879ab48..31222df414 100644 --- a/docs/building.md +++ b/docs/building.md @@ -180,6 +180,7 @@ cmake --build --preset macos-default-relwithdebinfo Alternate presets available: * `macos-default-debug`: Clang, Debug +* `macos-default-debug-asan`: Clang, Debug, AddressSanitizer **ninja (Linux)** @@ -191,8 +192,10 @@ cmake --build --preset linux-default-relwithdebinfo Alternate presets available: * `linux-default-debug`: GCC, Debug +* `linux-default-debug-asan`: GCC, Debug, AddressSanitizer * `linux-clang-relwithdebinfo`: Clang, RelWithDebInfo * `linux-clang-debug`: Clang, Debug +* `linux-clang-debug-asan`: Clang, Debug, AddressSanitizer **ninja (Windows)** @@ -204,6 +207,7 @@ cmake --build --preset windows-msvc-relwithdebinfo Alternate presets available: * `windows-msvc-debug`: MSVC, Debug +* `windows-msvc-debug-asan`: MSVC, Debug, AddressSanitizer * `windows-clang-relwithdebinfo`: Clang-cl, RelWithDebInfo * `windows-clang-debug`: Clang-cl, Debug diff --git a/src/dusk/asan_options.c b/src/dusk/asan_options.c new file mode 100644 index 0000000000..6bfb55f28d --- /dev/null +++ b/src/dusk/asan_options.c @@ -0,0 +1,3 @@ +const char* __asan_default_options(void) { + return "abort_on_error=1:symbolize=1:intercept_memcmp=0:detect_leaks=0"; +} From 28a37f6b4fe807c26db38316df8f78be1e9a2e7e Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 8 Jun 2026 22:14:34 -0600 Subject: [PATCH 2/4] Check for sNoUseDrawMtxPtr in J3DModel::entry --- libs/JSystem/src/J3DGraphAnimator/J3DModel.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/JSystem/src/J3DGraphAnimator/J3DModel.cpp b/libs/JSystem/src/J3DGraphAnimator/J3DModel.cpp index 8c895d5077..8e111428cc 100644 --- a/libs/JSystem/src/J3DGraphAnimator/J3DModel.cpp +++ b/libs/JSystem/src/J3DGraphAnimator/J3DModel.cpp @@ -542,8 +542,11 @@ void J3DModel::viewCalc() { } #ifdef TARGET_PC - for (u16 i = 0; i < mModelData->getDrawMtxNum(); ++i) { - dusk::frame_interp::record_final_mtx(getDrawMtxPtr()[i]); + Mtx* drawMtx = getDrawMtxPtr(); + if (drawMtx != J3DMtxBuffer::sNoUseDrawMtxPtr) { + for (u16 i = 0; i < mModelData->getDrawMtxNum(); ++i) { + dusk::frame_interp::record_final_mtx(drawMtx[i]); + } } #endif From a58f64ed80b4a1db073a09b968f470347458261f Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 8 Jun 2026 22:49:28 -0600 Subject: [PATCH 3/4] Update aurora --- CMakeLists.txt | 4 +--- extern/aurora | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8954e9357a..80be4f3fe4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -378,9 +378,7 @@ set(GAME_INCLUDE_DIRS find_package(Threads REQUIRED) set(GAME_LIBS aurora::core aurora::gx aurora::gd aurora::si aurora::vi aurora::pad aurora::mtx aurora::os aurora::dvd aurora::card freeverb cxxopts::cxxopts absl::flat_hash_map nlohmann_json::nlohmann_json TracyClient fmt::fmt - Threads::Threads) - -list(APPEND GAME_LIBS zstd::libzstd) + Threads::Threads zstd::libzstd) if (DUSK_ENABLE_SENTRY_NATIVE) list(APPEND GAME_LIBS sentry) diff --git a/extern/aurora b/extern/aurora index 1ebb33f112..cc9aa81ce7 160000 --- a/extern/aurora +++ b/extern/aurora @@ -1 +1 @@ -Subproject commit 1ebb33f112c893c352faabc96356d63648cef711 +Subproject commit cc9aa81ce756a2c9826a747ca9940c1f5d1e55db From 34e1e740abda473b4c594c8217a9d28c51f79296 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 8 Jun 2026 23:14:51 -0600 Subject: [PATCH 4/4] Update aurora --- extern/aurora | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/aurora b/extern/aurora index cc9aa81ce7..6fa2cbb961 160000 --- a/extern/aurora +++ b/extern/aurora @@ -1 +1 @@ -Subproject commit cc9aa81ce756a2c9826a747ca9940c1f5d1e55db +Subproject commit 6fa2cbb961626c1ef1b13eb12a5b3b43d3bde5f0