CMake: Fix sanitizer builds
The sanitizer flags need to be applied to all compilation units, and to all final link stages. As this is whole-project (dawn + tint), these options have been promoted to DAWN_ options. Bug: dawn:1339 Change-Id: I17beb5bd2a8f15de9d8f13d132356b5c663d71bf Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86143 Kokoro-Run: Ben Clayton <bclayton@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
d820f48f35
commit
96e245e576
|
@ -113,6 +113,10 @@ if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
|
||||||
set(BUILD_SAMPLES ON)
|
set(BUILD_SAMPLES ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
option_if_not_defined(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF)
|
||||||
|
option_if_not_defined(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF)
|
||||||
|
option_if_not_defined(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
|
||||||
|
|
||||||
option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
|
option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
|
||||||
option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
|
option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
|
||||||
option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
|
option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
|
||||||
|
@ -155,6 +159,30 @@ if(DAWN_ENABLE_PIC)
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# common_compile_options - sets compiler and linker options common for dawn and
|
||||||
|
# tint on the given target
|
||||||
|
################################################################################
|
||||||
|
function(common_compile_options TARGET)
|
||||||
|
if (COMPILER_IS_LIKE_GNU)
|
||||||
|
target_compile_options(${TARGET} PRIVATE
|
||||||
|
-fno-exceptions
|
||||||
|
-fno-rtti
|
||||||
|
)
|
||||||
|
|
||||||
|
if (${DAWN_ENABLE_MSAN})
|
||||||
|
target_compile_options(${TARGET} PRIVATE -fsanitize=memory)
|
||||||
|
target_link_options(${TARGET} PRIVATE -fsanitize=memory)
|
||||||
|
elseif (${DAWN_ENABLE_ASAN})
|
||||||
|
target_compile_options(${TARGET} PRIVATE -fsanitize=address)
|
||||||
|
target_link_options(${TARGET} PRIVATE -fsanitize=address)
|
||||||
|
elseif (${DAWN_ENABLE_UBSAN})
|
||||||
|
target_compile_options(${TARGET} PRIVATE -fsanitize=undefined)
|
||||||
|
target_link_options(${TARGET} PRIVATE -fsanitize=undefined)
|
||||||
|
endif()
|
||||||
|
endif(COMPILER_IS_LIKE_GNU)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Dawn's public and internal "configs"
|
# Dawn's public and internal "configs"
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -251,10 +279,6 @@ option_if_not_defined(TINT_BUILD_REMOTE_COMPILE "Build the remote-compile tool f
|
||||||
|
|
||||||
set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
|
set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
|
||||||
|
|
||||||
option_if_not_defined(TINT_ENABLE_MSAN "Enable memory sanitizer" OFF)
|
|
||||||
option_if_not_defined(TINT_ENABLE_ASAN "Enable address sanitizer" OFF)
|
|
||||||
option_if_not_defined(TINT_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
|
|
||||||
|
|
||||||
option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
|
option_if_not_defined(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
|
||||||
|
|
||||||
option_if_not_defined(TINT_EMIT_COVERAGE "Emit code coverage information" OFF)
|
option_if_not_defined(TINT_EMIT_COVERAGE "Emit code coverage information" OFF)
|
||||||
|
@ -279,9 +303,9 @@ message(STATUS "Tint build AST fuzzer: ${TINT_BUILD_AST_FUZZER}")
|
||||||
message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}")
|
message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}")
|
||||||
message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
|
message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
|
||||||
message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
|
message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
|
||||||
message(STATUS "Tint build with ASAN: ${TINT_ENABLE_ASAN}")
|
message(STATUS "Tint build with ASAN: ${DAWN_ENABLE_ASAN}")
|
||||||
message(STATUS "Tint build with MSAN: ${TINT_ENABLE_MSAN}")
|
message(STATUS "Tint build with MSAN: ${DAWN_ENABLE_MSAN}")
|
||||||
message(STATUS "Tint build with UBSAN: ${TINT_ENABLE_UBSAN}")
|
message(STATUS "Tint build with UBSAN: ${DAWN_ENABLE_UBSAN}")
|
||||||
message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
|
message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
|
||||||
message(STATUS "Tint build remote-compile tool: ${TINT_BUILD_REMOTE_COMPILE}")
|
message(STATUS "Tint build remote-compile tool: ${TINT_BUILD_REMOTE_COMPILE}")
|
||||||
|
|
||||||
|
@ -438,24 +462,7 @@ function(tint_core_compile_options TARGET)
|
||||||
target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_WRITER=$<BOOL:${TINT_BUILD_SPV_WRITER}>)
|
target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_SPV_WRITER=$<BOOL:${TINT_BUILD_SPV_WRITER}>)
|
||||||
target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_WRITER=$<BOOL:${TINT_BUILD_WGSL_WRITER}>)
|
target_compile_definitions(${TARGET} PUBLIC -DTINT_BUILD_WGSL_WRITER=$<BOOL:${TINT_BUILD_WGSL_WRITER}>)
|
||||||
|
|
||||||
if (COMPILER_IS_LIKE_GNU)
|
common_compile_options(${TARGET})
|
||||||
target_compile_options(${TARGET} PRIVATE
|
|
||||||
-std=c++17
|
|
||||||
-fno-exceptions
|
|
||||||
-fno-rtti
|
|
||||||
)
|
|
||||||
|
|
||||||
if (${TINT_ENABLE_MSAN})
|
|
||||||
target_compile_options(${TARGET} PRIVATE -fsanitize=memory)
|
|
||||||
target_link_options(${TARGET} PRIVATE -fsanitize=memory)
|
|
||||||
elseif (${TINT_ENABLE_ASAN})
|
|
||||||
target_compile_options(${TARGET} PRIVATE -fsanitize=address)
|
|
||||||
target_link_options(${TARGET} PRIVATE -fsanitize=address)
|
|
||||||
elseif (${TINT_ENABLE_UBSAN})
|
|
||||||
target_compile_options(${TARGET} PRIVATE -fsanitize=undefined)
|
|
||||||
target_link_options(${TARGET} PRIVATE -fsanitize=undefined)
|
|
||||||
endif()
|
|
||||||
endif(COMPILER_IS_LIKE_GNU)
|
|
||||||
|
|
||||||
if (TINT_EMIT_COVERAGE)
|
if (TINT_EMIT_COVERAGE)
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||||
|
|
|
@ -131,9 +131,9 @@ if [ "$BUILD_SYSTEM" == "cmake" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$BUILD_SANITIZER" == "asan" ]; then
|
if [ "$BUILD_SANITIZER" == "asan" ]; then
|
||||||
COMMON_CMAKE_FLAGS+=" -DTINT_ENABLE_ASAN=1"
|
COMMON_CMAKE_FLAGS+=" -DDAWN_ENABLE_ASAN=1"
|
||||||
elif [ "$BUILD_SANITIZER" == "ubsan" ]; then
|
elif [ "$BUILD_SANITIZER" == "ubsan" ]; then
|
||||||
COMMON_CMAKE_FLAGS+=" -DTINT_ENABLE_UBSAN=1"
|
COMMON_CMAKE_FLAGS+=" -DDAWN_ENABLE_UBSAN=1"
|
||||||
export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
|
export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
add_library(dawn_sample_utils STATIC ${DAWN_DUMMY_FILE})
|
add_library(dawn_sample_utils STATIC ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawn_sample_utils)
|
||||||
target_sources(dawn_sample_utils PRIVATE
|
target_sources(dawn_sample_utils PRIVATE
|
||||||
"SampleUtils.cpp"
|
"SampleUtils.cpp"
|
||||||
"SampleUtils.h"
|
"SampleUtils.h"
|
||||||
|
@ -29,13 +30,17 @@ target_link_libraries(dawn_sample_utils PUBLIC
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(CppHelloTriangle "CppHelloTriangle.cpp")
|
add_executable(CppHelloTriangle "CppHelloTriangle.cpp")
|
||||||
|
common_compile_options(CppHelloTriangle)
|
||||||
target_link_libraries(CppHelloTriangle dawn_sample_utils)
|
target_link_libraries(CppHelloTriangle dawn_sample_utils)
|
||||||
|
|
||||||
add_executable(CHelloTriangle "CHelloTriangle.cpp")
|
add_executable(CHelloTriangle "CHelloTriangle.cpp")
|
||||||
|
common_compile_options(CHelloTriangle)
|
||||||
target_link_libraries(CHelloTriangle dawn_sample_utils)
|
target_link_libraries(CHelloTriangle dawn_sample_utils)
|
||||||
|
|
||||||
add_executable(ComputeBoids "ComputeBoids.cpp")
|
add_executable(ComputeBoids "ComputeBoids.cpp")
|
||||||
|
common_compile_options(ComputeBoids)
|
||||||
target_link_libraries(ComputeBoids dawn_sample_utils)
|
target_link_libraries(ComputeBoids dawn_sample_utils)
|
||||||
|
|
||||||
add_executable(Animometer "Animometer.cpp")
|
add_executable(Animometer "Animometer.cpp")
|
||||||
|
common_compile_options(Animometer)
|
||||||
target_link_libraries(Animometer dawn_sample_utils)
|
target_link_libraries(Animometer dawn_sample_utils)
|
||||||
|
|
|
@ -64,6 +64,7 @@ DawnJSONGenerator(
|
||||||
# directory, they don't see the GENERATED property and fail to configure
|
# directory, they don't see the GENERATED property and fail to configure
|
||||||
# because the file doesn't exist on disk.
|
# because the file doesn't exist on disk.
|
||||||
add_library(dawn_headers STATIC ${DAWN_DUMMY_FILE})
|
add_library(dawn_headers STATIC ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawn_headers)
|
||||||
target_sources(dawn_headers PRIVATE
|
target_sources(dawn_headers PRIVATE
|
||||||
"${DAWN_INCLUDE_DIR}/dawn/dawn_wsi.h"
|
"${DAWN_INCLUDE_DIR}/dawn/dawn_wsi.h"
|
||||||
${DAWN_HEADERS_GEN_SOURCES}
|
${DAWN_HEADERS_GEN_SOURCES}
|
||||||
|
@ -83,6 +84,7 @@ DawnJSONGenerator(
|
||||||
# This headers only library needs to be a STATIC library, see comment for
|
# This headers only library needs to be a STATIC library, see comment for
|
||||||
# dawn_headers above.
|
# dawn_headers above.
|
||||||
add_library(dawncpp_headers STATIC ${DAWN_DUMMY_FILE})
|
add_library(dawncpp_headers STATIC ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawncpp_headers)
|
||||||
target_sources(dawncpp_headers PRIVATE
|
target_sources(dawncpp_headers PRIVATE
|
||||||
"${DAWN_INCLUDE_DIR}/dawn/EnumClassBitmasks.h"
|
"${DAWN_INCLUDE_DIR}/dawn/EnumClassBitmasks.h"
|
||||||
${DAWNCPP_HEADERS_GEN_SOURCES}
|
${DAWNCPP_HEADERS_GEN_SOURCES}
|
||||||
|
@ -100,6 +102,7 @@ DawnJSONGenerator(
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(dawncpp STATIC ${DAWN_DUMMY_FILE})
|
add_library(dawncpp STATIC ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawncpp)
|
||||||
target_sources(dawncpp PRIVATE ${DAWNCPP_GEN_SOURCES})
|
target_sources(dawncpp PRIVATE ${DAWNCPP_GEN_SOURCES})
|
||||||
target_link_libraries(dawncpp PUBLIC dawncpp_headers)
|
target_link_libraries(dawncpp PUBLIC dawncpp_headers)
|
||||||
|
|
||||||
|
@ -114,6 +117,7 @@ DawnJSONGenerator(
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(dawn_proc ${DAWN_DUMMY_FILE})
|
add_library(dawn_proc ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawn_proc)
|
||||||
target_compile_definitions(dawn_proc PRIVATE "WGPU_IMPLEMENTATION")
|
target_compile_definitions(dawn_proc PRIVATE "WGPU_IMPLEMENTATION")
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
target_compile_definitions(dawn_proc PRIVATE "WGPU_SHARED_LIBRARY")
|
target_compile_definitions(dawn_proc PRIVATE "WGPU_SHARED_LIBRARY")
|
||||||
|
|
|
@ -21,6 +21,7 @@ DawnGenerator(
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(dawn_common STATIC ${DAWN_DUMMY_FILE})
|
add_library(dawn_common STATIC ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawn_common)
|
||||||
target_sources(dawn_common PRIVATE
|
target_sources(dawn_common PRIVATE
|
||||||
${DAWN_VERSION_AUTOGEN_SOURCES}
|
${DAWN_VERSION_AUTOGEN_SOURCES}
|
||||||
"Alloc.h"
|
"Alloc.h"
|
||||||
|
|
|
@ -19,6 +19,7 @@ DawnJSONGenerator(
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(dawn_native ${DAWN_DUMMY_FILE})
|
add_library(dawn_native ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawn_native)
|
||||||
|
|
||||||
target_compile_definitions(dawn_native PRIVATE "DAWN_NATIVE_IMPLEMENTATION")
|
target_compile_definitions(dawn_native PRIVATE "DAWN_NATIVE_IMPLEMENTATION")
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
|
@ -548,6 +549,7 @@ DawnJSONGenerator(
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(webgpu_dawn ${DAWN_DUMMY_FILE})
|
add_library(webgpu_dawn ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(webgpu_dawn)
|
||||||
target_link_libraries(webgpu_dawn PRIVATE dawn_native)
|
target_link_libraries(webgpu_dawn PRIVATE dawn_native)
|
||||||
target_compile_definitions(webgpu_dawn PRIVATE "WGPU_IMPLEMENTATION")
|
target_compile_definitions(webgpu_dawn PRIVATE "WGPU_IMPLEMENTATION")
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
|
|
|
@ -61,6 +61,7 @@ add_subdirectory(interop)
|
||||||
add_library(dawn_node SHARED
|
add_library(dawn_node SHARED
|
||||||
"Module.cpp"
|
"Module.cpp"
|
||||||
)
|
)
|
||||||
|
common_compile_options(dawn_node)
|
||||||
set_target_properties(dawn_node PROPERTIES
|
set_target_properties(dawn_node PROPERTIES
|
||||||
PREFIX ""
|
PREFIX ""
|
||||||
OUTPUT_NAME "dawn"
|
OUTPUT_NAME "dawn"
|
||||||
|
|
|
@ -66,6 +66,7 @@ add_library(dawn_node_binding STATIC
|
||||||
"GPUTextureView.cpp"
|
"GPUTextureView.cpp"
|
||||||
"GPUTextureView.h"
|
"GPUTextureView.h"
|
||||||
)
|
)
|
||||||
|
common_compile_options(dawn_node_binding)
|
||||||
|
|
||||||
target_include_directories(dawn_node_binding
|
target_include_directories(dawn_node_binding
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
|
|
@ -47,6 +47,7 @@ add_library(dawn_node_interop STATIC
|
||||||
"${INTEROP_WEBGPU_H}"
|
"${INTEROP_WEBGPU_H}"
|
||||||
"${INTEROP_WEBGPU_CPP}"
|
"${INTEROP_WEBGPU_CPP}"
|
||||||
)
|
)
|
||||||
|
common_compile_options(dawn_node_interop)
|
||||||
|
|
||||||
target_include_directories(dawn_node_interop
|
target_include_directories(dawn_node_interop
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
add_library(dawn_platform ${DAWN_DUMMY_FILE})
|
add_library(dawn_platform ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawn_platform)
|
||||||
|
|
||||||
target_compile_definitions(dawn_platform PRIVATE "DAWN_PLATFORM_IMPLEMENTATION")
|
target_compile_definitions(dawn_platform PRIVATE "DAWN_PLATFORM_IMPLEMENTATION")
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
add_library(dawn_utils STATIC ${DAWN_DUMMY_FILE})
|
add_library(dawn_utils STATIC ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawn_utils)
|
||||||
target_sources(dawn_utils PRIVATE
|
target_sources(dawn_utils PRIVATE
|
||||||
"ComboRenderBundleEncoderDescriptor.cpp"
|
"ComboRenderBundleEncoderDescriptor.cpp"
|
||||||
"ComboRenderBundleEncoderDescriptor.h"
|
"ComboRenderBundleEncoderDescriptor.h"
|
||||||
|
|
|
@ -19,6 +19,7 @@ DawnJSONGenerator(
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(dawn_wire ${DAWN_DUMMY_FILE})
|
add_library(dawn_wire ${DAWN_DUMMY_FILE})
|
||||||
|
common_compile_options(dawn_wire)
|
||||||
|
|
||||||
target_compile_definitions(dawn_wire PRIVATE "DAWN_WIRE_IMPLEMENTATION")
|
target_compile_definitions(dawn_wire PRIVATE "DAWN_WIRE_IMPLEMENTATION")
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
|
|
Loading…
Reference in New Issue