From patchwork Mon Nov 30 20:29:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 106591 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.41946.1796070602947978312 for ; Mon, 30 Nov 2026 12:30:03 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@pengutronix.de header.s=20260414 header.b=DtcqdArC; spf=pass (domain: pengutronix.de, ip: 185.203.200.13, mailfrom: m.felsch@pengutronix.de) Received: from dude06.red.stw.pengutronix.de (dude06.red.stw.4.pengutronix.de [10.17.1.27]) (Authenticated sender: relay-from-dude06.red.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 087E22020B9; Mon, 30 Nov 2026 21:29:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796070596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bJhswD4cFcrAqAKWuYr9mKdNznhZaGWwpGwduIZBVBw=; b=DtcqdArCdWjF18jZ9SiDwQ5VP4E4sggA6pSY83/r+2z97Z7gw71L7M0uvxUvpWuRfPkK+H 4vNMx4dLg1swOe/XCPgufogofJo/EWNOlUfwXLvlAXViruZleUEzwUFnyDhsSAIBgPPeiO quXd9u8c4u/2eSSNz+Fvvd0XEsvmk2A8AfOpKAa+M9D9YzqTJJpm6MvX71ZsCNus7CwvU8 LWUKSMMWuxJbmzPEV4AHVF9xfmlxQ5az8mq5mOWRy7f8dQ2tLVqeRXEjrT/01T+Tmrpl3J Q1tCwlL/vsPp/HfQh9Qbs8ltyncuj+i+Yob+qVGD5hizMDFO19fHDqR8jK02SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796070596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bJhswD4cFcrAqAKWuYr9mKdNznhZaGWwpGwduIZBVBw=; b=Acpeln3N/tcHnPhNfcBdVW0V4GToiGx0IYdxfvBZ8trViRbd5G+myx6jPHI4+fFkRD5NwX +25wYajlnpFJ8gERJkHtlk/xf1U890DLFziEBsaFIN0kRabEos6NZkun95tJNv69VxYaZ7 1nflU5MQekEQtnTublF6tq5a+2kPN+T30Z6KTh+IU+neKdPvau8455/VaM4Dh0wEZf9sbh voYxG7vOWshMKLAiEzmvlUPXYY6ERQAxpyDy7S2EjSufrMpkKJ1Q9fIzuqCuczImJR5g9h m49jb/kIiCoyHim1gRB/yzBsa3X9owmQlvsRpqY5kbvwuWl1C/gQ0QzNN5xMag== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=relay-from-dude06.red.stw.pengutronix.de smtp.mailfrom=m.felsch@pengutronix.de ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1796070596; a=rsa-sha256; cv=none; b=C/XX19tfm3YiqAddljOLrOYv4t5PVjA1g6zZLoYS6koVV573b9Q9PQ2b43SquHZMmBRfWY Zfd/BI5qVaQPI4Puz0SLJHMkDBObxe6L75E3iCxwRW8jZFqI5OWgBZjRRiqcuuTBqdKIut 17x2RNJOeNaKu4Weknix9UuBOJKpfwmED72Hq9oH41SL2cE+yXFEftCa5SW3gPCNRUIZyT gx2QIkFJCW5+Zq8VSs5dA7qDW9YCUGbKkgv1ClfTpygKhu+VLlJh34cbKqVBhNTaYGc3MH L/9iFPIRrBLpVpkabz27cPzWfjtgb1a3CAEjoui1ANsVcOng7vbrhYboVO4YqQ== Received: from dude06.red.stw.pengutronix.de (localhost [IPv6:::1]) by dude06.red.stw.pengutronix.de (Postfix) with ESMTP id F217B6415DC; Mon, 30 Nov 2026 21:29:55 +0100 (CET) From: Marco Felsch Date: Mon, 30 Nov 2026 21:29:55 +0100 Subject: [PATCH] rust: enable fully static linking with TCLIBC=glibc MIME-Version: 1.0 Message-Id: <20261130-mfe-rust-static-glibc-v1-1-5c24d978d5ef@pengutronix.de> X-B4-Tracking: v=1; b=H4sIAMLcDWsC/x3MPQqAMAxA4atIZgNNFQevIg61phrwj6aKIN7d4 vgN7z2gHIUV2uKByJeo7FsGlQX42W0To4zZYI1tiCqDa2CMpybU5JJ4nBYZPJrgXU3BjtwQ5Pa IHOT+v13/vh87MHZMZwAAAA== X-Change-ID: 20261130-mfe-rust-static-glibc-0fca41f2de61 To: openembedded-core@lists.openembedded.org Cc: yocto@pengutronix.de, Marco Felsch , Marco Felsch X-Mailer: b4 0.14.2 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Mon, 30 Nov 2026 20:30:13 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251645 From: Marco Felsch 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 --- 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(-) --- base-commit: 39019629a4ad25557f120ec98305a4a2ad6a8558 change-id: 20261130-mfe-rust-static-glibc-0fca41f2de61 Best regards, 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")