Skip to content

Commit f63ba2a

Browse files
committed
Auto merge of #148851 - Zalathar:rollup-4y7ywyd, r=Zalathar
Rollup of 16 pull requests Successful merges: - rust-lang/rust#146627 (Simplify `jemalloc` setup) - rust-lang/rust#147753 (Suggest add bounding value for RangeTo) - rust-lang/rust#147832 (rustdoc: Don't pass `RenderOptions` to `DocContext`) - rust-lang/rust#147974 (Improve diagnostics for buffer reuse with borrowed references) - rust-lang/rust#148080 ([rustdoc] Fix invalid jump to def macro link generation) - rust-lang/rust#148465 (Adjust spans into the `for` loops context before creating the new desugaring spans.) - rust-lang/rust#148500 (Update git index before running diff-index) - rust-lang/rust#148531 (rustc_target: introduce Abi, Env, Os) - rust-lang/rust#148536 (cmse: add test for `async` and `const` functions) - rust-lang/rust#148770 (implement `feature(c_variadic_naked_functions)`) - rust-lang/rust#148780 (fix filecheck typos in tests) - rust-lang/rust#148819 (Remove specialized warning for removed target) - rust-lang/rust#148830 (miri subtree update) - rust-lang/rust#148833 (Update rustbook dependencies) - rust-lang/rust#148834 (fix(rustdoc): Color doctest errors) - rust-lang/rust#148841 (Remove more `#[must_use]` from portable-simd) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3264b55 + e823b03 commit f63ba2a

38 files changed

+1020
-472
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ serde_json = { version = "1.0", optional = true }
3333
# But only for some targets, it fails for others. Rustc configures this in its CI, but we can't
3434
# easily use that since we support of-tree builds.
3535
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies.tikv-jemalloc-sys]
36-
version = "0.6.0"
37-
features = ['unprefixed_malloc_on_supported_platforms']
36+
version = "0.6.1"
37+
features = ['override_allocator_on_supported_platforms']
3838

3939
[target.'cfg(unix)'.dependencies]
4040
libc = "0.2"

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ceb7df7e6f17c92c7d49f7e4f02df0e68bc9b38b
1+
8401398e1f14a24670ee1a3203713dc2f0f8b3a8

src/bin/miri.rs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ extern crate rustc_middle;
2020
extern crate rustc_session;
2121
extern crate rustc_span;
2222

23+
/// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs
24+
/// and https://github.com/rust-lang/rust/pull/146627 for why we need this `use` statement.
25+
#[cfg(any(target_os = "linux", target_os = "macos"))]
26+
use tikv_jemalloc_sys as _;
27+
2328
mod log;
2429

2530
use std::env;
@@ -392,48 +397,7 @@ fn parse_range(val: &str) -> Result<Range<u32>, &'static str> {
392397
Ok(from..to)
393398
}
394399

