Skip to content

Force the linker not to drop jemalloc shim on Linux#11114

Merged
bkchr merged 5 commits intomasterfrom
sigurpol-frame-omni-bencher-link-jemalloc-allocator
Feb 19, 2026
Merged

Force the linker not to drop jemalloc shim on Linux#11114
bkchr merged 5 commits intomasterfrom
sigurpol-frame-omni-bencher-link-jemalloc-allocator

Conversation

@sigurpol
Copy link
Copy Markdown
Contributor

@sigurpol sigurpol commented Feb 19, 2026

Force the linker to keep the polkadot_jemalloc_shim crate and its #[global_allocator] in all binaries that depend on it. Without it, the linker might drop it since it is seen as a dependency with no referenced symbols. The issue happens only on a subset of combination of rust version and linker (e.g. on CI with Ubunti 24.04, rust 1.88.0 + gcc/ld strips the jemalloc crate from the binary but not rust 1.92.0 and also rust 1.88.0 + clang/mold works fine.

One way to reproduce the issue on my local Ubuntu machine using frame-omni-bencher as reference (current latest version v0.17.2 has the shim with jemalloc-allocator feature as dependency, as coming from PR #11069 ):

  1. building with rust 1.92.0 / gcc +ld => the linker doesn't strip jemalloc allocator from the binary:
nm frame-omni-bencher | grep -i jemalloc
000000000149bf60 t _GLOBAL__sub_I_jemalloc_nodump_allocator.cc
0000000000eacae0 t jemalloc_constructor
0000000000eacd50 t _rjem_je_jemalloc_postfork_child
0000000000eacc70 t _rjem_je_jemalloc_postfork_parent
0000000000eacaf0 t _rjem_je_jemalloc_prefork
000000000262bb08 b _ZN7rocksdbL18jemalloc_type_infoB5cxx11E
  1. building with rust 1.88.0 / gcc + ld => the linker strips aways it
000000000027f8c0 t _GLOBAL__sub_I_jemalloc_nodump_allocator.cc
00000000023a3598 b _ZN7rocksdbL18jemalloc_type_infoB5cxx11E
  1. building with rust 1.88.0 / clang + mold => the linker keeps it (same as 1.)

Since currently CI relies on Ubuntu 24.04 gcc /ld + rust 1.88.0, we go here for the conservative approach to force the linker not to drop with the extern crate change in all impacted binaries.

Next step - outside this PR - is to bump rust version.

Force the linker to keep the polkadot_jemalloc_shim crate and its
#[global_allocator]. Without it, the linker might drop it since it is
seen as a dependency with no referenced symbols. The issue happens only
on a subset of combination of rust version and linker (e.g. on CI with
Ubunti 24.04, rust 1.88.0 + gcc/ld strips the jemalloc crate from the
binary but not rust 1.92.0 and also rust 1.88.0 + clang/mold works fine)
@sigurpol
Copy link
Copy Markdown
Contributor Author

/cmd prdoc --audience runtime_dev --bump patch

Copy link
Copy Markdown
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Please do this change to every binary using the shim.

Comment thread substrate/utils/frame/omni-bencher/src/main.rs Outdated
sigurpol and others added 2 commits February 19, 2026 13:38
Co-authored-by: Bastian Köcher <git@kchr.de>
@sigurpol
Copy link
Copy Markdown
Contributor Author

Please do this change to every binary using the shim.

Done it here: d8ecd9e

@sigurpol sigurpol added T12-benchmarks This PR/Issue is related to benchmarking and weights. A4-backport-stable2512 Pull request must be backported to the stable2512 release branch A4-backport-stable2603 Pull request must be backported to the stable2603 release branch labels Feb 19, 2026
@sigurpol sigurpol changed the title frame-omni-bencher: force the linker not to drop jemalloc shim on Linux orce the linker not to drop jemalloc shim on Linux Feb 19, 2026
@sigurpol sigurpol changed the title orce the linker not to drop jemalloc shim on Linux Force the linker not to drop jemalloc shim on Linux Feb 19, 2026
@sigurpol sigurpol requested a review from bkchr February 19, 2026 13:52
@sigurpol sigurpol requested a review from seadanda February 19, 2026 14:03
@bkchr bkchr added this pull request to the merge queue Feb 19, 2026
Merged via the queue into master with commit d774715 Feb 19, 2026
309 of 317 checks passed
@bkchr bkchr deleted the sigurpol-frame-omni-bencher-link-jemalloc-allocator branch February 19, 2026 15:46
paritytech-release-backport-bot Bot pushed a commit that referenced this pull request Feb 19, 2026
Force the linker to keep the `polkadot_jemalloc_shim` crate and its
`#[global_allocator]` in all binaries that depend on it. Without it, the
linker might drop it since it is seen as a dependency with no referenced
symbols. The issue happens only on a subset of combination of rust
version and linker (e.g. on CI with Ubunti 24.04, rust 1.88.0 + gcc/ld
strips the jemalloc crate from the binary but not rust 1.92.0 and also
rust 1.88.0 + clang/mold works fine.

One way to reproduce the issue on my local Ubuntu machine using
`frame-omni-bencher` as reference (current latest version v0.17.2 has
the shim with jemalloc-allocator feature as dependency, as coming from
PR #11069 ):
1. building with rust 1.92.0 / gcc +ld => the linker doesn't strip
jemalloc allocator from the binary:
```bash
nm frame-omni-bencher | grep -i jemalloc
000000000149bf60 t _GLOBAL__sub_I_jemalloc_nodump_allocator.cc
0000000000eacae0 t jemalloc_constructor
0000000000eacd50 t _rjem_je_jemalloc_postfork_child
0000000000eacc70 t _rjem_je_jemalloc_postfork_parent
0000000000eacaf0 t _rjem_je_jemalloc_prefork
000000000262bb08 b _ZN7rocksdbL18jemalloc_type_infoB5cxx11E
```
2. building with rust 1.88.0 / gcc + ld => the linker strips aways it
```bash
000000000027f8c0 t _GLOBAL__sub_I_jemalloc_nodump_allocator.cc
00000000023a3598 b _ZN7rocksdbL18jemalloc_type_infoB5cxx11E
```

3. building with rust 1.88.0 / clang + mold => the linker keeps it (same
as 1.)

Since currently CI relies on Ubuntu 24.04 gcc /ld + rust 1.88.0, we go
here for the conservative approach to force the linker not to drop with
the `extern crate` change in all impacted binaries.

Next step - outside this PR - is to bump rust version.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
(cherry picked from commit d774715)
@paritytech-release-backport-bot
Copy link
Copy Markdown

Successfully created backport PR for stable2512:

paritytech-release-backport-bot Bot pushed a commit that referenced this pull request Feb 19, 2026
Force the linker to keep the `polkadot_jemalloc_shim` crate and its
`#[global_allocator]` in all binaries that depend on it. Without it, the
linker might drop it since it is seen as a dependency with no referenced
symbols. The issue happens only on a subset of combination of rust
version and linker (e.g. on CI with Ubunti 24.04, rust 1.88.0 + gcc/ld
strips the jemalloc crate from the binary but not rust 1.92.0 and also
rust 1.88.0 + clang/mold works fine.

One way to reproduce the issue on my local Ubuntu machine using
`frame-omni-bencher` as reference (current latest version v0.17.2 has
the shim with jemalloc-allocator feature as dependency, as coming from
PR #11069 ):
1. building with rust 1.92.0 / gcc +ld => the linker doesn't strip
jemalloc allocator from the binary:
```bash
nm frame-omni-bencher | grep -i jemalloc
000000000149bf60 t _GLOBAL__sub_I_jemalloc_nodump_allocator.cc
0000000000eacae0 t jemalloc_constructor
0000000000eacd50 t _rjem_je_jemalloc_postfork_child
0000000000eacc70 t _rjem_je_jemalloc_postfork_parent
0000000000eacaf0 t _rjem_je_jemalloc_prefork
000000000262bb08 b _ZN7rocksdbL18jemalloc_type_infoB5cxx11E
```
2. building with rust 1.88.0 / gcc + ld => the linker strips aways it
```bash
000000000027f8c0 t _GLOBAL__sub_I_jemalloc_nodump_allocator.cc
00000000023a3598 b _ZN7rocksdbL18jemalloc_type_infoB5cxx11E
```

3. building with rust 1.88.0 / clang + mold => the linker keeps it (same
as 1.)

Since currently CI relies on Ubuntu 24.04 gcc /ld + rust 1.88.0, we go
here for the conservative approach to force the linker not to drop with
the `extern crate` change in all impacted binaries.

Next step - outside this PR - is to bump rust version.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
(cherry picked from commit d774715)
@paritytech-release-backport-bot
Copy link
Copy Markdown

Successfully created backport PR for stable2603:

sigurpol added a commit that referenced this pull request Feb 19, 2026
Backport #11114 into `stable2603` from sigurpol.

See the
[documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md)
on how to use this bot.

<!--
  # To be used by other automation, do not modify:
  original-pr-number: #${pull_number}
-->

Co-authored-by: Paolo La Camera <paolo@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
sigurpol added a commit that referenced this pull request Feb 20, 2026
Backport #11114 into `stable2512` from sigurpol.

See the
[documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md)
on how to use this bot.

<!--
  # To be used by other automation, do not modify:
  original-pr-number: #${pull_number}
-->

Co-authored-by: Paolo La Camera <paolo@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
arturgontijo pushed a commit to moonbeam-foundation/polkadot-sdk that referenced this pull request Apr 1, 2026
Backport paritytech#11114 into `stable2512` from sigurpol.

See the
[documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md)
on how to use this bot.

<!--
  # To be used by other automation, do not modify:
  original-pr-number: #${pull_number}
-->

Co-authored-by: Paolo La Camera <paolo@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A4-backport-stable2512 Pull request must be backported to the stable2512 release branch A4-backport-stable2603 Pull request must be backported to the stable2603 release branch T12-benchmarks This PR/Issue is related to benchmarking and weights.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants