From 0edfad088a0e3c2949c294bdb53332a89a75a25b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 26 Jul 2016 14:53:07 +0800 Subject: [PATCH] cmake: exclude private symbols in public libs we should avoid exposing non-public symbols from user facing dynamic libraries. so pass '--exclude-libs' with appropriate argument to linker. as libcephfs does not add the ((visibility ("default"))) specifier to the exported symbols, we can not set the default visiblity to hidden for libcephfs, and "-export-symbols-regex" is a libtool option, we need to develop a way for cmake to fix the visibility of libcephfs. it's still a TODO. * librados - pass '--exclude-libs=ALL' to linker - add buffer.cc to librados, so we can use '--exclude-libs=ALL'. * libcephfs: pass '--exclude-libs=libcommon.a,libclient.a,libosdc.a' to linker * libcommon - extract common_buffer_obj from libcommon, to avoid compilation this source file repeatly. * tests: - link against common_internal_objs explicitly if the test in question is using the internal symbols. * ceph-client-debug: - link against client explicitly, and do not link against librados anymore, as it is not used in this tool. Fixes: http://tracker.ceph.com/issues/16556 Signed-off-by: Kefu Chai --- src/CMakeLists.txt | 11 +++++++++-- src/librados/CMakeLists.txt | 6 ++++-- src/test/CMakeLists.txt | 7 ++++--- src/test/librados/CMakeLists.txt | 1 + src/tools/CMakeLists.txt | 2 +- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e3ff71bdc6..2ed57d665fd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -350,6 +350,9 @@ if(HAVE_GOOD_YASM_ELF64) common/crc32c_intel_fast_zero_asm.S) endif(HAVE_GOOD_YASM_ELF64) +add_library(common_buffer_obj OBJECT + common/buffer.cc) + add_library(common_texttable_obj OBJECT common/TextTable.cc) @@ -399,6 +402,7 @@ set(libcommon_files common/TrackedOp.cc common/SloppyCRCMap.cc common/types.cc + $ $ log/Log.cc log/SubsystemMap.cc @@ -432,7 +436,6 @@ set(libcommon_files common/pipe.c common/ceph_argparse.cc common/ceph_context.cc - common/buffer.cc common/code_environment.cc common/dout.cc common/signal.cc @@ -762,10 +765,14 @@ if(WITH_LIBCEPHFS) target_link_libraries(cephfs LINK_PRIVATE client ${CRYPTO_LIBS} ${EXTRALIBS}) if(ENABLE_SHARED) + foreach(name common client osdc) + set(CEPHFS_LINK_FLAGS "${CEPHFS_LINK_FLAGS} -Wl,--exclude-libs,lib${name}.a") + endforeach() set_target_properties(cephfs PROPERTIES OUTPUT_NAME cephfs VERSION 1.0.0 - SOVERSION 1) + SOVERSION 1 + LINK_FLAGS ${CEPHFS_LINK_FLAGS}) endif(ENABLE_SHARED) install(TARGETS cephfs DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(DIRECTORY diff --git a/src/librados/CMakeLists.txt b/src/librados/CMakeLists.txt index b4335a606b8..0ce0c4848d4 100644 --- a/src/librados/CMakeLists.txt +++ b/src/librados/CMakeLists.txt @@ -4,7 +4,8 @@ add_library(librados_objs OBJECT RadosClient.cc) add_library(librados ${CEPH_SHARED} librados.cc - $) + $ + $) add_dependencies(librados osdc) if(WITH_LTTNG) add_dependencies(librados rados-tp) @@ -20,6 +21,7 @@ if(ENABLE_SHARED) # use COMPILE_FLAGS for the backward compatibility with cmake 2.8.11, should have been: # CXX_VISIBILITY_PRESET hidden # VISIBILITY_INLINES_HIDDEN ON - COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden") + COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden" + LINK_FLAGS "-Wl,--exclude-libs,ALL") endif(ENABLE_SHARED) install(TARGETS librados DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 144334df969..38ffbda0ab4 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -338,6 +338,7 @@ set_target_properties(test_rgw_ldap PROPERTIES COMPILE_FLAGS ${UNITTEST_CXX_FLAGS}) target_link_libraries(test_rgw_ldap librados + common ${OPENLDAP_LIBRARIES} ${Boost_LIBRARIES} ${UNITTEST_LIBS} @@ -558,14 +559,14 @@ add_executable(unittest_encoding encoding.cc ) add_ceph_unittest(unittest_encoding ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_encoding) -target_link_libraries(unittest_encoding librados pthread rt m ${BLKID_LIBRARIES}) +target_link_libraries(unittest_encoding common librados pthread rt m ${BLKID_LIBRARIES}) # unittest_addrs add_executable(unittest_addrs test_addrs.cc ) add_ceph_unittest(unittest_addrs ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_addrs) -target_link_libraries(unittest_addrs librados pthread rt m ${BLKID_LIBRARIES}) +target_link_libraries(unittest_addrs common librados pthread rt m ${BLKID_LIBRARIES}) # unittest_workqueue add_executable(unittest_workqueue @@ -740,7 +741,7 @@ add_executable(unittest_heartbeatmap heartbeat_map.cc ) add_ceph_unittest(unittest_heartbeatmap ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_heartbeatmap) -target_link_libraries(unittest_heartbeatmap global) +target_link_libraries(unittest_heartbeatmap common global) if(${WITH_RADOSGW}) # unittest_formatter diff --git a/src/test/librados/CMakeLists.txt b/src/test/librados/CMakeLists.txt index 53dedfcf2d2..237f85899da 100644 --- a/src/test/librados/CMakeLists.txt +++ b/src/test/librados/CMakeLists.txt @@ -3,6 +3,7 @@ set(libradostest_srcs test.cc TestCase.cc) add_library(radostest STATIC ${libradostest_srcs}) +target_link_libraries(radostest common json_spirit) set_target_properties(radostest PROPERTIES COMPILE_FLAGS ${UNITTEST_CXX_FLAGS}) # ceph_test_rados_api_cmd diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index d8f6b5964f3..360330b83c6 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -41,7 +41,7 @@ endif(WITH_FUSE) install(TARGETS ceph-objectstore-tool DESTINATION bin) add_executable(ceph-client-debug ceph-client-debug.cc) -target_link_libraries(ceph-client-debug cephfs librados global common) +target_link_libraries(ceph-client-debug cephfs global client) install(TARGETS ceph-client-debug DESTINATION bin) add_executable(ceph-kvstore-tool ceph_kvstore_tool.cc) -- 2.39.5