Skip to content

Commit e67dcc6

Browse files
Auto merge of #141993 - tgross35:use-in-tree-builtins, r=<try>
Use the in-tree `compiler-builtins` for the sysroot Many of `std`'s dependency have a dependency on the crates.io `compiler-builtins` when used with the feature `rustc-std-workspace-core`. Use a Cargo patch to select the in-tree version instead. `compiler-builtins` is also added as a dependency of `rustc-std-workspace-core` so these crates can remove their crates.io dependency in the future. Zulip discussion: [#t-compiler > Using in-tree compiler-builtins](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Using.20in-tree.20compiler-builtins/with/522445336) Once this merges, the following PRs will need to make it to a release for the relevant crates: - rust-lang/getopts#119 (can merge at any time) - rust-lang/hashbrown#625 (can merge at any time) - rust-lang/stdarch#1825 - rust-lang/rustc-demangle#80 - rust-lang/cfg-if#84 - unicode-rs/unicode-width#77 The above should cover all tier 1 targets with no `std` features enabled. The remaining cover the rest: - alexcrichton/dlmalloc-rs#50 (wasm, xous, sgx) - gimli-rs/gimli#769 - r-efi/r-efi#89 (efi) - r-efi/r-efi-alloc#9 (efi) - fortanix/rust-sgx#770 (sgx) - hermit-os/hermit-rs#718 (hermit) - bytecodealliance/wasi-rs#108 (wasi) - gimli-rs/addr2line#345 - oyvindln/adler2#2 - BurntSushi/memchr#180 - Frommi/miniz_oxide#173 - gimli-rs/object#777 try-job: dist-x86_64-linux try-job: x86_64-gnu try-job: x86_64-gnu-aux try-job: test-various try-job: `*android*`
2 parents 8072811 + 974d437 commit e67dcc6

File tree

17 files changed

+92
-29
lines changed

17 files changed

+92
-29
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,11 +3118,12 @@ dependencies = [
31183118

31193119
[[package]]
31203120
name = "rustc-build-sysroot"
3121-
version = "0.5.7"
3121+
version = "0.5.8"
31223122
source = "registry+https://github.com/rust-lang/crates.io-index"
3123-
checksum = "10edc2e4393515193bd766e2f6c050b0536a68e56f2b6d56c07ababfdc114ff0"
3123+
checksum = "16d115ad7e26e0d1337f64ae6598f758194696afc2e9f34c8a6f24582529c3dc"
31243124
dependencies = [
31253125
"anyhow",
3126+
"regex",
31263127
"rustc_version",
31273128
"tempfile",
31283129
"walkdir",

compiler/rustc_codegen_gcc/build_system/build_sysroot/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ resolver = "2"
66

77
[dependencies]
88
core = { path = "./sysroot_src/library/core" }
9-
compiler_builtins = "0.1"
109
alloc = { path = "./sysroot_src/library/alloc" }
1110
std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] }
1211
test = { path = "./sysroot_src/library/test" }
@@ -16,6 +15,7 @@ proc_macro = { path = "./sysroot_src/library/proc_macro" }
1615
rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" }
1716
rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" }
1817
rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-std" }
18+
compiler_builtins = { path = "./sysroot_src/library/compiler-builtins/compiler-builtins" }
1919

2020
# For compiler-builtins we always use a high number of codegen units.
2121
# The goal here is to place every single intrinsic into its own object

