From: Kefu Chai Date: Tue, 30 Sep 2025 10:38:31 +0000 (+0800) Subject: cmake: convert erasure_code and json_spirit to OBJECT libraries X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=585b64d07773d6ea9845eb6c8d5a612d28999b94;p=ceph.git cmake: convert erasure_code and json_spirit to OBJECT libraries 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 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ab6dc257623..d7eb278861a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -567,9 +567,11 @@ set(ceph_common_objs $ $ $ - $) + $ + $ + $) set(ceph_common_deps - json_spirit erasure_code extblkdev arch crc32 + common_utf8 extblkdev arch crc32 ${LIB_RESOLV} Boost::thread Boost::system diff --git a/src/cls/CMakeLists.txt b/src/cls/CMakeLists.txt index f234ad049e9..f311b6ef3a0 100644 --- a/src/cls/CMakeLists.txt +++ b/src/cls/CMakeLists.txt @@ -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) diff --git a/src/erasure-code/CMakeLists.txt b/src/erasure-code/CMakeLists.txt index 6ced377fe3c..85fac56aa56 100644 --- a/src/erasure-code/CMakeLists.txt +++ b/src/erasure-code/CMakeLists.txt @@ -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 $<$:dlfcn_win32> ${CMAKE_DL_LIBS}) diff --git a/src/erasure-code/lrc/CMakeLists.txt b/src/erasure-code/lrc/CMakeLists.txt index e7fb8ea0247..ea52a3d621e 100644 --- a/src/erasure-code/lrc/CMakeLists.txt +++ b/src/erasure-code/lrc/CMakeLists.txt @@ -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}) diff --git a/src/json_spirit/CMakeLists.txt b/src/json_spirit/CMakeLists.txt index 681ac909e63..0049dde9217 100644 --- a/src/json_spirit/CMakeLists.txt +++ b/src/json_spirit/CMakeLists.txt @@ -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) diff --git a/src/test/erasure-code/CMakeLists.txt b/src/test/erasure-code/CMakeLists.txt index 429d29d536a..3647eee1ac5 100644 --- a/src/test/erasure-code/CMakeLists.txt +++ b/src/test/erasure-code/CMakeLists.txt @@ -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} ) diff --git a/src/test/librados/CMakeLists.txt b/src/test/librados/CMakeLists.txt index 30893d1422d..c0fffa7ee48 100644 --- a/src/test/librados/CMakeLists.txt +++ b/src/test/librados/CMakeLists.txt @@ -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 diff --git a/src/tools/ceph-dencoder/CMakeLists.txt b/src/tools/ceph-dencoder/CMakeLists.txt index 32f7f11d63b..f0a3f81ea1b 100644 --- a/src/tools/ceph-dencoder/CMakeLists.txt +++ b/src/tools/ceph-dencoder/CMakeLists.txt @@ -50,7 +50,6 @@ target_link_libraries(denc-mod-osd os osd mon - erasure_code global) if(WITH_RADOSGW)