]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
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)
commit585b64d07773d6ea9845eb6c8d5a612d28999b94
treeb17355e2407fbef8c78dd9d43030ad48a7a219df
parent8611241dc028e3b148e236f6c5d350f9f0381cb1
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 <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