library/Cargo.lock

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ dependencies = [
6262
[[package]]
6363
name = "compiler_builtins"
6464
version = "0.1.160"
65-
source = "registry+https://github.com/rust-lang/crates.io-index"
66-
checksum = "6376049cfa92c0aa8b9ac95fae22184b981c658208d4ed8a1dc553cd83612895"
6765
dependencies = [
6866
"cc",
69-
"rustc-std-workspace-core",
67+
"core",
7068
]
7169

7270
[[package]]
@@ -304,6 +302,7 @@ dependencies = [
304302
name = "rustc-std-workspace-core"
305303
version = "1.99.0"
306304
dependencies = [
305+
"compiler_builtins",
307306
"core",
308307
]
309308

library/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ rustc-demangle.opt-level = "s"
5050
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
5151
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
5252
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }
53+
compiler_builtins = { path = "compiler-builtins/compiler-builtins" }

library/alloc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bench = false
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
19-
compiler_builtins = { version = "=0.1.160", features = ['rustc-dep-of-std'] }
19+
compiler_builtins = { path = "../compiler-builtins/compiler-builtins", features = ["rustc-dep-of-std"] }
2020

2121
[features]
2222
compiler-builtins-mem = ['compiler_builtins/mem']

library/compiler-builtins/compiler-builtins/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ doctest = false
1717
test = false
1818

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

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

library/compiler-builtins/compiler-builtins/src/aarch64_linux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! To avoid breaking backwards compat, C toolchains introduced a concept of "outlined atomics",
55
//! where atomic operations call into the compiler runtime to dispatch between two depending on
66
//! which is supported on the current CPU.
7-
//! 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.
7+
//! 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.
88
//!
99
//! Currently we only support LL/SC, because LSE requires `getauxval` from libc in order to do runtime detection.
1010
//! Use the `compiler-rt` intrinsics if you want LSE support.

library/compiler-builtins/compiler-builtins/src/arm_linux.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ use core::{arch, mem};
44
// Kernel-provided user-mode helper functions:
55
// https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt
66
unsafe fn __kuser_cmpxchg(oldval: u32, newval: u32, ptr: *mut u32) -> bool {
7-
let f: extern "C" fn(u32, u32, *mut u32) -> u32 = mem::transmute(0xffff0fc0usize as *const ());
7+
// FIXME(volatile): the third parameter is a volatile pointer
8+
// SAFETY: kernel docs specify a known address with the given signature
9+
let f = unsafe {
10+
mem::transmute::<_, extern "C" fn(u32, u32, *mut u32) -> u32>(0xffff0fc0usize as *const ())
11+
};
812
f(oldval, newval, ptr) == 0
913
}
1014

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

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

102109
loop {
103-
let curval_aligned = atomic_load_aligned::<T>(aligned_ptr);
110+
// FIXME(safety): preconditions review needed
111+
let curval_aligned = unsafe { atomic_load_aligned::<T>(aligned_ptr) };
104112
let curval = extract_aligned(curval_aligned, shift, mask);
105113
let newval = f(curval);
106114
let newval_aligned = insert_aligned(curval_aligned, newval, shift, mask);
107-
if __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) {
115+
// FIXME(safety): preconditions review needed
116+
if unsafe { __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) } {
108117
return g(curval, newval);
109118
}
110119
}
@@ -116,13 +125,15 @@ unsafe fn atomic_cmpxchg<T>(ptr: *mut T, oldval: u32, newval: u32) -> u32 {
116125
let (shift, mask) = get_shift_mask(ptr);
117126

118127
loop {
119-
let curval_aligned = atomic_load_aligned::<T>(aligned_ptr);
128+
// FIXME(safety): preconditions review needed
129+
let curval_aligned = unsafe { atomic_load_aligned::<T>(aligned_ptr) };
120130
let curval = extract_aligned(curval_aligned, shift, mask);
121131
if curval != oldval {
122132
return curval;
123133
}
124134
let newval_aligned = insert_aligned(curval_aligned, newval, shift, mask);
125-
if __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) {
135+
// FIXME(safety): preconditions review needed
136+
if unsafe { __kuser_cmpxchg(curval_aligned, newval_aligned, aligned_ptr) } {
126137
return oldval;
127138
}
128139
}
@@ -132,7 +143,14 @@ macro_rules! atomic_rmw {
132143
($name:ident, $ty:ty, $op:expr, $fetch:expr) => {
133144
intrinsics! {
134145
pub unsafe extern "C" fn $name(ptr: *mut $ty, val: $ty) -> $ty {
135-
atomic_rmw(ptr, |x| $op(x as $ty, val) as u32, |old, new| $fetch(old, new)) as $ty
146+
// FIXME(safety): preconditions review needed
147+
unsafe {
148+
atomic_rmw(
149+
ptr,
150+
|x| $op(x as $ty, val) as u32,
151+
|old, new| $fetch(old, new)
152+
) as $ty
153+
}
136154
}
137155
}
138156
};
@@ -149,7 +167,8 @@ macro_rules! atomic_cmpxchg {
149167
($name:ident, $ty:ty) => {
150168
intrinsics! {
151169
pub unsafe extern "C" fn $name(ptr: *mut $ty, oldval: $ty, newval: $ty) -> $ty {
152-
atomic_cmpxchg(ptr, oldval as u32, newval as u32) as $ty
170+
// FIXME(safety): preconditions review needed
171+
unsafe { atomic_cmpxchg(ptr, oldval as u32, newval as u32) as $ty }
153172
}
154173
}
155174
};
@@ -285,6 +304,7 @@ atomic_cmpxchg!(__sync_val_compare_and_swap_4, u32);
285304

286305
intrinsics! {
287306
pub unsafe extern "C" fn __sync_synchronize() {
288-
__kuser_memory_barrier();
307+
// SAFETY: preconditions are the same as the calling function.
308+
unsafe { __kuser_memory_barrier() };
289309
}
290310
}

library/panic_abort/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ doc = false
1313

1414
[dependencies]
1515
core = { path = "../core" }
16-
compiler_builtins = "0.1.0"
16+
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
1717

1818
[target.'cfg(target_os = "android")'.dependencies]
1919
libc = { version = "0.2", default-features = false }

library/panic_unwind/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ doc = false
1515
alloc = { path = "../alloc" }
1616
core = { path = "../core" }
1717
unwind = { path = "../unwind" }
18-
compiler_builtins = "0.1.0"
18+
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
1919
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
2020

2121
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]

library/rustc-std-workspace-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ path = "lib.rs"
1212

1313
[dependencies]
1414
core = { path = "../core" }
15+
compiler_builtins = { path = "../compiler-builtins/compiler-builtins", features = ["compiler-builtins"] }

library/rustc-std-workspace-core/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
#![no_core]
33

44
pub use core::*;
5+
6+
// Crate must be brought into scope so it appears in the crate graph for anything that
7+
// depends on `rustc-std-workspace-core`.
8+
use compiler_builtins as _;

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1818
panic_unwind = { path = "../panic_unwind", optional = true }
1919
panic_abort = { path = "../panic_abort" }
2020
core = { path = "../core", public = true }
21-
compiler_builtins = { version = "=0.1.160" }
21+
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
2222
unwind = { path = "../unwind" }
2323
hashbrown = { version = "0.15", default-features = false, features = [
2424
'rustc-dep-of-std',

library/unwind/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ doc = false
1515

1616
[dependencies]
1717
core = { path = "../core" }
18-
compiler_builtins = "0.1.0"
18+
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
1919
cfg-if = "1.0"
2020

2121
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]

src/tools/miri/cargo-miri/Cargo.lock

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
# It is not intended for manual editing.
33
version = 4
44

5+
[[package]]
6+
name = "aho-corasick"
7+
version = "1.1.3"
8+
source = "registry+https://github.com/rust-lang/crates.io-index"
9+
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
10+
dependencies = [
11+
"memchr",
12+
]
13+
514
[[package]]
615
name = "anyhow"
716
version = "1.0.97"
@@ -206,13 +215,43 @@ dependencies = [
206215
"thiserror",
207216
]
208217

218+
[[package]]
219+
name = "regex"
220+
version = "1.11.1"
221+
source = "registry+https://github.com/rust-lang/crates.io-index"
222+
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
223+
dependencies = [
224+
"aho-corasick",
225+
"memchr",
226+
"regex-automata",
227+
"regex-syntax",
228+
]
229+
230+
[[package]]
231+
name = "regex-automata"
232+
version = "0.4.9"
233+
source = "registry+https://github.com/rust-lang/crates.io-index"
234+
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
235+
dependencies = [
236+
"aho-corasick",
237+
"memchr",
238+
"regex-syntax",
239+
]
240+
241+
[[package]]
242+
name = "regex-syntax"
243+
version = "0.8.5"
244+
source = "registry+https://github.com/rust-lang/crates.io-index"
245+
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
246+
209247
[[package]]
210248
name = "rustc-build-sysroot"
211-
version = "0.5.7"
249+
version = "0.5.8"
212250
source = "registry+https://github.com/rust-lang/crates.io-index"
213-
checksum = "10edc2e4393515193bd766e2f6c050b0536a68e56f2b6d56c07ababfdc114ff0"
251+
checksum = "16d115ad7e26e0d1337f64ae6598f758194696afc2e9f34c8a6f24582529c3dc"
214252
dependencies = [
215253
"anyhow",
254+
"regex",
216255
"rustc_version",
217256
"tempfile",
218257
"walkdir",

src/tools/miri/cargo-miri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ directories = "6"
1818
rustc_version = "0.4"
1919
serde_json = "1.0.40"
2020
cargo_metadata = "0.19"
21-
rustc-build-sysroot = "0.5.7"
21+
rustc-build-sysroot = "0.5.8"
2222

2323
# Enable some feature flags that dev-dependencies need but dependencies
2424
# do not. This makes `./miri install` after `./miri build` faster.

tests/run-make/linker-warning/short-error.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
error: linking with `./fake-linker` failed: exit status: 1
22
|
3-
= note: "./fake-linker" "-m64" "/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/build-root/test/run-make/linker-warning/rmake_out" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "main" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "run_make_error"
3+
= note: "./fake-linker" "-m64" "/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/build-root/test/run-make/linker-warning/rmake_out" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "main" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "run_make_error"
44
= note: some arguments are omitted. use `--verbose` to show all linker arguments
55
= note: error: baz
66

0 commit comments

Comments
 (0)