]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: convert erasure_code and json_spirit to OBJECT libraries 65729/head
authorKefu Chai <k.chai@proxmox.com>
Tue, 30 Sep 2025 10:38:31 +0000 (18:38 +0800)
committerKefu Chai <k.chai@proxmox.com>
Sat, 6 Dec 2025 12:30:16 +0000 (20:30 +0800)
This resolves a circular dependency issue where ceph-common was linked
against erasure_code and json_spirit static libraries, while these
libraries themselves referenced symbols from ceph-common, creating an
unresolvable circular dependency. The static libraries were incorrectly
marked PUBLIC, causing executables linking against ceph-common to also
link against them directly.

The circular dependency manifested as linker errors in tests like
ceph_test_ino_release_cb, where libjson_spirit.a and liberasure_code.a
contained undefined references to ceph-common symbols (e.g.,
ceph::__ceph_assert_fail and get_str_list) that couldn't be resolved
due to the linking order.

For instance, ceph_test_ino_release_cb failed to link:
```
/usr/bin/ld: ../../../lib/libcephfs.so.2.0.0: undefined reference to symbol '_ZN4ceph18__ceph_assert_failERKNS_11assert_dataE'
/usr/bin/ld: ../../../lib/libceph-common.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
```

Changes:

- Convert erasure_code and json_spirit from STATIC to OBJECT libraries
- Embed their object files directly into ceph-common during linking,
  breaking the circular dependency and preventing public propagation
  of these dependencies to downstream targets
- Remove direct linkage from targets that already get these symbols
  through ceph-common dependencies:
  * Erasure code unit tests (unittest_erasure_code_isa,
    unittest_erasure_code_plugin_isa, unittest_erasure_code_example)
  * Test libraries (radostest)
  * Plugins (denc-mod-osd, cls_refcount, cls_rgw, cls_lua, ec_lrc)

This also prevents ODR violations that would occur if targets linked
against these libraries directly while also getting them from
ceph-common. Such violations cause undefined behavior including
segmentation faults, as static variables and vtables would exist in
duplicate, leading to crashes during destruction or when accessing
shared state.

For example, before removing direct linkage from plugins, ceph-dencoder
would segfault on certain object types:

  /ceph/src/test/encoding/readable.sh: line 111: Segmentation fault
  $CEPH_DENCODER type ScrubMap import ... decode encode decode dump_json

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/CMakeLists.txt
src/cls/CMakeLists.txt
src/erasure-code/CMakeLists.txt
src/erasure-code/lrc/CMakeLists.txt
src/json_spirit/CMakeLists.txt
src/test/erasure-code/CMakeLists.txt
src/test/librados/CMakeLists.txt
src/tools/ceph-dencoder/CMakeLists.txt

index ab6dc2576232bc6e00a9c176f4bc5644fa62ae10..d7eb278861a1664a45df6172ee617156b836c678 100644 (file)
@@ -567,9 +567,11 @@ set(ceph_common_objs
   $<TARGET_OBJECTS:compressor_objs>
   $<TARGET_OBJECTS:common-objs>
   $<TARGET_OBJECTS:common_mountcephfs_objs>
-  $<TARGET_OBJECTS:crush_objs>)
+  $<TARGET_OBJECTS:crush_objs>
+  $<TARGET_OBJECTS:json_spirit>
+  $<TARGET_OBJECTS:erasure_code>)
 set(ceph_common_deps
-  json_spirit erasure_code extblkdev arch crc32
+  common_utf8 extblkdev arch crc32
   ${LIB_RESOLV}
   Boost::thread
   Boost::system
index f234ad049e9a633e35f6ba2a9edabb743fd35353..f311b6ef3a0f5db59bbe69196ffb84f1a4802408 100644 (file)
@@ -95,7 +95,6 @@ set(cls_refcount_srcs
   refcount/cls_refcount_ops.cc
   ${CMAKE_SOURCE_DIR}/src/common/ceph_json.cc)
 add_library(cls_refcount SHARED ${cls_refcount_srcs})
-target_link_libraries(cls_refcount json_spirit)
 set_target_properties(cls_refcount PROPERTIES
   VERSION "1.0.0"
   SOVERSION "1"
@@ -198,7 +197,7 @@ if (WITH_RADOSGW)
     rgw/cls_rgw_types.cc
     ${CMAKE_SOURCE_DIR}/src/common/ceph_json.cc)
   add_library(cls_rgw SHARED ${cls_rgw_srcs})
-  target_link_libraries(cls_rgw ${FMT_LIB} json_spirit)
+  target_link_libraries(cls_rgw ${FMT_LIB})
   target_include_directories(cls_rgw
          PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw/driver/rados"
          PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw")
@@ -252,8 +251,7 @@ if (NOT WIN32)
     CXX_VISIBILITY_PRESET hidden)
   install(TARGETS cls_lua DESTINATION ${cls_dir})
   target_link_libraries(cls_lua
-      ${LUA_LIBRARIES}
-      json_spirit)
+      ${LUA_LIBRARIES})
   target_include_directories(cls_lua PRIVATE "${LUA_INCLUDE_DIR}")
 endif (NOT WIN32)
 
