Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 8 additions & 0 deletions compiler/rustc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
#![feature(rustc_private)]
// Several crates are depended upon but unused so that they are present in the sysroot
#![expect(unused_crate_dependencies)]
#![cfg_attr(not(bootstrap), feature(on_broken_pipe))]

#[cfg_attr(not(bootstrap), std::io::on_broken_pipe)]
#[cfg(not(bootstrap))]
fn on_broken_pipe() -> std::io::OnBrokenPipe {
// FIXME(#131436): Ideally there would be no use of e.g. `println!()` in the compiler.
std::io::OnBrokenPipe::Kill
}

// A note about jemalloc: rustc uses jemalloc when built for CI and
// distribution. The obvious way to do this is with the `#[global_allocator]`
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_builtin_macros/src/eii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ fn eii_(
foreign_item_name,
impl_unsafe,
decl_span,
&attrs_from_decl,
)));

return_items.into_iter().map(wrap_item).collect()
Expand Down Expand Up @@ -353,9 +354,22 @@ fn generate_attribute_macro_to_implement(
foreign_item_name: Ident,
impl_unsafe: bool,
decl_span: Span,
attrs_from_decl: &[Attribute],
) -> ast::Item {
let mut macro_attrs = ThinVec::new();

// To avoid e.g. `error: attribute macro has missing stability attribute`
// errors for eii's in std.
macro_attrs.extend_from_slice(attrs_from_decl);

// Needed to avoid lots of unrelated "missing stability attribute" errors on
// unrelated items.
macro_attrs.push(ecx.attr_name_value_str(
sym::rustc_macro_transparency,
sym::transparent,
span,
));

// #[builtin_macro(eii_shared_macro)]
macro_attrs.push(ecx.attr_nested_word(sym::rustc_builtin_macro, sym::eii_shared_macro, span));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ enum Ordering {
}

#[lang = "start"]
fn start<T: Termination + 'static>(
main: fn() -> T,
argc: isize,
argv: *const *const u8,
_sigpipe: u8,
) -> isize {
fn start<T: Termination + 'static>(main: fn() -> T, argc: isize, argv: *const *const u8) -> isize {
if argc == 3 {
unsafe {
puts(*argv as *const i8);
Expand Down
16 changes: 4 additions & 12 deletions compiler/rustc_codegen_cranelift/src/main_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ pub(crate) fn maybe_create_entry_wrapper(
is_jit: bool,
is_primary_cgu: bool,
) {
let (main_def_id, sigpipe) = match tcx.entry_fn(()) {
Some((def_id, entry_ty)) => (
def_id,
match entry_ty {
EntryFnType::Main { sigpipe } => sigpipe,
},
),
let main_def_id = match tcx.entry_fn(()) {
Some((def_id, EntryFnType::Main)) => def_id,
None => return,
};

Expand All @@ -33,14 +28,13 @@ pub(crate) fn maybe_create_entry_wrapper(
return;
}

create_entry_fn(tcx, module, main_def_id, is_jit, sigpipe);
create_entry_fn(tcx, module, main_def_id, is_jit);

fn create_entry_fn(
tcx: TyCtxt<'_>,
m: &mut dyn Module,
rust_main_def_id: DefId,
ignore_lang_start_wrapper: bool,
sigpipe: u8,
) {
let main_ret_ty = tcx.fn_sig(rust_main_def_id).no_bound_vars().unwrap().output();
// Given that `main()` has no arguments,
Expand Down Expand Up @@ -91,7 +85,6 @@ pub(crate) fn maybe_create_entry_wrapper(
bcx.switch_to_block(block);
let arg_argc = bcx.append_block_param(block, m.target_config().pointer_type());
let arg_argv = bcx.append_block_param(block, m.target_config().pointer_type());
let arg_sigpipe = bcx.ins().iconst(types::I8, sigpipe as i64);

let main_func_ref = m.declare_func_in_func(main_func_id, bcx.func);

Expand Down Expand Up @@ -149,8 +142,7 @@ pub(crate) fn maybe_create_entry_wrapper(
let main_val = bcx.ins().func_addr(m.target_config().pointer_type(), main_func_ref);

let func_ref = m.declare_func_in_func(start_func_id, bcx.func);
let call_inst =
bcx.ins().call(func_ref, &[main_val, arg_argc, arg_argv, arg_sigpipe]);
let call_inst = bcx.ins().call(func_ref, &[main_val, arg_argc, arg_argv]);
bcx.inst_results(call_inst)[0]
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ fn start<T: Termination + 'static>(
main: fn() -> T,
argc: isize,
argv: *const *const u8,
_sigpipe: u8,
) -> isize {
if argc == 3 {
unsafe { puts(*argv); }
Expand Down
14 changes: 3 additions & 11 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let ptr_ty = cx.type_ptr();
let (arg_argc, arg_argv) = get_argc_argv(&mut bx);

let EntryFnType::Main { sigpipe } = entry_type;
let EntryFnType::Main = entry_type;
let (start_fn, start_ty, args, instance) = {
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, DUMMY_SP);
let start_instance = ty::Instance::expect_resolve(
Expand All @@ -548,16 +548,8 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
);
let start_fn = cx.get_fn_addr(start_instance);

let i8_ty = cx.type_i8();
let arg_sigpipe = bx.const_u8(sigpipe);

let start_ty = cx.type_func(&[cx.val_ty(rust_main), isize_ty, ptr_ty, i8_ty], isize_ty);
(
start_fn,
start_ty,
vec![rust_main, arg_argc, arg_argv, arg_sigpipe],
Some(start_instance),
)
let start_ty = cx.type_func(&[cx.val_ty(rust_main), isize_ty, ptr_ty], isize_ty);
(start_fn, start_ty, vec![rust_main, arg_argc, arg_argv], Some(start_instance))
};

let result = bx.call(start_ty, None, None, start_fn, &args, None, instance);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ declare_features! (
(unstable, offset_of_enum, "1.75.0", Some(120141)),
/// Allows using fields with slice type in offset_of!
(unstable, offset_of_slice, "1.81.0", Some(126151)),
/// Allows changing pre-main() `SIGPIPE` behavior
(unstable, on_broken_pipe, "CURRENT_RUSTC_VERSION", Some(150588)),
/// Allows using `#[optimize(X)]`.
(unstable, optimize_attribute, "1.34.0", Some(54882)),
/// Allows specifying nop padding on functions for dynamic patching.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::errors;

pub(crate) fn check_for_entry_fn(tcx: TyCtxt<'_>) {
match tcx.entry_fn(()) {
Some((def_id, EntryFnType::Main { .. })) => check_main_fn_ty(tcx, def_id),
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
_ => {}
}
}
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_hir_typeck/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>
}

fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id: LocalDefId) {
// build type `fn(main: fn() -> T, argc: isize, argv: *const *const u8, sigpipe: u8)`
// build type `fn(main: fn() -> T, argc: isize, argv: *const *const u8)`

// make a Ty for the generic on the fn for diagnostics
// FIXME: make the lang item generic checks check for the right generic *kind*
Expand All @@ -231,12 +231,7 @@ fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id:
);

let expected_sig = ty::Binder::dummy(tcx.mk_fn_sig(
[
main_fn_ty,
tcx.types.isize,
Ty::new_imm_ptr(tcx, Ty::new_imm_ptr(tcx, tcx.types.u8)),
tcx.types.u8,
],
[main_fn_ty, tcx.types.isize, Ty::new_imm_ptr(tcx, Ty::new_imm_ptr(tcx, tcx.types.u8))],
tcx.types.isize,
false,
fn_sig.safety,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use rustc_span::edition::{DEFAULT_EDITION, Edition};
use rustc_span::source_map::{RealFileLoader, SourceMapInputs};
use rustc_span::{FileName, SourceFileHashAlgorithm, sym};
use rustc_target::spec::{
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel,
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
};

use crate::interface::{initialize_checked_jobserver, parse_cfg};
Expand Down Expand Up @@ -838,7 +838,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(no_trait_vptr, true);
tracked!(no_unique_section_names, true);
tracked!(offload, vec![Offload::Device]);
tracked!(on_broken_pipe, OnBrokenPipe::Kill);
tracked!(osx_rpath_install_name, true);
tracked!(packed_bundled_libs, true);
tracked!(panic_abort_tests, true);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ impl<'v> RootCollector<'_, 'v> {
/// the return type of `main`. This is not needed when
/// the user writes their own `start` manually.
fn push_extra_entry_roots(&mut self) {
let Some((main_def_id, EntryFnType::Main { .. })) = self.entry_fn else {
let Some((main_def_id, EntryFnType::Main)) = self.entry_fn else {
return;
};

Expand Down
15 changes: 3 additions & 12 deletions compiler/rustc_passes/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId};
use rustc_hir::{CRATE_HIR_ID, ItemId, Node, find_attr};
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{CrateType, EntryFnType, sigpipe};
use rustc_session::config::{CrateType, EntryFnType};
use rustc_span::{RemapPathScopeComponents, Span, sym};

use crate::errors::{ExternMain, MultipleRustcMain, NoMainErr};
Expand Down Expand Up @@ -76,7 +76,7 @@ fn check_and_search_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId, EntryFnType)> {
if let Some((local_def_id, _)) = visitor.rustc_main_fn {
let def_id = local_def_id.to_def_id();
Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx) }))
Some((def_id, EntryFnType::Main))
} else {
// The actual resolution of main happens in the resolver, this here
if let Some(main_def) = tcx.resolutions(()).main_def
Expand All @@ -90,22 +90,13 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
return None;
}

return Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx) }));
return Some((def_id, EntryFnType::Main));
}
no_main_err(tcx, visitor);
None
}
}

