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_instructions.h 105 fuzzer_pass_permute_phi_operands.h 106 fuzzer_pass_propagate_instructions_down.h 107 fuzzer_pass_propagate_instructions_up.h 108 fuzzer_pass_push_ids_through_variables.h 109 fuzzer_pass_replace_adds_subs_muls_with_carrying_extended.h 110 fuzzer_pass_replace_branches_from_dead_blocks_with_exits.h 111 fuzzer_pass_replace_copy_memories_with_loads_stores.h 112 fuzzer_pass_replace_copy_objects_with_stores_loads.h 113 fuzzer_pass_replace_irrelevant_ids.h 114 fuzzer_pass_replace_linear_algebra_instructions.h 115 fuzzer_pass_replace_loads_stores_with_copy_memories.h 116 fuzzer_pass_replace_opphi_ids_from_dead_predecessors.h 117 fuzzer_pass_replace_opselects_with_conditional_branches.h 118 fuzzer_pass_replace_parameter_with_global.h 119 fuzzer_pass_replace_params_with_struct.h 120 fuzzer_pass_split_blocks.h 121 fuzzer_pass_swap_commutable_operands.h 122 fuzzer_pass_swap_conditional_branch_operands.h 123 fuzzer_pass_toggle_access_chain_instruction.h 124 fuzzer_pass_wrap_regions_in_selections.h 125 fuzzer_util.h 126 id_use_descriptor.h 127 instruction_descriptor.h 128 instruction_message.h 129 overflow_id_source.h 130 pass_management/repeated_pass_instances.h 131 pass_management/repeated_pass_manager.h 132 pass_management/repeated_pass_manager_looped_with_recommendations.h 133 pass_management/repeated_pass_manager_random_with_recommendations.h 134 pass_management/repeated_pass_manager_simple.h 135 pass_management/repeated_pass_recommender.h 136 pass_management/repeated_pass_recommender_standard.h 137 protobufs/spirvfuzz_protobufs.h 138 pseudo_random_generator.h 139 random_generator.h 140 replayer.h 141 shrinker.h 142 transformation.h 143 transformation_access_chain.h 144 transformation_add_bit_instruction_synonym.h 145 transformation_add_constant_boolean.h 146 transformation_add_constant_composite.h 147 transformation_add_constant_null.h 148 transformation_add_constant_scalar.h 149 transformation_add_copy_memory.h 150 transformation_add_dead_block.h 151 transformation_add_dead_break.h 152 transformation_add_dead_continue.h 153 transformation_add_early_terminator_wrapper.h 154 transformation_add_function.h 155 transformation_add_global_undef.h 156 transformation_add_global_variable.h 157 transformation_add_image_sample_unused_components.h 158 transformation_add_local_variable.h 159 transformation_add_loop_preheader.h 160 transformation_add_loop_to_create_int_constant_synonym.h 161 transformation_add_no_contraction_decoration.h 162 transformation_add_opphi_synonym.h 163 transformation_add_parameter.h 164 transformation_add_relaxed_decoration.h 165 transformation_add_spec_constant_op.h 166 transformation_add_synonym.h 167 transformation_add_type_array.h 168 transformation_add_type_boolean.h 169 transformation_add_type_float.h 170 transformation_add_type_function.h 171 transformation_add_type_int.h 172 transformation_add_type_matrix.h 173 transformation_add_type_pointer.h 174 transformation_add_type_struct.h 175 transformation_add_type_vector.h 176 transformation_adjust_branch_weights.h 177 transformation_composite_construct.h 178 transformation_composite_extract.h 179 transformation_composite_insert.h 180 transformation_compute_data_synonym_fact_closure.h 181 transformation_context.h 182 transformation_duplicate_region_with_selection.h 183 transformation_equation_instruction.h 184 transformation_expand_vector_reduction.h 185 transformation_flatten_conditional_branch.h 186 transformation_function_call.h 187 transformation_inline_function.h 188 transformation_invert_comparison_operator.h 189 transformation_load.h 190 transformation_make_vector_operation_dynamic.h 191 transformation_merge_blocks.h 192 transformation_merge_function_returns.h 193 transformation_move_block_down.h 194 transformation_move_instruction_down.h 195 transformation_mutate_pointer.h 196 transformation_outline_function.h 197 transformation_permute_function_parameters.h 198 transformation_permute_phi_operands.h 199 transformation_propagate_instruction_down.h 200 transformation_propagate_instruction_up.h 201 transformation_push_id_through_variable.h 202 transformation_record_synonymous_constants.h 203 transformation_replace_add_sub_mul_with_carrying_extended.h 204 transformation_replace_boolean_constant_with_constant_binary.h 205 transformation_replace_branch_from_dead_block_with_exit.h 206 transformation_replace_constant_with_uniform.h 207 transformation_replace_copy_memory_with_load_store.h 208 transformation_replace_copy_object_with_store_load.h 209 transformation_replace_id_with_synonym.h 210 transformation_replace_irrelevant_id.h 211 transformation_replace_linear_algebra_instruction.h 212 transformation_replace_load_store_with_copy_memory.h 213 transformation_replace_opphi_id_from_dead_predecessor.h 214 transformation_replace_opselect_with_conditional_branch.h 215 transformation_replace_parameter_with_global.h 216 transformation_replace_params_with_struct.h 217 transformation_set_function_control.h 218 transformation_set_loop_control.h 219 transformation_set_memory_operands_mask.h 220 transformation_set_selection_control.h 221 transformation_split_block.h 222 transformation_store.h 223 transformation_swap_commutable_operands.h 224 transformation_swap_conditional_branch_operands.h 225 transformation_toggle_access_chain_instruction.h 226 transformation_vector_shuffle.h 227 transformation_wrap_early_terminator_in_function.h 228 transformation_wrap_region_in_selection.h 229 uniform_buffer_element_descriptor.h 230 ${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.h 231 232 added_function_reducer.cpp 233 available_instructions.cpp 234 call_graph.cpp 235 counter_overflow_id_source.cpp 236 data_descriptor.cpp 237 fact_manager/constant_uniform_facts.cpp 238 fact_manager/data_synonym_and_id_equation_facts.cpp 239 fact_manager/dead_block_facts.cpp 240 fact_manager/fact_manager.cpp 241 fact_manager/irrelevant_value_facts.cpp 242 fact_manager/livesafe_function_facts.cpp 243 force_render_red.cpp 244 fuzzer.cpp 245 fuzzer_context.cpp 246 fuzzer_pass.cpp 247 fuzzer_pass_add_access_chains.cpp 248 fuzzer_pass_add_bit_instruction_synonyms.cpp 249 fuzzer_pass_add_composite_extract.cpp 250 fuzzer_pass_add_composite_inserts.cpp 251 fuzzer_pass_add_composite_types.cpp 252 fuzzer_pass_add_copy_memory.cpp 253 fuzzer_pass_add_dead_blocks.cpp 254 fuzzer_pass_add_dead_breaks.cpp 255 fuzzer_pass_add_dead_continues.cpp 256 fuzzer_pass_add_equation_instructions.cpp 257 fuzzer_pass_add_function_calls.cpp 258 fuzzer_pass_add_global_variables.cpp 259 fuzzer_pass_add_image_sample_unused_components.cpp 260 fuzzer_pass_add_loads.cpp 261 fuzzer_pass_add_local_variables.cpp 262 fuzzer_pass_add_loop_preheaders.cpp 263 fuzzer_pass_add_loops_to_create_int_constant_synonyms.cpp 264 fuzzer_pass_add_no_contraction_decorations.cpp 265 fuzzer_pass_add_opphi_synonyms.cpp 266 fuzzer_pass_add_parameters.cpp 267 fuzzer_pass_add_relaxed_decorations.cpp 268 fuzzer_pass_add_stores.cpp 269 fuzzer_pass_add_synonyms.cpp 270 fuzzer_pass_add_vector_shuffle_instructions.cpp 271 fuzzer_pass_adjust_branch_weights.cpp 272 fuzzer_pass_adjust_function_controls.cpp 273 fuzzer_pass_adjust_loop_controls.cpp 274 fuzzer_pass_adjust_memory_operands_masks.cpp 275 fuzzer_pass_adjust_selection_controls.cpp 276 fuzzer_pass_apply_id_synonyms.cpp 277 fuzzer_pass_construct_composites.cpp 278 fuzzer_pass_copy_objects.cpp 279 fuzzer_pass_donate_modules.cpp 280 fuzzer_pass_duplicate_regions_with_selections.cpp 281 fuzzer_pass_expand_vector_reductions.cpp 282 fuzzer_pass_flatten_conditional_branches.cpp 283 fuzzer_pass_inline_functions.cpp 284 fuzzer_pass_invert_comparison_operators.cpp 285 fuzzer_pass_interchange_signedness_of_integer_operands.cpp 286 fuzzer_pass_interchange_zero_like_constants.cpp 287 fuzzer_pass_make_vector_operations_dynamic.cpp 288 fuzzer_pass_merge_blocks.cpp 289 fuzzer_pass_merge_function_returns.cpp 290 fuzzer_pass_mutate_pointers.cpp 291 fuzzer_pass_obfuscate_constants.cpp 292 fuzzer_pass_outline_functions.cpp 293 fuzzer_pass_permute_blocks.cpp 294 fuzzer_pass_permute_function_parameters.cpp 295 fuzzer_pass_permute_instructions.cpp 296 fuzzer_pass_permute_phi_operands.cpp 297 fuzzer_pass_propagate_instructions_down.cpp 298 fuzzer_pass_propagate_instructions_up.cpp 299 fuzzer_pass_push_ids_through_variables.cpp 300 fuzzer_pass_replace_adds_subs_muls_with_carrying_extended.cpp 301 fuzzer_pass_replace_branches_from_dead_blocks_with_exits.cpp 302 fuzzer_pass_replace_copy_memories_with_loads_stores.cpp 303 fuzzer_pass_replace_copy_objects_with_stores_loads.cpp 304 fuzzer_pass_replace_irrelevant_ids.cpp 305 fuzzer_pass_replace_linear_algebra_instructions.cpp 306 fuzzer_pass_replace_loads_stores_with_copy_memories.cpp 307 fuzzer_pass_replace_opphi_ids_from_dead_predecessors.cpp 308 fuzzer_pass_replace_opselects_with_conditional_branches.cpp 309 fuzzer_pass_replace_parameter_with_global.cpp 310 fuzzer_pass_replace_params_with_struct.cpp 311 fuzzer_pass_split_blocks.cpp 312 fuzzer_pass_swap_commutable_operands.cpp 313 fuzzer_pass_swap_conditional_branch_operands.cpp 314 fuzzer_pass_toggle_access_chain_instruction.cpp 315 fuzzer_pass_wrap_regions_in_selections.cpp 316 fuzzer_util.cpp 317 id_use_descriptor.cpp 318 instruction_descriptor.cpp 319 instruction_message.cpp 320 overflow_id_source.cpp 321 pass_management/repeated_pass_manager.cpp 322 pass_management/repeated_pass_manager_looped_with_recommendations.cpp 323 pass_management/repeated_pass_manager_random_with_recommendations.cpp 324 pass_management/repeated_pass_manager_simple.cpp 325 pass_management/repeated_pass_recommender.cpp 326 pass_management/repeated_pass_recommender_standard.cpp 327 pseudo_random_generator.cpp 328 random_generator.cpp 329 replayer.cpp 330 shrinker.cpp 331 transformation.cpp 332 transformation_access_chain.cpp 333 transformation_add_bit_instruction_synonym.cpp 334 transformation_add_constant_boolean.cpp 335 transformation_add_constant_composite.cpp 336 transformation_add_constant_null.cpp 337 transformation_add_constant_scalar.cpp 338 transformation_add_copy_memory.cpp 339 transformation_add_dead_block.cpp 340 transformation_add_dead_break.cpp 341 transformation_add_dead_continue.cpp 342 transformation_add_early_terminator_wrapper.cpp 343 transformation_add_function.cpp 344 transformation_add_global_undef.cpp 345 transformation_add_global_variable.cpp 346 transformation_add_image_sample_unused_components.cpp 347 transformation_add_local_variable.cpp 348 transformation_add_loop_preheader.cpp 349 transformation_add_loop_to_create_int_constant_synonym.cpp 350 transformation_add_no_contraction_decoration.cpp 351 transformation_add_opphi_synonym.cpp 352 transformation_add_parameter.cpp 353 transformation_add_relaxed_decoration.cpp 354 transformation_add_spec_constant_op.cpp 355 transformation_add_synonym.cpp 356 transformation_add_type_array.cpp 357 transformation_add_type_boolean.cpp 358 transformation_add_type_float.cpp 359 transformation_add_type_function.cpp 360 transformation_add_type_int.cpp 361 transformation_add_type_matrix.cpp 362 transformation_add_type_pointer.cpp 363 transformation_add_type_struct.cpp 364 transformation_add_type_vector.cpp 365 transformation_adjust_branch_weights.cpp 366 transformation_composite_construct.cpp 367 transformation_composite_extract.cpp 368 transformation_composite_insert.cpp 369 transformation_compute_data_synonym_fact_closure.cpp 370 transformation_context.cpp 371 transformation_duplicate_region_with_selection.cpp 372 transformation_equation_instruction.cpp 373 transformation_expand_vector_reduction.cpp 374 transformation_flatten_conditional_branch.cpp 375 transformation_function_call.cpp 376 transformation_inline_function.cpp 377 transformation_invert_comparison_operator.cpp 378 transformation_load.cpp 379 transformation_make_vector_operation_dynamic.cpp 380 transformation_merge_blocks.cpp 381 transformation_merge_function_returns.cpp 382 transformation_move_block_down.cpp 383 transformation_move_instruction_down.cpp 384 transformation_mutate_pointer.cpp 385 transformation_outline_function.cpp 386 transformation_permute_function_parameters.cpp 387 transformation_permute_phi_operands.cpp 388 transformation_propagate_instruction_down.cpp 389 transformation_propagate_instruction_up.cpp 390 transformation_push_id_through_variable.cpp 391 transformation_record_synonymous_constants.cpp 392 transformation_replace_add_sub_mul_with_carrying_extended.cpp 393 transformation_replace_boolean_constant_with_constant_binary.cpp 394 transformation_replace_branch_from_dead_block_with_exit.cpp 395 transformation_replace_constant_with_uniform.cpp 396 transformation_replace_copy_memory_with_load_store.cpp 397 transformation_replace_copy_object_with_store_load.cpp 398 transformation_replace_id_with_synonym.cpp 399 transformation_replace_irrelevant_id.cpp 400 transformation_replace_linear_algebra_instruction.cpp 401 transformation_replace_load_store_with_copy_memory.cpp 402 transformation_replace_opphi_id_from_dead_predecessor.cpp 403 transformation_replace_opselect_with_conditional_branch.cpp 404 transformation_replace_parameter_with_global.cpp 405 transformation_replace_params_with_struct.cpp 406 transformation_set_function_control.cpp 407 transformation_set_loop_control.cpp 408 transformation_set_memory_operands_mask.cpp 409 transformation_set_selection_control.cpp 410 transformation_split_block.cpp 411 transformation_store.cpp 412 transformation_swap_commutable_operands.cpp 413 transformation_swap_conditional_branch_operands.cpp 414 transformation_toggle_access_chain_instruction.cpp 415 transformation_vector_shuffle.cpp 416 transformation_wrap_early_terminator_in_function.cpp 417 transformation_wrap_region_in_selection.cpp 418 uniform_buffer_element_descriptor.cpp 419 ${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc 420 ) 421 422 if(MSVC AND (NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))) 423 # Enable parallel builds across four cores for this lib 424 add_definitions(/MP4) 425 endif() 426 427 spvtools_pch(SPIRV_TOOLS_FUZZ_SOURCES pch_source_fuzz) 428 429 add_library(SPIRV-Tools-fuzz ${SPIRV_TOOLS_FUZZ_SOURCES}) 430 431 spvtools_default_compile_options(SPIRV-Tools-fuzz) 432 433 # Compilation of the auto-generated protobuf source file will yield warnings, 434 # which we have no control over and thus wish to ignore. 435 if(${COMPILER_IS_LIKE_GNU}) 436 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc PROPERTIES COMPILE_FLAGS -w) 437 endif() 438 if(MSVC) 439 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/protobufs/spvtoolsfuzz.pb.cc PROPERTIES COMPILE_FLAGS /w) 440 endif() 441 442 target_include_directories(SPIRV-Tools-fuzz 443 PUBLIC 444 $<BUILD_INTERFACE:${spirv-tools_SOURCE_DIR}/include> 445 $<BUILD_INTERFACE:${SPIRV_HEADER_INCLUDE_DIR}> 446 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> 447 PRIVATE ${spirv-tools_BINARY_DIR} 448 PRIVATE ${CMAKE_BINARY_DIR}) 449 450 # The fuzzer reuses a lot of functionality from the SPIRV-Tools library. 451 target_link_libraries(SPIRV-Tools-fuzz 452 PUBLIC ${SPIRV_TOOLS_FULL_VISIBILITY} 453 PUBLIC SPIRV-Tools-opt 454 PUBLIC SPIRV-Tools-reduce 455 PUBLIC protobuf::libprotobuf) 456 457 set_property(TARGET SPIRV-Tools-fuzz PROPERTY FOLDER "SPIRV-Tools libraries") 458 spvtools_check_symbol_exports(SPIRV-Tools-fuzz) 459 460 if(ENABLE_SPIRV_TOOLS_INSTALL) 461 install(TARGETS SPIRV-Tools-fuzz EXPORT SPIRV-Tools-fuzzTargets 462 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 463 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 464 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 465 export(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTarget.cmake) 466 467 spvtools_config_package_dir(SPIRV-Tools-fuzz PACKAGE_DIR) 468 install(EXPORT SPIRV-Tools-fuzzTargets FILE SPIRV-Tools-fuzzTarget.cmake 469 DESTINATION ${PACKAGE_DIR}) 470 471 spvtools_generate_config_file(SPIRV-Tools-fuzz) 472 install(FILES ${CMAKE_BINARY_DIR}/SPIRV-Tools-fuzzConfig.cmake DESTINATION ${PACKAGE_DIR}) 473 endif(ENABLE_SPIRV_TOOLS_INSTALL) 474 475endif(SPIRV_BUILD_FUZZER) 476