index 6ced377fe3ca4a1df02d7e9a340f1982d26f09a5..85fac56aa56c4379deffa42dc29267712260212f 100644 (file)
@@ -32,7 +32,7 @@ if(WITH_EC_ISA_PLUGIN)
   set(EC_ISA_LIB ec_isa)
 endif()
 
-add_library(erasure_code STATIC ErasureCodePlugin.cc)
+add_library(erasure_code OBJECT ErasureCodePlugin.cc)
 target_link_libraries(erasure_code $<$<PLATFORM_ID:Windows>:dlfcn_win32>
                       ${CMAKE_DL_LIBS})
 
index e7fb8ea0247abf24da5e6f26bc7b4cb4ed6bc86a..ea52a3d621eaff34fbc62da1f3a24a6549bdeda8 100644 (file)
@@ -11,5 +11,4 @@ set(lrc_srcs
 add_library(ec_lrc SHARED ${lrc_srcs})
 set_target_properties(ec_lrc PROPERTIES
   INSTALL_RPATH "")
-target_link_libraries(ec_lrc json_spirit)
 install(TARGETS ec_lrc DESTINATION ${erasure_plugin_dir})
index 681ac909e631041716d0f264e871f4b0a90234c0..0049dde92172bbb4bcb0686ead357444e9ed9be2 100644 (file)
@@ -1,4 +1,4 @@
-add_library(json_spirit STATIC
+add_library(json_spirit OBJECT
   json_spirit_reader.cpp
   json_spirit_writer.cpp)
 target_link_libraries(json_spirit common_utf8 Boost::thread)
index 429d29d536adf6b50133c485de9a508be6fe3a9c..3647eee1ac5de3975f54d2839207302aa646a57d 100644 (file)
@@ -106,7 +106,6 @@ target_link_libraries(unittest_erasure_code_isa
   global
   ceph-common
   ec_isa
-  erasure_code
   )
 
 #unittest_erasure_code_plugin_isa
@@ -120,7 +119,6 @@ target_link_libraries(unittest_erasure_code_plugin_isa
   global
   ceph-common
   ${CMAKE_DL_LIBS}
-  erasure_code
   )
 add_dependencies(unittest_erasure_code_plugin_isa
   ec_isa)
@@ -176,7 +174,6 @@ target_link_libraries(unittest_erasure_code_example
   global
   ${CMAKE_DL_LIBS}
   ceph-common
-  erasure_code
   ${UNITTEST_LIBS}
   )
 
index 30893d1422dedb5da700f0bc3559e013efd61e33..c0fffa7ee4865b3b20169c788066489bfe537a3c 100644 (file)
@@ -11,7 +11,6 @@ add_library(radostest STATIC
 target_link_libraries(radostest PUBLIC
   GTest::GTest
   ceph-common
-  json_spirit
   ${GSSAPI_LIBRARIES} ${EXTRALIBS})
 add_library(radostest-cxx STATIC
   testcase_cxx.cc
index 32f7f11d63bcc21d9da1d9759ff0c11e2840e919..f0a3f81ea1b3bda786ca96fc67bcdd5188dcff91 100644 (file)
@@ -50,7 +50,6 @@ target_link_libraries(denc-mod-osd
   os
   osd
   mon
-  erasure_code
   global)
 
 if(WITH_RADOSGW)