Skip to content

Commit 07e1f83

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 c25685b commit 07e1f83

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

init/Kconfig

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

1930+
config RUSTC_LLVM_VERSION_TEXT
1931+
string
1932+
depends on RUST
1933+
default $(shell,command -v $(RUSTC) >/dev/null 2>&1 && $(RUSTC) -v --version | grep '^LLVM version' | sed -e 's/^.*: *//' || echo n)
1934+
19301935
config BINDGEN_VERSION_TEXT
19311936
string
19321937
depends on RUST

scripts/generate_rust_target.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,23 @@ 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+
let mut llvm_version: u32 = 18;
156+
if cfg.has("RUSTC_LLVM_VERSION_TEXT") {
157+
let llvm_str = cfg.0.get("CONFIG_RUSTC_LLVM_VERSION_TEXT").unwrap().split_once(".").unwrap().0;
158+
llvm_version = llvm_str.parse().unwrap();
159+
}
160+
// intentially broken indent
161+
if llvm_version >= 18 {
162+
ts.push(
163+
"data-layout",
164+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
165+
);
166+
} else {
155167
ts.push(
156168
"data-layout",
157169
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
158170
);
171+
}
159172
let mut features = "-3dnow,-3dnowa,-mmx,+soft-float".to_string();
160173
if cfg.has("RETPOLINE") {
161174
features += ",+retpoline-external-thunk";

0 commit comments

Comments
 (0)