* [PATCH] rust: enable fully static linking with TCLIBC=glibc
@ 2026-11-30 20:29 Marco Felsch
2026-12-03 6:38 ` [OE-core] " Mathieu Dubois-Briand
0 siblings, 1 reply; 3+ messages in thread
From: Marco Felsch @ 2026-11-30 20:29 UTC (permalink / raw)
To: openembedded-core; +Cc: yocto, Marco Felsch, Marco Felsch
From: Marco Felsch <marco.felsch@gmail.com>
Rust binaries built with TCLIBC=glibc and -C target-feature=+crt-static
were still dynamically linked, because the generated target spec only set
crt-static-respected for musl, so rustc ignored +crt-static. Upstream rustc
sets it for all Linux targets (base/linux.rs), so do the same. No other
change is needed: with crt-static the libc and unwind crates statically
link libc, libm, libpthread, libdl, librt, libutil, libgcc_eh and libgcc,
which glibc and libgcc already provide in the target sysroot.
Rename rust-static-musl-test to rust-static-test and RustStaticMuslTest to
RustStaticTest with a musl and a new glibc test, as the same check applies
to both.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
Add the moment only musl supports static builds albeit everything is in
place to static link against glibc as well. Of course the static linked
binary is not as small as musl builds, but a BSP can avoid multiconfig
setups.
I've tested this with rsinit, a Rust based initrd application which
requires only a dm-verity params file in addition to the static linked
Rust binary bundled as CPIO.
Regards,
Marco
---
.../rust/rust-static-musl-test/src/main.rs | 3 ---
.../Cargo.lock | 2 +-
.../Cargo.toml | 2 +-
.../rust/rust-static-test/src/main.rs | 3 +++
...atic-musl-test_0.1.bb => rust-static-test_0.1.bb} | 6 ++----
meta/classes-recipe/rust-target-config.bbclass | 4 +++-
meta/lib/oeqa/selftest/cases/rust.py | 20 ++++++++++++--------
7 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/meta-selftest/recipes-devtools/rust/rust-static-musl-test/src/main.rs b/meta-selftest/recipes-devtools/rust/rust-static-musl-test/src/main.rs
deleted file mode 100644
index 85dcaf9df57252777c507a923954a21d460237f4..0000000000000000000000000000000000000000
--- a/meta-selftest/recipes-devtools/rust/rust-static-musl-test/src/main.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-fn main() {
- println!("static-musl-ok");
-}
diff --git a/meta-selftest/recipes-devtools/rust/rust-static-musl-test/Cargo.lock b/meta-selftest/recipes-devtools/rust/rust-static-test/Cargo.lock
similarity index 58%
rename from meta-selftest/recipes-devtools/rust/rust-static-musl-test/Cargo.lock
rename to meta-selftest/recipes-devtools/rust/rust-static-test/Cargo.lock
index cb488024c31b58403487518daf031a456d5a9ff1..16d319cbad5ab351aeb066f4f91942a1443b15ec 100644
--- a/meta-selftest/recipes-devtools/rust/rust-static-musl-test/Cargo.lock
+++ b/meta-selftest/recipes-devtools/rust/rust-static-test/Cargo.lock
@@ -1,5 +1,5 @@
version = 3
[[package]]
-name = "rust-static-musl-test"
+name = "rust-static-test"
version = "0.1.0"
diff --git a/meta-selftest/recipes-devtools/rust/rust-static-musl-test/Cargo.toml b/meta-selftest/recipes-devtools/rust/rust-static-test/Cargo.toml
similarity index 59%
rename from meta-selftest/recipes-devtools/rust/rust-static-musl-test/Cargo.toml
rename to meta-selftest/recipes-devtools/rust/rust-static-test/Cargo.toml
index d7071302bde25aaa3f9c669f3d39fc5c87de9817..0504567e322aa5eff43faf554bea27d10d1b2159 100644
--- a/meta-selftest/recipes-devtools/rust/rust-static-musl-test/Cargo.toml
+++ b/meta-selftest/recipes-devtools/rust/rust-static-test/Cargo.toml
@@ -1,4 +1,4 @@
[package]
-name = "rust-static-musl-test"
+name = "rust-static-test"
version = "0.1.0"
edition = "2021"
diff --git a/meta-selftest/recipes-devtools/rust/rust-static-test/src/main.rs b/meta-selftest/recipes-devtools/rust/rust-static-test/src/main.rs
new file mode 100644
index 0000000000000000000000000000000000000000..8f7367522333874670c83cf02cbc59f752bde4cf
--- /dev/null
+++ b/meta-selftest/recipes-devtools/rust/rust-static-test/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("static-ok");
+}
diff --git a/meta-selftest/recipes-devtools/rust/rust-static-musl-test_0.1.bb b/meta-selftest/recipes-devtools/rust/rust-static-test_0.1.bb
similarity index 66%
rename from meta-selftest/recipes-devtools/rust/rust-static-musl-test_0.1.bb
rename to meta-selftest/recipes-devtools/rust/rust-static-test_0.1.bb
index 442c24c1da9246e2f0c5f2f033e9e8299ff4c6d0..c7492cf4cb4f879e948cbe77c3d987a68e5d5d8f 100644
--- a/meta-selftest/recipes-devtools/rust/rust-static-musl-test_0.1.bb
+++ b/meta-selftest/recipes-devtools/rust/rust-static-test_0.1.bb
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT
-# Minimal Rust binary to test static musl linking (bug 16076)
+# Minimal Rust binary to test static musl (bug 16076) and glibc linking
-SUMMARY = "Minimal Rust binary for static musl linking regression test"
+SUMMARY = "Minimal Rust binary for static linking regression test"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
@@ -15,6 +15,4 @@ CARGO_SRC_DIR = ""
inherit cargo
-COMPATIBLE_HOST = ".*-musl.*"
-
SSTATE_SKIP_CREATION = "1"
diff --git a/meta/classes-recipe/rust-target-config.bbclass b/meta/classes-recipe/rust-target-config.bbclass
index 89fbd19374696ef72f26568ec0b608ec785521ee..8a3ab41f8f41c450394b1821152d1303391a0992 100644
--- a/meta/classes-recipe/rust-target-config.bbclass
+++ b/meta/classes-recipe/rust-target-config.bbclass
@@ -438,7 +438,9 @@ def rust_gen_target(d, thing, wd, arch):
tspec['has-thread-local'] = True
tspec['position-independent-executables'] = True
tspec['panic-strategy'] = d.getVar("RUST_PANIC_STRATEGY")
- if "musl" in tspec['llvm-target']:
+ # Like upstream rustc's base Linux target, honour -C target-feature=+crt-static
+ # for both glibc and musl
+ if tspec['os'] == "linux":
tspec['crt-static-respected'] = True
# AArch64 AAPCS64 requires non-leaf frame pointers per
# https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#the-frame-pointer
diff --git a/meta/lib/oeqa/selftest/cases/rust.py b/meta/lib/oeqa/selftest/cases/rust.py
index 03af98345eb9a69748e7184007396e5b56cd039b..f27ccaf81b83b2ad52579dc542f93e6de2fdf576 100644
--- a/meta/lib/oeqa/selftest/cases/rust.py
+++ b/meta/lib/oeqa/selftest/cases/rust.py
@@ -152,22 +152,20 @@ class RustSelfTestSystemEmulated(OESelftestTestCase, OEPTestResultTestCase):
for test in test_results:
self.ptest_result(ptestsuite, test, test_results[test])
-# Regression test for bug 16076 - verify static linking with TCLIBC=musl
-class RustStaticMuslTest(OESelftestTestCase):
+# Regression test for bug 16076 - verify static linking with TCLIBC=musl and glibc
+class RustStaticTest(OESelftestTestCase):
- RECIPE = "rust-static-musl-test"
+ RECIPE = "rust-static-test"
- def setUp(self):
- super().setUp()
+ def check_static_linking(self, tclibc):
self.write_config(
- 'TCLIBC = "musl"\n'
- 'RUSTFLAGS:append:pn-%s = " -C target-feature=+crt-static"\n' % self.RECIPE
+ 'TCLIBC = "%s"\n'
+ 'RUSTFLAGS:append:pn-%s = " -C target-feature=+crt-static"\n' % (tclibc, self.RECIPE)
)
result = bitbake(self.RECIPE, ignore_status=True)
self.assertEqual(result.status, 0,
msg="bitbake %s failed:\n%s" % (self.RECIPE, result.output))
- def test_static_musl_linking(self):
workdir = get_bb_var("WORKDIR", self.RECIPE)
cargo_target_subdir = get_bb_var("CARGO_TARGET_SUBDIR", self.RECIPE)
pn = get_bb_var("PN", self.RECIPE)
@@ -180,3 +178,9 @@ class RustStaticMuslTest(OESelftestTestCase):
self.assertIn("statically linked", result.output,
msg="Binary is not statically linked. Regression of bug 16076.\n"
"file output: %s" % result.output)
+
+ def test_static_glibc_linking(self):
+ self.check_static_linking("glibc")
+
+ def test_static_musl_linking(self):
+ self.check_static_linking("musl")
---
base-commit: 39019629a4ad25557f120ec98305a4a2ad6a8558
change-id: 20261130-mfe-rust-static-glibc-0fca41f2de61
Best regards,
--
Marco Felsch <m.felsch@pengutronix.de>
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [OE-core] [PATCH] rust: enable fully static linking with TCLIBC=glibc
2026-11-30 20:29 [PATCH] rust: enable fully static linking with TCLIBC=glibc Marco Felsch
@ 2026-12-03 6:38 ` Mathieu Dubois-Briand
2026-12-03 10:52 ` Marco Felsch
0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Dubois-Briand @ 2026-12-03 6:38 UTC (permalink / raw)
To: Marco Felsch, openembedded-core; +Cc: yocto, Marco Felsch
On Mon Nov 30, 2026 at 9:29 PM CET, Marco Felsch wrote:
> From: Marco Felsch <marco.felsch@gmail.com>
>
> Rust binaries built with TCLIBC=glibc and -C target-feature=+crt-static
> were still dynamically linked, because the generated target spec only set
> crt-static-respected for musl, so rustc ignored +crt-static. Upstream rustc
> sets it for all Linux targets (base/linux.rs), so do the same. No other
> change is needed: with crt-static the libc and unwind crates statically
> link libc, libm, libpthread, libdl, librt, libutil, libgcc_eh and libgcc,
> which glibc and libgcc already provide in the target sysroot.
>
> Rename rust-static-musl-test to rust-static-test and RustStaticMuslTest to
> RustStaticTest with a musl and a new glibc test, as the same check applies
> to both.
>
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
> Add the moment only musl supports static builds albeit everything is in
> place to static link against glibc as well. Of course the static linked
> binary is not as small as musl builds, but a BSP can avoid multiconfig
> setups.
>
> I've tested this with rsinit, a Rust based initrd application which
> requires only a dm-verity params file in addition to the static linked
> Rust binary bundled as CPIO.
>
> Regards,
> Marco
Hi Marco,
It looks like the added test is failing on ARM host:
2026-12-02 22:03:55,845 - oe-selftest - INFO - ... FAIL
2026-12-02 22:03:55,845 - oe-selftest - INFO - 1: 49/54 804/840 (46.30s) (1 failed) (rust.RustStaticTest.test_static_glibc_linking)
2026-12-02 22:03:55,845 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):
File "/srv/pokybuild/yocto-worker/oe-selftest-armhost/build/layers/openembedded-core/meta/lib/oeqa/selftest/cases/rust.py", line 184, in test_static_glibc_linking
self.check_static_linking("glibc")
File "/srv/pokybuild/yocto-worker/oe-selftest-armhost/build/layers/openembedded-core/meta/lib/oeqa/selftest/cases/rust.py", line 167, in check_static_linking
self.assertEqual(result.status, 0,
File "/usr/lib64/python3.12/unittest/case.py", line 885, in assertEqual
assertion_func(first, second, msg=msg)
File "/usr/lib64/python3.12/unittest/case.py", line 878, in _baseAssertEqual
raise self.failureException(msg)
AssertionError: 1 != 0 : bitbake rust-static-test failed:
https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/5420
Can you have a look at the issue?
Thanks,
Mathieu
--
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [OE-core] [PATCH] rust: enable fully static linking with TCLIBC=glibc
2026-12-03 6:38 ` [OE-core] " Mathieu Dubois-Briand
@ 2026-12-03 10:52 ` Marco Felsch
0 siblings, 0 replies; 3+ messages in thread
From: Marco Felsch @ 2026-12-03 10:52 UTC (permalink / raw)
To: Mathieu Dubois-Briand; +Cc: openembedded-core, yocto, Marco Felsch
On 26-12-03 07:38, Mathieu Dubois-Briand wrote:
> On Mon Nov 30, 2026 at 9:29 PM CET, Marco Felsch wrote:
> > From: Marco Felsch <marco.felsch@gmail.com>
> >
> > Rust binaries built with TCLIBC=glibc and -C target-feature=+crt-static
> > were still dynamically linked, because the generated target spec only set
> > crt-static-respected for musl, so rustc ignored +crt-static. Upstream rustc
> > sets it for all Linux targets (base/linux.rs), so do the same. No other
> > change is needed: with crt-static the libc and unwind crates statically
> > link libc, libm, libpthread, libdl, librt, libutil, libgcc_eh and libgcc,
> > which glibc and libgcc already provide in the target sysroot.
> >
> > Rename rust-static-musl-test to rust-static-test and RustStaticMuslTest to
> > RustStaticTest with a musl and a new glibc test, as the same check applies
> > to both.
> >
> > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > ---
> > Add the moment only musl supports static builds albeit everything is in
> > place to static link against glibc as well. Of course the static linked
> > binary is not as small as musl builds, but a BSP can avoid multiconfig
> > setups.
> >
> > I've tested this with rsinit, a Rust based initrd application which
> > requires only a dm-verity params file in addition to the static linked
> > Rust binary bundled as CPIO.
> >
> > Regards,
> > Marco
>
> Hi Marco,
>
> It looks like the added test is failing on ARM host:
>
> 2026-12-02 22:03:55,845 - oe-selftest - INFO - ... FAIL
> 2026-12-02 22:03:55,845 - oe-selftest - INFO - 1: 49/54 804/840 (46.30s) (1 failed) (rust.RustStaticTest.test_static_glibc_linking)
> 2026-12-02 22:03:55,845 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):
> File "/srv/pokybuild/yocto-worker/oe-selftest-armhost/build/layers/openembedded-core/meta/lib/oeqa/selftest/cases/rust.py", line 184, in test_static_glibc_linking
> self.check_static_linking("glibc")
> File "/srv/pokybuild/yocto-worker/oe-selftest-armhost/build/layers/openembedded-core/meta/lib/oeqa/selftest/cases/rust.py", line 167, in check_static_linking
> self.assertEqual(result.status, 0,
> File "/usr/lib64/python3.12/unittest/case.py", line 885, in assertEqual
> assertion_func(first, second, msg=msg)
> File "/usr/lib64/python3.12/unittest/case.py", line 878, in _baseAssertEqual
> raise self.failureException(msg)
> AssertionError: 1 != 0 : bitbake rust-static-test failed:
>
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/5420
>
> Can you have a look at the issue?
Sure, already did and will send a v2.
Appreciate the heads-up :)
Regards,
Marco
>
> Thanks,
> Mathieu
>
> --
> Mathieu Dubois-Briand, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 10:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 20:29 [PATCH] rust: enable fully static linking with TCLIBC=glibc Marco Felsch
2026-12-03 6:38 ` [OE-core] " Mathieu Dubois-Briand
2026-12-03 10:52 ` Marco Felsch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.