395-
#[cfg(any(target_os = "linux", target_os = "macos"))]
396-
fn jemalloc_magic() {
397-
// These magic runes are copied from
398-
// <https://github.com/rust-lang/rust/blob/e89bd9428f621545c979c0ec686addc6563a394e/compiler/rustc/src/main.rs#L39>.
399-
// See there for further comments.
400-
use std::os::raw::{c_int, c_void};
401-
402-
use tikv_jemalloc_sys as jemalloc_sys;
403-
404-
#[used]
405-
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
406-
#[used]
407-
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
408-
jemalloc_sys::posix_memalign;
409-
#[used]
410-
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
411-
#[used]
412-
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
413-
#[used]
414-
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
415-
#[used]
416-
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
417-
418-
// On OSX, jemalloc doesn't directly override malloc/free, but instead
419-
// registers itself with the allocator's zone APIs in a ctor. However,
420-
// the linker doesn't seem to consider ctors as "used" when statically
421-
// linking, so we need to explicitly depend on the function.
422-
#[cfg(target_os = "macos")]
423-
{
424-
unsafe extern "C" {
425-
fn _rjem_je_zone_register();
426-
}
427-
428-
#[used]
429-
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
430-
}
431-
}
432-
433400
fn main() {
434-
#[cfg(any(target_os = "linux", target_os = "macos"))]
435-
jemalloc_magic();
436-
437401
let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
438402

439403
// Snapshot a copy of the environment before `rustc` starts messing with it.

src/concurrency/thread.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_index::{Idx, IndexVec};
1515
use rustc_middle::mir::Mutability;
1616
use rustc_middle::ty::layout::TyAndLayout;
1717
use rustc_span::Span;
18+
use rustc_target::spec::Os;
1819

1920
use crate::concurrency::GlobalDataRaceHandler;
2021
use crate::shims::tls;
@@ -471,7 +472,7 @@ impl<'tcx> ThreadManager<'tcx> {
471472
) {
472473
ecx.machine.threads.threads[ThreadId::MAIN_THREAD].on_stack_empty =
473474
Some(on_main_stack_empty);
474-
if ecx.tcx.sess.target.os.as_ref() != "windows" {
475+
if ecx.tcx.sess.target.os != Os::Windows {
475476
// The main thread can *not* be joined on except on windows.
476477
ecx.machine.threads.threads[ThreadId::MAIN_THREAD].join_status =
477478
ThreadJoinStatus::Detached;

src/eval.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_hir::def_id::DefId;
1414
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutCx};
1515
use rustc_middle::ty::{self, Ty, TyCtxt};
1616
use rustc_session::config::EntryFnType;
17+
use rustc_target::spec::Os;
1718

1819
use crate::concurrency::GenmcCtx;
1920
use crate::concurrency::thread::TlsAllocAction;
@@ -341,7 +342,7 @@ pub fn create_ecx<'tcx>(
341342
ecx.machine.argv = Some(argv_place.ptr());
342343
}
343344
// Store command line as UTF-16 for Windows `GetCommandLineW`.
344-
if tcx.sess.target.os == "windows" {
345+
if tcx.sess.target.os == Os::Windows {
345346
// Construct a command string with all the arguments.
346347
let cmd_utf16: Vec<u16> = args_to_utf16_command_string(config.args.iter());
347348

src/helpers.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_middle::ty::{self, IntTy, Ty, TyCtxt, UintTy};
1919
use rustc_session::config::CrateType;
2020
use rustc_span::{Span, Symbol};
2121
use rustc_symbol_mangling::mangle_internal_symbol;
22+
use rustc_target::spec::Os;
2223

2324
use crate::*;
2425

@@ -234,7 +235,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
234235

235236
/// Helper function to get a `libc` constant as a `Scalar`.
236237
fn eval_libc(&self, name: &str) -> Scalar {
237-
if self.eval_context_ref().tcx.sess.target.os == "windows" {
238+
if self.eval_context_ref().tcx.sess.target.os == Os::Windows {
238239
panic!(
239240
"`libc` crate is not reliably available on Windows targets; Miri should not use it there"
240241
);
@@ -290,7 +291,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
290291
/// Helper function to get the `TyAndLayout` of a `libc` type
291292
fn libc_ty_layout(&self, name: &str) -> TyAndLayout<'tcx> {
292293
let this = self.eval_context_ref();
293-
if this.tcx.sess.target.os == "windows" {
294+
if this.tcx.sess.target.os == Os::Windows {
294295
panic!(
295296
"`libc` crate is not reliably available on Windows targets; Miri should not use it there"
296297
);
@@ -669,7 +670,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
669670
/// Helper function used inside the shims of foreign functions to assert that the target OS
670671
/// is `target_os`. It panics showing a message with the `name` of the foreign function
671672
/// if this is not the case.
672-
fn assert_target_os(&self, target_os: &str, name: &str) {
673+
fn assert_target_os(&self, target_os: Os, name: &str) {
673674
assert_eq!(
674675
self.eval_context_ref().tcx.sess.target.os,
675676
target_os,
@@ -680,9 +681,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
680681
/// Helper function used inside shims of foreign functions to check that the target OS
681682
/// is one of `target_oses`. It returns an error containing the `name` of the foreign function
682683
/// in a message if this is not the case.
683-
fn check_target_os(&self, target_oses: &[&str], name: Symbol) -> InterpResult<'tcx> {
684-
let target_os = self.eval_context_ref().tcx.sess.target.os.as_ref();
685-
if !target_oses.contains(&target_os) {
684+
fn check_target_os(&self, target_oses: &[Os], name: Symbol) -> InterpResult<'tcx> {
685+
let target_os = &self.eval_context_ref().tcx.sess.target.os;
686+
if !target_oses.contains(target_os) {
686687
throw_unsup_format!("`{name}` is not supported on {target_os}");
687688
}
688689
interp_ok(())
@@ -918,7 +919,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
918919
/// Always returns a `Vec<u32>` no matter the size of `wchar_t`.
919920
fn read_wchar_t_str(&self, ptr: Pointer) -> InterpResult<'tcx, Vec<u32>> {
920921
let this = self.eval_context_ref();
921-
let wchar_t = if this.tcx.sess.target.os == "windows" {
922+
let wchar_t = if this.tcx.sess.target.os == Os::Windows {
922923
// We don't have libc on Windows so we have to hard-code the type ourselves.
923924
this.machine.layouts.u16
924925
} else {

src/machine.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_span::def_id::{CrateNum, DefId};
3131
use rustc_span::{Span, SpanData, Symbol};
3232
use rustc_symbol_mangling::mangle_internal_symbol;
3333
use rustc_target::callconv::FnAbi;
34-
use rustc_target::spec::Arch;
34+
use rustc_target::spec::{Arch, Os};
3535

3636
use crate::alloc_addresses::EvalContextExt;
3737
use crate::concurrency::cpu_affinity::{self, CpuAffinityMask};
@@ -739,7 +739,7 @@ impl<'tcx> MiriMachine<'tcx> {
739739
);
740740
let threads = ThreadManager::new(config);
741741
let mut thread_cpu_affinity = FxHashMap::default();
742-
if matches!(&*tcx.sess.target.os, "linux" | "freebsd" | "android") {
742+
if matches!(&tcx.sess.target.os, Os::Linux | Os::FreeBsd | Os::Android) {
743743
thread_cpu_affinity
744744
.insert(threads.active_thread(), CpuAffinityMask::new(&layout_cx, config.num_cpus));
745745
}
@@ -1353,8 +1353,11 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
13531353
}
13541354

13551355
#[inline(always)]
1356-
fn runtime_checks(ecx: &InterpCx<'tcx, Self>, r: mir::RuntimeChecks) -> InterpResult<'tcx, bool> {
1357-
interp_ok(r.value(&ecx.tcx.sess))
1356+
fn runtime_checks(
1357+
ecx: &InterpCx<'tcx, Self>,
1358+
r: mir::RuntimeChecks,
1359+
) -> InterpResult<'tcx, bool> {
1360+
interp_ok(r.value(ecx.tcx.sess))
13581361
}
13591362

13601363
#[inline(always)]

src/shims/alloc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_ast::expand::allocator::SpecialAllocatorMethod;
33
use rustc_middle::ty::Ty;
44
use rustc_span::Symbol;
55
use rustc_target::callconv::FnAbi;
6-
use rustc_target::spec::Arch;
6+
use rustc_target::spec::{Arch, Os};
77

88
use crate::*;
99

@@ -19,10 +19,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1919
// This is given by `alignof(max_align_t)`. The following list is taken from
2020
// `library/std/src/sys/alloc/mod.rs` (where this is called `MIN_ALIGN`) and should
2121
// be kept in sync.
22-
let os = this.tcx.sess.target.os.as_ref();
22+
let os = &this.tcx.sess.target.os;
2323
let max_fundamental_align = match &this.tcx.sess.target.arch {
24-
Arch::RiscV32 if matches!(os, "espidf" | "zkvm") => 4,
25-
Arch::Xtensa if matches!(os, "espidf") => 4,
24+
Arch::RiscV32 if matches!(os, Os::EspIdf | Os::Zkvm) => 4,
25+
Arch::Xtensa if matches!(os, Os::EspIdf) => 4,
2626
Arch::X86
2727
| Arch::Arm
2828
| Arch::M68k
@@ -54,7 +54,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5454
| Arch::Nvptx64
5555
| Arch::PowerPC64LE
5656
| Arch::SpirV
57-
| Arch::Unknown(_)) => bug!("unsupported target architecture for malloc: `{arch}`"),
57+
| Arch::Other(_)) => bug!("unsupported target architecture for malloc: `{arch}`"),
5858
};
5959
// The C standard only requires sufficient alignment for any *type* with size less than or
6060
// equal to the size requested. Types one can define in standard C seem to never have an alignment

src/shims/env.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ffi::{OsStr, OsString};
22

33
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_target::spec::Os;
45

56
use self::shims::unix::UnixEnvVars;
67
use self::shims::windows::WindowsEnvVars;
@@ -48,7 +49,7 @@ impl<'tcx> EnvVars<'tcx> {
4849

4950
let env_vars = if ecx.target_os_is_unix() {
5051
EnvVars::Unix(UnixEnvVars::new(ecx, env_vars)?)
51-
} else if ecx.tcx.sess.target.os == "windows" {
52+
} else if ecx.tcx.sess.target.os == Os::Windows {
5253
EnvVars::Windows(WindowsEnvVars::new(ecx, env_vars)?)
5354
} else {
5455
// For "none" targets (i.e., without an OS).
@@ -118,7 +119,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
118119
let this = self.eval_context_ref();
119120
let index = thread.to_u32();
120121
let target_os = &this.tcx.sess.target.os;
121-
if target_os == "linux" || target_os == "netbsd" {
122+
if matches!(target_os, Os::Linux | Os::NetBsd) {
122123
// On Linux, the main thread has PID == TID so we uphold this. NetBSD also appears
123124
// to exhibit the same behavior, though I can't find a citation.
124125
this.get_pid().strict_add(index)

src/shims/extern_static.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Provides the `extern static` that this platform expects.
22
3+
use rustc_target::spec::Os;
4+
35
use crate::*;
46

57
impl<'tcx> MiriMachine<'tcx> {
@@ -49,28 +51,28 @@ impl<'tcx> MiriMachine<'tcx> {
4951
Self::add_extern_static(ecx, "environ", environ);
5052
}
5153

52-
match ecx.tcx.sess.target.os.as_ref() {
53-
"linux" => {
54+
match &ecx.tcx.sess.target.os {
55+
Os::Linux => {
5456
Self::null_ptr_extern_statics(
5557
ecx,
5658
&["__cxa_thread_atexit_impl", "__clock_gettime64"],
5759
)?;
5860
Self::weak_symbol_extern_statics(ecx, &["getrandom", "gettid", "statx"])?;
5961
}
60-
"freebsd" => {
62+
Os::FreeBsd => {
6163
Self::null_ptr_extern_statics(ecx, &["__cxa_thread_atexit_impl"])?;
6264
}
63-
"android" => {
65+
Os::Android => {
6466
Self::null_ptr_extern_statics(ecx, &["bsd_signal"])?;
6567
Self::weak_symbol_extern_statics(ecx, &["signal", "getrandom", "gettid"])?;
6668
}
67-
"windows" => {
69+
Os::Windows => {
6870
// "_tls_used"
6971
// This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
7072
let val = ImmTy::from_int(0, ecx.machine.layouts.u8);
7173
Self::alloc_extern_static(ecx, "_tls_used", val)?;
7274
}
73-
"illumos" | "solaris" => {
75+
Os::Illumos | Os::Solaris => {
7476
Self::weak_symbol_extern_statics(ecx, &["pthread_setname_np"])?;
7577
}
7678
_ => {} // No "extern statics" supported on this target

0 commit comments

Comments
 (0)