]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cmake: convert erasure_code and json_spirit to OBJECT libraries wip-cmake-link-ceph-common-kefu
authorKefu Chai <k.chai@proxmox.com>
Tue, 30 Sep 2025 10:38:31 +0000 (18:38 +0800)
committerKefu Chai <k.chai@proxmox.com>
Wed, 1 Oct 2025 02:35:07 +0000 (10:35 +0800)
Changes

- convert erasure_code and json_spirit to OBJECT libraries
- do not link erasure unittests against erasure_code which has been
  already included by ceph-common. otherwise we'd have two copies of
  erasure_code in these unit test executables. this violates the ODR,
  and leds to undefined behaviors like segment fault as static variables
  would be destructed twice.

This resolves a circular dependency issue where:
- ceph-common was linked against erasure_code and json_spirit static libraries
- These static libraries were incorrectly marked PUBLIC, causing executables
  linking against ceph-common to also link against them directly
- The static libraries themselves referenced symbols from ceph-common,
  creating an unresolvable circular dependency

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.

By converting these to OBJECT libraries, we ensure their object files
are incorporated directly into ceph-common during linking, breaking
the circular dependency and preventing the public propagation of
these dependencies to downstream targets.

For instance, ceph_test_ino_release_cb failed to link, because it was
linked against libjson_spirit.a:
```
/usr/bin/c++ -g -O2 -ffile-prefix-map=/home/kefu/dev/ceph=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-z,relro -rdynamic -Wl,--dependency-file=CMakeFiles/ceph_tes
t_ino_release_cb.dir/link.d CMakeFiles/ceph_test_ino_release_cb.dir/test_ino_release_cb.cc.o -o ../../../bin/ceph_test_ino_release_cb  -Wl,-rpath,/home/kefu/dev/ceph/obj-x86_64-linux-gnu/lib: ../../../lib/libcephfs.so.2.0.0 ../../../lib/libceph-common.so.
2 ../../../lib/libjson_spirit.a ../../../lib/libcommon_utf8.a ../../../lib/liberasure_code.a ../../../lib/libextblkdev.a -lcap -lresolv ../../../boost/lib/libboost_thread.a ../../../boost/lib/libboost_chrono.a ../../../boost/lib/libboost_atomic.a ../../..
/boost/lib/libboost_system.a ../../../boost/lib/libboost_random.a ../../../boost/lib/libboost_program_options.a ../../../boost/lib/libboost_date_time.a ../../../boost/lib/libboost_iostreams.a ../../../boost/lib/libboost_regex.a ../../../lib/libfmt.a /usr/
lib/x86_64-linux-gnu/libblkid.so /usr/lib/x86_64-linux-gnu/libcrypto.so -ldl /usr/lib/x86_64-linux-gnu/libudev.so /usr/lib/x86_64-linux-gnu/libibverbs.so /usr/lib/x86_64-linux-gnu/librdmacm.so /usr/lib/x86_64-linux-gnu/libz.so ../../opentelemetry-cpp/sdk/
src/trace/libopentelemetry_trace.a ../../opentelemetry-cpp/sdk/src/resource/libopentelemetry_resources.a ../../opentelemetry-cpp/sdk/src/common/libopentelemetry_common.a ../../opentelemetry-cpp/exporters/jaeger/libopentelemetry_exporter_jaeger_trace.a ../
../opentelemetry-cpp/ext/src/http/client/curl/libopentelemetry_http_client_curl.a /usr/lib/x86_64-linux-gnu/libcurl.so /usr/lib/x86_64-linux-gnu/libthrift.so ../../breakpad_project-prefix/lib/libbreakpad_client.a  -Wl,--as-needed -latomic
make  -f src/test/msgr/CMakeFiles/ceph_perf_msgr_client.dir/build.make src/test/msgr/CMakeFiles/ceph_perf_msgr_client.dir/depend     `
/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
make[2]: *** [src/test/fs/CMakeFiles/ceph_test_ino_release_cb.dir/build.make:134: bin/ceph_test_ino_release_cb] Error 1
```
while libjson_spirit.a does reference symbol(s) exposed by ceph-common:

```
$ nm -C ../../../lib/libjson_spirit.a | grep __ceph_assert_fail\(ceph::assert_data
                 U ceph::__ceph_assert_fail(ceph::assert_data const&)
                 U ceph::__ceph_assert_fail(ceph::assert_data const&)`
```

the same applied to liberasure_code.a:

```
$ nm -C lib/liberasure_code.a | grep get_str_list
                 U get_str_list(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)
```

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

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 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