diff mbox series

[scarthgap,2/2] rust: enable dynamic LLVM linking by default

Message ID 20261120032846.2692732-3-sunilkumar.dora@windriver.com
State New
Headers show
Series rust: link LLVM dynamically | expand

Commit Message

Dora, Sunil Kumar Nov. 20, 2026, 3:28 a.m. UTC
From: Sunil Dora <sunilkumar.dora@windriver.com>

Backport of master "rust: enable dynamic LLVM linking by default" [1].
On master rust links against the llvm recipe, here against rust-llvm
which provides libLLVM-17.so now.

rustc segfaults (e.g. in llvm::X86ReadAdvanceTable) when
rust-llvm-native comes from sstate built on a host with binutils >= 2.45
and rust-native is linked on a host with an older ld.
This is binutils PR ld/32991 [2]: newer gas emits R_X86_64_GOTPCRELX for
"push foo@GOTPCREL(%rip)" and an ld without the fix rewrites the push
into a call, so the statically linked LLVM code in librustc_driver jumps
into data at runtime. scarthgap links the static rust-llvm libs the same
way master did before the fix.

With dynamic linking the host ld only sees the exported symbols of
libLLVM and does not relink any LLVM code.

Add llvm-shared PACKAGECONFIG, default on for native, nativesdk and
target like master. Native only is not enough, target rust bootstraps
its own rustc with the target settings and crashes the same way. Remove
llvm-shared to get the static build back.

Selftest image installs rust-llvm-libllvm now, the test binaries need
it (master installs llvm there).

[1] https://git.openembedded.org/openembedded-core/commit/?id=d0671c3dad87a063b3a41dd07cde89b5684e692c
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=32991

[YOCTO #16058]

Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
---
 meta/lib/oeqa/selftest/cases/rust.py      | 2 +-
 meta/recipes-devtools/rust/rust_1.75.0.bb | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/rust.py b/meta/lib/oeqa/selftest/cases/rust.py
index 26f132edc4..b2ad7c099f 100644
--- a/meta/lib/oeqa/selftest/cases/rust.py
+++ b/meta/lib/oeqa/selftest/cases/rust.py
@@ -51,7 +51,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"]
+        default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp", "rust-llvm-libllvm"]
         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.75.0.bb b/meta/recipes-devtools/rust/rust_1.75.0.bb
index b9348bf050..b2fac12428 100644
--- a/meta/recipes-devtools/rust/rust_1.75.0.bb
+++ b/meta/recipes-devtools/rust/rust_1.75.0.bb
@@ -20,6 +20,9 @@  DEPENDS += "rust-llvm (=${PV})"
 
 RDEPENDS:${PN}:append:class-target = " gcc g++ binutils"
 
+PACKAGECONFIG ??= "llvm-shared"
+PACKAGECONFIG[llvm-shared] = ",,,"
+
 # Otherwise we'll depend on what we provide
 INHIBIT_DEFAULT_RUST_DEPS:class-native = "1"
 # We don't need to depend on gcc-native because yocto assumes it exists
@@ -128,6 +131,7 @@  python do_configure() {
 
     # [llvm]
     config.add_section("llvm")
+    config.set("llvm", "link-shared", e(bb.utils.contains('PACKAGECONFIG', 'llvm-shared', True, False, d)))
     config.set("llvm", "static-libstdcpp", e(False))
     if "llvm" in (d.getVar('TC_CXX_RUNTIME') or ""):
         config.set("llvm", "use-libcxx", e(True))