Rearrange libraries and build files.

This is the first change in an attempt to arrange the linking so that
more errors are detected at link-time.

- All files in server/core but for gateway.c are linked to one shared
  library called maxscale-common.
- The files log_manager/log_manager.cc and utils/skygw_utils.cc are
  built into maxscale-common as well.
- MaxScale itself consists now only of gateway.c and is linked with
  maxscale-common.
- All plugins link with maxscale-common.
- All executables link in addition with {EMBEDDED_LIB}.

After this change, the change (MXS-517) where query_classifier is the
only component that uses ${EMBEDDED_LIB} and the rest mysqlclient can
be made much cleaner.

After a few additional steps, all shared libraries can be linked with
the linker flags "-Wl,-z,defs", which directs the linker to resolve
all symbols. That will require that all shared libraries list all the
libraries they need, but will at the same time ensure that any
missing symbols are detected at link-time and not at run-time.
This commit is contained in:
Johan Wikman
2016-01-22 13:24:49 +02:00
parent a61cedb1aa
commit 1f241a5ed1
19 changed files with 101 additions and 120 deletions

View File

@ -1,19 +1,17 @@
if(BUILD_TESTS OR BUILD_TOOLS)
add_library(fullcore STATIC random_jkiss.c adminusers.c atomic.c config.c buffer.c dbusers.c dcb.c filter.c gwbitmask.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c memlog.c modutil.c monitor.c poll.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c gwdirs.c externcmd.c maxscale_pcre2.c)
if(WITH_JEMALLOC)
target_link_libraries(fullcore ${JEMALLOC_LIBRARIES})
elseif(WITH_TCMALLOC)
target_link_libraries(fullcore ${TCMALLOC_LIBRARIES})
endif()
target_link_libraries(fullcore ${CURL_LIBRARIES} utils ${PCRE2_LIBRARIES} log_manager pthread ${LZMA_LINK_FLAGS} ${EMBEDDED_LIB} ${PCRE_LINK_FLAGS} ssl aio rt crypt dl crypto inih z m stdc++)
add_dependencies(fullcore pcre2)
add_library(maxscale-common SHARED adminusers.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c gw_utils.c hashtable.c hint.c housekeeper.c load_utils.c maxscale_pcre2.c memlog.c modutil.c monitor.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c ${CMAKE_SOURCE_DIR}/log_manager/log_manager.cc ${CMAKE_SOURCE_DIR}/utils/skygw_utils.cc)
target_link_libraries(maxscale-common ${EMBEDDED_LIB} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${PCRE_LINK_FLAGS} ${CURL_LIBRARIES} ssl aio pthread crypt dl crypto inih z rt m stdc++)
if(WITH_JEMALLOC)
target_link_libraries(maxscale-common ${JEMALLOC_LIBRARIES})
elseif(WITH_TCMALLOC)
target_link_libraries(maxscale-common ${TCMALLOC_LIBRARIES})
endif()
add_executable(maxscale atomic.c buffer.c spinlock.c gateway.c
gw_utils.c utils.c dcb.c load_utils.c session.c service.c server.c
poll.c config.c users.c hashtable.c dbusers.c thread.c gwbitmask.c
monitor.c adminusers.c secrets.c filter.c modutil.c hint.c
housekeeper.c memlog.c resultset.c gwdirs.c externcmd.c random_jkiss.c maxscale_pcre2.c)
add_dependencies(maxscale-common pcre2)
install(TARGETS maxscale-common DESTINATION ${MAXSCALE_LIBDIR})
add_executable(maxscale gateway.c)
add_dependencies(maxscale pcre2)
if(WITH_JEMALLOC)
@ -22,15 +20,15 @@ elseif(WITH_TCMALLOC)
target_link_libraries(maxscale ${TCMALLOC_LIBRARIES})
endif()
target_link_libraries(maxscale ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${EMBEDDED_LIB} ${PCRE_LINK_FLAGS} ${CURL_LIBRARIES} log_manager utils ssl aio pthread crypt dl crypto inih z rt m stdc++)
target_link_libraries(maxscale maxscale-common)
install(TARGETS maxscale DESTINATION ${MAXSCALE_BINDIR})
add_executable(maxkeys maxkeys.c spinlock.c secrets.c utils.c gwdirs.c random_jkiss.c ${CMAKE_SOURCE_DIR}/log_manager/log_manager.cc)
target_link_libraries(maxkeys utils pthread crypt crypto ${PCRE2_LIBRARIES})
add_executable(maxkeys maxkeys.c)
target_link_libraries(maxkeys maxscale-common)
install(TARGETS maxkeys DESTINATION ${MAXSCALE_BINDIR})
add_executable(maxpasswd maxpasswd.c spinlock.c secrets.c utils.c gwdirs.c random_jkiss.c ${CMAKE_SOURCE_DIR}/log_manager/log_manager.cc)
target_link_libraries(maxpasswd utils pthread crypt crypto ${PCRE2_LIBRARIES})
add_executable(maxpasswd maxpasswd.c)
target_link_libraries(maxpasswd maxscale-common)
install(TARGETS maxpasswd DESTINATION ${MAXSCALE_BINDIR})
if(BUILD_TESTS)

