From a8954729886e49b2dde48a8cb0b6c315b826c660 Mon Sep 17 00:00:00 2001 From: tamnd <1218621+tamnd@users.noreply.github.com> Date: Sat, 3 Oct 2026 19:00:31 +0700 Subject: [PATCH] Pass the era's assembler version to rucc The kernel reads the assembler version from `$(CC) -Wa,--version` in scripts/as-version.sh, so rucc printed its own gas default of 2.46 and CONFIG_AS_VERSION differed from the gcc build. The persona now carries -fgnu-as-version from the era, and the shim drops it before calling the other compiler, the same as -fgnuc-version. --- crates/rk-shim/src/bringup.rs | 23 +++++++++++++++++------ crates/rk/src/build.rs | 10 +++++++--- crates/rk/src/flags.rs | 1 + crates/rk/src/probes.rs | 5 ++++- crates/rk/src/syntax.rs | 1 + 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/crates/rk-shim/src/bringup.rs b/crates/rk-shim/src/bringup.rs index 7a417eb..f858db0 100644 --- a/crates/rk-shim/src/bringup.rs +++ b/crates/rk-shim/src/bringup.rs @@ -68,13 +68,16 @@ const NEWER_THAN_BRINGUP: &[&str] = &["-fzero-init-padding-bits="]; /// The arguments a call hands to its compiler. /// -/// rk puts the era's persona in `CC` as `-fgnuc-version=`, which only rucc knows. GCC refuses +/// rk puts the era's persona in `CC` as `-fgnuc-version=` and `-fgnu-as-version=`, which only rucc +/// knows. GCC refuses /// it, so a delegated call leaves it out, along with the flags in [`NEWER_THAN_BRINGUP`]. Every /// other argument goes through as kbuild wrote it. #[must_use] pub fn passed_on(args: &[String], delegated: bool) -> Vec { let refused = |a: &str| { - a.starts_with("-fgnuc-version=") || NEWER_THAN_BRINGUP.iter().any(|f| a.starts_with(f)) + a.starts_with("-fgnuc-version=") + || a.starts_with("-fgnu-as-version=") + || NEWER_THAN_BRINGUP.iter().any(|f| a.starts_with(f)) }; args.iter() .filter(|a| !(delegated && refused(a))) @@ -177,10 +180,18 @@ mod tests { #[test] fn the_persona_is_not_passed_on_to_the_other_compiler() { - let args: Vec = ["-fgnuc-version=14.2.0", "-m16", "-c", "-o", "a.o", "a.S"] - .iter() - .map(|s| (*s).to_string()) - .collect(); + let args: Vec = [ + "-fgnuc-version=14.2.0", + "-fgnu-as-version=2.44", + "-m16", + "-c", + "-o", + "a.o", + "a.S", + ] + .iter() + .map(|s| (*s).to_string()) + .collect(); assert_eq!(passed_on(&args, true), ["-m16", "-c", "-o", "a.o", "a.S"]); assert_eq!(passed_on(&args, false), args, "rucc keeps it"); } diff --git a/crates/rk/src/build.rs b/crates/rk/src/build.rs index 07e6c51..606a666 100644 --- a/crates/rk/src/build.rs +++ b/crates/rk/src/build.rs @@ -3,8 +3,9 @@ //! The tree is never written to. kbuild's output goes under `O=`, and the compiler is the shim, //! copied into the build directory with an `rk-cc.toml` naming the real compiler, so that every //! sub make, including the ones that clean their environment, still goes through it. When the -//! compiler is rucc, the era's persona is part of `CC`, as `rk-cc -fgnuc-version=14.2.0`, which -//! is what a user building by hand would write too. +//! compiler is rucc, the era's persona is part of `CC`, as `rk-cc -fgnuc-version=14.2.0 +//! -fgnu-as-version=2.44`, which is what a user building by hand would write too. The second one +//! is what `scripts/as-version.sh` reads, so `CONFIG_AS_VERSION` matches the reference's binutils. //! //! Nothing else is added to the command line, with one exception that changes no code: //! `--stack-usage` passes `KCFLAGS=-fstack-usage`, as the kernel's own `scripts/stackusage` does, @@ -524,7 +525,10 @@ pub fn run(plan: &Plan) -> Result { .map_err(|e| format!("writing the shim's settings: {e}"))?; let persona = if plan.compiler.rucc { - vec![format!("-fgnuc-version={}", plan.era.gnuc)] + vec![ + format!("-fgnuc-version={}", plan.era.gnuc), + format!("-fgnu-as-version={}", plan.era.gnu_as), + ] } else { Vec::new() }; diff --git a/crates/rk/src/flags.rs b/crates/rk/src/flags.rs index d9bc201..ba845b1 100644 --- a/crates/rk/src/flags.rs +++ b/crates/rk/src/flags.rs @@ -98,6 +98,7 @@ pub fn normalize(words: &[String], dirs: &[(&str, &str)]) -> Vec { continue; } if word.starts_with("-fgnuc-version=") + || word.starts_with("-fgnu-as-version=") || word.starts_with("-Wp,-MD,") || word.starts_with("-Wp,-MMD,") || matches!(word.as_str(), "-MD" | "-MMD") diff --git a/crates/rk/src/probes.rs b/crates/rk/src/probes.rs index 663b6fc..1f100c5 100644 --- a/crates/rk/src/probes.rs +++ b/crates/rk/src/probes.rs @@ -26,7 +26,10 @@ pub fn question(record: &CompileRecord) -> String { args.next(); continue; } - if arg.starts_with("-fgnuc-version=") || (arg.starts_with("-o") && arg.len() > 2) { + if arg.starts_with("-fgnuc-version=") + || arg.starts_with("-fgnu-as-version=") + || (arg.starts_with("-o") && arg.len() > 2) + { continue; } if arg.contains(".tmp_") { diff --git a/crates/rk/src/syntax.rs b/crates/rk/src/syntax.rs index b60cbc1..edddf0c 100644 --- a/crates/rk/src/syntax.rs +++ b/crates/rk/src/syntax.rs @@ -46,6 +46,7 @@ pub fn replay_args(record: &CompileRecord, extra: &[String]) -> Vec { || arg.starts_with("-Wp,-MD,") || arg.starts_with("-Wp,-MMD,") || arg.starts_with("-fgnuc-version=") + || arg.starts_with("-fgnu-as-version=") { continue; }