1# Copyright (c) 2019 Google LLC 2 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15if(SPIRV_BUILD_FUZZER) 16 17 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/protobufs) 18 19 set(PROTOBUF_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/protobufs/spvtoolsfuzz.proto) 20 21 set( 22 SPIRV_FUZZ_PROTOC_COMMAND 23 "protobuf::protoc" 24 CACHE 25 STRING 26 "The command to invoke the protobuf compiler (protoc). By default it is the protobufs::protoc CMake target. It should be overridden when cross-compiling, such as for Android.") 27 28 add_custom_command( 29 OUTPUT protobufs/spvtoolsfuzz.pb.cc protobufs/spvtoolsfuzz.pb.h 30 COMMAND "${SPIRV_FUZZ_PROTOC_COMMAND}" 31 -I=${CMAKE_CURRENT_SOURCE_DIR}/protobufs 32 --cpp_out=protobufs 33 ${PROTOBUF_SOURCE} 34 DEPENDS ${PROTOBUF_SOURCE} 35 COMMENT "Generate protobuf sources from proto definition file." 36 ) 37 38 set(SPIRV_TOOLS_FUZZ_SOURCES 39 added_function_reducer.h 40 available_instructions.h 41 call_graph.h 42 comparator_deep_blocks_first.h 43 counter_overflow_id_source.h 44 data_descriptor.h 45 equivalence_relation.h 46 fact_manager/constant_uniform_facts.h 47 fact_manager/data_synonym_and_id_equation_facts.h 48 fact_manager/dead_block_facts.h 49 fact_manager/fact_manager.h 50 fact_manager/irrelevant_value_facts.h 51 fact_manager/livesafe_function_facts.h 52 force_render_red.h 53 fuzzer.h 54 fuzzer_context.h 55 fuzzer_pass.h 56 fuzzer_pass_add_access_chains.h 57 fuzzer_pass_add_bit_instruction_synonyms.h 58 fuzzer_pass_add_composite_extract.h 59 fuzzer_pass_add_composite_inserts.h 60 fuzzer_pass_add_composite_types.h 61 fuzzer_pass_add_copy_memory.h 62 fuzzer_pass_add_dead_blocks.h 63 fuzzer_pass_add_dead_breaks.h 64 fuzzer_pass_add_dead_continues.h 65 fuzzer_pass_add_equation_instructions.h 66 fuzzer_pass_add_function_calls.h 67 fuzzer_pass_add_global_variables.h 68 fuzzer_pass_add_image_sample_unused_components.h 69 fuzzer_pass_add_loads.h 70 fuzzer_pass_add_local_variables.h 71 fuzzer_pass_add_loop_preheaders.h 72 fuzzer_pass_add_loops_to_create_int_constant_synonyms.h 73 fuzzer_pass_add_no_contraction_decorations.h 74 fuzzer_pass_add_opphi_synonyms.h 75 fuzzer_pass_add_parameters.h 76 fuzzer_pass_add_relaxed_decorations.h 77 fuzzer_pass_add_stores.h 78 fuzzer_pass_add_synonyms.h 79 fuzzer_pass_add_vector_shuffle_instructions.h 80 fuzzer_pass_adjust_branch_weights.h 81 fuzzer_pass_adjust_function_controls.h 82 fuzzer_pass_adjust_loop_controls.h 83 fuzzer_pass_adjust_memory_operands_masks.h 84 fuzzer_pass_adjust_selection_controls.h 85 fuzzer_pass_apply_id_synonyms.h 86 fuzzer_pass_construct_composites.h 87 fuzzer_pass_copy_objects.h 88 fuzzer_pass_donate_modules.h 89 fuzzer_pass_duplicate_regions_with_selections.h 90 fuzzer_pass_expand_vector_reductions.h 91 fuzzer_pass_flatten_conditional_branches.h 92 fuzzer_pass_inline_functions.h 93 fuzzer_pass_invert_comparison_operators.h 94 fuzzer_pass_interchange_signedness_of_integer_operands.h 95 fuzzer_pass_interchange_zero_like_constants.h 96 fuzzer_pass_make_vector_operations_dynamic.h 97 fuzzer_pass_merge_blocks.h 98 fuzzer_pass_merge_function_returns.h 99 fuzzer_pass_mutate_pointers.h 100 fuzzer_pass_obfuscate_constants.h 101 fuzzer_pass_outline_functions.h 102 fuzzer_pass_permute_blocks.h 103 fuzzer_pass_permute_function_parameters.h 104 fuzzer_pass_permute_function_variables.h 105 fuzzer_pass_permute_instructions.h 106 fuzzer_pass_permute_phi_operands.h 107 fuzzer_pass_propagate_instructions_down.h 108 fuzzer_pass_propagate_instructions_up.h 109 fuzzer_pass_push_ids_through_variables.h 110 fuzzer_pass_replace_adds_subs_muls_with_carrying_extended.h 111 fuzzer_pass_replace_branches_from_dead_blocks_with_exits.h 112 fuzzer_pass_replace_copy_memories_with_loads_stores.h 113 fuzzer_pass_replace_copy_objects_with_stores_loads.h 114 fuzzer_pass_replace_irrelevant_ids.h 115 fuzzer_pass_replace_linear_algebra_instructions.h 116 fuzzer_pass_replace_loads_stores_with_copy_memories.h 117 fuzzer_pass_replace_opphi_ids_from_dead_predecessors.h 118 fuzzer_pass_replace_opselects_with_conditional_branches.h 119 fuzzer_pass_replace_parameter_with_global.h 120 fuzzer_pass_replace_params_with_struct.h 121 fuzzer_pass_split_blocks.h 122 fuzzer_pass_swap_commutable_operands.h 123 fuzzer_pass_swap_conditional_branch_operands.h 124 fuzzer_pass_swap_functions.h 125 fuzzer_pass_toggle_access_chain_instruction.h 126 fuzzer_pass_wrap_regions_in_selections.h 127 fuzzer_pass_wrap_vector_synonym.h 128 fuzzer_util.h 129 id_use_descriptor.h 130 instruction_descriptor.h 131 instruction_message.h 132 overflow_id_source.h 133 pass_management/repeated_pass_instances.h 134 pass_management/repeated_pass_manager.h 135 pass_management/repeated_pass_manager_looped_with_recommendations.h 136 pass_management/repeated_pass_manager_random_with_recommendations.h 137 pass_management/repeated_pass_manager_simple.h 138 pass_management/repeated_pass_recommender.h 139 pass_management/repeated_pass_recommender_standard.h 140 protobufs/spirvfuzz_protobufs.h 141 pseudo_random_generator.h 142 random_generator.h 143 replayer.h 144 shrinker.h 145 transformation.h 146 transformation_access_chain.h 147 transformation_add_bit_instruction_synonym.h 148 transformation_add_constant_boolean.h 149 transformation_add_constant_composite.h 150 transformation_add_constant_null.h 151 transformation_add_constant_scalar.h 152 transformation_add_copy_memory.h 153 transformation_add_dead_block.h 154 transformation_add_dead_break.h 155 transformation_add_dead_continue.h 156 transformation_add_early_terminator_wrapper.h 157 transformation_add_function.h 158 transformation_add_global_undef.h 159 transformation_add_global_variable.h 160 transformation_add_image_sample_unused_components.h 161 transformation_add_local_variable.h 162 transformation_add_loop_preheader.h 163 transformation_add_loop_to_create_int_constant_synonym.h 164 transformation_add_no_contraction_decoration.h 165 transformation_add_opphi_synonym.h 166 transformation_add_parameter.h 167 transformation_add_relaxed_decoration.h 168 transformation_add_spec_constant_op.h 169 transformation_add_synonym.h 170 transformation_add_type_array.h 171 transformation_add_type_boolean.h 172 transformation_add_type_float.h 173 transformation_add_type_function.h 174 transformation_add_type_int.h 175 transformation_add_type_matrix.h 176 transformation_add_type_pointer.h 177 transformation_add_type_struct.h 178 transformation_add_type_vector.h 179 transformation_adjust_branch_weights.h 180 transformation_composite_construct.h 181 transformation_composite_extract.h 182 transformation_composite_insert.h 183 transformation_compute_data_synonym_fact_closure.h 184 transformation_context.h 185 transformation_duplicate_region_with_selection.h 186 transformation_equation_instruction.h 187 transformation_expand_vector_reduction.h 188 transformation_flatten_conditional_branch.h 189 transformation_function_call.h 190 transformation_inline_function.h 191 transformation_invert_comparison_operator.h 192 transformation_load.h 193 transformation_make_vector_operation_dynamic.h 194 transformation_merge_blocks.h 195 transformation_merge_function_returns.h 196 transformation_move_block_down.h 197 transformation_move_instruction_down.h 198 transformation_mutate_pointer.h 199 transformation_outline_function.h 200 transformation_permute_function_parameters.h 201 transformation_permute_phi_operands.h 202 transformation_propagate_instruction_down.h 203 transformation_propagate_instruction_up.h 204 transformation_push_id_through_variable.h 205 transformation_record_synonymous_constants.h 206 transformation_replace_add_sub_mul_with_carrying_extended.h 207 transformation_replace_boolean_constant_with_constant_binary.h 208 transformation_replace_branch_from_dead_block_with_exit.h 209 transformation_replace_constant_with_uniform.h 210 transformation_replace_copy_memory_with_load_store.h 211 transformation_replace_copy_object_with_store_load.h 212 transformation_replace_id_with_synonym.h 213 transformation_replace_irrelevant_id.h 214 transformation_replace_linear_algebra_instruction.h 215 transformation_replace_load_store_with_copy_memory.h 216 transformation_replace_opphi_id_from_dead_predecessor.h 217 transformation_replace_opselect_with_conditional_branch.h 218 transformation_replace_parameter_with_global.h 219 transformation_replace_params_with_struct.h 220 transformation_set_function_control.h 221 transformation_set_loop_control.h 222 transformation_set_memory_operands_mask.h 223 transformation_set_selection_control.h 224 transformation_split_block.h 225 transformation_store.h 226 transformation_swap_commutable_operands.h 227 transformation_swap_conditional_branch_operands.h 228 transformation_swap_function_variables.h 229 transformation_swap_two_functions.h 230 transformation_toggle_access_chain_instruction.h 231 transformation_vector_shuffle.h 232 transformation_wrap_early_terminator_in_function.h 233 transformation_wrap_region_in_selection.h 234 transformation_wrap_vector_synonym.h 235 uniform_buffer_element_descriptor.h 236 ${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.h 237 238 added_function_reducer.cpp 239 available_instructions.cpp 240 call_graph.cpp 241 counter_overflow_id_source.cpp 242 data_descriptor.cpp 243 fact_manager/constant_uniform_facts.cpp 244 fact_manager/data_synonym_and_id_equation_facts.cpp 245 fact_manager/dead_block_facts.cpp 246 fact_manager/fact_manager.cpp 247 fact_manager/irrelevant_value_facts.cpp 248 fact_manager/livesafe_function_facts.cpp 249 force_render_red.cpp 250 fuzzer.cpp 251 fuzzer_context.cpp 252 fuzzer_pass.cpp 253 fuzzer_pass_add_access_chains.cpp 254 fuzzer_pass_add_bit_instruction_synonyms.cpp 255 fuzzer_pass_add_composite_extract.cpp 256 fuzzer_pass_add_composite_inserts.cpp 257 fuzzer_pass_add_composite_types.cpp 258 fuzzer_pass_add_copy_memory.cpp 259 fuzzer_pass_add_dead_blocks.cpp 260 fuzzer_pass_add_dead_breaks.cpp 261 fuzzer_pass_add_dead_continues.cpp 262 fuzzer_pass_add_equation_instructions.cpp 263 fuzzer_pass_add_function_calls.cpp 264 fuzzer_pass_add_global_variables.cpp 265 fuzzer_pass_add_image_sample_unused_components.cpp 266 fuzzer_pass_add_loads.cpp 267 fuzzer_pass_add_local_variables.cpp 268 fuzzer_pass_add_loop_preheaders.cpp 269 fuzzer_pass_add_loops_to_create_int_constant_synonyms.cpp 270 fuzzer_pass_add_no_contraction_decorations.cpp 271 fuzzer_pass_add_opphi_synonyms.cpp 272 fuzzer_pass_add_parameters.cpp 273 fuzzer_pass_add_relaxed_decorations.cpp 274 fuzzer_pass_add_stores.cpp 275 fuzzer_pass_add_synonyms.cpp 276 fuzzer_pass_add_vector_shuffle_instructions.cpp 277 fuzzer_pass_adjust_branch_weights.cpp 278 fuzzer_pass_adjust_function_controls.cpp 279 fuzzer_pass_adjust_loop_controls.cpp 280 fuzzer_pass_adjust_memory_operands_masks.cpp 281 fuzzer_pass_adjust_selection_controls.cpp 282 fuzzer_pass_apply_id_synonyms.cpp 283 fuzzer_pass_construct_composites.cpp 284 fuzzer_pass_copy_objects.cpp 285 fuzzer_pass_donate_modules.cpp 286 fuzzer_pass_duplicate_regions_with_selections.cpp 287 fuzzer_pass_expand_vector_reductions.cpp 288 fuzzer_pass_flatten_conditional_branches.cpp 289 fuzzer_pass_inline_functions.cpp 290 fuzzer_pass_invert_comparison_operators.cpp 291 fuzzer_pass_interchange_signedness_of_integer_operands.cpp 292 fuzzer_pass_interchange_zero_like_constants.cpp 293 fuzzer_pass_make_vector_operations_dynamic.cpp 294 fuzzer_pass_merge_blocks.cpp 295 fuzzer_pass_merge_function_returns.cpp 296 fuzzer_pass_mutate_pointers.cpp 297 fuzzer_pass_obfuscate_constants.cpp 298 fuzzer_pass_outline_functions.cpp 299 fuzzer_pass_permute_blocks.cpp 300 fuzzer_pass_permute_function_parameters.cpp 301 fuzzer_pass_permute_function_variables.cpp 302 fuzzer_pass_permute_instructions.cpp 303 fuzzer_pass_permute_phi_operands.cpp 304 fuzzer_pass_propagate_instructions_down.cpp 305 fuzzer_pass_propagate_instructions_up.cpp 306 fuzzer_pass_push_ids_through_variables.cpp 307 fuzzer_pass_replace_adds_subs_muls_with_carrying_extended.cpp 308 fuzzer_pass_replace_branches_from_dead_blocks_with_exits.cpp 309 fuzzer_pass_replace_copy_memories_with_loads_stores.cpp 310 fuzzer_pass_replace_copy_objects_with_stores_loads.cpp 311 fuzzer_pass_replace_irrelevant_ids.cpp 312 fuzzer_pass_replace_linear_algebra_instructions.cpp 313 fuzzer_pass_replace_loads_stores_with_copy_memories.cpp 314 fuzzer_pass_replace_opphi_ids_from_dead_predecessors.cpp 315 fuzzer_pass_replace_opselects_with_conditional_branches.cpp 316 fuzzer_pass_replace_parameter_with_global.cpp 317 fuzzer_pass_replace_params_with_struct.cpp 318 fuzzer_pass_split_blocks.cpp 319 fuzzer_pass_swap_commutable_operands.cpp 320 fuzzer_pass_swap_conditional_branch_operands.cpp 321 fuzzer_pass_swap_functions.cpp 322 fuzzer_pass_toggle_access_chain_instruction.cpp 323 fuzzer_pass_wrap_regions_in_selections.cpp 324 fuzzer_pass_wrap_vector_synonym.cpp 325 fuzzer_util.cpp 326 id_use_descriptor.cpp 327 instruction_descriptor.cpp 328 instruction_message.cpp 329 overflow_id_source.cpp 330 pass_management/repeated_pass_manager.cpp 331 pass_management/repeated_pass_manager_looped_with_recommendations.cpp 332 pass_management/repeated_pass_manager_random_with_recommendations.cpp 333 pass_management/repeated_pass_manager_simple.cpp 334 pass_management/repeated_pass_recommender.cpp 335 pass_management/repeated_pass_recommender_standard.cpp 336 pseudo_random_generator.cpp 337 random_generator.cpp 338 replayer.cpp 339 shrinker.cpp 340 transformation.cpp 341 transformation_access_chain.cpp 342 transformation_add_bit_instruction_synonym.cpp 343 transformation_add_constant_boolean.cpp 344 transformation_add_constant_composite.cpp 345 transformation_add_constant_null.cpp 346 transformation_add_constant_scalar.cpp 347 transformation_add_copy_memory.cpp 348 transformation_add_dead_block.cpp 349 transformation_add_dead_break.cpp 350 transformation_add_dead_continue.cpp 351 transformation_add_early_terminator_wrapper.cpp 352 transformation_add_function.cpp 353 transformation_add_global_undef.cpp 354 transformation_add_global_variable.cpp 355 transformation_add_image_sample_unused_components.cpp 356 transformation_add_local_variable.cpp 357 transformation_add_loop_preheader.cpp 358 transformation_add_loop_to_create_int_constant_synonym.cpp 359 transformation_add_no_contraction_decoration.cpp 360 transformation_add_opphi_synonym.cpp 361 transformation_add_parameter.cpp 362 transformation_add_relaxed_decoration.cpp 363 transformation_add_spec_constant_op.cpp 364 transformation_add_synonym.cpp 365 transformation_add_type_array.cpp 366 transformation_add_type_boolean.cpp 367 transformation_add_type_float.cpp 368 transformation_add_type_function.cpp 369 transformation_add_type_int.cpp 370 transformation_add_type_matrix.cpp 371 transformation_add_type_pointer.cpp 372 transformation_add_type_struct.cpp 373 transformation_add_type_vector.cpp 374 transformation_adjust_branch_weights.cpp 375 transformation_composite_construct.cpp 376 transformation_composite_extract.cpp 377 transformation_composite_insert.cpp 378 transformation_compute_data_synonym_fact_closure.cpp 379 transformation_context.cpp 380 transformation_duplicate_region_with_selection.cpp 381 transformation_equation_instruction.cpp 382 transformation_expand_vector_reduction.cpp 383 transformation_flatten_conditional_branch.cpp 384 transformation_function_call.cpp 385 transformation_inline_function.cpp 386 transformation_invert_comparison_operator.cpp 387 transformation_load.cpp 388 transformation_make_vector_operation_dynamic.cpp 389 transformation_merge_blocks.cpp 390 transformation_merge_function_returns.cpp 391 transformation_move_block_down.cpp 392 transformation_move_instruction_down.cpp 393 transformation_mutate_pointer.cpp 394 transformation_outline_function.cpp 395 transformation_permute_function_parameters.cpp 396 transformation_permute_phi_operands.cpp 397 transformation_propagate_instruction_down.cpp 398 transformation_propagate_instruction_up.cpp 399 transformation_push_id_through_variable.cpp 400 transformation_record_synonymous_constants.cpp 401 transformation_replace_add_sub_mul_with_carrying_extended.cpp 402 transformation_replace_boolean_constant_with_constant_binary.cpp 403 transformation_replace_branch_from_dead_block_with_exit.cpp 404 transformation_replace_constant_with_uniform.cpp 405 transformation_replace_copy_memory_with_load_store.cpp 406 transformation_replace_copy_object_with_store_load.cpp 407 transformation_replace_id_with_synonym.cpp 408 transformation_replace_irrelevant_id.cpp 409 transformation_replace_linear_algebra_instruction.cpp 410 transformation_replace_load_store_with_copy_memory.cpp 411 transformation_replace_opphi_id_from_dead_predecessor.cpp 412 transformation_replace_opselect_with_conditional_branch.cpp 413 transformation_replace_parameter_with_global.cpp 414 transformation_replace_params_with_struct.cpp 415 transformation_set_function_control.cpp 416 transformation_set_loop_control.cpp 417 transformation_set_memory_operands_mask.cpp 418 transformation_set_selection_control.cpp 419 transformation_split_block.cpp 420 transformation_store.cpp 421 transformation_swap_commutable_operands.cpp 422 transformation_swap_conditional_branch_operands.cpp 423 transformation_swap_function_variables.cpp 424 transformation_swap_two_functions.cpp 425 transformation_toggle_access_chain_instruction.cpp 426 transformation_vector_shuffle.cpp 427 transformation_wrap_early_terminator_in_function.cpp 428 transformation_wrap_region_in_selection.cpp 429 transformation_wrap_vector_synonym.cpp 430 uniform_buffer_element_descriptor.cpp 431 ${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc 432 ) 433 434 if(MSVC AND (NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))) 435 # Enable parallel builds across four cores for this lib 436 add_definitions(/MP4) 437 endif() 438 439 spvtools_pch(SPIRV_TOOLS_FUZZ_SOURCES pch_source_fuzz) 440 441 add_library(SPIRV-Tools-fuzz ${SPIRV_TOOLS_FUZZ_SOURCES}) 442 443 spvtools_default_compile_options(SPIRV-Tools-fuzz) 444 445 # Compilation of the auto-generated protobuf source file will yield warnings, 446 # which we have no control over and thus wish to ignore. 447 if(${COMPILER_IS_LIKE_GNU}) 448 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc PROPERTIES COMPILE_FLAGS -w) 449 endif() 450 if(MSVC) 451 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc PROPERTIES COMPILE_FLAGS /w) 452 endif() 453 454 target_include_directories(SPIRV-Tools-fuzz 455 PUBLIC 456 $<BUILD_INTERFACE:${spirv-tools_SOURCE_DIR}/include> 457 $<BUILD_INTERFACE:${SPIRV_HEADER_INCLUDE_DIR}> 458 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> 459 PRIVATE ${spirv-tools_BINARY_DIR} 460 PRIVATE ${CMAKE_BINARY_DIR}) 461 462 # The fuzzer reuses a lot of functionality from the SPIRV-Tools library. 463 target_link_libraries(SPIRV-Tools-fuzz 464 PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY} 465 PUBLIC SPIRV-Tools-opt 466 PUBLIC SPIRV-Tools-reduce 467 PUBLIC protobuf::libprotobuf) 468 469 set_property(TARGET SPIRV-Tools-fuzz PROPERTY FOLDER "SPIRV-Tools libraries") 470 spvtools_check_symbol_exports(SPIRV-Tools-fuzz) 471 472 if(ENABLE_SPIRV_TOOLS_INSTALL) 473 install(TARGETS SPIRV-Tools-fuzz EXPORT SPIRV-Tools-fuzzTargets 474 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 475 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 476 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 477 export(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTarget.cmake) 478 479 spvtools_config_package_dir(SPIRV-Tools-fuzz PACKAGE_DIR) 480 install(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTarget.cmake 481 DESTINATION ${PACKAGE_DIR}) 482 483 spvtools_generate_config_file(SPIRV-Tools-fuzz) 484 install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-fuzzConfig.cmake DESTINATION ${PACKAGE_DIR}) 485 endif(ENABLE_SPIRV_TOOLS_INSTALL) 486 487endif(SPIRV_BUILD_FUZZER) 488