fn sigpipe(tcx: TyCtxt<'_>) -> u8 {
match tcx.sess.opts.unstable_opts.on_broken_pipe {
rustc_target::spec::OnBrokenPipe::Default => sigpipe::DEFAULT,
rustc_target::spec::OnBrokenPipe::Kill => sigpipe::SIG_DFL,
rustc_target::spec::OnBrokenPipe::Error => sigpipe::SIG_IGN,
rustc_target::spec::OnBrokenPipe::Inherit => sigpipe::INHERIT,
}
}

fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {
let sp = tcx.def_span(CRATE_DEF_ID);

Expand Down
17 changes: 3 additions & 14 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ mod cfg;
mod externs;
mod native_libs;
mod print_request;
pub mod sigpipe;

/// The different settings that the `-C strip` flag can have.
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
Expand Down Expand Up @@ -1493,15 +1492,7 @@ impl UnstableOptions {
// The type of entry function, so users can have their own entry functions
#[derive(Copy, Clone, PartialEq, Hash, Debug, HashStable_Generic)]
pub enum EntryFnType {
Main {
/// Specifies what to do with `SIGPIPE` before calling `fn main()`.
///
/// What values that are valid and what they mean must be in sync
/// across rustc and libstd, but we don't want it public in libstd,
/// so we take a bit of an unusual approach with simple constants
/// and an `include!()`.
sigpipe: u8,
},
Main,
}

#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, Encodable, BlobDecodable)]
Expand Down Expand Up @@ -3069,9 +3060,8 @@ pub(crate) mod dep_tracking {
use rustc_span::edition::Edition;
use rustc_span::{RealFileName, RemapPathScopeComponents};
use rustc_target::spec::{
CodeModel, FramePointer, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel,
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTuple,
TlsModel,
CodeModel, FramePointer, MergeFunctions, PanicStrategy, RelocModel, RelroLevel,
SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTuple, TlsModel,
};

use super::{
Expand Down Expand Up @@ -3146,7 +3136,6 @@ pub(crate) mod dep_tracking {
InstrumentXRay,
CrateType,
MergeFunctions,
OnBrokenPipe,
PanicStrategy,
RelroLevel,
OptLevel,
Expand Down
25 changes: 0 additions & 25 deletions compiler/rustc_session/src/config/sigpipe.rs

This file was deleted.

20 changes: 3 additions & 17 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use rustc_macros::{BlobDecodable, Encodable};
use rustc_span::edition::Edition;
use rustc_span::{RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm};
use rustc_target::spec::{
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility,
TargetTuple, TlsModel,
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel,
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTuple,
TlsModel,
};

use crate::config::*;
Expand Down Expand Up @@ -805,7 +805,6 @@ mod desc {
pub(crate) const parse_time_passes_format: &str = "`text` (default) or `json`";
pub(crate) const parse_passes: &str = "a space-separated list of passes, or `all`";
pub(crate) const parse_panic_strategy: &str = "either `unwind`, `abort`, or `immediate-abort`";
pub(crate) const parse_on_broken_pipe: &str = "either `kill`, `error`, or `inherit`";
pub(crate) const parse_patchable_function_entry: &str = "either two comma separated integers (total_nops,prefix_nops), with prefix_nops <= total_nops, or one integer (total_nops)";
pub(crate) const parse_opt_panic_strategy: &str = parse_panic_strategy;
pub(crate) const parse_relro_level: &str = "one of: `full`, `partial`, or `off`";
Expand Down Expand Up @@ -1206,17 +1205,6 @@ pub mod parse {
true
}

pub(crate) fn parse_on_broken_pipe(slot: &mut OnBrokenPipe, v: Option<&str>) -> bool {
match v {
// OnBrokenPipe::Default can't be explicitly specified
Some("kill") => *slot = OnBrokenPipe::Kill,
Some("error") => *slot = OnBrokenPipe::Error,
Some("inherit") => *slot = OnBrokenPipe::Inherit,
_ => return false,
}
true
}

pub(crate) fn parse_patchable_function_entry(
slot: &mut PatchableFunctionEntry,
v: Option<&str>,
Expand Down Expand Up @@ -2538,8 +2526,6 @@ options! {
Mandatory setting:
`=Enable`
Currently the only option available"),
on_broken_pipe: OnBrokenPipe = (OnBrokenPipe::Default, parse_on_broken_pipe, [TRACKED],
"behavior of std::io::ErrorKind::BrokenPipe (SIGPIPE)"),
osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
"pass `-install_name @rpath/...` to the macOS linker (default: no)"),
packed_bundled_libs: bool = (false, parse_bool, [TRACKED],
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ symbols! {
old_name,
omit_gdb_pretty_printer_section,
on,
on_broken_pipe,
on_const,
on_unimplemented,
opaque,
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,14 +840,6 @@ crate::target_spec_enum! {
parse_error_type = "panic strategy";
}

#[derive(Clone, Copy, Debug, PartialEq, Hash, Encodable, BlobDecodable, HashStable_Generic)]
pub enum OnBrokenPipe {
Default,
Kill,
Error,
Inherit,
}

impl PanicStrategy {
pub const fn desc_symbol(&self) -> Symbol {
match *self {
Expand Down
Loading
Loading