Skip to content

rust: link LLVM dynamically

[email protected] openembedded-core 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2rust-llvm: build and install the LLVM shared librarymeta/recipes-devtools/rust/rust-llvm_1.75.0.bb+14 -10 replies
2/2rust: enable dynamic LLVM linking by defaultmeta/lib/oeqa/selftest/cases/rust.py meta/recipes-devtools/rust/rust_1.75.0.bb+5 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [scarthgap][PATCH 0/2] rust: link LLVM dynamically

From: Sunil Dora <[email protected]>

This is the scarthgap backport for the rustc segfault, YOCTO #16058. It follows the RFC and discussion from June/July [1].

Root cause is a binutils bug, PR ld/32991 [2]. From binutils 2.45 gas emits R_X86_64_GOTPCRELX for "push foo@GOTPCREL(%rip)". An older ld which does not have the fix converts that push into a call. So when rust-llvm-native comes from sstate built on a >= 2.45 host and rust-native gets linked on a host with an older ld, librustc_driver jumps into LLVM data and rustc crashes. Details are in the bug [3].

master fixed this with [4], rustc links libLLVM.so there so the host ld never touches the LLVM objects, without it scarthgap is broken whenever sstate is shared between >= 2.45 and older hosts (Debian 12/13, Ubuntu 22.04/24.04, the pinned buildtools) and the distros have not picked up the ld fix.

It is opt-out via PACKAGECONFIG, and Alex also suggested to just take the backport.

master only needed rust changes because the llvm recipe already builds the shared lib (rust-llvm was dropped there [5]). scarthgap still has rust 1.75 with rust-llvm, which builds only static libs. Hence two patches:

1/2 rust-llvm: build libLLVM-17.so, install in ${libdir}, package as
rust-llvm-libllvm. rust is not touched here.
2/2 rust: llvm-shared PACKAGECONFIG, default on for native, nativesdk
and target. Native only does not work, Yoann already hit that in the RFC, target rust bootstraps its own rustc with target settings. Remove llvm-shared from PACKAGECONFIG to get static back.

Tested on scarthgap with both patches:

- rust-native, target rust, SDK build. librustc_driver has libLLVM-17.so in NEEDED now, size 142MB -> 70MB (native)
- rustc and cargo on qemux86-64 and from the SDK, testsdk passes
- multilib, musl, qemuarm, qemuppc, qemuarm64 build
- llvm-shared removed: librustc_driver static again, no libLLVM-17.so in DT_NEEDED, 142MB like before
- oe-selftest rust: same result with and without the series

Size: An image with rust is about 15MB bigger.

[1] https://lists.openembedded.org/g/openembedded-core/topic/119988126?msg=241069
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=32991
[3] https://bugzilla.yoctoproject.org/show_bug.cgi?id=16058#c86
[4] https://git.openembedded.org/openembedded-core/commit/?id=d0671c3dad87a063b3a41dd07cde89b5684e692c
rust: enable dynamic LLVM linking by default
[5] https://git.openembedded.org/openembedded-core/commit/?id=c116828a876853cd5b53f7bd4607f0037fef4ee4
rust: Drop rust-llvm

Sunil Dora (2):
rust-llvm: build and install the LLVM shared library
rust: enable dynamic LLVM linking by default

 meta/lib/oeqa/selftest/cases/rust.py           |  2 +-
 meta/recipes-devtools/rust/rust-llvm_1.75.0.bb | 15 ++++++++++++++-
 meta/recipes-devtools/rust/rust_1.75.0.bb      |  4 ++++
 3 files changed, 19 insertions(+), 2 deletions(-)
Signature · 1 line
2.49.0