Skip to content

cmake: select the linker with CMAKE_LINKER_TYPE - #72620

Merged
tchaikov merged 5 commits into
ceph:mainfrom
Doracly:lld-linker
Nov 30, 2026
Merged

tchaikov merged 5 commits into
ceph:mainfrom
Doracly:lld-linker

Conversation

@Doracly

@Doracly Doracly commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

-DCMAKE_LINKER_TYPE=BFD|LLD|MOLD selects the linker and makes lld usable. Of the three, lld links Ceph fastest and with the least CPU and memory (numbers below). It replaces WITH_MOLD, which is in no release and is removed rather than deprecated.

CMake handles CMAKE_LINKER_TYPE from 3.29 on; older CMake gets it as -fuse-ld. The Python extensions, which setuptools links, get the same linker either way.

The last two commits group the build speed-ups in the developer guide under one section and document the option there, ahead of ccache: it needs only a package and costs neither disk space nor memory. The grouping commit is identical to the one in #71901, so the two PRs merge cleanly in either order.

Fixes to the mold support from #69711

  • mold drops the base-version symvers in librados_c.cc, so a mold-linked librados exported rados_connect and friends as LIBRADOS_PRIVATE and lost the four compat definitions; lld rejects them outright. librados now always links with ld.bfd where it uses symvers.
  • That, not --exclude-libs, is what hid rados_* under mold, so the workaround that disabled --exclude-libs for mold is dropped.
  • The _rados_* glob added to librados.map made every build, including ld.bfd ones, export the 250 internal _rados_* functions behind the C API. A separate commit removes it.

--copy-dt-needed-entries in the libcephfs and fs tests

#71494 passes the option only where check_linker_flag() accepts it. That caches its result, so a tree configured with ld.bfd keeps passing the option after switching to lld or mold, which reject it. The first commit unsets the cached result before the check, so it reruns on each configure.

Testing

Clang 21 + lld (with crimson) and GCC 15 + mold, Debug, before the rebase onto #71494:

  • all builds; every binary and library loads with all symbols resolved (ldd -r), apart from plugins that take symbols from their host
  • librados exports match ld.bfd (rados_* versions unchanged, no _rados_*)
  • vstart cluster: HEALTH_OK, rados put/get, rbd create, Python rados, rbd, cephfs and rgw import, ceph-dencoder list_types
  • all unittest_*: 252/252 passed with both
  • configure: default, BFD, LLD, MOLD, unusable linker

Configuring one tree (CMake 4.2, Clang 21) with BFD, LLD, BFD and MOLD in turn passes --copy-dt-needed-entries to 10, 0, 10 and 0 targets and gives the Python extensions the same linker when building and installing.

With mold < 3.0, ceph-dencoder additionally needs #73958.

Link performance

Clang Debug (-O0), idle 24-thread machine, outputs on tmpfs, the default 13
parallel links:

linker 62 vstart binaries (2.5 GiB) 336 test binaries (15.4 GiB) CPU (tests) peak heap (tests)
ld.bfd 2.46 10.7 s 50 s 768 s 13.5 GiB
lld 21.1.8 1.8 s 11 s 236 s 1.7 GiB
mold 2.40.4 2.1 s 24 s 565 s 5.4 GiB

mold is faster only one link at a time (the vstart set in sequence: mold 5.4 s,
lld 7.0 s, ld.bfd 46 s) and is CPU-bound from four parallel links on.
lld 17 to 21 perform the same. With -Og objects all three link faster
(ld.bfd about 2x).

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@Doracly

Doracly commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@Doracly

Doracly commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Added a commit that passes --copy-dt-needed-entries only where the linker accepts it (the libcephfs/fs tests failed to link with lld and mold), and split the doc commit into a grouping commit shared with #71901 plus the linker section.

Comment thread doc/dev/developer_guide/essentials.rst Resolved
@Doracly

Doracly commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@Doracly
Doracly requested a review from a team as a code owner October 26, 2026 13:37
@Doracly

Doracly commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@Doracly

