Skip to content

Commit 869ca6a

Browse files
committed
Auto merge of #134299 - RalfJung:remove-start, r=compiler-errors
remove support for the (unstable) #[start] attribute As explained by `@Noratrieb:` `#[start]` should be deleted. It's nothing but an accidentally leaked implementation detail that's a not very useful mix between "portable" entrypoint logic and bad abstraction. I think the way the stable user-facing entrypoint should work (and works today on stable) is pretty simple: - `std`-using cross-platform programs should use `fn main()`. the compiler, together with `std`, will then ensure that code ends up at `main` (by having a platform-specific entrypoint that gets directed through `lang_start` in `std` to `main` - but that's just an implementation detail) - `no_std` platform-specific programs should use `#![no_main]` and define their own platform-specific entrypoint symbol with `#[no_mangle]`, like `main`, `_start`, `WinMain` or `my_embedded_platform_wants_to_start_here`. most of them only support a single platform anyways, and need cfg for the different platform's ways of passing arguments or other things *anyways* `#[start]` is in a super weird position of being neither of those two. It tries to pretend that it's cross-platform, but its signature is a total lie. Those arguments are just stubbed out to zero on ~~Windows~~ wasm, for example. It also only handles the platform-specific entrypoints for a few platforms that are supported by `std`, like Windows or Unix-likes. `my_embedded_platform_wants_to_start_here` can't use it, and neither could a libc-less Linux program. So we have an attribute that only works in some cases anyways, that has a signature that's a total lie (and a signature that, as I might want to add, has changed recently, and that I definitely would not be comfortable giving *any* stability guarantees on), and where there's a pretty easy way to get things working without it in the first place. Note that this feature has **not** been RFCed in the first place. *This comment was posted [in May](rust-lang/rust#29633 (comment)) and so far nobody spoke up in that issue with a usecase that would require keeping the attribute.* Closes rust-lang/rust#29633 try-job: x86_64-gnu-nopt try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: test-various
2 parents 23a32e3 + c4a3398 commit 869ca6a

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

Diff for: src/main_shim.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
22
use rustc_hir::LangItem;
33
use rustc_middle::ty::{AssocKind, GenericArg};
4-
use rustc_session::config::{EntryFnType, sigpipe};
4+
use rustc_session::config::EntryFnType;
55
use rustc_span::{DUMMY_SP, Ident};
66

77
use crate::prelude::*;
@@ -14,10 +14,9 @@ pub(crate) fn maybe_create_entry_wrapper(
1414
is_jit: bool,
1515
is_primary_cgu: bool,
1616
) {
17-
let (main_def_id, (is_main_fn, sigpipe)) = match tcx.entry_fn(()) {
17+
let (main_def_id, sigpipe) = match tcx.entry_fn(()) {
1818
Some((def_id, entry_ty)) => (def_id, match entry_ty {
19-
EntryFnType::Main { sigpipe } => (true, sigpipe),
20-
EntryFnType::Start => (false, sigpipe::DEFAULT),
19+
EntryFnType::Main { sigpipe } => sigpipe,
2120
}),
2221
None => return,
2322
};
@@ -31,14 +30,13 @@ pub(crate) fn maybe_create_entry_wrapper(
3130
return;
3231
}
3332

34-
create_entry_fn(tcx, module, main_def_id, is_jit, is_main_fn, sigpipe);
33+
create_entry_fn(tcx, module, main_def_id, is_jit, sigpipe);
3534

3635
fn create_entry_fn(
3736
tcx: TyCtxt<'_>,
3837
m: &mut dyn Module,
3938
rust_main_def_id: DefId,
4039
ignore_lang_start_wrapper: bool,
41-
is_main_fn: bool,
4240
sigpipe: u8,
4341
) {
4442
let main_ret_ty = tcx.fn_sig(rust_main_def_id).no_bound_vars().unwrap().output();
@@ -94,8 +92,8 @@ pub(crate) fn maybe_create_entry_wrapper(
9492

9593
let main_func_ref = m.declare_func_in_func(main_func_id, &mut bcx.func);
9694

97-
let result = if is_main_fn && ignore_lang_start_wrapper {
98-
// regular main fn, but ignoring #[lang = "start"] as we are running in the jit
95+
let result = if ignore_lang_start_wrapper {
96+
// ignoring #[lang = "start"] as we are running in the jit
9997
// FIXME set program arguments somehow
10098
let call_inst = bcx.ins().call(main_func_ref, &[]);
10199
let call_results = bcx.func.dfg.inst_results(call_inst).to_owned();
@@ -133,7 +131,8 @@ pub(crate) fn maybe_create_entry_wrapper(
133131
types::I64 => bcx.ins().sextend(types::I64, res),
134132
_ => unimplemented!("16bit systems are not yet supported"),
135133
}
136-
} else if is_main_fn {
134+
} else {
135+
// Regular main fn invoked via start lang item.
137136
let start_def_id = tcx.require_lang_item(LangItem::Start, None);
138137
let start_instance = Instance::expect_resolve(
139138
tcx,
@@ -150,10 +149,6 @@ pub(crate) fn maybe_create_entry_wrapper(
150149
let call_inst =
151150
bcx.ins().call(func_ref, &[main_val, arg_argc, arg_argv, arg_sigpipe]);
152151
bcx.inst_results(call_inst)[0]
153-
} else {
154-
// using user-defined start fn
155-
let call_inst = bcx.ins().call(main_func_ref, &[arg_argc, arg_argv]);
156-
bcx.inst_results(call_inst)[0]
157152
};
158153

159154
bcx.ins().return_(&[result]);

0 commit comments

Comments
 (0)