rust: Enable dynamic linking with llvm
PATCH 1/1 rust: Enable dynamic linking with llvm
From: Sunil Dora <[email protected]>
YOCTO #16058
When llvm-native is built with a newer toolchain (e.g. GCC 15) and reused on a system with an older linker, rustc emit segfault at runtime.
This issue occurs because rustc, which is statically linked with LLVM libraries, was built on one machine using a newer toolchain and then executed on another machine that has an older linker. To prevent crash, LLVM now linked with rustc dynamically.
Added llvm as dependency to provide libllvm.so at runtime.
--- meta/lib/oeqa/selftest/cases/rust.py | 2 +- meta/recipes-devtools/rust/rust_1.93.0.bb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/rust.py +1 -1
@@ -47,7 +47,7 @@ class RustSelfTestSystemEmulated(OESelftestTestCase, OEPTestResultTestCase): bitbake("{} -c test_compile".format(recipe)) builddir = get_bb_var("RUSTSRC", "rust") # build core-image-minimal with required packages - default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp", "libzstd", "openssl"] + default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp", "libzstd", "llvm", "openssl"] features = [] features.append('IMAGE_FEATURES += "ssh-server-dropbear"') features.append('CORE_IMAGE_EXTRA_INSTALL += "{0}"'.format(" ".join(default_installed_packages)))
meta/recipes-devtools/rust/rust_1.93.0.bb +1 -0
@@ -124,6 +124,7 @@ python do_configure() { # [llvm] config.add_section("llvm") + config.set("llvm", "link-shared", e(True)) config.set("llvm", "static-libstdcpp", e(False)) config.set("llvm", "download-ci-llvm", e(False)) if "llvm" in (d.getVar('TC_CXX_RUNTIME') or ""):
Signature · 1 line
2.49.0
Quoted 12 lines · Sunil Kumar via lists.openembedded.org
From: Sunil Dora <[email protected]>
YOCTO #16058
When llvm-native is built with a newer toolchain (e.g. GCC 15) and reused on a system with an older linker, rustc emit segfault at runtime.
This issue occurs because rustc, which is statically linked with LLVM libraries, was built on one machine using a newer toolchain and then executed on another machine that has an older linker. To prevent crash, LLVM now linked with rustc dynamically.
What’s the impact on the native sysroot and target packages when we link rust against all of libLLVM.so dynamically vs statically linking the pieces that are used?
Ross
Quoted 4 lines · Ross Burton
What’s the impact on the native sysroot and target packages when we link rust against all of libLLVM.so dynamically vs statically linking the pieces that are used?
Hi Ross,
Below are the observed impacts when linking Rust against shared libLLVM.so versus statically linking LLVM components.
On Native:
**********
All required LLVM-related libraries were already present in recipe-sysroot-native before switching Rust to dynamic LLVM. Dynamic linking does not introduce any new native dependencies. Existing llvm-native artifacts are reused.
Static:
-rw-r--r-- 1 xxx users 213M Feb 13 00:29 librustc_driver-4b6f2c2478f9ef2c.so Dynamic:
-rw-r--r-- 1 xxx users 132M Feb 13 00:52 librustc_driver-4b6f2c2478f9ef2c.so
So on native we see ~81 MB reduction in librustc_driver, with no additional sysroot growth.
On Target:
**********librustc_driver shrinks from 144.8 MB to 84.2 MB (~60 MB reduction). However, dynamic linking introduces shared libLLVM.so plus a few runtime dependencies.
Static:
root@qemux86-64:~# ls -lh /usr/lib/librustc_driver-*.so -rw-r--r-- 1 root root 144.8M Apr 5 2011 /usr/lib/librustc_driver-151eed90355bbdac.so
Dynamic:
root@qemux86-64:~# ls -lh /usr/lib/librustc_driver-*.so -rw-r--r-- 1 root root 84.2M Apr 5 2011 /usr/lib/librustc_driver-151eed90355bbdac.so
New dynamic dependencies:
root@qemux86-64:~# ldd /usr/lib/librustc_driver-*.so libLLVM.so.21.1 libffi.so.8 libxml2.so.16
Size contribution on target:
- libLLVM.so.21.1 ≈ 75.5 MB
- libxml2.so.16 ≈ 1.2 MB
- libffi.so.8 ≈ 42.5 KB
When LLVM is only used by Rust, this results in a net image increase of approximately 15–16 MB.
Quoted 45 lines · Sunil Kumar via lists.openembedded.org
On Thu, Feb 12, 2026 at 10:36 PM, Ross Burton wrote:
What’s the impact on the native sysroot and target packages when we link rust against all of libLLVM.so dynamically vs statically linking the pieces that are used?
Hi Ross,
Below are the observed impacts when linking Rust against shared libLLVM.so versus statically linking LLVM components.
On Native:
**********
All required LLVM-related libraries were already present in recipe-sysroot-native before switching Rust to dynamic LLVM. Dynamic linking does not introduce any new native dependencies. Existing llvm-native artifacts are reused.Static:
-rw-r--r-- 1 xxx users 213M Feb 13 00:29
librustc_driver-4b6f2c2478f9ef2c.so
Dynamic:
-rw-r--r-- 1 xxx users 132M Feb 13 00:52
librustc_driver-4b6f2c2478f9ef2c.soSo on native we see ~81 MB reduction in
librustc_driver, with no additional sysroot growth.On Target:
**********librustc_drivershrinks from 144.8 MB to 84.2 MB (~60 MB reduction). However, dynamic linking introduces shared libLLVM.so plus a few runtime dependencies.Static:
root@qemux86-64:~# ls -lh /usr/lib/librustc_driver-*.so -rw-r--r-- 1 root root 144.8M Apr 5 2011 /usr/lib/librustc_driver-151eed90355bbdac.soDynamic:
root@qemux86-64:~# ls -lh /usr/lib/librustc_driver-*.so -rw-r--r-- 1 root root 84.2M Apr 5 2011 /usr/lib/librustc_driver-151eed90355bbdac.soNew dynamic dependencies:
root@qemux86-64:~# ldd /usr/lib/librustc_driver-*.so libLLVM.so.21.1 libffi.so.8 libxml2.so.16
Quoted 6 lines
Size contribution on target:
- libLLVM.so.21.1 ≈ 75.5 MB
- libxml2.so.16 ≈ 1.2 MB
- libffi.so.8 ≈ 42.5 KBWhen LLVM is only used by Rust, this results in a net image increase of approximately 15–16 MB.
Good, that's annoying but acceptable increase: ~7% to work-around this bug.
I'm still a bit uncomfortable with changing the way that target Rust is built to deal with a Rust-native problem. Also there's the question about dynamic linking increasing runtime by a small amount. Finally, I worry that few people/distros change the default linking to by dynamic.
So I won't object to this work-around especially if we can easily limit it to -native. Have you tried that? In a few years, we won't have this mix of toolchain versions and can drop this change
so if this gets merged please open a tracking bug so that we don't forget.
../Randy
Quoted 9 lines
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#231138):https://lists.openembedded.org/g/openembedded-core/message/231138 Mute This Topic:https://lists.openembedded.org/mt/117777483/3616765
Group Owner:[email protected] Unsubscribe:https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 2 lines
# Randy MacLeod # Wind River Linux
Quoted 10 lines · Randy MacLeod
I'm still a bit uncomfortable with changing the way that target Rust is built to deal with
a Rust-native problem. Also there's the question about dynamic linking increasing runtime
by a small amount. Finally, I worry that few people/distros change the default linking to by dynamic.So I won't object to this work-around especially if we can easily limit it to -native. Have you tried that?
Hi Randy,
I’ve now limited the change as you suggested:
- rust-native links with LLVM dynamically
- rust-target links with LLVM statically
This keeps the workaround only in -native and avoids changing how the target toolchain is built. I reran the relevant tests and didn’t see any regressions or runtime issues. I’ll send V3 shortly with this approach.
Thanks,
Sunil Dora
Quoted 3 lines · Sunil Kumar via lists.openembedded.org
This issue occurs because rustc, which is statically linked with LLVM libraries, was built on one machine using a newer toolchain and then executed on another machine that has an older linker.
I don't think the above is quite accurate? The issue is maybe better explained step by step:
- llvm-native is built with a newer (e.g. gcc 15/binutils2.45) toolchain
- rust-native is statically linked with parts of llvm-native using an older toolchain (e.g. binutils 2.40), which does it incorrectly
- rust-native is executed (toolchain is not relevant at this step anymore), and crashes inside statically linked llvm code
Quoted 3 lines
Signed-off-by Sunil Dora <[email protected]>Signed-off-by Alexander Kanavin <[email protected]>Signed-off-by Deepesh Varatharajan <[email protected]>
"Signed-off-by:" tags are sensitive. They're like real signatures, in the sense that you can only add your own, and never other people's (even if they gave you 'permission' via some side channel). If you want to acknowledge others, you should do it with an informal tag, e.g. Suggested-by or Tested-by, or just say "Thanks to Alex for X, and Deepech for Y".
Alex
Hi Alex,
Thanks for the clarification — you're right, my earlier wording was not precise. I’ll update the commit message accordingly and resend as v2.
Also, thanks for pointing out the Signed-off-by guidance — I’ll remove the additional tags and use appropriate acknowledgements instead.
Quoted 11 lines · Sunil Kumar via lists.openembedded.org Dora
From: Sunil Dora <[email protected]>
YOCTO #16058
When llvm-native is built with a newer toolchain (e.g. GCC 15) and reused on a system with an older linker, rustc emit segfault at runtime.
This issue occurs because rustc, which is statically linked with LLVM libraries, was built on one machine using a newer toolchain and then executed on another machine that has an older linker. To prevent crash, LLVM now linked with rustc dynamically.
Quoted 6 lines
Added llvm as dependency to provide libllvm.so at runtime.
Signed-off-by Sunil Dora <[email protected]>Signed-off-by Alexander Kanavin <[email protected]>Signed-off-by Deepesh Varatharajan <[email protected]>---
Hi Sunil,
It looks like this is breaking some builds:
ERROR: rust-1.93.0-r0 do_install: Execution of '/srv/pokybuild/yocto-worker/qemux86-world-alt/build/build/tmp/work/x86-64-v3-poky-linux/rust/1.93.0/temp/run.do_install.3402703' failed with exit code 1
...
| error: failed to run custom build command for `rustc_llvm v0.0.0 (/srv/pokybuild/yocto-worker/qemux86-world-alt/build/build/tmp/work/x86-64-v3-poky-linux/rust/1.93.0/sources/rustc-1.93.0-src/compiler/rustc_llvm)` | | Caused by: | process didn't exit successfully: `/srv/pokybuild/yocto-worker/qemux86-world-alt/build/build/tmp/work/x86-64-v3-poky-linux/rust/1.93.0/sources/rustc-1.93.0-src/build/x86_64-unknown-linux-gnu/stage2-rustc/release/build/rustc_llvm-de72af8bf33c0296/build-script-build` (exit status: 101) ... | --- stderr | llvm-config: error: libLLVM-21.so is missing
https://autobuilder.yoctoproject.org/valkyrie/#/builders/17/builds/3020
Can you have a look at this issue?
Thanks,
Mathieu
Signature · 3 lines
Mathieu Dubois-Briand, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 3 lines · Mathieu Dubois-Briand
| --- stderr
| llvm-config: error: libLLVM-21.so is missing
Hi Mathieu,
Thanks for the report and logs.
I’ve looked into the issue and was able to reproduce and debug the failure. It turns out to be related to the multilib configuration.
I’ve identified the appropriate fix and am preparing a v2 update, which I’ll send out shortly.
Best regards,
Sunil