diff --git a/CMakeLists.txt b/CMakeLists.txt index a1d4f28de7..5a6f2903b1 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 () @@ -351,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) @@ -493,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 () # Add embedded data to target 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/extern/aurora b/extern/aurora index 1ebb33f112..6fa2cbb961 160000 --- a/extern/aurora +++ b/extern/aurora @@ -1 +1 @@ -Subproject commit 1ebb33f112c893c352faabc96356d63648cef711 +Subproject commit 6fa2cbb961626c1ef1b13eb12a5b3b43d3bde5f0 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 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"; +}