From c2e72b6a6f4f2dfec97d1aa99f3af6cb1035d2bc Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 21 Oct 2026 11:25:36 +0200 Subject: [PATCH 1/5] [WIP] Update to Cranelift 0.138 --- Cargo.lock | 76 +++++++++++++++++++++++++-------------------------- Cargo.toml | 24 ++++++++-------- src/vtable.rs | 2 +- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9b921615f..27f1f4886b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,27 +43,27 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cranelift-assembler-x64" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3307701abcb90554ee72fdb0db36ee0334a4abe380c4d87a5b04a6942613c3a" +checksum = "ffc59783095ce0f8ddb9af2422f7c0af9a1be10ebd61ae26128cedb231102ab3" dependencies = [ "cranelift-assembler-x64-meta", ] [[package]] name = "cranelift-assembler-x64-meta" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e62d0e19f9f5fa0c4243236df1ffdf139d207600b4402ac41ceba8dbe7ca0f3d" +checksum = "b8375e366701e3397adc5a81134e70dbc1484541a48cc5e794cbf59bcedec9e8" dependencies = [ "cranelift-srcgen", ] [[package]] name = "cranelift-bforest" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47784bc3c4b57c0182bb8ff04aae5d5f5fc6bae8ba26b1212c9a659b90dab84e" +checksum = "496bd88b12e7678d4985fe7326eb40d895c1f08d25420454a8ea988f63c1ad15" dependencies = [ "cranelift-entity", "wasmtime-internal-core", @@ -71,18 +71,18 @@ dependencies = [ [[package]] name = "cranelift-bitset" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13d120406f713dbce1940751e77bbb14daad1261379b7200c19285953e79a1d" +checksum = "2ebeb641fe524cbfe114c8cb6360c07507fb351f753b16c6617fe3e05b3084e3" dependencies = [ "wasmtime-internal-core", ] [[package]] name = "cranelift-codegen" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a53dbec33ff86909e44be6f0ec2d17841aa38b931013707c9fc7279f1f0e5760" +checksum = "dfd64aa9248dcba9434da432ae86b8d25d23b16cf0a6f1d9a583c2e98a18276e" dependencies = [ "bumpalo", "cranelift-assembler-x64", @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42295b38e9182954cb32a71812e3d64d66a90efc0a2ababb73e465ad4a1efccf" +checksum = "279c9c34931640c26d3d667a98810db1a0eeb6f1c852f1c129b69dc73564d6f8" dependencies = [ "cranelift-assembler-x64-meta", "cranelift-codegen-shared", @@ -119,24 +119,24 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5200fa877fb64cd30cabe0603f394333f88f69adf63e4db8d48a111d0c9d0dd" +checksum = "52134a51b54394a6065651ffbc111dfd66149ae5d696b5f114a113e669129ecf" [[package]] name = "cranelift-control" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b86250e480795fbb4425ea703bca7b75282998458ce74f5360843a31949f2bbc" +checksum = "3d032756eef35c0f490e68992066c1b2d6c6e61383ef45cf13cafd4f2b30fb60" dependencies = [ "arbitrary", ] [[package]] name = "cranelift-entity" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "903c6592c7d600c251d20929f143543b7303ac70b072ad3394d65b29caf56f69" +checksum = "4ebdb75af51a87b3bb3d3ddd01d2b43810fa2462c5d495980ff163203e1c0a5b" dependencies = [ "cranelift-bitset", "wasmtime-internal-core", @@ -144,9 +144,9 @@ dependencies = [ [[package]] name = "cranelift-frontend" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b929f09b82a270e2aae062945cf86cd9db39c59ad9bead6986ea6b09fcf8a969" +checksum = "4f9a90588ea9d07ebdc77e75f40d00722acc968a29adfebc936bd1866f011a70" dependencies = [ "cranelift-codegen", "hashbrown 0.17.0", @@ -157,15 +157,15 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c5809e8636a37e5a25ecc35242d33d6e7391c49b67488b83446e2898af2a2f" +checksum = "5ed624a59ddd36a2291dcb778a0b7495b8db4c67fc5276ec8b2f018bb1aca3a6" [[package]] name = "cranelift-jit" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a86db0c01bd2f7f86fedbebd6bee15ab40d74bd1a87b35e19b2a1a07612427ba" +checksum = "df49ce23c92b723a66239fe982616a664584e34524bd83087513a2a767eb6605" dependencies = [ "anyhow", "cranelift-codegen", @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb4f4b6e71b257549ffa6f14ddc0c314f332f66c7531b3c9a645c290a9d1effa" +checksum = "5df2de5ceef42973486bdd64dbe3a18a003aeeb74f231362cca5f5b77a81739a" dependencies = [ "anyhow", "cranelift-codegen", @@ -196,9 +196,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "815c559daf605a5b4ea35530604643c1e87504353c0d1a14763f9c2b9d518493" +checksum = "5c6a9838449254a89a6b040804177c546f68da25e893a53dd940620102abe345" dependencies = [ "cranelift-codegen", "libc", @@ -208,9 +208,9 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78f98e6d6b502fa10bd1bb95776544033169d0c1860d6fe1ada03109ea500eb4" +checksum = "47eb627c518fc63c11bade98e34140ce0a503a622167762f9d2ea45b1591715f" dependencies = [ "anyhow", "cranelift-codegen", @@ -223,9 +223,9 @@ dependencies = [ [[package]] name = "cranelift-srcgen" -version = "0.137.0" +version = "0.138.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d633ff621e7f31a943431da0d7dd37c4376766c60bd7171216de1c7ccabfb370" +checksum = "9a4bb25f99483bae9140f93014bb79fce0f53f91701a9c80bd7da6a40f45d97b" [[package]] name = "crc32fast" @@ -299,9 +299,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.186" +version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" [[package]] name = "libloading" @@ -501,9 +501,9 @@ checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "wasmtime-internal-core" -version = "50.0.0" +version = "51.0.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83d4ac46034b149aed44335595402503094a04e3b70d0cff8c169d83437318b8" +checksum = "afd6f24e32c187262610b999951eb83659dc5d88aa0f6c61bb71e68e14823ea5" dependencies = [ "hashbrown 0.17.0", "libm", @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "wasmtime-internal-jit-icache-coherence" -version = "50.0.0" +version = "51.0.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf25a1b3b925915f845927967554400554db9cebd3a7038a6fca0cf6e9bbaf6a" +checksum = "423f8dff0eb07c394cc11ee8e4d302f141e0d6960bf736affcc303b2093bedbc" dependencies = [ "libc", "wasmtime-internal-core", diff --git a/Cargo.toml b/Cargo.toml index 9b919976f7..a8d33bf14b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,12 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { version = "0.137.0", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } -cranelift-frontend = { version = "0.137.0" } -cranelift-module = { version = "0.137.0" } -cranelift-native = { version = "0.137.0" } -cranelift-jit = { version = "0.137.0", optional = true } -cranelift-object = { version = "0.137.0", default-features = false } +cranelift-codegen = { version = "0.138.0-rc.1", default-features = false, features = ["std", "timing", "unwind", "all-native-arch"] } +cranelift-frontend = { version = "0.138.0-rc.1" } +cranelift-module = { version = "0.138.0-rc.1" } +cranelift-native = { version = "0.138.0-rc.1" } +cranelift-jit = { version = "0.138.0-rc.1", optional = true } +cranelift-object = { version = "0.138.0-rc.1", default-features = false } target-lexicon = "0.13" gimli = { version = "0.33", default-features = false, features = ["write"] } object = { version = "0.40.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } @@ -24,12 +24,12 @@ smallvec = "1.8.1" # Uncomment to use an unreleased version of cranelift #[patch.crates-io] -#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-50.0.0" } -#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-50.0.0" } -#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-50.0.0" } -#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-50.0.0" } -#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-50.0.0" } -#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-50.0.0" } +#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-51.0.0" } +#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-51.0.0" } +#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-51.0.0" } +#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-51.0.0" } +#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-51.0.0" } +#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-51.0.0" } # Uncomment to use local checkout of cranelift #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } diff --git a/src/vtable.rs b/src/vtable.rs index 2bb1944cc2..9f5fade3fa 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -7,7 +7,7 @@ use crate::prelude::*; pub(crate) fn vtable_memflags() -> MemFlagsData { let mut flags = MemFlagsData::trusted(); // A vtable access is always aligned and will never trap. - flags.set_readonly(); // A vtable is always read-only. + flags.set_readonly(true); // A vtable is always read-only. flags } From 5287f4545822e7c5c35219bff72cfe41d4ce6f15 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 21 Oct 2026 11:31:54 +0200 Subject: [PATCH 2/5] Use fcvt_to_{u,s}int_sat for 8 and 16 bit ints --- src/cast.rs | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/cast.rs b/src/cast.rs index abf4326f91..e9ec098143 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -115,33 +115,6 @@ pub(crate) fn clif_int_or_float_cast( vec![AbiParam::new(types::I128)], &[from], )[0] - } else if to_ty == types::I8 || to_ty == types::I16 { - // FIXME implement fcvt_to_*int_sat.i8/i16 - let val = if to_signed { - fx.bcx.ins().fcvt_to_sint_sat(types::I32, from) - } else { - fx.bcx.ins().fcvt_to_uint_sat(types::I32, from) - }; - let (min, max) = match (to_ty, to_signed) { - (types::I8, false) => (0, i64::from(u8::MAX)), - (types::I16, false) => (0, i64::from(u16::MAX)), - (types::I8, true) => (i64::from(i8::MIN as u32), i64::from(i8::MAX as u32)), - (types::I16, true) => (i64::from(i16::MIN as u32), i64::from(i16::MAX as u32)), - _ => unreachable!(), - }; - let min_val = fx.bcx.ins().iconst(types::I32, min); - let max_val = fx.bcx.ins().iconst(types::I32, max); - - let val = if to_signed { - let has_underflow = fx.bcx.ins().icmp_imm_s(IntCC::SignedLessThan, val, min); - let has_overflow = fx.bcx.ins().icmp_imm_s(IntCC::SignedGreaterThan, val, max); - let bottom_capped = fx.bcx.ins().select(has_underflow, min_val, val); - fx.bcx.ins().select(has_overflow, max_val, bottom_capped) - } else { - let has_overflow = fx.bcx.ins().icmp_imm_u(IntCC::UnsignedGreaterThan, val, max); - fx.bcx.ins().select(has_overflow, max_val, val) - }; - fx.bcx.ins().ireduce(to_ty, val) } else if to_signed { fx.bcx.ins().fcvt_to_sint_sat(to_ty, from) } else { From 32fed3ab12ee718b6fa1c1b3e6e4862279a19b24 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 21 Oct 2026 11:26:06 +0200 Subject: [PATCH 3/5] Enable atomic 128bit int support --- ...0027-stdlib-128bit-atomic-operations.patch | 58 ------------------- ...sroot_tests-128bit-atomic-operations.patch | 39 ------------- scripts/setup_rust_fork.sh | 3 - src/intrinsics/mod.rs | 32 ---------- 4 files changed, 132 deletions(-) delete mode 100644 patches/0027-stdlib-128bit-atomic-operations.patch delete mode 100644 patches/0027-sysroot_tests-128bit-atomic-operations.patch diff --git a/patches/0027-stdlib-128bit-atomic-operations.patch b/patches/0027-stdlib-128bit-atomic-operations.patch deleted file mode 100644 index f821099e68..0000000000 --- a/patches/0027-stdlib-128bit-atomic-operations.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 5d7c709608b01301d4628d2159265936d4440b67 Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Thu, 18 Feb 2021 18:45:28 +0100 -Subject: [PATCH] Disable 128bit atomic operations - -Cranelift doesn't support them yet ---- - library/core/src/panic/unwind_safe.rs | 4 ++-- - library/core/src/sync/atomic.rs | 4 ++-- - 2 files changed, 4 insertions(+), 4 deletions(-) - -diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs -index bf2e61d..cb82b07 100644 ---- a/library/core/src/panic/unwind_safe.rs -+++ b/library/core/src/panic/unwind_safe.rs -@@ -217,7 +217,7 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicI32 {} - #[cfg(target_has_atomic_load_store = "64")] - #[stable(feature = "integer_atomics_stable", since = "1.34.0")] - impl RefUnwindSafe for crate::sync::atomic::AtomicI64 {} --#[cfg(target_has_atomic_load_store = "128")] -+#[cfg(false)] - #[unstable(feature = "integer_atomics", issue = "99069")] - impl RefUnwindSafe for crate::sync::atomic::AtomicI128 {} - -@@ -236,7 +236,7 @@ impl RefUnwindSafe for crate::sync::atomic::AtomicU32 {} - #[cfg(target_has_atomic_load_store = "64")] - #[stable(feature = "integer_atomics_stable", since = "1.34.0")] - impl RefUnwindSafe for crate::sync::atomic::AtomicU64 {} --#[cfg(target_has_atomic_load_store = "128")] -+#[cfg(false)] - #[unstable(feature = "integer_atomics", issue = "99069")] - impl RefUnwindSafe for crate::sync::atomic::AtomicU128 {} - -diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs -index e676a38..b6a9a3c 100644 ---- a/library/core/src/sync/atomic.rs -+++ b/library/core/src/sync/atomic.rs -@@ -3850,7 +3850,7 @@ atomic_int! { - 8, - u64 AtomicU64 - } --#[cfg(any(target_has_atomic_load_store = "128", doc))] -+#[cfg(false)] - atomic_int! { - target_has_atomic_load_store = "128", - target_has_atomic = "128", -@@ -3869,7 +3869,7 @@ atomic_int! { - 16, - i128 AtomicI128 - } --#[cfg(any(target_has_atomic_load_store = "128", doc))] -+#[cfg(false)] - atomic_int! { - target_has_atomic_load_store = "128", - target_has_atomic = "128", --- -2.48.1 - diff --git a/patches/0027-sysroot_tests-128bit-atomic-operations.patch b/patches/0027-sysroot_tests-128bit-atomic-operations.patch deleted file mode 100644 index 6ec25732ab..0000000000 --- a/patches/0027-sysroot_tests-128bit-atomic-operations.patch +++ /dev/null @@ -1,39 +0,0 @@ -From ad7ffe71baba46865f2e65266ab025920dfdc20b Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Thu, 18 Feb 2021 18:45:28 +0100 -Subject: [PATCH] Disable 128bit atomic operations - -Cranelift doesn't support them yet ---- - library/core/src/panic/unwind_safe.rs | 6 ----- - library/core/src/sync/atomic.rs | 38 --------------------------- - library/core/tests/atomic.rs | 4 --- - 4 files changed, 4 insertions(+), 50 deletions(-) - -diff --git a/coretests/tests/lib.rs b/coretests/tests/lib.rs -index 1e336bf..35e6f54 100644 ---- a/coretests/tests/lib.rs -+++ b/coretests/tests/lib.rs -@@ -2,4 +2,3 @@ - // tidy-alphabetical-start - #![cfg_attr(not(panic = "abort"), feature(reentrant_lock))] --#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))] - #![feature(abort_immediate)] - #![feature(array_ptr_get)] -diff --git a/coretests/tests/atomic.rs b/coretests/tests/atomic.rs -index b735957..ea728b6 100644 ---- a/coretests/tests/atomic.rs -+++ b/coretests/tests/atomic.rs -@@ -185,10 +185,6 @@ fn atomic_alignment() { - assert_eq!(align_of::(), size_of::()); - #[cfg(target_has_atomic = "64")] - assert_eq!(align_of::(), size_of::()); -- #[cfg(target_has_atomic = "128")] -- assert_eq!(align_of::(), size_of::()); -- #[cfg(target_has_atomic = "128")] -- assert_eq!(align_of::(), size_of::()); - #[cfg(target_has_atomic = "ptr")] - assert_eq!(align_of::(), size_of::()); - #[cfg(target_has_atomic = "ptr")] --- -2.26.2.7.g19db9cfb68 diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index f888e73813..32ded6cef4 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -19,9 +19,6 @@ git checkout --no-progress "$(rustc -V | cut -d' ' -f3 | tr -d '(')" git submodule update --quiet --init src/tools/cargo library/backtrace library/stdarch -git -c user.name=Dummy -c user.email=dummy@example.com -c commit.gpgSign=false \ - am ../patches/*-stdlib-*.patch - cat > config.toml <( let ty = generic_args.type_at(0); match ty.kind() { - ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => { - // FIXME implement 128bit atomics - if fx.tcx.is_compiler_builtins(LOCAL_CRATE) { - // special case for compiler-builtins to avoid having to patch it - crate::base::codegen_panic_nounwind( - fx, - "128bit atomics not yet supported", - source_info.span, - ); - return Ok(()); - } else { - fx.tcx - .dcx() - .span_fatal(source_info.span, "128bit atomics not yet supported"); - } - } ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, source_info.span, ty); @@ -795,22 +779,6 @@ fn codegen_regular_intrinsic_call<'tcx>( let ty = generic_args.type_at(0); match ty.kind() { - ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => { - // FIXME implement 128bit atomics - if fx.tcx.is_compiler_builtins(LOCAL_CRATE) { - // special case for compiler-builtins to avoid having to patch it - crate::base::codegen_panic_nounwind( - fx, - "128bit atomics not yet supported", - source_info.span, - ); - return Ok(()); - } else { - fx.tcx - .dcx() - .span_fatal(source_info.span, "128bit atomics not yet supported"); - } - } ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { report_atomic_type_validation_error(fx, intrinsic, source_info.span, ty); From 9be65f92d75b7f0ab93db6b50517002987b9ac46 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 21 Oct 2026 15:31:51 +0200 Subject: [PATCH 4/5] [WIP] --- src/lib.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a1c21c1e19..66bdccf815 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ use std::sync::Arc; use cranelift_codegen::isa::TargetIsa; use cranelift_codegen::settings::{self, Configurable}; use rustc_codegen_ssa::traits::CodegenBackend; -use rustc_codegen_ssa::{CompiledModules, CrateInfo, TargetConfig, back}; +use rustc_codegen_ssa::{CompiledModules, CrateInfo, TargetConfig, back, target_features}; use rustc_data_structures::unord::UnordSet; use rustc_log::tracing::info; use rustc_middle::dep_graph::WorkProductMap; @@ -154,7 +154,7 @@ impl CodegenBackend for CraneliftCodegenBackend { } CodegenBackendInit { - global_backend_features: vec![], + global_backend_features: global_llvm_features(sess), // FIXME workaround for rust-lang/rustc_codegen_cranelift#1717 replaced_intrinsics: vec![sym::fma], fallback_intrinsics: vec![sym::type_id_eq], @@ -344,7 +344,7 @@ fn build_isa(sess: &Session, jit: bool) -> Arc { let flags = settings::Flags::new(flags_builder); - let isa_builder = match sess.opts.cg.target_cpu.as_deref() { + let mut isa_builder = match sess.opts.cg.target_cpu.as_deref() { Some(NATIVE_CPU) => cranelift_native::builder_with_options(true).unwrap(), Some(value) => { let mut builder = @@ -371,12 +371,32 @@ fn build_isa(sess: &Session, jit: bool) -> Arc { } }; + if let target_lexicon::Architecture::X86_64 = target_tuple.architecture + && sess.global_backend_features.iter().any(|feat| feat == "+cmpxchg16b") + { + isa_builder.enable("has_cmpxchg16b").unwrap(); + } + match isa_builder.finish(flags) { Ok(target_isa) => target_isa, Err(err) => sess.dcx().fatal(format!("failed to build TargetIsa: {}", err)), } } +fn global_llvm_features(sess: &EarlySession) -> Vec { + let mut features = vec![]; + + let mut extend_backend_features = |feature: &str, enable: bool| { + let enable_disable = if enable { '+' } else { '-' }; + features.push(format!("{}{}", enable_disable, feature)); + }; + + target_features::target_spec_to_backend_features(sess, &mut extend_backend_features); + target_features::flag_to_backend_features(sess, extend_backend_features); + + features +} + /// This is the entrypoint for a hot plugged rustc_codegen_cranelift #[unsafe(no_mangle)] pub fn __rustc_codegen_backend() -> Box { From f4ede658d6f2e8fe8db4196e09c37d546973a745 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 28 Oct 2026 16:18:33 +0100 Subject: [PATCH 5/5] [WIP] Support volatile FIXME breaks rayon_core due to doing read_volatile on a non-scalar type --- src/intrinsics/mod.rs | 60 +++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index b8a26cafd1..f0f8aa21a9 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -688,23 +688,37 @@ fn codegen_regular_intrinsic_call<'tcx>( sym::volatile_load | sym::unaligned_volatile_load => { intrinsic_args!(fx, args => (ptr); intrinsic); - - // Cranelift treats loads as volatile by default - // FIXME correctly handle unaligned_volatile_load let inner_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap()); - let val = CValue::by_ref(Pointer::new(ptr.load_scalar(fx)), inner_layout); + let ptr = ptr.load_scalar(fx); + + let clif_ty = fx.clif_type(inner_layout.ty).unwrap(); + let value = fx.bcx.ins().load( + clif_ty, + MemFlagsData::new() + .with_volatile(true) + .with_aligned(intrinsic != sym::unaligned_volatile_load), + ptr, + 0, + ); + + let val = CValue::by_val(value, inner_layout); ret.write_cvalue(fx, val); } sym::volatile_store | sym::unaligned_volatile_store | sym::nontemporal_store => { intrinsic_args!(fx, args => (ptr, val); intrinsic); let ptr = ptr.load_scalar(fx); + let val = val.load_scalar(fx); - // Cranelift treats stores as volatile by default - // FIXME correctly handle unaligned_volatile_store // FIXME actually do nontemporal stores if requested (but do not just emit MOVNT on x86; // see the LLVM backend for details) - let dest = CPlace::for_ptr(Pointer::new(ptr), val.layout()); - dest.write_cvalue(fx, val); + fx.bcx.ins().store( + MemFlagsData::new() + .with_volatile(true) + .with_aligned(intrinsic != sym::unaligned_volatile_store), + val, + ptr, + 0, + ); } sym::ptr_offset_from | sym::ptr_offset_from_unsigned => { @@ -754,10 +768,11 @@ fn codegen_regular_intrinsic_call<'tcx>( } sym::atomic_load => { intrinsic_args!(fx, args => (ptr); intrinsic); + let ty = generic_args.type_at(0); + // FIXME: this ignores the atomic ordering. + let volatile = generic_args.const_at(2).to_value().to_leaf().try_to_bool().unwrap(); let ptr = ptr.load_scalar(fx); - // FIXME: this ignores the atomic ordering and the volatile flag. - let ty = generic_args.type_at(0); match ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { @@ -767,17 +782,26 @@ fn codegen_regular_intrinsic_call<'tcx>( } let clif_ty = fx.clif_type(ty).unwrap(); - let val = fx.bcx.ins().atomic_load(clif_ty, MemFlagsData::trusted(), ptr); + let val = fx.bcx.ins().atomic_load( + clif_ty, + if volatile { + MemFlagsData::new().with_volatile(true).with_aligned(true) + } else { + MemFlagsData::trusted() + }, + ptr, + ); let val = CValue::by_val(val, fx.layout_of(ty)); ret.write_cvalue(fx, val); } sym::atomic_store => { intrinsic_args!(fx, args => (ptr, val); intrinsic); + let ty = generic_args.type_at(0); + // FIXME: this ignores the atomic ordering. + let volatile = generic_args.const_at(2).to_value().to_leaf().try_to_bool().unwrap(); let ptr = ptr.load_scalar(fx); - // FIXME: this ignores the atomic ordering and the volatile flag. - let ty = generic_args.type_at(0); match ty.kind() { ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {} _ => { @@ -788,7 +812,15 @@ fn codegen_regular_intrinsic_call<'tcx>( let val = val.load_scalar(fx); - fx.bcx.ins().atomic_store(MemFlagsData::trusted(), val, ptr); + fx.bcx.ins().atomic_store( + if volatile { + MemFlagsData::new().with_volatile(true).with_aligned(true) + } else { + MemFlagsData::trusted() + }, + val, + ptr, + ); } sym::atomic_xchg => { intrinsic_args!(fx, args => (ptr, new); intrinsic);