diff mbox series

[scarthgap,16/16] rust: Enable dynamic linking with llvm

Message ID cb0608195e2c2893b4915f4d0f62679afbc1f2b5.1774823430.git.yoann.congal@smile.fr
State Not Applicable, archived
Delegated to: Yoann Congal
Headers show
Series [scarthgap,01/16] tzdata,tzcode-native: Upgrade 2025b -> 2025c | expand

Commit Message

Yoann Congal March 29, 2026, 10:37 p.m. UTC
From: Sunil Dora <sunilkumar.dora@windriver.com>

Fixes [Yocto #16058]

A segmentation fault occurs in rustc (e.g. in
llvm::X86ReadAdvanceTable) when reusing sstate artifacts built with
different host toolchain versions.

Issue sequence:
1. llvm-native is built with a newer toolchain
   (e.g. GCC 15/Binutils 2.45).
2. rust-native is later built with an older linker.
   (e.g. GCC 12/Binutils 2.40).
3. The older linker statically links parts of llvm-native into
   librustc_driver.
4. The resulting binary crashes at runtime inside the statically
   linked LLVM code.

The corruption happens at link time when mixing static native objects
produced by different toolchain generations.

Enable dynamic LLVM linking (link-shared = true) for rust-native so rustc
links against libLLVM.so instead of static archives, avoiding host linker
incompatibilities when reusing sstate artifacts.

Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
Suggested-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 74ba238ff1ba1e9b612aece1989b828f3a8f8770)
Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
 meta/recipes-devtools/rust/rust_1.75.0.bb | 2 ++
 1 file changed, 2 insertions(+)

Comments

Yoann Congal March 29, 2026, 10:43 p.m. UTC | #1
On Mon Mar 30, 2026 at 12:37 AM CEST, Yoann Congal wrote:
> From: Sunil Dora <sunilkumar.dora@windriver.com>
>
> Fixes [Yocto #16058]
>
> A segmentation fault occurs in rustc (e.g. in
> llvm::X86ReadAdvanceTable) when reusing sstate artifacts built with
> different host toolchain versions.
>
> Issue sequence:
> 1. llvm-native is built with a newer toolchain
>    (e.g. GCC 15/Binutils 2.45).
> 2. rust-native is later built with an older linker.
>    (e.g. GCC 12/Binutils 2.40).
> 3. The older linker statically links parts of llvm-native into
>    librustc_driver.
> 4. The resulting binary crashes at runtime inside the statically
>    linked LLVM code.
>
> The corruption happens at link time when mixing static native objects
> produced by different toolchain generations.
>
> Enable dynamic LLVM linking (link-shared = true) for rust-native so rustc
> links against libLLVM.so instead of static archives, avoiding host linker
> incompatibilities when reusing sstate artifacts.
>
> Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
> Suggested-by: Alexander Kanavin <alex@linutronix.de>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> (cherry picked from commit 74ba238ff1ba1e9b612aece1989b828f3a8f8770)
> Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
> ---

I did not wanted to send that patch, please ignore.

>  meta/recipes-devtools/rust/rust_1.75.0.bb | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/meta/recipes-devtools/rust/rust_1.75.0.bb b/meta/recipes-devtools/rust/rust_1.75.0.bb
> index b9348bf0507..f037bb33715 100644
> --- a/meta/recipes-devtools/rust/rust_1.75.0.bb
> +++ b/meta/recipes-devtools/rust/rust_1.75.0.bb
> @@ -128,6 +128,8 @@ python do_configure() {
>  
>      # [llvm]
>      config.add_section("llvm")
> +    if d.getVar('PN') == "rust-native":
> +        config.set("llvm", "link-shared", e(True))
>      config.set("llvm", "static-libstdcpp", e(False))
>      if "llvm" in (d.getVar('TC_CXX_RUNTIME') or ""):
>          config.set("llvm", "use-libcxx", e(True))
diff mbox series

Patch

diff --git a/meta/recipes-devtools/rust/rust_1.75.0.bb b/meta/recipes-devtools/rust/rust_1.75.0.bb
index b9348bf0507..f037bb33715 100644
--- a/meta/recipes-devtools/rust/rust_1.75.0.bb
+++ b/meta/recipes-devtools/rust/rust_1.75.0.bb
@@ -128,6 +128,8 @@  python do_configure() {
 
     # [llvm]
     config.add_section("llvm")
+    if d.getVar('PN') == "rust-native":
+        config.set("llvm", "link-shared", e(True))
     config.set("llvm", "static-libstdcpp", e(False))
     if "llvm" in (d.getVar('TC_CXX_RUNTIME') or ""):
         config.set("llvm", "use-libcxx", e(True))