public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [PATCH] rust: Enable dynamic linking with llvm
@ 2026-02-12 16:50 sunilkumar.dora
  2026-02-12 17:05 ` [OE-core] " Ross Burton
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: sunilkumar.dora @ 2026-02-12 16:50 UTC (permalink / raw)
  To: openembedded-core; +Cc: Randy.MacLeod, Sundeep.Kokkonda, alex

From: Sunil Dora <sunilkumar.dora@windriver.com>

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.

Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
---
 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(-)

diff --git a/meta/lib/oeqa/selftest/cases/rust.py b/meta/lib/oeqa/selftest/cases/rust.py
index 3ae1946e43..7614941661 100644
--- a/meta/lib/oeqa/selftest/cases/rust.py
+++ b/meta/lib/oeqa/selftest/cases/rust.py
@@ -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)))
diff --git a/meta/recipes-devtools/rust/rust_1.93.0.bb b/meta/recipes-devtools/rust/rust_1.93.0.bb
index a25f65f674..cfee48ec78 100644
--- a/meta/recipes-devtools/rust/rust_1.93.0.bb
+++ b/meta/recipes-devtools/rust/rust_1.93.0.bb
@@ -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 ""):
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [OE-core] [PATCH] rust: Enable dynamic linking with llvm
  2026-02-12 16:50 [PATCH] rust: Enable dynamic linking with llvm sunilkumar.dora
@ 2026-02-12 17:05 ` Ross Burton
  2026-02-13 19:51   ` Dora, Sunil Kumar
  2026-02-12 17:52 ` [OE-core] " Alexander Kanavin
  2026-02-15 16:35 ` [OE-core] " Mathieu Dubois-Briand
  2 siblings, 1 reply; 9+ messages in thread
From: Ross Burton @ 2026-02-12 17:05 UTC (permalink / raw)
  To: SunilKumar.Dora@windriver.com
  Cc: openembedded-core@lists.openembedded.org,
	Randy.MacLeod@windriver.com, Sundeep.Kokkonda@windriver.com,
	alex@linutronix.de

On 12 Feb 2026, at 16:50, Dora, Sunil Kumar via lists.openembedded.org <SunilKumar.Dora=windriver.com@lists.openembedded.org> wrote:
> 
> From: Sunil Dora <sunilkumar.dora@windriver.com>
> 
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [OE-core] [PATCH] rust: Enable dynamic linking with llvm
  2026-02-12 16:50 [PATCH] rust: Enable dynamic linking with llvm sunilkumar.dora
  2026-02-12 17:05 ` [OE-core] " Ross Burton
@ 2026-02-12 17:52 ` Alexander Kanavin
  2026-02-13 19:53   ` Dora, Sunil Kumar
  2026-02-15 16:35 ` [OE-core] " Mathieu Dubois-Briand
  2 siblings, 1 reply; 9+ messages in thread
From: Alexander Kanavin @ 2026-02-12 17:52 UTC (permalink / raw)
  To: SunilKumar.Dora; +Cc: openembedded-core, Randy.MacLeod, Sundeep.Kokkonda, alex

On Thu, 12 Feb 2026 at 17:51, Dora, Sunil Kumar via
lists.openembedded.org
<SunilKumar.Dora=windriver.com@lists.openembedded.org> wrote:
> 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

> Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
> Signed-off-by: Alexander Kanavin <alex@linutronix.de>
> Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>

"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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] rust: Enable dynamic linking with llvm
  2026-02-12 17:05 ` [OE-core] " Ross Burton
@ 2026-02-13 19:51   ` Dora, Sunil Kumar
  2026-02-17 14:24     ` [OE-core] " Randy MacLeod
  0 siblings, 1 reply; 9+ messages in thread
From: Dora, Sunil Kumar @ 2026-02-13 19:51 UTC (permalink / raw)
  To: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 1784 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2262 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] rust: Enable dynamic linking with llvm
  2026-02-12 17:52 ` [OE-core] " Alexander Kanavin
@ 2026-02-13 19:53   ` Dora, Sunil Kumar
  0 siblings, 0 replies; 9+ messages in thread
