Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
x86: rust: set rustc-abi=x86-softfloat on rustc>=1.86.0
Browse files Browse the repository at this point in the history
commit 6273a05 upstream.

When using Rust on the x86 architecture, we are currently using the
unstable target.json feature to specify the compilation target. Rustc is
going to change how softfloat is specified in the target.json file on
x86, thus update generate_rust_target.rs to specify softfloat using the
new option.

Note that if you enable this parameter with a compiler that does not
recognize it, then that triggers a warning but it does not break the
build.

[ For future reference, this solves the following error:

        RUSTC L rust/core.o
      error: Error loading target specification: target feature
      `soft-float` is incompatible with the ABI but gets enabled in
      target spec. Run `rustc --print target-list` for a list of
      built-in targets

  - Miguel ]

Cc: <[email protected]> # Needed in 6.12.y and 6.13.y only (Rust is pinned in older LTSs).
Link: rust-lang/rust#136146
Signed-off-by: Alice Ryhl <[email protected]>
Acked-by: Dave Hansen <[email protected]> # for x86
Link: https://lore.kernel.org/r/[email protected]
[ Added 6.13.y too to Cc: stable tag and added reasoning to avoid
  over-backporting. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Darksonn authored and gregkh committed Feb 13, 2025
1 parent 589fab3 commit 3633530
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/generate_rust_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ impl KernelConfig {
let option = "CONFIG_".to_owned() + option;
self.0.contains_key(&option)
}

/// Is the rustc version at least `major.minor.patch`?
fn rustc_version_atleast(&self, major: u32, minor: u32, patch: u32) -> bool {
let check_version = 100000 * major + 100 * minor + patch;
let actual_version = self
.0
.get("CONFIG_RUSTC_VERSION")
.unwrap()
.parse::<u32>()
.unwrap();
check_version <= actual_version
}
}

fn main() {
Expand All @@ -182,6 +194,9 @@ fn main() {
}
} else if cfg.has("X86_64") {
ts.push("arch", "x86_64");
if cfg.rustc_version_atleast(1, 86, 0) {
ts.push("rustc-abi", "x86-softfloat");
}
ts.push(
"data-layout",
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
Expand Down Expand Up @@ -215,6 +230,9 @@ fn main() {
panic!("32-bit x86 only works under UML");
}
ts.push("arch", "x86");
if cfg.rustc_version_atleast(1, 86, 0) {
ts.push("rustc-abi", "x86-softfloat");
}
ts.push(
"data-layout",
"e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128",
Expand Down

0 comments on commit 3633530

Please sign in to comment.