]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: exclude private symbols in public libs
authorKefu Chai <kchai@redhat.com>
Tue, 26 Jul 2016 06:53:07 +0000 (14:53 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 28 Jul 2016 11:15:04 +0000 (19:15 +0800)
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 <kchai@redhat.com>
src/CMakeLists.txt
src/librados/CMakeLists.txt
src/test/CMakeLists.txt
src/test/librados/CMakeLists.txt
src/tools/CMakeLists.txt

index 2e3ff71bdc62f10f1dd0999e31ec07929dbaa8cf..2ed57d665fde00d33c5ab20191f6e0a70087e1c8 100644 (file)
@@ -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
+  $<TARGET_OBJECTS:common_buffer_obj>
   $<TARGET_OBJECTS:common_texttable_obj>
   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
index b4335a606b86df8383ee774206b5036e46a825dc..0ce0c4848d45079b4a96ce8dfff6dac2580c2a79 100644 (file)
@@ -4,7 +4,8 @@ add_library(librados_objs OBJECT
   RadosClient.cc)
 add_library(librados ${CEPH_SHARED}
   librados.cc
-  $<TARGET_OBJECTS:librados_objs>)
+  $<TARGET_OBJECTS:librados_objs>
+  $<TARGET_OBJECTS:common_buffer_obj>)
 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})
index 144334df96947875d568acfdbcf6f4cc29a6450e..38ffbda0ab4213bf7ef6c6f121a54d1d35fcbb5d 100644 (file)
@@ -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
index 53dedfcf2d21f19bf3ec72e449f8f759640fd6f5..237f85899da7fda14fa1ad7deae0c4b5d8de10b1 100644 (file)
@@ -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
index d8f6b5964f35e591bcaff5e1d2443fed7adcfe42..360330b83c6c9b739675358c18f14adfabb4465b 100644 (file)
@@ -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)