View File

@ -1,50 +1,50 @@
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${ERRMSG} ${CMAKE_CURRENT_BINARY_DIR})
add_executable(test_mysql_users test_mysql_users.c)
add_executable(test_hash testhash.c ../random_jkiss.c)
add_executable(test_hint testhint.c ../random_jkiss.c)
add_executable(test_spinlock testspinlock.c ../random_jkiss.c)
add_executable(test_filter testfilter.c)
add_executable(test_buffer testbuffer.c ../random_jkiss.c)
add_executable(test_dcb testdcb.c)
add_executable(test_modutil testmodutil.c)
add_executable(test_poll testpoll.c)
add_executable(test_service testservice.c)
add_executable(test_server testserver.c)
add_executable(test_users testusers.c)
add_executable(test_adminusers testadminusers.c)
add_executable(testmemlog testmemlog.c ../random_jkiss.c)
add_executable(test_buffer testbuffer.c)
add_executable(test_dcb testdcb.c)
add_executable(test_filter testfilter.c)
add_executable(test_hash testhash.c)
add_executable(test_hint testhint.c)
add_executable(test_modutil testmodutil.c)
add_executable(test_mysql_users test_mysql_users.c)
add_executable(test_poll testpoll.c)
add_executable(test_server testserver.c)
add_executable(test_service testservice.c)
add_executable(test_spinlock testspinlock.c)
add_executable(test_users testusers.c)
add_executable(testfeedback testfeedback.c)
add_executable(testmaxscalepcre2 testmaxscalepcre2.c ../random_jkiss.c)
target_link_libraries(test_mysql_users MySQLClient fullcore)
target_link_libraries(test_hash fullcore log_manager)
target_link_libraries(test_hint fullcore log_manager)
target_link_libraries(test_spinlock fullcore log_manager)
target_link_libraries(test_filter fullcore)
target_link_libraries(test_buffer fullcore log_manager)
target_link_libraries(test_dcb fullcore)
target_link_libraries(test_modutil fullcore utils log_manager)
target_link_libraries(test_poll fullcore)
target_link_libraries(test_service fullcore)
target_link_libraries(test_server fullcore)
target_link_libraries(test_users fullcore)
target_link_libraries(test_adminusers fullcore)
target_link_libraries(testmemlog fullcore log_manager)
target_link_libraries(testfeedback fullcore)
target_link_libraries(testmaxscalepcre2 fullcore log_manager)
add_test(Internal-TestMySQLUsers test_mysql_users)
add_test(Internal-TestHash test_hash)
add_test(Internal-TestHint test_hint)
add_test(Internal-TestSpinlock test_spinlock)
add_test(Internal-TestFilter test_filter)
add_executable(testmaxscalepcre2 testmaxscalepcre2.c)
add_executable(testmemlog testmemlog.c)
target_link_libraries(test_adminusers maxscale-common)
target_link_libraries(test_buffer maxscale-common)
target_link_libraries(test_dcb maxscale-common)
target_link_libraries(test_filter maxscale-common)
target_link_libraries(test_hash maxscale-common )
target_link_libraries(test_hint maxscale-common )
target_link_libraries(test_modutil maxscale-common)
target_link_libraries(test_mysql_users MySQLClient maxscale-common)
target_link_libraries(test_poll maxscale-common)
target_link_libraries(test_server maxscale-common)
target_link_libraries(test_service maxscale-common)
target_link_libraries(test_spinlock maxscale-common )
target_link_libraries(test_users maxscale-common)
target_link_libraries(testfeedback maxscale-common)
target_link_libraries(testmaxscalepcre2 maxscale-common )
target_link_libraries(testmemlog maxscale-common )
add_test(Internal-TestAdminUsers test_adminusers)
add_test(Internal-TestBuffer test_buffer)
add_test(Internal-TestDCB test_dcb)
add_test(Internal-TestModutil test_modutil)
add_test(Internal-TestPoll test_poll)
add_test(Internal-TestService test_service)
add_test(Internal-TestServer test_server)
add_test(Internal-TestUsers test_users)
add_test(Internal-TestAdminUsers test_adminusers)
add_test(Internal-TestMemlog testmemlog)
add_test(Internal-TestFilter test_filter)
add_test(Internal-TestHash test_hash)
add_test(Internal-TestHint test_hint)
add_test(Internal-TestMaxScalePCRE2 testmaxscalepcre2)
add_test(Internal-TestMemlog testmemlog)
add_test(Internal-TestModutil test_modutil)
add_test(Internal-TestMySQLUsers test_mysql_users)
add_test(Internal-TestPoll test_poll)
add_test(Internal-TestServer test_server)
add_test(Internal-TestService test_service)
add_test(Internal-TestSpinlock test_spinlock)
add_test(Internal-TestUsers test_users)
add_test(TestFeedback testfeedback)
set_tests_properties(TestFeedback PROPERTIES TIMEOUT 30)