diff --git a/src/fuzzers/CMakeLists.txt b/src/fuzzers/CMakeLists.txt index 97a050d265..74097cb00e 100644 --- a/src/fuzzers/CMakeLists.txt +++ b/src/fuzzers/CMakeLists.txt @@ -22,16 +22,26 @@ if ( NOT DEFINED ZEEK_FUZZING_ENGINE AND DEFINED ENV{LIB_FUZZING_ENGINE} ) endif () endif () +# The bind library is handled a bit hack-ishly since it defaults to linking it +# as static library by default on Linux, but at least on one common distro, +# that static library wasn't compiled with -fPIC and so not usable in the +# shared library we're trying to build. So instead, the fuzzer executable, not +# the shared lib, links it. +string(REGEX MATCH ".*\\.a$" _have_static_bind_lib "${BIND_LIBRARY}") + macro(ADD_FUZZ_TARGET _name) set(_fuzz_target zeek-${_name}-fuzzer) set(_fuzz_source ${_name}-fuzzer.cc) add_executable(${_fuzz_target} ${_fuzz_source} ${ARGN}) - target_link_libraries(${_fuzz_target} - zeek_fuzzer_shared - ${BIND_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) + target_link_libraries(${_fuzz_target} zeek_fuzzer_shared) + + if ( _have_static_bind_lib ) + target_link_libraries(${_fuzz_target} ${BIND_LIBRARY}) + endif () + + target_link_libraries(${_fuzz_target} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) if ( DEFINED ZEEK_FUZZING_ENGINE ) target_link_libraries(${_fuzz_target} ${ZEEK_FUZZING_ENGINE}) @@ -55,12 +65,11 @@ add_library(zeek_fuzzer_shared SHARED set(zeek_fuzzer_shared_deps) foreach(_dep ${zeekdeps} ) - # The bind library is handled a bit hack-ishly since it defaults to - # linking it as static library by default on Linux, but at least - # on one common distro, that static library wasn't compiled with -fPIC - # and so not usable in the shared library we're trying to build. - # So instead, the fuzzer executable, not the shared lib, links it. - if ( NOT "${_dep}" STREQUAL "${BIND_LIBRARY}" ) + if ( "${_dep}" STREQUAL "${BIND_LIBRARY}" ) + if ( NOT _have_static_bind_lib ) + set(zeek_fuzzer_shared_deps ${zeek_fuzzer_shared_deps} ${_dep}) + endif () + else () set(zeek_fuzzer_shared_deps ${zeek_fuzzer_shared_deps} ${_dep}) endif () endforeach ()