diff --git a/cmake/FlowCommands.cmake b/cmake/FlowCommands.cmake index f8dfe66653..4d7fa4f2c2 100644 --- a/cmake/FlowCommands.cmake +++ b/cmake/FlowCommands.cmake @@ -189,7 +189,7 @@ endfunction() function(add_flow_target) set(options EXECUTABLE STATIC_LIBRARY - DYNAMIC_LIBRARY) + DYNAMIC_LIBRARY LINK_TEST) set(oneValueArgs NAME) set(multiValueArgs SRCS COVERAGE_FILTER_OUT DISABLE_ACTOR_DIAGNOSTICS ADDL_SRCS) cmake_parse_arguments(AFT "${options}" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") @@ -277,6 +277,12 @@ function(add_flow_target) set(strip_target ON) add_library(${AFT_NAME} DYNAMIC ${sources} ${AFT_ADDL_SRCS}) endif() + if(AFT_LINK_TEST) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/linktest) + set(strip_target ON) + set(target_type exec) + add_executable(${AFT_NAME} ${sources} ${AFT_ADDL_SRCS}) + endif() foreach(src IN LISTS sources AFT_ADDL_SRCS) get_filename_component(dname ${CMAKE_CURRENT_SOURCE_DIR} NAME) diff --git a/contrib/crc32/crc32_wrapper.c b/contrib/crc32/crc32_wrapper.c index 2edfd7778d..fbf1aa5bac 100644 --- a/contrib/crc32/crc32_wrapper.c +++ b/contrib/crc32/crc32_wrapper.c @@ -45,6 +45,7 @@ static unsigned int crc32_align(unsigned int crc, unsigned char* p, unsigned lon unsigned int CRC32_FUNCTION_ASM(unsigned int crc, unsigned char* p, unsigned long len); unsigned int CRC32_FUNCTION(unsigned int crc, unsigned char* p, unsigned long len) { +#ifdef __powerpc64 // avoid link failures on systems without CRC32_FUNCTION_ASM declared unsigned int prealign; unsigned int tail; @@ -76,6 +77,6 @@ out: #ifdef CRC_XOR crc ^= 0xffffffff; #endif - +#endif return crc; } diff --git a/fdbclient/CMakeLists.txt b/fdbclient/CMakeLists.txt index 3fbd7965cc..6b5ee87788 100644 --- a/fdbclient/CMakeLists.txt +++ b/fdbclient/CMakeLists.txt @@ -89,6 +89,9 @@ if(WIN32) add_dependencies(fdbclient_sampling_actors fdbclient_actors) endif() +add_flow_target(LINK_TEST NAME fdbclientlinktest SRCS ${FDBCLIENT_SRCS} LinkTest.cpp ADDL_SRCS ${options_srcs}) +target_link_libraries(fdbclientlinktest PRIVATE fdbclient rapidxml) # re-link rapidxml due to private link interface + if(BUILD_AZURE_BACKUP) target_link_libraries(fdbclient PRIVATE curl uuid azure-storage-lite) target_link_libraries(fdbclient_sampling PRIVATE curl uuid azure-storage-lite) diff --git a/fdbclient/LinkTest.cpp b/fdbclient/LinkTest.cpp new file mode 100644 index 0000000000..73dcd817a2 --- /dev/null +++ b/fdbclient/LinkTest.cpp @@ -0,0 +1,8 @@ +// When creating a static or shared library, undefined symbols will be ignored. +// Since we want to ensure no symbols from other modules are used, each module +// will create an executable so the linker will throw errors if it can't find +// the declaration of a symbol. This class defines a dummy main function so the +// executable can be built. +int main() { + return 0; +} diff --git a/fdbrpc/CMakeLists.txt b/fdbrpc/CMakeLists.txt index de92e266e9..ab10b6e90b 100644 --- a/fdbrpc/CMakeLists.txt +++ b/fdbrpc/CMakeLists.txt @@ -25,6 +25,10 @@ add_flow_target(STATIC_LIBRARY NAME fdbrpc_sampling SRCS ${FDBRPC_SRCS} DISABLE_ACTOR_DIAGNOSTICS ${FDBRPC_SRCS_DISABLE_ACTOR_DIAGNOSTICS}) +add_flow_target(LINK_TEST NAME fdbrpclinktest SRCS ${FDBRPC_SRCS} LinkTest.cpp DISABLE_ACTOR_DIAGNOSTICS ${FDBRPC_SRCS_DISABLE_ACTOR_DIAGNOSTICS}) +target_link_libraries(fdbrpclinktest PRIVATE fdbrpc rapidjson) +target_include_directories(fdbrpclinktest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libeio) + if(COMPILE_EIO) add_library(eio STATIC libeio/eio.c) if(USE_VALGRIND) diff --git a/fdbrpc/LinkTest.cpp b/fdbrpc/LinkTest.cpp new file mode 100644 index 0000000000..73dcd817a2 --- /dev/null +++ b/fdbrpc/LinkTest.cpp @@ -0,0 +1,8 @@ +// When creating a static or shared library, undefined symbols will be ignored. +// Since we want to ensure no symbols from other modules are used, each module +// will create an executable so the linker will throw errors if it can't find +// the declaration of a symbol. This class defines a dummy main function so the +// executable can be built. +int main() { + return 0; +} diff --git a/flow/CMakeLists.txt b/flow/CMakeLists.txt index 3034c77ba6..2a943da5a1 100644 --- a/flow/CMakeLists.txt +++ b/flow/CMakeLists.txt @@ -2,6 +2,10 @@ find_package(Threads REQUIRED) fdb_find_sources(FLOW_SRCS) +# Remove files with `main` defined so we can create a link test executable. +list(REMOVE_ITEM FLOW_SRCS TLSTest.cpp) +list(REMOVE_ITEM FLOW_SRCS MkCertCli.cpp) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") list(APPEND FLOW_SRCS aarch64/memcmp.S aarch64/memcpy.S) endif() @@ -13,7 +17,14 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY add_flow_target(STATIC_LIBRARY NAME flow SRCS ${FLOW_SRCS}) add_flow_target(STATIC_LIBRARY NAME flow_sampling SRCS ${FLOW_SRCS}) -foreach(ft flow flow_sampling) +# When creating a static or shared library, undefined symbols will be ignored. +# Since we want to ensure no symbols from other modules are used, create an +# executable so the linker will throw errors if it can't find the declaration +# of a symbol. +add_flow_target(LINK_TEST NAME flowlinktest SRCS ${FLOW_SRCS} LinkTest.cpp) +target_link_libraries(flowlinktest PRIVATE flow stacktrace) + +foreach(ft flow flow_sampling flowlinktest) target_include_directories(${ft} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include") target_link_libraries(${ft} PRIVATE stacktrace) @@ -68,7 +79,6 @@ if(WIN32) add_dependencies(flow_sampling_actors flow_actors) endif() - add_executable(mkcert MkCertCli.cpp) target_link_libraries(mkcert PUBLIC flow) diff --git a/flow/LinkTest.cpp b/flow/LinkTest.cpp new file mode 100644 index 0000000000..73dcd817a2 --- /dev/null +++ b/flow/LinkTest.cpp @@ -0,0 +1,8 @@ +// When creating a static or shared library, undefined symbols will be ignored. +// Since we want to ensure no symbols from other modules are used, each module +// will create an executable so the linker will throw errors if it can't find +// the declaration of a symbol. This class defines a dummy main function so the +// executable can be built. +int main() { + return 0; +}