Doracly commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@Doracly

Doracly commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@Doracly

Doracly commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test api

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@Doracly

Doracly commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

librados now checks whether CMake defines the BFD linker type instead of checking the CMake version: CMake defines linker types for FreeBSD only from 4.2 on, so LINKER_TYPE BFD failed to configure there with 3.29 to 4.1. Without the type it falls back to -fuse-ld=bfd. @wjwithagen, could you check this on FreeBSD?

@wjwithagen

Copy link
Copy Markdown
Member

librados now checks whether CMake defines the BFD linker type instead of checking the CMake version: CMake defines linker types for FreeBSD only from 4.2 on, so LINKER_TYPE BFD failed to configure there with 3.29 to 4.1. Without the type it falls back to -fuse-ld=bfd. @wjwithagen, could you check this on FreeBSD?

I've been offline for a few days, and catching up on my Ceph stuff.
This one I'll put on my to-check list.

And as further remarks:

  1. Yes LLD has less of an impact whilest linking on both CPU and MEM.
  2. I think I have current version in wjwwithagen:ceph-freebsd where LLD is able to use the linker-map to get the versioning. But LLD is more picky than LD in the symbols defined, the match is the be quite exact. Otherwise you end up with "symbol undefined errors".

So I'm not using ld-bfd or gnu-ld, as far as my recollection goes, but that I'll check as well.

Comment thread src/CMakeLists.txt Resolved
Comment thread src/librados/librados.map Resolved
Comment thread cmake/modules/Distutils.cmake Resolved
check_linker_flag() caches its result, so a build tree configured with
ld.bfd keeps passing the option after switching to lld or mold, which
reject it. Unset the cached result before the check.

Assisted-by: claude-opus-5-5
Signed-off-by: Dominik Raddatz <[email protected]>
@Doracly

Doracly commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@tchaikov tchaikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are close. i'd wait for @wjwithagen 's check once the last comment is addressed.

Comment thread CMakeLists.txt Resolved
WITH_MOLD only knew mold. Select the linker with CMAKE_LINKER_TYPE (BFD,
LLD, MOLD) instead, which CMake handles from 3.29 on; older CMake gets
it as -fuse-ld. Drop WITH_MOLD, which is in no release; use
-DCMAKE_LINKER_TYPE=MOLD instead.

librados always links with ld.bfd where it uses symvers. lld rejects its
base-version symvers; mold drops them, so a mold-linked librados
exported rados_connect and friends as LIBRADOS_PRIVATE and lost the four
compat definitions. That, not --exclude-libs, hid rados_* under mold,
so stop disabling --exclude-libs for mold.

On FreeBSD, the GNU ld default for Clang now only applies when no
linker is selected; it used to override the -fuse-ld of older CMake.

Python extensions get the linker through LDFLAGS below CMake 3.29 and
through CMAKE_C_USING_LINKER_<TYPE> in LDSHARED from 3.29 on, which
replaces the mold case in Distutils.

Assisted-by: claude-opus-5-5
Signed-off-by: Dominik Raddatz <[email protected]>
The _rados_* glob added to librados.map for mold exports the 250
internal functions behind the C API. librados now links with ld.bfd
wherever it uses symvers, so drop it.

Assisted-by: claude-opus-5-5
Signed-off-by: Dominik Raddatz <[email protected]>
Make ccache a subsection of a new "Speeding up local builds" section, so
other ways to shorten builds can sit next to it.

Assisted-by: claude-opus-5-5
Signed-off-by: Dominik Raddatz <[email protected]>
List the linker first among the build speed-ups: it needs only a package
and costs neither disk space nor memory.

Assisted-by: claude-opus-5-5
Signed-off-by: Dominik Raddatz <[email protected]>
@Doracly

Doracly commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@wjwithagen One more FreeBSD change since my last comment: the Clang block in src/CMakeLists.txt now adds -fuse-ld=/usr/local/bin/ld only when CMAKE_LINKER_TYPE is unset. Before, it overrode the selected linker with CMake < 3.29.

