KhronosGroup / SPIRV-Tools

Apache License 2.0
1.08k stars 555 forks source link

spirv-fuzz: I could not link test_fuzz unless change link.txt #3857

Open ghost opened 4 years ago

ghost commented 4 years ago

When ld is linking c++ excutable test_fuzz, linker command would be command failed just like:

/bin/ld: ../../source/fuzz/libSPIRV-Tools-fuzz.so: undefined reference to `spvtools::utils::CLIMessageConsumer(spv_message_level_t, char const, spv_position_t const&, char const)' clang: error: linker command failed with exit code 1 (use -v to see invocation)

So,I copyed c++ object cli_consumer.cpp.o which contains function CLIMessageConsumer(spv_message_level_t level, const char*,const spv_position_t& position, const char* message) from /SPIRV-Tools/$build_directory/External/spirv-tools/tools/CMakeFiles/spirv-fuzz.dir/ to /SPIRV-Tools/$build_directory/test/fuzz/CMakeFiles/test_fuzz.dir/ and changed /SPIRV-Tools/$build_directory/test/fuzz/CMakeFiles/test_fuzz.dir/link.txt to insert path of cli_consumer.cpp.o into linking command just like:

/bin/clang++ -g -rdynamic -Wl,-undefined,error CMakeFiles/test_fuzz.dir/cli_consumer.cpp.o CMakeFiles/test_fuzz.dir/call_graph_test.cpp.o CMakeFiles/test_fuzz.dir/comparator_deep_blocks_first_test.cpp.o CMakeFiles/test_fuzz.dir/data_synonym_transformation_test.cpp.o CMakeFiles/test_fuzz.dir/equivalence_relation_test.cpp.o CMakeFiles/test_fuzz.dir/fact_manager_test.cpp.o CMakeFiles/test_fuzz.dir/fuzz_test_util.cpp.o CMakeFiles/test_fuzz.dir/fuzzer_pass_add_opphi_synonyms_test.cpp.o CMakeFiles/test_fuzz.dir/fuzzer_pass_construct_composites_test.cpp.o CMakeFiles/test_fuzz.dir/fuzzer_pass_donate_modules_test.cpp.o CMakeFiles/test_fuzz.dir/fuzzer_pass_outline_functions_test.cpp.o CMakeFiles/test_fuzz.dir/instruction_descriptor_test.cpp.o CMakeFiles/test_fuzz.dir/fuzzer_pass_test.cpp.o CMakeFiles/test_fuzz.dir/replayer_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_access_chain_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_bit_instruction_synonym_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_constant_boolean_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_constant_composite_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_constant_null_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_constant_scalar_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_copy_memory_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_dead_block_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_dead_break_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_dead_continue_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_function_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_global_undef_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_global_variable_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_image_sample_unused_components_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_local_variable_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_loop_preheader_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_loop_to_create_int_constant_synonym_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_no_contraction_decoration_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_opphi_synonym_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_parameter_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_relaxed_decoration_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_synonym_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_type_array_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_type_boolean_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_type_float_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_type_function_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_type_int_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_type_matrix_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_type_pointer_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_type_struct_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_add_type_vector_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_adjust_branch_weights_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_composite_construct_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_composite_extract_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_composite_insert_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_compute_data_synonym_fact_closure_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_duplicate_region_with_selection_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_equation_instruction_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_flatten_conditional_branch_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_function_call_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_inline_function_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_invert_comparison_operator_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_load_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_make_vector_operation_dynamic_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_merge_blocks_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_move_block_down_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_move_instruction_down_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_mutate_pointer_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_outline_function_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_permute_function_parameters_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_permute_phi_operands_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_propagate_instruction_up_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_push_id_through_variable_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_add_sub_mul_with_carrying_extended_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_boolean_constant_with_constant_binary_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_copy_object_with_store_load_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_constant_with_uniform_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_copy_memory_with_load_store_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_id_with_synonym_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_irrelevant_id_test.cpp.o which contains function CLIMessageConsumer(spv_message_level_t level, const char,const spv_position_t& position, const char message) CMakeFiles/test_fuzz.dir/transformation_replace_linear_algebra_instruction_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_load_store_with_copy_memory_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_opphi_id_from_dead_predecessor_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_opselect_with_conditional_branch_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_parameter_with_global_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_replace_params_with_struct_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_set_function_control_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_set_loop_control_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_set_memory_operands_mask_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_set_selection_control_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_split_block_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_store_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_swap_commutable_operands_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_swap_conditional_branch_operands_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_toggle_access_chain_instruction_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_record_synonymous_constants_test.cpp.o CMakeFiles/test_fuzz.dir/transformation_vector_shuffle_test.cpp.o CMakeFiles/test_fuzz.dir/uniform_buffer_element_descriptor_test.cpp.o -o test_fuzz -Wl,-rpath,/root/文档/glslang/build/External/spirv-tools/source/fuzz:/root/文档/glslang/build/lib:/root/文档/glslang/build/External/spirv-tools/external/protobuf/cmake ../../source/fuzz/libSPIRV-Tools-fuzz.so ../../external/effcee/effcee/libeffcee.a ../../../../lib/libgmock_maind.so ../../source/opt/libSPIRV-Tools-opt.a ../../source/libSPIRV-Tools.a -lrt ../../external/protobuf/cmake/libprotobufd.so.4.0.0.2 /usr/lib/x86_64-linux-gnu/libz.so ../../external/effcee/third_party/re2/libre2.a ../../../../lib/libgmockd.so ../../../../lib/libgtestd.so -pthread

So ld can reference function and link test _fuzz successfully.

afd commented 4 years ago

Are you following the instructions for building spirv-fuzz in the top-level README.md? Could you give the exact sequence of commands that you're using to build?

ghost commented 4 years ago

Yes, I did. But when I enable spirv-fuzz, error always be occured when it is linking excusable test_fuzz because ld can't find this function. So I searched this function in visual studio code. And then I found the object which is built from cli_consumer.cpp.

ghost commented 4 years ago

I usually config cmake project with cmake gui but not commandline excutable. And then I would like to use gnu make

afd commented 4 years ago

Can you try going carefully through the instructions in:

kokoro/scripts/linux/build.sh

?

If you could provide a log of the commands and their output that would be good - the specific command that is failing and the reason why should become apparent then.

ghost commented 4 years ago

I tried and build is successful. When i build it as a sub project in vulkan-hpp, this problem still exists. and I will view config of spirv-tools build directory and test it

ghost commented 4 years ago

When I enabled BUILD_SHARED_LIBS, ld will failed to link excutable test_fuzz