diff --git a/CMakeLists.txt b/CMakeLists.txt index 81da07aeb1a..000122f35e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,13 +192,6 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland/Services) include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland/Libraries) include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland) -# FIXME: vptr sanitizing requires.. intense ABI wrangling of std::type_info -# And would be better served by porting ubsan_type_hash_itanium.cpp from compiler-rt -if (ENABLE_UNDEFINED_SANITIZER) - add_compile_options(-fsanitize=undefined -fno-sanitize=vptr) - add_link_options(-fsanitize=undefined -fno-sanitize=vptr) -endif() - add_custom_target(components ALL) option(BUILD_EVERYTHING "Build all optional components" ON) @@ -219,6 +212,17 @@ endif() add_subdirectory(AK) add_subdirectory(Kernel) +# FIXME: vptr sanitizing requires.. intense ABI wrangling of std::type_info +# And would be better served by porting ubsan_type_hash_itanium.cpp from compiler-rt +if (ENABLE_UNDEFINED_SANITIZER) + add_compile_options(-fsanitize=undefined -fno-sanitize=vptr) + add_link_options(-fsanitize=undefined -fno-sanitize=vptr) + + if (UNDEFINED_BEHAVIOR_IS_FATAL) + add_compile_options(-fno-sanitize-recover=undefined) + endif() +endif() + if (ENABLE_MOLD_LINKER) add_link_options(-fuse-ld=mold) endif() diff --git a/Documentation/AdvancedBuildInstructions.md b/Documentation/AdvancedBuildInstructions.md index 521fa49b557..7b7aae98649 100644 --- a/Documentation/AdvancedBuildInstructions.md +++ b/Documentation/AdvancedBuildInstructions.md @@ -46,7 +46,8 @@ There are some optional features that can be enabled during compilation that are - `ENABLE_KERNEL_COVERAGE_COLLECTION`: enables the KCOV API and kernel coverage collection instrumentation. Only useful for coverage guided kernel fuzzing. - `ENABLE_USERSPACE_COVERAGE_COLLECTION`: enables coverage collection instrumentation for userspace. Currently only works with a Clang build. - `ENABLE_MEMORY_SANITIZER`: enables runtime checks for uninitialized memory accesses in Lagom test cases. -- `ENABLE_UNDEFINED_SANITIZER`: builds in runtime checks for [undefined behavior](https://en.wikipedia.org/wiki/Undefined_behavior) (like null pointer dereferences and signed integer overflows) in Lagom test cases. +- `ENABLE_UNDEFINED_SANITIZER`: builds in runtime checks for [undefined behavior](https://en.wikipedia.org/wiki/Undefined_behavior) (like null pointer dereferences and signed integer overflows) in Lagom and the SerenityOS userland. +- `UNDEFINED_BEHAVIOR_IS_FATAL`: makes all undefined behavior sanitizer errors non-recoverable. This option reduces the performance overhead of `ENABLE_UNDEFINED_SANITIZER`. - `ENABLE_COMPILER_EXPLORER_BUILD`: Skip building non-library entities in Lagom (this only applies to Lagom). - `ENABLE_FUZZERS`: builds [fuzzers](../Meta/Lagom/ReadMe.md#fuzzing) for various parts of the system. - `ENABLE_FUZZERS_LIBFUZZER`: builds Clang libFuzzer-based [fuzzers](../Meta/Lagom/ReadMe.md#fuzzing) for various parts of the system. diff --git a/Ladybird/CMakeLists.txt b/Ladybird/CMakeLists.txt index 00c4a123d5e..39378b3c5a3 100644 --- a/Ladybird/CMakeLists.txt +++ b/Ladybird/CMakeLists.txt @@ -41,6 +41,9 @@ endif() if (ENABLE_UNDEFINED_SANITIZER) add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) + if (UNDEFINED_BEHAVIOR_IS_FATAL) + add_compile_options(-fno-sanitize-recover=undefined) + endif() add_link_options(-fsanitize=undefined) endif() diff --git a/Meta/CMake/common_options.cmake b/Meta/CMake/common_options.cmake index 7b9c504df0c..7cd1aca6af1 100644 --- a/Meta/CMake/common_options.cmake +++ b/Meta/CMake/common_options.cmake @@ -9,6 +9,7 @@ endif() serenity_option(ENABLE_COMPILETIME_FORMAT_CHECK ON CACHE BOOL "Enable compiletime format string checks") serenity_option(ENABLE_UNDEFINED_SANITIZER OFF CACHE BOOL "Enable undefined behavior sanitizer testing in gcc/clang") +serenity_option(UNDEFINED_BEHAVIOR_IS_FATAL OFF CACHE BOOL "Make undefined behavior sanitizer errors non-recoverable") serenity_option(ENABLE_ALL_THE_DEBUG_MACROS OFF CACHE BOOL "Enable all debug macros to validate they still compile") serenity_option(ENABLE_ALL_DEBUG_FACILITIES OFF CACHE BOOL "Enable all noisy debug symbols and options. Not recommended for normal developer use") diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 4a347495924..5d300fe58ba 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -119,6 +119,9 @@ endif() if (ENABLE_UNDEFINED_SANITIZER) add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) + if (UNDEFINED_BEHAVIOR_IS_FATAL) + add_compile_options(-fno-sanitize-recover=undefined) + endif() set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=undefined") endif()