Skip to content

cmake: implement WITH_MOLD option for Mold linker support - #69711

Merged
ronen-fr merged 2 commits into
ceph:mainfrom
ronen-fr:wip-rf-mold3
Jun 30, 2026
Merged

ronen-fr merged 2 commits into
ceph:mainfrom
ronen-fr:wip-rf-mold3

Conversation

@ronen-fr

@ronen-fr ronen-fr commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Add a WITH_MOLD cmake option that auto-configures the build for the
Mold linker. When enabled, cmake finds the mold binary, sets it as
the linker, and injects -fuse-ld= into all linker flag variables.

Some Mold-specific workarounds are dependent on the WITH_MOLD
options. These Mold-specific changes include wprkarounds for
instances where Mold handles several linker features differently
from ld.bfd:

  • --exclude-libs,ALL hides .symver-aliased symbols (e.g. rados_*)
    even when the version script lists them as global. Detect Mold
    (via USING_MOLD_LINKER) and disable --exclude-libs; version
    scripts already control symbol visibility.

  • Duplicate symbols across static archives are treated as errors.
    Merge crimson-alien-common into crimson-alienstore as a single
    archive. For crimson-osd, link crimson-alienstore before
    crimson-common with --allow-multiple-definition so the alien
    thread's non-crimson definitions win (Mold picks first definition).

  • Python/Cython extension builds (via Distutils.cmake) invoked the
    system default linker. Pass -fuse-ld= via MOLD_FUSE_LD_FLAG so
    extensions link with the configured linker.

  • Some API symbols (rados_*) were not explicitly listed in
    the linker version script, making them unavailable for
    external linking. These were added to librados.map

@ronen-fr

Copy link
Copy Markdown
Contributor Author

Working nicely for Crimson clusters - with and without the WITH_MOLD flag.

@sunyuechi

sunyuechi commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor
CMAKE_EXE_LINKER_FLAGS: " -fuse-ld=/usr/sbin/mold"
[2/2] /usr/sbin/gcc -DCHECK_FUNCTION_EXISTS=memset_s -fuse-ld=/usr/sbin/mold ... -o cmTC_662fe
gcc: error: unrecognized command-line option '-fuse-ld=/usr/sbin/mold'

I'm using gcc16, and found that -fuse-ld= does not accept a full path (even when the path is correct).

After applying https://github.com/sunyuechi/ceph-ci/blob/main/fork-patches/1050-fix-mold.patch, the build succeeds.

Then via vstart:

--seastore OK
--bluestore FAIL

osd - OSD::main: running mkfs
osd - OSD::mkfs: starting store mkfs
osd - Aborting Got SIGSEGV on shard 0 - Stopping all shards

There may still be duplicate symbols.

@ronen-fr

Copy link
Copy Markdown
Contributor Author

I'm using gcc16, and found that -fuse-ld= does not accept a full path (even when the path is correct).

I'll try to test with gcc16, and get the changes to work.

@ronen-fr

Copy link
Copy Markdown
Contributor Author

@sunyuechi - I now have a running cluster build with gcc-16 and Mold. I am not using the patch you have suggested.
Will clean the changes up a bit, then update the PR.

@ronen-fr

Copy link
Copy Markdown
Contributor Author

@sunyuechi - please try now

@ronen-fr

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

1 similar comment
@ronen-fr

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@sunyuechi

Copy link
Copy Markdown
Contributor

Yeah, GCC 16 builds fine now, but --bluestore still has issues.

@ronen-fr

Copy link
Copy Markdown
Contributor Author

Yeah, GCC 16 builds fine now, but --bluestore still has issues.

thank you. Will try to solve.

@mkogan1
mkogan1 self-requested a review June 28, 2026 08:25

@mkogan1 mkogan1 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.

checked on RHEL 10.2 with source /usr/lib/gcc-toolset/15-env.source

ccache -C
rm -rf ./build

./do_cmake.sh ... -DWITH_MOLD=OFF

time (cmake --build ./build --parallel $(nproc --ignore=5) -- vstart)
17418.57s user 1089.74s system 2541% cpu 12:08.18 total
                                         ^^^^^^^^

ccache -C
rm -rf ./build

./do_cmake.sh ... -DWITH_MOLD=ON

time (cmake --build ./build --parallel $(nproc --ignore=5) -- vstart)
16951.44s user 1057.92s system 2738% cpu 10:57.70 total
                                         ^^^^^^^^

@ronen-fr

ronen-fr commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@sunyuechi

Yeah, GCC 16 builds fine now, but --bluestore still has issues.

thank you. Will try to solve.

The updated version was tested with both alienstore (bluestore) and seastore.
(I did not yet re-test with g++-16)

ronen-fr and others added 2 commits June 28, 2026 14:53
Mold handles several linker features differently from ld.bfd:

- --exclude-libs,ALL hides .symver-aliased symbols (e.g. rados_*)
  even when the version script lists them as global. Detect Mold
  (via USING_MOLD_LINKER) and disable --exclude-libs; version
  scripts already control symbol visibility.

- Duplicate symbols across static archives are treated as errors.
  Merge crimson-alien-common into crimson-alienstore as a single
  archive. For crimson-osd, link crimson-alienstore before
  crimson-common with --allow-multiple-definition so the alien
  thread's non-crimson definitions win (Mold picks first definition).

- Python/Cython extension builds (via Distutils.cmake) invoked the
  system default linker. Pass -fuse-ld= via MOLD_FUSE_LD_FLAG so
  extensions link with the configured linker.

- Add rados_* and _rados_* to librados.map global section for Mold
  compatibility with .symver aliases.

Co-authored-by: Mark Kogan <[email protected]>
Signed-off-by: Ronen Friedman <[email protected]>
Add a WITH_MOLD cmake option that auto-configures the build for
the Mold linker. When enabled, cmake finds mold, sets CMAKE_LINKER,
injects -fuse-ld=mold into all linker flag variables, and sets
USING_MOLD_LINKER which gates the Mold-specific workarounds added
in the previous commit.

Usage: cmake -DWITH_MOLD=ON ...

Assisted-by: Claude <claude.ai>
Signed-off-by: Ronen Friedman <[email protected]>
@ronen-fr

Copy link
Copy Markdown
Contributor Author

@mkogan1 - can you retest the final version?

@mkogan1

mkogan1 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@mkogan1 - can you retest the final version?

ACK, looks good -- on latest w/ -DWITH_MOLD=ON:

time (cmake --build ./build --parallel $(nproc --ignore=5) -- vstart)
17645.63s user 1086.32s system 3096% cpu 10:04.97 total
                                         ^^^^^^^^

(reminder - for comparison w/ -DWITH_MOLD=OFF it's 12:08.18 total)

@ronen-fr

Copy link
Copy Markdown
Contributor Author

Merging based on my Teuthology runs.

@ronen-fr
ronen-fr merged commit 5e9da92 into ceph:main Jun 30, 2026
8 of 9 checks passed
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.

3 participants