diff --git a/cumulus/polkadot-omni-node/src/main.rs b/cumulus/polkadot-omni-node/src/main.rs index 9bc669504d8cc..8dde8f7fd6836 100644 --- a/cumulus/polkadot-omni-node/src/main.rs +++ b/cumulus/polkadot-omni-node/src/main.rs @@ -21,6 +21,10 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] +// Force the linker to keep the polkadot_jemalloc_shim crate (and its #[global_allocator]). +#[cfg(target_os = "linux")] +extern crate polkadot_jemalloc_shim; + use polkadot_omni_node_lib::{ chain_spec::DiskChainSpecLoader, extra_subcommand::NoExtraSubcommand, run_with_custom_cli, runtime::DefaultRuntimeResolver, CliConfig as CliConfigT, RunConfig, NODE_VERSION, diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index 52eac2ce8b657..52ba1944e3655 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -19,6 +19,10 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] +// Force the linker to keep the polkadot_jemalloc_shim crate (and its #[global_allocator]). +#[cfg(target_os = "linux")] +extern crate polkadot_jemalloc_shim; + mod chain_spec; use polkadot_omni_node_lib::{ diff --git a/polkadot/src/main.rs b/polkadot/src/main.rs index 4a41e14d15611..252b2b931ca79 100644 --- a/polkadot/src/main.rs +++ b/polkadot/src/main.rs @@ -18,6 +18,10 @@ #![warn(missing_docs)] +// Force the linker to keep the polkadot_jemalloc_shim crate (and its #[global_allocator]). +#[cfg(target_os = "linux")] +extern crate polkadot_jemalloc_shim; + use color_eyre::eyre; fn main() -> eyre::Result<()> { diff --git a/prdoc/pr_11114.prdoc b/prdoc/pr_11114.prdoc new file mode 100644 index 0000000000000..da4b2770faeeb --- /dev/null +++ b/prdoc/pr_11114.prdoc @@ -0,0 +1,19 @@ +title: 'Force the linker not to drop jemalloc shim on Linux' +doc: +- audience: Runtime Dev + description: "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 Ubuntu 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).\n" +crates: +- name: frame-omni-bencher + bump: patch +- name: polkadot + bump: patch +- name: polkadot-parachain-bin + bump: patch +- name: polkadot-omni-node + bump: patch diff --git a/substrate/utils/frame/omni-bencher/src/main.rs b/substrate/utils/frame/omni-bencher/src/main.rs index f0f9ab753b074..a62a9145c3146 100644 --- a/substrate/utils/frame/omni-bencher/src/main.rs +++ b/substrate/utils/frame/omni-bencher/src/main.rs @@ -17,6 +17,10 @@ mod command; +// Force the linker to keep the polkadot_jemalloc_shim crate (and its #[global_allocator]). +#[cfg(target_os = "linux")] +extern crate polkadot_jemalloc_shim; + use clap::Parser; use sc_cli::Result; use tracing_subscriber::EnvFilter;