From: Dora, Sunil Kumar @ 2026-02-13 19:53 UTC (permalink / raw)
  To: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

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.

[-- Attachment #2: Type: text/html, Size: 424 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [OE-core] [PATCH] rust: Enable dynamic linking with llvm
  2026-02-12 16:50 [PATCH] rust: Enable dynamic linking with llvm sunilkumar.dora
  2026-02-12 17:05 ` [OE-core] " Ross Burton
  2026-02-12 17:52 ` [OE-core] " Alexander Kanavin
@ 2026-02-15 16:35 ` Mathieu Dubois-Briand
  2026-02-16 12:47   ` Dora, Sunil Kumar
  2 siblings, 1 reply; 9+ messages in thread
From: Mathieu Dubois-Briand @ 2026-02-15 16:35 UTC (permalink / raw)
  To: SunilKumar.Dora, openembedded-core; +Cc: Randy.MacLeod, Sundeep.Kokkonda, alex

On Thu Feb 12, 2026 at 5:50 PM CET, Sunil Kumar via lists.openembedded.org Dora wrote:
> From: Sunil Dora <sunilkumar.dora@windriver.com>
>
> 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.
>
> Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
> Signed-off-by: Alexander Kanavin <alex@linutronix.de>
> Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
> ---

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

-- 
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] rust: Enable dynamic linking with llvm
  2026-02-15 16:35 ` [OE-core] " Mathieu Dubois-Briand
@ 2026-02-16 12:47   ` Dora, Sunil Kumar
  0 siblings, 0 replies; 9+ messages in thread
From: Dora, Sunil Kumar @ 2026-02-16 12:47 UTC (permalink / raw)
  To: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

On Sun, Feb 15, 2026 at 10:05 PM, Mathieu Dubois-Briand wrote:

> 
> | --- 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

[-- Attachment #2: Type: text/html, Size: 755 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [OE-core] [PATCH] rust: Enable dynamic linking with llvm
  2026-02-13 19:51   ` Dora, Sunil Kumar
@ 2026-02-17 14:24     ` Randy MacLeod
  2026-02-18 17:26       ` Dora, Sunil Kumar
  0 siblings, 1 reply; 9+ messages in thread
From: Randy MacLeod @ 2026-02-17 14:24 UTC (permalink / raw)
  To: SunilKumar.Dora, openembedded-core

[-- Attachment #1: Type: text/plain, Size: 3168 bytes --]

On 2026-02-13 2:51 p.m., Dora, Sunil Kumar via lists.openembedded.org wrote:
> 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.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.


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



>
> -=-=-=-=-=-=-=-=-=-=-=-
> 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:openembedded-core+owner@lists.openembedded.org
> Unsubscribe:https://lists.openembedded.org/g/openembedded-core/unsub [randy.macleod@windriver.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>

-- 
# Randy MacLeod
# Wind River Linux

[-- Attachment #2: Type: text/html, Size: 5369 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] rust: Enable dynamic linking with llvm
  2026-02-17 14:24     ` [OE-core] " Randy MacLeod
@ 2026-02-18 17:26       ` Dora, Sunil Kumar
  0 siblings, 0 replies; 9+ messages in thread
From: Dora, Sunil Kumar @ 2026-02-18 17:26 UTC (permalink / raw)
  To: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 877 bytes --]

On Tue, Feb 17, 2026 at 07:54 PM, Randy MacLeod wrote:

> 
> 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

[-- Attachment #2: Type: text/html, Size: 1057 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-02-18 17:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-12 16:50 [PATCH] rust: Enable dynamic linking with llvm sunilkumar.dora
2026-02-12 17:05 ` [OE-core] " Ross Burton
2026-02-13 19:51   ` Dora, Sunil Kumar
2026-02-17 14:24     ` [OE-core] " Randy MacLeod
2026-02-18 17:26       ` Dora, Sunil Kumar
2026-02-12 17:52 ` [OE-core] " Alexander Kanavin
2026-02-13 19:53   ` Dora, Sunil Kumar
2026-02-15 16:35 ` [OE-core] " Mathieu Dubois-Briand
2026-02-16 12:47   ` Dora, Sunil Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox