diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index adcc59844b..9a50ede597 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -395,7 +395,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-pie") # secure to run in production builds. Useful for coverage guided fuzzing. if (ENABLE_KERNEL_COVERAGE_COLLECTION) add_definitions(-DENABLE_KERNEL_COVERAGE_COLLECTION) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-coverage=trace-pc") + add_compile_options(-fsanitize-coverage=trace-pc) set(KCOV_EXCLUDED_SOURCES # Make sure we don't instrument any code called from __sanitizer_cov_trace_pc # otherwise we'll end up with recursive calls to that function. @@ -427,7 +427,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") # is not currently meant to be used, besides when developing Kernel ASAN support. # if (ENABLE_KERNEL_ADDRESS_SANITIZER) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=kernel-address") + add_compile_options(-fsanitize=kernel-address) endif() add_compile_definitions(KERNEL) diff --git a/Kernel/Prekernel/CMakeLists.txt b/Kernel/Prekernel/CMakeLists.txt index a950245170..4efcd4eef2 100644 --- a/Kernel/Prekernel/CMakeLists.txt +++ b/Kernel/Prekernel/CMakeLists.txt @@ -34,4 +34,9 @@ add_custom_command( ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Prekernel" DESTINATION boot) -set_source_files_properties(${SOURCES} PROPERTIES COMPILE_FLAGS "-fno-sanitize-coverage=trace-pc -fno-sanitize=kernel-address") + +# Remove options which the Prekernel environment doesn't support. +get_target_property(PREKERNEL_TARGET_OPTIONS ${PREKERNEL_TARGET} COMPILE_OPTIONS) +list(REMOVE_ITEM PREKERNEL_TARGET_OPTIONS "-fsanitize-coverage=trace-pc") +list(REMOVE_ITEM PREKERNEL_TARGET_OPTIONS "-fsanitize=kernel-address") +set_target_properties(${PREKERNEL_TARGET} PROPERTIES COMPILE_OPTIONS "${PREKERNEL_TARGET_OPTIONS}")