Skip to content

Commit 4a6c0c7

Browse files
committed
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 d475bc8 commit 4a6c0c7

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,$(RUSTC) --version 2>/dev/null)"
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
@@ -158,10 +158,29 @@ fn main() {
158158
}
159159
} else if cfg.has("X86_64") {
160160
ts.push("arch", "x86_64");
161-
ts.push(
162-
"data-layout",
163-
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
164-
);
161+
let mut llvm_version: u32 = 18;
162+
if cfg.has("RUSTC_LLVM_VERSION_TEXT") {
163+
let llvm_str = cfg
164+
.0
165+
.get("CONFIG_RUSTC_LLVM_VERSION_TEXT")
166+
.unwrap()
167+
.split_once(".")
168+
.unwrap()
169+
.0;
170+
llvm_version = llvm_str.parse().unwrap();
171+
}
172+
// intentially broken indent
173+
if llvm_version >= 18 {
174+
ts.push(
175+
"data-layout",
176+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
177+
);
178+
} else {
179+
ts.push(
180+
"data-layout",
181+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
182+
);
183+
}
165184
let mut features = "-mmx,+soft-float".to_string();
166185
if cfg.has("MITIGATION_RETPOLINE") {
167186
features += ",+retpoline-external-thunk";

0 commit comments

Comments
 (0)