Skip to content

Update from rust-lang/rust #946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 53 commits into from
Jun 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
a0e1120
Rollup merge of #142036 - tgross35:update-builtins, r=tgross35
matthiaskrgr Jun 5, 2025
b13f70d
Auto merge of #142081 - matthiaskrgr:rollup-secpezz, r=matthiaskrgr
bors Jun 5, 2025
6a98e64
Merge from rustc
Jun 6, 2025
3913351
Merge pull request #4380 from rust-lang/rustup-2025-06-06
oli-obk Jun 6, 2025
08791a6
Merge pull request #4378 from RalfJung/flock
RalfJung Jun 6, 2025
6cac3c8
Auto merge of #142074 - oli-obk:its-finally-gone, r=petrochenkov
bors Jun 8, 2025
2356769
Use the in-tree `compiler-builtins`
tgross35 Jun 4, 2025
8f802ae
compiler-builtins: Fix a `rustdoc::bare-urls` error
tgross35 Jun 5, 2025
bdb121c
Auto merge of #142085 - compiler-errors:perf-self-obl, r=lcnr
bors Jun 8, 2025
8a682dc
Auto merge of #142095 - joshtriplett:optimize-veccache, r=SparrowLii
bors Jun 8, 2025
714314f
compiler-builtins: Resolve `unsafe_op_in_unsafe_fn` on Arm32 Android
tgross35 Jun 8, 2025
d17f101
compiler-builtins: Specify `:r` registers for `usize`
tgross35 Jun 8, 2025
d1d8fb2
compiler-builtins: Emit `rustc-check-cfg` earlier
tgross35 Jun 9, 2025
cf68a37
Rollup merge of #141993 - tgross35:use-in-tree-builtins, r=bjorn3
tgross35 Jun 9, 2025
4bad7eb
Rollup merge of #142208 - Urgau:dead_code-const_, r=petrochenkov
tgross35 Jun 9, 2025
d37806c
Rollup merge of #142238 - RalfJung:nonnull_provenance, r=workingjubilee
tgross35 Jun 9, 2025
46b8cd8
Auto merge of #142253 - tgross35:rollup-img49op, r=tgross35
bors Jun 9, 2025
f98b680
Auto merge of #142250 - lnicola:sync-from-ra, r=lnicola
bors Jun 10, 2025
5b3482f
Merge from rustc
Jun 10, 2025
6665859
Auto merge of #142109 - weihanglo:update-cargo, r=weihanglo
bors Jun 10, 2025
eb1e2a3
Merge pull request #4393 from rust-lang/rustup-2025-06-10
RalfJung Jun 10, 2025
d7a9213
Merge pull request #4394 from RalfJung/smallvec
RalfJung Jun 10, 2025
319637f
add a fixme to use `extern_custom` when available
folkertdev Jun 9, 2025
0f8e54c
use `#[naked]` for `__rust_probestack`
folkertdev Jun 3, 2025
f939562
merge the sgx/fortanix `__rust_probestack` into the general `x86_64` one
folkertdev Jun 3, 2025
c885ce0
indent the probestack inline assembly
folkertdev Jun 3, 2025
aa46c30
Merge pull request #4382 from RalfJung/dup
RalfJung Jun 10, 2025
df2fc9a
Merge pull request #4389 from RalfJung/native-lib-search-order
RalfJung Jun 10, 2025
58af319
Auto merge of #141451 - lcnr:canonicalize-env-cache, r=compiler-errors
bors Jun 10, 2025
5baa1c0
Rollup merge of #134442 - epage:change, r=workingjubilee
fmease Jun 10, 2025
174d2e7
Rollup merge of #140766 - sayantn:stabilize-keylocker, r=traviscross,…
fmease Jun 10, 2025
6323f8d
Rollup merge of #141642 - xizheyin:issue-141619, r=BoxyUwU
fmease Jun 10, 2025
0396996
Rollup merge of #141818 - mati865:dont-create-msi-from-non-windows, r…
fmease Jun 10, 2025
c69df25
Rollup merge of #141909 - Shourya742:2025-06-01-add-execution-context…
fmease Jun 10, 2025
1d07d94
Rollup merge of #141992 - folkertdev:probestack-naked-function, r=tgr…
fmease Jun 10, 2025
e162979
Rollup merge of #142101 - lolbinarycat:core-dedup-ptr-docs-139190-pt2…
fmease Jun 10, 2025
90f3181
Rollup merge of #142102 - kiseitai3:141714_stdin_read_to_string_docs,…
fmease Jun 10, 2025
0813b1e
Rollup merge of #142124 - oli-obk:transmute-cast, r=scottmcm
fmease Jun 10, 2025
d74a804
Rollup merge of #142240 - fee1-dead-contrib:push-zkkzoxlymslv, r=oli-obk
fmease Jun 10, 2025
f364381
Rollup merge of #142258 - teohhanhui:docs/platform-support-linux-kern…
fmease Jun 10, 2025
55fcb3e
Rollup merge of #142262 - aDotInTheVoid:nomemchr, r=Noratrieb
fmease Jun 10, 2025
38d880a
Rollup merge of #142271 - workingjubilee:fn-ptrs-have-two-different-l…
fmease Jun 10, 2025
ddd71f4
Rollup merge of #142275 - aDotInTheVoid:gen-ty-of, r=fmease
fmease Jun 10, 2025
84e0ef6
Rollup merge of #142288 - RalfJung:const-eval-comments, r=oli-obk
fmease Jun 10, 2025
b08f6d8
Auto merge of #142299 - fmease:rollup-u86s80a, r=fmease
bors Jun 10, 2025
6fa2e03
Auto merge of #142292 - RalfJung:miri-sync, r=RalfJung
bors Jun 10, 2025
277a0cc
Auto merge of #141883 - oli-obk:remove-check-mod-loops, r=nnethercote
bors Jun 10, 2025
8d1b2b5
Auto merge of #142090 - compiler-errors:perf-stable-root-var, r=lcnr
bors Jun 11, 2025
2f92476
Auto merge of #136594 - pascaldekloe:fmt-int128, r=tgross35
bors Jun 12, 2025
2d43ce8
Auto merge of #142127 - compiler-errors:nested-goals-certainty, r=lcnr
bors Jun 12, 2025
fc6b151
Update the upstream Rust version
tgross35 Jun 14, 2025
6e475af
Merge ref 'd087f112b7d1:/library/compiler-builtins' from https://gith…
tgross35 Jun 14, 2025
7c46e92
Work around out-of-tree testing with a shim crate
tgross35 Jun 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[workspace]
resolver = "2"
members = [
"builtins-shim",
"builtins-test",
"compiler-builtins",
"crates/josh-sync",
"crates/libm-macros",
"crates/musl-math-sys",
Expand All @@ -14,8 +14,8 @@ members = [
]

default-members = [
"builtins-shim",
"builtins-test",
"compiler-builtins",
"crates/libm-macros",
"libm",
"libm-test",
Expand All @@ -26,6 +26,10 @@ exclude = [
# and `mangled-names` disabled, which is the opposite of what is needed for
# other tests, so it makes sense to keep it out of the workspace.
"builtins-test-intrinsics",
# We test via the `builtins-shim` crate, so exclude the `compiler-builtins`
# that has a dependency on `core`. See `builtins-shim/Cargo.toml` for more
# details.
"compiler-builtins",
]

[profile.release]
Expand Down
63 changes: 63 additions & 0 deletions builtins-shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# NOTE: Must be kept in sync with `../compiler-builtins/Cargo.toml`.
#
# The manifest at `../compiler-builtins` is what actually gets used in the
# rust-lang/rust tree; however, we can't build it out of tree because it
# depends on `core` by path, and even optional Cargo dependencies need to be
# available at build time. So, we work around this by having this "shim"
# manifest that is identical except for the `core` dependency and forwards
# to the same sources, which acts as the `compiler-builtins` Cargo entrypoint
# for out of tree testing

[package]
name = "compiler_builtins"
version = "0.1.160"
authors = ["Jorge Aparicio <[email protected]>"]
description = "Compiler intrinsics used by the Rust compiler."
repository = "https://github.com/rust-lang/compiler-builtins"
license = "MIT AND Apache-2.0 WITH LLVM-exception AND (MIT OR Apache-2.0)"
edition = "2024"
publish = false
links = "compiler-rt"

build = "../compiler-builtins/build.rs"

[lib]
path = "../compiler-builtins/src/lib.rs"
bench = false
doctest = false
test = false

[build-dependencies]
cc = { optional = true, version = "1.2" }

[features]
default = ["compiler-builtins"]

# Enable compilation of C code in compiler-rt, filling in some more optimized
# implementations and also filling in unimplemented intrinsics
c = ["dep:cc"]

# Workaround for the Cranelift codegen backend. Disables any implementations
# which use inline assembly and fall back to pure Rust versions (if available).
no-asm = []

# Workaround for codegen backends which haven't yet implemented `f16` and
# `f128` support. Disabled any intrinsics which use those types.
no-f16-f128 = []

# Flag this library as the unstable compiler-builtins lib
compiler-builtins = []

# Generate memory-related intrinsics like memcpy
mem = []

# Mangle all names so this can be linked in with other versions or other
# compiler-rt implementations. Also used for testing
mangled-names = []

# Only used in the compiler's build system
rustc-dep-of-std = ["compiler-builtins"]

# This makes certain traits and function specializations public that
# are not normally public but are required by the `builtins-test`
unstable-public-internals = []
2 changes: 1 addition & 1 deletion builtins-test-intrinsics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish = false
license = "MIT OR Apache-2.0"

[dependencies]
compiler_builtins = { path = "../compiler-builtins", features = ["compiler-builtins"] }
compiler_builtins = { path = "../builtins-shim", features = ["compiler-builtins"] }
panic-handler = { path = "../crates/panic-handler" }

[features]
Expand Down
2 changes: 1 addition & 1 deletion builtins-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rustc_apfloat = "0.2.2"
iai-callgrind = { version = "0.14.1", optional = true }

[dependencies.compiler_builtins]
path = "../compiler-builtins"
path = "../builtins-shim"
default-features = false
features = ["unstable-public-internals"]

Expand Down
10 changes: 7 additions & 3 deletions compiler-builtins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# NOTE: Must be kept in sync with `../builtins-shim/Cargo.toml`.
#
# This manifest is actually used in-tree by rust-lang/rust,
# `../builtins-shim/Cargo.toml` is used by out-of-tree testing. See the other
# manifest for further details.

[package]
name = "compiler_builtins"
version = "0.1.160"
Expand All @@ -15,9 +21,7 @@ doctest = false
test = false

[dependencies]
# For more information on this dependency see
# https://github.com/rust-lang/rust/tree/master/library/rustc-std-workspace-core
core = { version = "1.0.1", optional = true, package = "rustc-std-workspace-core" }
core = { path = "../../core", optional = true }

[build-dependencies]
cc = { optional = true, version = "1.2" }
Expand Down
5 changes: 3 additions & 2 deletions compiler-builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ fn main() {

println!("cargo:compiler-rt={}", cwd.join("compiler-rt").display());

println!("cargo::rustc-check-cfg=cfg(kernel_user_helpers)");
println!("cargo::rustc-check-cfg=cfg(feature, values(\"mem-unaligned\"))");

// Emscripten's runtime includes all the builtins
if target.os == "emscripten" {
return;
Expand All @@ -44,7 +47,6 @@ fn main() {
}

// These targets have hardware unaligned access support.
println!("cargo::rustc-check-cfg=cfg(feature, values(\"mem-unaligned\"))");
if target.arch.contains("x86_64")
|| target.arch.contains("x86")
|| target.arch.contains("aarch64")
Expand Down Expand Up @@ -75,7 +77,6 @@ fn main() {
// Only emit the ARM Linux atomic emulation on pre-ARMv6 architectures. This
// includes the old androideabi. It is deprecated but it is available as a
// rustc target (arm-linux-androideabi).
println!("cargo::rustc-check-cfg=cfg(kernel_user_helpers)");
if llvm_target[0] == "armv4t"
|| llvm_target[0] == "armv5te"
|| target.triple == "arm-linux-androideabi"
Expand Down
2 changes: 1 addition & 1 deletion compiler-builtins/src/aarch64_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! To avoid breaking backwards compat, C toolchains introduced a concept of "outlined atomics",
//! where atomic operations call into the compiler runtime to dispatch between two depending on
//! which is supported on the current CPU.
//! See https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/making-the-most-of-the-arm-architecture-in-gcc-10#:~:text=out%20of%20line%20atomics for more discussion.
//! See <https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/making-the-most-of-the-arm-architecture-in-gcc-10#:~:text=out%20of%20line%20atomics> for more discussion.
//!
//! Currently we only support LL/SC, because LSE requires `getauxval` from libc in order to do runtime detection.
//! Use the `compiler-rt` intrinsics if you want LSE support.
Expand Down
40 changes: 30 additions & 10 deletions compiler-builtins/src/arm_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ use core::{arch, mem};
// Kernel-provided user-mode helper functions:
// https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt
unsafe fn __kuser_cmpxchg(oldval: u32, newval: u32, ptr: *mut u32) -> bool {
let f: extern "C" fn(u32, u32, *mut u32) -> u32 = mem::transmute(0xffff0fc0usize as *const ());
// FIXME(volatile): the third parameter is a volatile pointer
// SAFETY: kernel docs specify a known address with the given signature
let f = unsafe {
mem::transmute::<_, extern "C" fn(u32, u32, *mut u32) -> u32>(0xffff0fc0usize as *const ())
};
f(oldval, newval, ptr) == 0
}

unsafe fn __kuser_memory_barrier() {
let f: extern "C" fn() = mem::transmute(0xffff0fa0usize as *const ());
// SAFETY: kernel docs specify a known address with the given signature
let f = unsafe { mem::transmute::<_, extern "C" fn()>(0xffff0fa0usize as *const ()) };
f();
}

Expand Down Expand Up @@ -67,8 +72,10 @@ fn insert_aligned(aligned: u32, val: u32, shift: u32, mask: u32) -> u32 {
/// - if `size_of::<T>() == 2`, `ptr` or `ptr` offset by 2 bytes must be valid for a relaxed atomic
/// read of 2 bytes.
/// - if `size_of::<T>() == 4`, `ptr` must be valid for a relaxed atomic read of 4 bytes.
// FIXME: assert some of the preconditions in debug mode
unsafe fn atomic_load_aligned<T>(ptr: *mut u32) -> u32 {
if mem::size_of::<T>() == 4 {
const { assert!(size_of::<T>() <= 4) };
if size_of::<T>() == 4 {
// SAFETY: As `T` has a size of 4, the caller garantees this is sound.
unsafe { AtomicU32::from_ptr(ptr).load(Ordering::Relaxed) }
} else {
Expand Down Expand Up @@ -100,11 +107,13 @@ unsafe fn atomic_rmw<T, F: Fn(u32) -> u32, G: Fn(u32, u32) -> u32>(ptr: *mut T,
let (shift, mask) = get_shift_mask(ptr);

loop {
let curval_aligned = atomic_load_aligned::<T>(aligned_ptr);
// FIXME(safety): preconditions review needed
let curval_aligned = unsafe { atomic_load_aligned::<T>(aligned_ptr) };
let curval = extract_aligned(curval_aligned, shift, mask);
let newval = f(curval);
let newval_aligned = insert_aligned(curval_aligned, newval, shift, mask);
if __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) {
// FIXME(safety): preconditions review needed
if unsafe { __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) } {
return g(curval, newval);
}
}
Expand All @@ -116,13 +125,15 @@ unsafe fn atomic_cmpxchg<T>(ptr: *mut T, oldval: u32, newval: u32) -> u32 {
let (shift, mask) = get_shift_mask(ptr);

loop {
let curval_aligned = atomic_load_aligned::<T>(aligned_ptr);
// FIXME(safety): preconditions review needed
let curval_aligned = unsafe { atomic_load_aligned::<T>(aligned_ptr) };
let curval = extract_aligned(curval_aligned, shift, mask);
if curval != oldval {
return curval;
}
let newval_aligned = insert_aligned(curval_aligned, newval, shift, mask);
if __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) {
// FIXME(safety): preconditions review needed
if unsafe { __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) } {
return oldval;
}
}
Expand All @@ -132,7 +143,14 @@ macro_rules! atomic_rmw {
($name:ident, $ty:ty, $op:expr, $fetch:expr) => {
intrinsics! {
pub unsafe extern "C" fn $name(ptr: *mut $ty, val: $ty) -> $ty {
atomic_rmw(ptr, |x| $op(x as $ty, val) as u32, |old, new| $fetch(old, new)) as $ty
// FIXME(safety): preconditions review needed
unsafe {
atomic_rmw(
ptr,
|x| $op(x as $ty, val) as u32,
|old, new| $fetch(old, new)
) as $ty
}
}
}
};
Expand All @@ -149,7 +167,8 @@ macro_rules! atomic_cmpxchg {
($name:ident, $ty:ty) => {
intrinsics! {
pub unsafe extern "C" fn $name(ptr: *mut $ty, oldval: $ty, newval: $ty) -> $ty {
atomic_cmpxchg(ptr, oldval as u32, newval as u32) as $ty
// FIXME(safety): preconditions review needed
unsafe { atomic_cmpxchg(ptr, oldval as u32, newval as u32) as $ty }
}
}
};
Expand Down Expand Up @@ -285,6 +304,7 @@ atomic_cmpxchg!(__sync_val_compare_and_swap_4, u32);

intrinsics! {
pub unsafe extern "C" fn __sync_synchronize() {
__kuser_memory_barrier();
// SAFETY: preconditions are the same as the calling function.
unsafe { __kuser_memory_barrier() };
}
}
1 change: 1 addition & 0 deletions compiler-builtins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#![feature(naked_functions)]
#![feature(repr_simd)]
#![feature(macro_metavar_expr_concat)]
#![feature(rustc_attrs)]
#![cfg_attr(f16_enabled, feature(f16))]
#![cfg_attr(f128_enabled, feature(f128))]
#![no_builtins]
Expand Down
6 changes: 3 additions & 3 deletions compiler-builtins/src/mem/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
"rep movsb",
"sub $7, %rsi",
"sub $7, %rdi",
"mov {qword_count}, %rcx",
"mov {qword_count:r}, %rcx",
"rep movsq",
"test {pre_byte_count:e}, {pre_byte_count:e}",
"add $7, %rsi",
Expand Down Expand Up @@ -212,7 +212,7 @@ pub unsafe fn c_string_length(mut s: *const core::ffi::c_char) -> usize {
let x = {
let r;
asm!(
"movdqa ({addr}), {dest}",
"movdqa ({addr:r}), {dest}",
addr = in(reg) s,
dest = out(xmm_reg) r,
options(att_syntax, nostack),
Expand All @@ -232,7 +232,7 @@ pub unsafe fn c_string_length(mut s: *const core::ffi::c_char) -> usize {
let x = {
let r;
asm!(
"movdqa ({addr}), {dest}",
"movdqa ({addr:r}), {dest}",
addr = in(reg) s,
dest = out(xmm_reg) r,
options(att_syntax, nostack),
Expand Down
Loading
Loading