When you get to it, could you check these on FreeBSD?

  1. Default build without CMAKE_LINKER_TYPE: should link with GNU ld as before.
  2. librados: it uses LINKER_TYPE BFD with CMake 4.2+ and -fuse-ld=bfd below. Does it configure and link, i.e. does Clang find ld.bfd?
  3. -DCMAKE_LINKER_TYPE=LLD: everything except librados links with lld. This also drops -Wno-unused-command-line-argument from the link flags, so new warnings there would be good to know.

Which CMake version do you build with?

@wjwithagen

Copy link
Copy Markdown
Member

Which CMake version do you build with?

FreeBSD 14 and on have atleast CMake 3.31

@wjwithagen

Copy link
Copy Markdown
Member

(LONG LONG answer below)

Short answer:
I can build a versioned librados.so.2.0.0 using lld

Oke, perhaps not the answer you are looking for, but none the less:

My working tree is in wjwithagen:ceph-freebsd. (https://github.com/wjwithagen/ceph/tree/ceph-freebsd)
I've taken that and loaded the code parts of this PR on top of it, and fixed a small conflict.

 git clone --no-hardlinks -b ceph-freebsd /home/wjw/Ceph.ggate /home/wjw/Src/Ceph/wip-pr-test
   146  23:57   cd /home/wjw/Src/Ceph/wip-pr-test
   147  23:57   git remote rename origin local
   148  23:57   git remote add ceph https://github.com/ceph/ceph.git
   149  23:57   git remote -v
   150  23:57   git fetch ceph refs/pull/72620/head:pr72620
   151  23:57   git --no-pager log --oneline -6 pr72620
   152  23:57   cd /home/wjw/Src/Ceph/wip-pr-test
   153  23:57   git checkout -b wip-pr72620 ceph-freebsd
   154  23:57   git --no-pager log --oneline -3
   155  23:57   git submodule update --init --recursive
   156  0:02    cd /home/wjw/Src/Ceph/wip-pr-test
   157  0:02    git cherry-pick 1960b5a953 bb637f1716 9fc925c294
   158  0:02    vi src/CMakeLists.txt

Note that in src/CMakeLists.txt I have:
@190

  if(FREEBSD)
    add_compile_options(-fexperimental-library)
    add_link_options(-fexperimental-library)
    # Need to use the GNU binutils linker to get versioning right.
#    string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=/usr/local/bin/ld -Wno-unused-command-line-argument")
#    string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=/usr/local/bin/ld -Wno-unused-command-line-argument")
    string(APPEND CMAKE_EXE_LINKER_FLAGS "  -Wno-unused-command-line-argument")
    string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wno-unused-command-line-argument")
  endif()

so I don't force any other linker than LDD, which is verified in the LINKER vars in:
grep -i "LINKER_FLAGS|LINK_FLAGS|LINKER_TYPE|fuse-ld" /home/wjw/Src/Ceph/wip-pr-test/build/CMakeCache.txt
CMAKE_EXE_LINKER_FLAGS:STRING=
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_MODULE_LINKER_FLAGS:STRING=
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_SHARED_LINKER_FLAGS:STRING=
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_STATIC_LINKER_FLAGS:STRING=
CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING=
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING=
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS
CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG
CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE
CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG
CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE
CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG
CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE
CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS
CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG
CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL
CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE
CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO
CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1
_CMAKE_SYSTEM_LINKER_TYPE:INTERNAL=LLD

After which I build librados...
Which results in:
The linker command:

wjw@> /usr/bin/clang++ -v -fPIC -g -DCEPH_DEV -O0 -g -Wno-unused-command-line-argument -Wno-unused-command-line-argument -Wl,--exclude-libs,ALL -Wl,--version-script=/home/wjw/Src/Ceph/wip-pr-test/src/librados/librados.map -fexperimental-library -Xlinker --dependency-file=src/librados/CMakeFiles/librados.dir/link.d -shared -Wl,-soname,librados.so.2 -o lib/librados.so.2.0.0 src/common/CMakeFiles/common_buffer_obj.dir/buffer.cc.o src/librados/CMakeFiles/librados.dir/librados_c.cc.o src/librados/CMakeFiles/librados.dir/librados_cxx.cc.o -L/usr/local/lib -Wl,-rpath,/usr/local/lib:/home/wjw/Src/Ceph/wip-pr-test/build/lib: lib/liblibrados_impl.a lib/libosdc.a lib/libceph-common.so.2 lib/libcls_lock_client.a /usr/local/lib/libcrypto.so /usr/lib/librt.so lib/libcommon_utf8.a lib/libextblkdev.a /usr/local/lib/libboost_thread.so.1.91.0 /usr/local/lib/libboost_atomic.so.1.91.0 /usr/local/lib/libboost_chrono.so.1.91.0 /usr/local/lib/libboost_context.so.1.91.0 /usr/local/lib/libboost_program_options.so.1.91.0 /usr/local/lib/libboost_container.so.1.91.0 /usr/local/lib/libboost_date_time.so.1.91.0 /usr/local/lib/libboost_iostreams.so.1.91.0 /usr/local/lib/libboost_random.so.1.91.0 /usr/local/lib/libboost_regex.so.1.91.0 lib/libfmtd.a /usr/lib/libexecinfo.so -lpthread -lrt
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd14.4
Thread model: posix
InstalledDir: /usr/bin
"/usr/bin/ld" --eh-frame-hdr -shared --hash-style=both --enable-new-dtags -o lib/librados.so.2.0.0 /usr/lib/crti.o /usr/lib/crtbeginS.o -L/usr/local/lib -L/usr/lib --exclude-libs ALL --version-script=/home/wjw/Src/Ceph/wip-pr-test/src/librados/librados.map --dependency-file=src/librados/CMakeFiles/librados.dir/link.d -soname librados.so.2 src/common/CMakeFiles/common_buffer_obj.dir/buffer.cc.o src/librados/CMakeFiles/librados.dir/librados_c.cc.o src/librados/CMakeFiles/librados.dir/librados_cxx.cc.o -rpath /usr/local/lib:/home/wjw/Src/Ceph/wip-pr-test/build/lib: lib/liblibrados_impl.a lib/libosdc.a lib/libceph-common.so.2 lib/libcls_lock_client.a /usr/local/lib/libcrypto.so /usr/lib/librt.so lib/libcommon_utf8.a lib/libextblkdev.a /usr/local/lib/libboost_thread.so.1.91.0 /usr/local/lib/libboost_atomic.so.1.91.0 /usr/local/lib/libboost_chrono.so.1.91.0 /usr/local/lib/libboost_context.so.1.91.0 /usr/local/lib/libboost_program_options.so.1.91.0 /usr/local/lib/libboost_container.so.1.91.0 /usr/local/lib/libboost_date_time.so.1.91.0 /usr/local/lib/libboost_iostreams.so.1.91.0 /usr/local/lib/libboost_random.so.1.91.0 /usr/local/lib/libboost_regex.so.1.91.0 lib/libfmtd.a /usr/lib/libexecinfo.so -lpthread -lrt -lc++ -lc++experimental -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtendS.o /usr/lib/crtn.o
wjw@> /usr/bin/ld -v
LLD 19.1.7 (FreeBSD llvmorg-19.1.7-0-gcd708029e0b2-1400007) (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2) (compatible with GNU linkers)

Which uses the basic clang linker `/usr/bin/ld`.
And note that I did need to work on `src/librados/librados.map` to get it compatible with `lld`

And versioning is there:

wjw@> readelf -V /home/wjw/Src/Ceph/wip-pr-test/build/lib/librados.so.2.0.0 | grep -A6 version_d
Version definition section '.gnu.version_d' contains 3 entries:
Addr: 0x0000000000008bc4 Offset: 0x00008bc4 Link: 8 (.dynstr)
000000: Rev: 1 Flags: BASE Index: 1 Cnt: 1 Name: librados.so.2
0x001c: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: LIBRADOS_PRIVATE
0x0038: Rev: 1 Flags: none Index: 3 Cnt: 1 Name: LIBRADOS_14.2.0


So IMHO ld.bfd is not really needed to build `librados.so` 

@Doracly

Doracly commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

jenkins retest this please

@Doracly

Doracly commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@wjwithagen thanks for testing! Your tree differs from the PR in two places: the FreeBSD block no longer adds -fuse-ld=/usr/local/bin/ld, and librados.map is changed. Your librados link line also lacks -fuse-ld=bfd, which the PR adds with CMake < 4.2 if HAVE_ATTR_SYMVER or HAVE_ASM_SYMVER is set. What do these two show in your CMakeCache.txt?

Could you share your librados.map change? If readelf --dyn-syms -W lib/librados.so.2 | grep rados_ioctx_pool_stat lists both the base and the LIBRADOS_14.2.0 version, librados could link with lld and the BFD exception could go in a follow-up.

For this PR, checks 1 and 2 from my last comment are still open on the unmodified branch.

@wjwithagen

Copy link
Copy Markdown
Member

@wjwithagen thanks for testing! Your tree differs from the PR in two places: the FreeBSD block no longer adds -fuse-ld=/usr/local/bin/ld, and librados.map is changed. Your librados link line also lacks -fuse-ld=bfd, which the PR adds with CMake < 4.2 if HAVE_ATTR_SYMVER or HAVE_ASM_SYMVER is set. What do these two show in your CMakeCache.txt?

Could you share your librados.map change? If readelf --dyn-syms -W lib/librados.so.2 | grep rados_ioctx_pool_stat lists both the base and the LIBRADOS_14.2.0 version, librados could link with lld and the BFD exception could go in a follow-up.

For this PR, checks 1 and 2 from my last comment are still open on the unmodified branch.

[~/Ceph.ggate/build] [email protected]> grep SYMVER CMakeCache.txt
HAVE_ASM_SYMVER:INTERNAL=FALSE
HAVE_ATTR_SYMVER:INTERNAL=FALSE

[~/Src/Ceph/ceph/ggate/ceph] [email protected]> git --no-pager diff origin/main -- src/librados/librados.map
diff --git a/src/librados/librados.map b/src/librados/librados.map
index 96dd5072d94..8330e351f7c 100644
--- a/src/librados/librados.map
+++ b/src/librados/librados.map
@@ -1,43 +1,42 @@
 LIBRADOS_PRIVATE {
-       global:
-               rados_*;
-               _rados_*;
-               extern "C++" {
-                       "guard variable for boost::asio::detail::call_stack<boost::asio::detail::strand_executor_service::strand_impl, unsigned char>::top_";
-                       "guard variable for boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl, unsigned char>::top_";
-                       "guard variable for boost::asio::detail::call_stack<boost::asio::detail::thread_context, boost::asio::detail::thread_info_base>::top_";
-                       "boost::asio::detail::call_stack<boost::asio::detail::strand_executor_service::strand_impl, unsigned char>::top_";
-                       "boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl, unsigned char>::top_";
-                       "boost::asio::detail::call_stack<boost::asio::detail::thread_context, boost::asio::detail::thread_info_base>::top_";
-
-               };
-       local:  *;
+        global:
+                rados_*;
+                _rados_*;
+                extern "C++" {
+                        "guard variable for boost::asio::detail::call_stack<boost::asio::detail::strand_executor_service::strand_impl, unsigned char>::top_";
+                        "guard variable for boost::asio::detail::call_stack<boost::asio::detail::thread_context, boost::asio::detail::thread_info_base>::top_";
+                        "boost::asio::detail::call_stack<boost::asio::detail::thread_context, boost::asio::detail::thread_info_base>::top_";
+                };
+        local:  *;
 };
-
 LIBRADOS_14.2.0 {
         global:
                 extern "C++" {
-                       ceph::buffer::v15_2_0::*;
-                       librados::v14_2_0::*;
-
+                        ceph::buffer::v15_2_0::*;
+                        "typeinfo for ceph::buffer::v15_2_0::error";
+                        "typeinfo name for ceph::buffer::v15_2_0::error";
+                        "typeinfo for ceph::buffer::v15_2_0::end_of_buffer";
+                        "typeinfo name for ceph::buffer::v15_2_0::end_of_buffer";
+                        "typeinfo for ceph::buffer::v15_2_0::malformed_input";
+                        "typeinfo name for ceph::buffer::v15_2_0::malformed_input";
+                        "typeinfo for ceph::buffer::v15_2_0::bad_alloc";
+                        "typeinfo name for ceph::buffer::v15_2_0::bad_alloc";
+                        librados::v14_2_0::*;
                         "typeinfo for librados::v14_2_0::ObjectOperation";
                         "typeinfo name for librados::v14_2_0::ObjectOperation";
                         "vtable for librados::v14_2_0::ObjectOperation";
-
                         "typeinfo for librados::v14_2_0::ObjectReadOperation";
                         "typeinfo name for librados::v14_2_0::ObjectReadOperation";
                         "vtable for librados::v14_2_0::ObjectReadOperation";
-
                         "typeinfo for librados::v14_2_0::ObjectWriteOperation";
                         "typeinfo name for librados::v14_2_0::ObjectWriteOperation";
                         "vtable for librados::v14_2_0::ObjectWriteOperation";
-
                         "typeinfo for librados::v14_2_0::WatchCtx";
                         "typeinfo name for librados::v14_2_0::WatchCtx";
                         "vtable for librados::v14_2_0::WatchCtx";
-
                         "typeinfo for librados::v14_2_0::WatchCtx2";
                         "typeinfo name for librados::v14_2_0::WatchCtx2";
                         "vtable for librados::v14_2_0::WatchCtx2";
                 };
 } LIBRADOS_PRIVATE;
+

 readelf --dyn-syms -W build/lib/librados.so.2 | grep rados_ioctx_pool_stat
   964: 00000000000ed470   937 FUNC    GLOBAL DEFAULT   15 rados_ioctx_pool_stat@@LIBRADOS_PRIVATE
  1045: 00000000000ed820   235 FUNC    GLOBAL DEFAULT   15 _rados_ioctx_pool_stat_base@@LIBRADOS_PRIVATE


From the last query I think you're are missing the 14_2_0 variants?
Like I said: LLD is very picky, and does not link if one of the symbols in the map is not available.
So much more care needs to be taken, when building the map-info.

So perhaps we need to add those (and others to the map?
Or as an alternative reason I don't have them is that I have messed up some of the attributes during compilation.

   465: 0000000000132ba0    57 FUNC    GLOBAL DEFAULT   15 _ZN8librados7v14_2_05IoCtx18from_rados_ioctx_tEPvRS1_@@LIBRADOS_14.2.0
   506: 00000000000ee970   253 FUNC    GLOBAL DEFAULT   15 rados_ioctx_get_pool_name@@LIBRADOS_PRIVATE
   517: 00000000000ed980   241 FUNC    GLOBAL DEFAULT   15 rados_ioctx_selfmanaged_snap_set_write_ctx@@LIBRADOS_PRIVATE
   522: 00000000000ed940    64 FUNC    GLOBAL DEFAULT   15 rados_ioctx_snap_set_read@@LIBRADOS_PRIVATE
   562: 00000000000ed360    98 FUNC    GLOBAL DEFAULT   15 rados_ioctx_create@@LIBRADOS_PRIVATE
   611: 00000000000eebb0    49 FUNC    GLOBAL DEFAULT   15 rados_ioctx_selfmanaged_snap_create@@LIBRADOS_PRIVATE
   674: 00000000000ed440    42 FUNC    GLOBAL DEFAULT   15 rados_ioctx_destroy@@LIBRADOS_PRIVATE
   675: 00000000000eef90    57 FUNC    GLOBAL DEFAULT   15 rados_ioctx_snap_get_stamp@@LIBRADOS_PRIVATE
   704: 00000000000ee780    73 FUNC    GLOBAL DEFAULT   15 rados_ioctx_pool_required_alignment2@@LIBRADOS_PRIVATE
   705: 00000000000eee60    57 FUNC    GLOBAL DEFAULT   15 rados_ioctx_snap_lookup@@LIBRADOS_PRIVATE
   791: 00000000000ee890   128 FUNC    GLOBAL DEFAULT   15 rados_ioctx_get_namespace@@LIBRADOS_PRIVATE
   806: 00000000000ee940    43 FUNC    GLOBAL DEFAULT   15 rados_ioctx_get_id@@LIBRADOS_PRIVATE
   817: 00000000000eec30    49 FUNC    GLOBAL DEFAULT   15 rados_ioctx_selfmanaged_snap_remove@@LIBRADOS_PRIVATE
   858: 00000000000eebf0    59 FUNC    GLOBAL DEFAULT   15 rados_aio_ioctx_selfmanaged_snap_create@@LIBRADOS_PRIVATE
   864: 00000000000eeea0   232 FUNC    GLOBAL DEFAULT   15 rados_ioctx_snap_get_name@@LIBRADOS_PRIVATE
   936: 00000000001393a0    93 FUNC    GLOBAL DEFAULT   15 _ZN8librados7v14_2_05Rados12ioctx_createEPKcRNS0_5IoCtxE@@LIBRADOS_14.2.0
   964: 00000000000ed470   937 FUNC    GLOBAL DEFAULT   15 rados_ioctx_pool_stat@@LIBRADOS_PRIVATE
  1011: 0000000000139400    93 FUNC    GLOBAL DEFAULT   15 _ZN8librados7v14_2_05Rados13ioctx_create2ElRNS0_5IoCtxE@@LIBRADOS_14.2.0
  1016: 00000000000eecb0   137 FUNC    GLOBAL DEFAULT   15 rados_ioctx_selfmanaged_snap_rollback@@LIBRADOS_PRIVATE
  1033: 00000000000eea70    49 FUNC    GLOBAL DEFAULT   15 rados_ioctx_snap_create@@LIBRADOS_PRIVATE
  1045: 00000000000ed820   235 FUNC    GLOBAL DEFAULT   15 _rados_ioctx_pool_stat_base@@LIBRADOS_PRIVATE
  1046: 00000000000eec70    59 FUNC    GLOBAL DEFAULT   15 rados_aio_ioctx_selfmanaged_snap_remove@@LIBRADOS_PRIVATE
  1097: 00000000000ee6d0    94 FUNC    GLOBAL DEFAULT   15 rados_ioctx_pool_requires_alignment2@@LIBRADOS_PRIVATE
  1105: 00000000000eed40   282 FUNC    GLOBAL DEFAULT   15 rados_ioctx_snap_list@@LIBRADOS_PRIVATE
  1128: 00000000000ee910    34 FUNC    GLOBAL DEFAULT   15 rados_ioctx_get_cluster@@LIBRADOS_PRIVATE
  1133: 00000000000ee7d0    84 FUNC    GLOBAL DEFAULT   15 rados_ioctx_locator_set_key@@LIBRADOS_PRIVATE
  1139: 00000000000ee680    70 FUNC    GLOBAL DEFAULT   15 rados_ioctx_pool_requires_alignment@@LIBRADOS_PRIVATE
  1150: 00000000000ed910    38 FUNC    GLOBAL DEFAULT   15 rados_ioctx_cct@@LIBRADOS_PRIVATE
  1155: 00000000000ee660    24 FUNC    GLOBAL DEFAULT   15 rados_ioctx_pool_get_auid@@LIBRADOS_PRIVATE
  1231: 00000000000eeab0    49 FUNC    GLOBAL DEFAULT   15 rados_ioctx_snap_remove@@LIBRADOS_PRIVATE
  1236: 00000000000ee640    24 FUNC    GLOBAL DEFAULT   15 rados_ioctx_pool_set_auid@@LIBRADOS_PRIVATE
  1242: 00000000000ee830    84 FUNC    GLOBAL DEFAULT   15 rados_ioctx_set_namespace@@LIBRADOS_PRIVATE
  1256: 00000000000eeaf0   129 FUNC    GLOBAL DEFAULT   15 rados_ioctx_snap_rollback@@LIBRADOS_PRIVATE
  1282: 00000000000ed3d0    98 FUNC    GLOBAL DEFAULT   15 rados_ioctx_create2@@LIBRADOS_PRIVATE
  1305: 00000000000ee730    67 FUNC    GLOBAL DEFAULT   15 rados_ioctx_pool_required_alignment@@LIBRADOS_PRIVATE

@Doracly

Doracly commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@wjwithagen thanks! If I read librados_c.cc correctly, with both checks FALSE the C functions only get LIBRADOS_PRIVATE from the map, without the base and LIBRADOS_14.2.0 versions. So I think their absence is expected and comes from the failed checks rather than from your map: building librados on Linux without symvers and with the PR's map gave me the same result. main should behave the same here. If your PR test tree has the same values, the PR's ld.bfd exception for librados doesn't apply there either, so check 2 may not matter on FreeBSD.

I assume your map edits drop entries for symbols your librados doesn't define. In my test, lld rejected such entries and ld.bfd ignored them. On Linux with Boost 1.87 the strand_service entries were missing as well, and linking librados with lld without symvers failed on exactly those two, so main is likely affected too. Would a follow-up be OK for that, e.g. passing --undefined-version for librados?

That would leave check 1: with the FreeBSD block as in the PR and no CMAKE_LINKER_TYPE, does the build still link with GNU ld?

@wjwithagen

Copy link
Copy Markdown
Member

I assume your map edits drop entries for symbols your librados doesn't define. In my test, lld rejected such entries and ld.bfd ignored them. On Linux with Boost 1.87 the strand_service entries were missing as well, and linking librados with lld without symvers failed on exactly those two, so main is likely affected too. Would a follow-up be OK for that, e.g. passing --undefined-version for librados?

That would leave check 1: with the FreeBSD block as in the PR and no CMAKE_LINKER_TYPE, does the build still link with GNU ld?

If you'd specify explicitly to use ld, than that is used. But in my environment that would fail, since I no longer load GNU tools.
And I do have a draft lingering that exactly does remove that part of src/CMakeLists.txt to only use lld since that is llvm default.

And like I said, lld is rather pedantic with the symbols, and fails to build. Whereas GNU ld is way more forgiving.
So for FreeBSD I'd like to continue on the road set: use only lld.

@Doracly

Doracly commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

@wjwithagen thanks! Then the PR leaves the default FreeBSD build as on main: without CMAKE_LINKER_TYPE, the FreeBSD block still adds -fuse-ld=/usr/local/bin/ld, and the librados ld.bfd exception doesn't apply since both symver checks fail. Switching FreeBSD to lld fits your draft; with CMake 4.2 or later, -DCMAKE_LINKER_TYPE=LLD already skips that block. Linking librados with lld (e.g. --undefined-version) belongs in a separate PR; it might fit your draft, since that's where lld becomes the default.

@tchaikov I think the FreeBSD side is settled. Is anything else missing here?

@Doracly
Doracly requested a review from tchaikov November 30, 2026 08:21

@tchaikov tchaikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@tchaikov

Copy link
Copy Markdown
Contributor

@Doracly could you push this change to ceph-ci to verify that the tree still builds with this change?

@Doracly

Doracly commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

@tchaikov ceph-ci built fff3bd9 on all 8 x86_64 targets, including the debug flavor on CentOS 9, Rocky 10 and Ubuntu 24.04: https://shaman.ceph.com/builds/ceph/wip-doracly-lld-linker/

@tchaikov
tchaikov merged commit cedafa8 into ceph:main Nov 30, 2026
16 checks passed
@tchaikov

Copy link
Copy Markdown
Contributor

thanks! merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants