Skip to content

Commit 81ef8d5

Browse files
committed
librados: disable symbol versions when building statically
When building internal libraries statically with `-DENABLE_SHARED=no`, linking `librados.a` always fails because the `LIBRADOS_C_API_DEFAULT_F` macro inserts an underscore prefix to all exported symbols. It does this so a versioned symbol with the real name can be created. Symbol versions however only work with shared libraries, and the linker fails to find the prefix-less symbols: FAILED: bin/ceph_radosacl : && /usr/bin/c++ -O0 -fPIC -fuse-ld=mold -Og -g -rdynamic src/tools/CMakeFiles/ceph_radosacl.dir/radosacl.cc.o -o bin/ceph_radosacl -Wl,-rpath,::::::::::::::::::::::::::::::: lib/liblibrados.a lib/libglobal.a lib/liblibrados_impl.a lib/libosdc.a lib/libcls_lock_client.a lib/libceph-common.a /usr/lib/aarch64-linux-gnu/libblkid.so /usr/lib/aarch64-linux-gnu/libcrypto.so lib/libjson_spirit.a lib/libcommon_utf8.a lib/libextblkdev.a -lcap 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/libfmtd.a lib/liberasure_code.a /usr/lib/aarch64-linux-gnu/libudev.so /usr/lib/aarch64-linux-gnu/libz.so -ldl /usr/lib/aarch64-linux-gnu/librt.a -lresolv -Wl,--as-needed -latomic && : mold: error: undefined symbol: rados_conf_parse_env >>> referenced by librados_cxx.cc >>> lib/liblibrados.a(librados_cxx.cc.o):(librados::v14_2_0::Rados::conf_parse_env(char const*) const) mold: error: undefined symbol: rados_nobjects_list_seek >>> referenced by librados_cxx.cc >>> lib/liblibrados.a(librados_cxx.cc.o):(librados::NObjectIteratorImpl::seek(unsigned int)) mold: error: undefined symbol: rados_conf_parse_argv_remainder >>> referenced by librados_cxx.cc >>> lib/liblibrados.a(librados_cxx.cc.o):(librados::v14_2_0::Rados::conf_parse_argv_remainder(int, char const**, char const**) const) mold: error: undefined symbol: rados_version >>> referenced by librados_cxx.cc >>> lib/liblibrados.a(librados_cxx.cc.o):(librados::v14_2_0::Rados::version(int*, int*, int*)) mold: error: undefined symbol: rados_nobjects_list_next2 >>> referenced by librados_c.cc >>> lib/liblibrados.a(librados_c.cc.o):(_rados_nobjects_list_next) >>> referenced by librados_cxx.cc >>> lib/liblibrados.a(librados_cxx.cc.o):(librados::NObjectIteratorImpl::get_next()) Signed-off-by: Max Kellermann <[email protected]>
1 parent 0d56b61 commit 81ef8d5

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/librados/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if(ENABLE_SHARED)
2929
set_property(TARGET librados APPEND_STRING PROPERTY
3030
LINK_FLAGS " -static-libstdc++ -static-libgcc")
3131
endif()
32+
target_compile_definitions(librados PRIVATE -DLIBRADOS_SHARED=1)
3233
endif()
3334
target_link_libraries(librados PRIVATE
3435
librados_impl osdc ceph-common cls_lock_client

src/librados/librados_c.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define tracepoint(...)
4545
#endif
4646

47-
#if defined(HAVE_ASM_SYMVER) || defined(HAVE_ATTR_SYMVER)
47+
#if defined(LIBRADOS_SHARED) && (defined(HAVE_ASM_SYMVER) || defined(HAVE_ATTR_SYMVER))
4848
// prefer __attribute__() over global asm(".symver"). because the latter
4949
// is not parsed by the compiler and is partitioned away by GCC if
5050
// lto-partitions is enabled, in other words, these asm() statements

0 commit comments

Comments
 (0)