Skip to content

Support #[start] #1825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jun 6, 2021 · 3 comments · Fixed by #1884
Closed

Support #[start] #1825

ghost opened this issue Jun 6, 2021 · 3 comments · Fixed by #1884

Comments

@ghost
Copy link

ghost commented Jun 6, 2021

The start feature allows to mark a function as the entry point and override the start lang item. It's currently not supported in Miri:

error: internal compiler error: src/tools/miri/src/eval.rs:110:9: main function must not take any arguments

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:1007:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.54.0-nightly (c79419af0 2021-06-04) running on x86_64-unknown-linux-gnu

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=b867b78dd787c573bdfb44c88fa856dc

bug!("main function must not take any arguments");

@RalfJung
Copy link
Member

RalfJung commented Jun 6, 2021

Interesting, so #[start] must have 2 arguments even though the start lang-item defined inside std has 0 arguments.

error[E0308]: `#[start]` function has wrong type
 --> src/main.rs:4:1
  |
4 | fn start() -> isize {
  | ^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
  |
  = note: expected fn pointer `fn(isize, *const *const u8) -> _`
             found fn pointer `fn() -> _`

@ghost
Copy link
Author

ghost commented Jun 6, 2021

the start lang-item defined inside std has 0 arguments

It's not the start lang item, but the main function, I think. The start lang item takes 3 arguments:

miri/src/eval.rs

Lines 195 to 199 in ef99830

// Call start function.
ecx.call_function(
start_instance,
Abi::Rust,
&[main_ptr.into(), argc.into(), argv.into()],

@RalfJung
Copy link
Member

RalfJung commented Jun 6, 2021

Ah, right. And then we pass a pointer to the main function. That one must indeed have no arguments or else the call you are citing above will not even be well-typed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant