Skip to content

Commit 8c75c34

Browse files
jannauhoshinolina
authored andcommitted
HACK: rust: x86: Set data-layout based on rustc's LLVM version
LLVM changed the data layout in x86 between 17 and 18 but Rust 1.77.0 and later checks for matching data layouts. Parse the used LLVM version from `rustc -v --version` and generate a matching target.json based on that. We might need to keep this even with rust 1.78 depending ron the rust package in Fedora 39. Link: https://lore.kernel.org/lkml/20240401212303.537355-4-ojeda@kernel.org/ Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 653f1f7 commit 8c75c34

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

init/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,11 @@ config RUSTC_VERSION_TEXT
19221922
depends on RUST
19231923
default $(shell,command -v $(RUSTC) >/dev/null 2>&1 && $(RUSTC) --version || echo n)
19241924

1925+
config RUSTC_LLVM_VERSION_TEXT
1926+
string
1927+
depends on RUST
1928+
default $(shell,command -v $(RUSTC) >/dev/null 2>&1 && $(RUSTC) -v --version | grep '^LLVM version' | sed -e 's/^.*: *//' || echo n)
1929+
19251930
config BINDGEN_VERSION_TEXT
19261931
string
19271932
depends on RUST

scripts/generate_rust_target.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,29 @@ fn main() {
152152
panic!("arm64 uses the builtin rustc aarch64-unknown-none target");
153153
} else if cfg.has("X86_64") {
154154
ts.push("arch", "x86_64");
155-
ts.push(
156-
"data-layout",
157-
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
158-
);
155+
let mut llvm_version: u32 = 18;
156+
if cfg.has("RUSTC_LLVM_VERSION_TEXT") {
157+
let llvm_str = cfg
158+
.0
159+
.get("CONFIG_RUSTC_LLVM_VERSION_TEXT")
160+
.unwrap()
161+
.split_once(".")
162+
.unwrap()
163+
.0;
164+
llvm_version = llvm_str.parse().unwrap();
165+
}
166+
// intentially broken indent
167+
if llvm_version >= 18 {
168+
ts.push(
169+
"data-layout",
170+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
171+
);
172+
} else {
173+
ts.push(
174+
"data-layout",
175+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
176+
);
177+
}
159178
let mut features = "-3dnow,-3dnowa,-mmx,+soft-float".to_string();
160179
if cfg.has("MITIGATION_RETPOLINE") {
161180
features += ",+retpoline-external-thunk";

0 commit comments

Comments
 (0)