diff options
| author | Boxy <rust@boxyuwu.dev> | 2025-02-25 21:27:44 +0000 | 
|---|---|---|
| committer | Boxy <rust@boxyuwu.dev> | 2025-02-25 21:27:44 +0000 | 
| commit | d9683df7c2f6d4141b1321e27635d2ce3167eaa4 (patch) | |
| tree | dce0d46d1b7d624ec9b9b09b2c1854f6245a5ff4 /compiler/rustc_driver_impl | |
| parent | 46392d1661540e256fd9573d8f06c2784a58c983 (diff) | |
| parent | 4ecd70ddd1039a3954056c1071e40278048476fa (diff) | |
| download | rust-d9683df7c2f6d4141b1321e27635d2ce3167eaa4.tar.gz rust-d9683df7c2f6d4141b1321e27635d2ce3167eaa4.zip | |
Merge from rustc
Diffstat (limited to 'compiler/rustc_driver_impl')
| -rw-r--r-- | compiler/rustc_driver_impl/Cargo.toml | 3 | ||||
| -rw-r--r-- | compiler/rustc_driver_impl/src/lib.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_driver_impl/src/pretty.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_driver_impl/src/signal_handler.rs | 50 | 
4 files changed, 52 insertions, 25 deletions
| diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index 07b88e59723..8593d1faba2 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -1,10 +1,11 @@ [package] name = "rustc_driver_impl" version = "0.0.0" -edition = "2021" +edition = "2024" [dependencies] # tidy-alphabetical-start +rustc_abi = { path = "../rustc_abi" } rustc_ast = { path = "../rustc_ast" } rustc_ast_lowering = { path = "../rustc_ast_lowering" } rustc_ast_passes = { path = "../rustc_ast_passes" } diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 4c47ce93dd5..a2ddff7183e 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -667,11 +667,12 @@ fn print_crate_info( return Compilation::Continue; }; let t_outputs = rustc_interface::util::build_output_filenames(attrs, sess); - let id = rustc_session::output::find_crate_name(sess, attrs); + let crate_name = passes::get_crate_name(sess, attrs); let crate_types = collect_crate_types(sess, attrs); for &style in &crate_types { - let fname = - rustc_session::output::filename_for_input(sess, style, id, &t_outputs); + let fname = rustc_session::output::filename_for_input( + sess, style, crate_name, &t_outputs, + ); println_info!("{}", fname.as_path().file_name().unwrap().to_string_lossy()); } } @@ -680,8 +681,7 @@ fn print_crate_info( // no crate attributes, print out an error and exit return Compilation::Continue; }; - let id = rustc_session::output::find_crate_name(sess, attrs); - println_info!("{id}"); + println_info!("{}", passes::get_crate_name(sess, attrs)); } Cfg => { let mut cfgs = sess @@ -747,8 +747,7 @@ fn print_crate_info( } } CallingConventions => { - let mut calling_conventions = rustc_target::spec::abi::all_names(); - calling_conventions.sort_unstable(); + let calling_conventions = rustc_abi::all_names(); println_info!("{}", calling_conventions.join("\n")); } RelocationModels diff --git a/compiler/rustc_driver_impl/src/pretty.rs b/compiler/rustc_driver_impl/src/pretty.rs index 576b1c76823..828a14e707c 100644 --- a/compiler/rustc_driver_impl/src/pretty.rs +++ b/compiler/rustc_driver_impl/src/pretty.rs @@ -164,8 +164,7 @@ impl<'tcx> pprust_hir::PpAnn for HirTypedAnn<'tcx> { if let pprust_hir::AnnNode::Expr(expr) = node { let typeck_results = self.maybe_typeck_results.get().or_else(|| { self.tcx - .hir() - .maybe_body_owned_by(expr.hir_id.owner.def_id) + .hir_maybe_body_owned_by(expr.hir_id.owner.def_id) .map(|body_id| self.tcx.typeck_body(body_id.id())) }); @@ -273,7 +272,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { let attrs = |id| hir_map.attrs(id); pprust_hir::print_crate( sm, - hir_map.root_module(), + tcx.hir_root_module(), src_name, src, &attrs, @@ -294,7 +293,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { } HirTree => { debug!("pretty printing HIR tree"); - format!("{:#?}", ex.tcx().hir().krate()) + format!("{:#?}", ex.tcx().hir_crate(())) } Mir => { let mut out = Vec::new(); @@ -317,7 +316,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { rustc_hir_analysis::check_crate(tcx); tcx.dcx().abort_if_errors(); debug!("pretty printing THIR tree"); - for did in tcx.hir().body_owners() { + for did in tcx.hir_body_owners() { let _ = writeln!(out, "{:?}:\n{}\n", did, thir_tree(tcx, did)); } out @@ -328,7 +327,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { rustc_hir_analysis::check_crate(tcx); tcx.dcx().abort_if_errors(); debug!("pretty printing THIR flat"); - for did in tcx.hir().body_owners() { + for did in tcx.hir_body_owners() { let _ = writeln!(out, "{:?}:\n{}\n", did, thir_flat(tcx, did)); } out diff --git a/compiler/rustc_driver_impl/src/signal_handler.rs b/compiler/rustc_driver_impl/src/signal_handler.rs index 08b7d937661..e7bc57c9749 100644 --- a/compiler/rustc_driver_impl/src/signal_handler.rs +++ b/compiler/rustc_driver_impl/src/signal_handler.rs @@ -6,6 +6,15 @@ use std::{fmt, mem, ptr, slice}; use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE}; +/// Signals that represent that we have a bug, and our prompt termination has +/// been ordered. +#[rustfmt::skip] +const KILL_SIGNALS: [(libc::c_int, &str); 3] = [ + (libc::SIGILL, "SIGILL"), + (libc::SIGBUS, "SIGBUS"), + (libc::SIGSEGV, "SIGSEGV") +]; + unsafe extern "C" { fn backtrace_symbols_fd(buffer: *const *mut libc::c_void, size: libc::c_int, fd: libc::c_int); } @@ -39,8 +48,19 @@ macro raw_errln($tokens:tt) { /// # Safety /// /// Caller must ensure that this function is not re-entered. -unsafe extern "C" fn print_stack_trace(_: libc::c_int) { +unsafe extern "C" fn print_stack_trace(signum: libc::c_int) { const MAX_FRAMES: usize = 256; + + let signame = { + let mut signame = "<unknown>"; + for sig in KILL_SIGNALS { + if sig.0 == signum { + signame = sig.1; + } + } + signame + }; + let stack = unsafe { // Reserve data segment so we don't have to malloc in a signal handler, which might fail // in incredibly undesirable and unexpected ways due to e.g. the allocator deadlocking @@ -54,7 +74,8 @@ unsafe extern "C" fn print_stack_trace(_: libc::c_int) { }; // Just a stack trace is cryptic. Explain what we're doing. - raw_errln!("error: rustc interrupted by SIGSEGV, printing backtrace\n"); + raw_errln!("error: rustc interrupted by {signame}, printing backtrace\n"); + let mut written = 1; let mut consumed = 0; // Begin elaborating return addrs into symbols and writing them directly to stderr @@ -94,7 +115,7 @@ unsafe extern "C" fn print_stack_trace(_: libc::c_int) { written += rem.len() + 1; let random_depth = || 8 * 16; // chosen by random diceroll (2d20) - if cyclic || stack.len() > random_depth() { + if (cyclic || stack.len() > random_depth()) && signum == libc::SIGSEGV { // technically speculation, but assert it with confidence anyway. // rustc only arrived in this signal handler because bad things happened // and this message is for explaining it's not the programmer's fault @@ -106,17 +127,22 @@ unsafe extern "C" fn print_stack_trace(_: libc::c_int) { written += 1; } raw_errln!("note: we would appreciate a report at https://github.com/rust-lang/rust"); - // get the current stack size WITHOUT blocking and double it - let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2; - raw_errln!("help: you can increase rustc's stack size by setting RUST_MIN_STACK={new_size}"); - written += 2; + written += 1; + if signum == libc::SIGSEGV { + // get the current stack size WITHOUT blocking and double it + let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2; + raw_errln!( + "help: you can increase rustc's stack size by setting RUST_MIN_STACK={new_size}" + ); + written += 1; + } if written > 24 { - // We probably just scrolled the earlier "we got SIGSEGV" message off the terminal - raw_errln!("note: backtrace dumped due to SIGSEGV! resuming signal"); + // We probably just scrolled the earlier "interrupted by {signame}" message off the terminal + raw_errln!("note: backtrace dumped due to {signame}! resuming signal"); }; } -/// When SIGSEGV is delivered to the process, print a stack trace and then exit. +/// When one of the KILL signals is delivered to the process, print a stack trace and then exit. pub(super) fn install() { unsafe { let alt_stack_size: usize = min_sigstack_size() + 64 * 1024; @@ -129,7 +155,9 @@ pub(super) fn install() { sa.sa_sigaction = print_stack_trace as libc::sighandler_t; sa.sa_flags = libc::SA_NODEFER | libc::SA_RESETHAND | libc::SA_ONSTACK; libc::sigemptyset(&mut sa.sa_mask); - libc::sigaction(libc::SIGSEGV, &sa, ptr::null_mut()); + for (signum, _signame) in KILL_SIGNALS { + libc::sigaction(signum, &sa, ptr::null_mut()); + } } } | 
