forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#3769 - primoly:miri-start, r=RalfJung
Add `miri_start` support This PR uses a function with the exported symbol `miri_start` as a drop-in alternative to `#[start]`. So the signature stays the same as suggested in [this comment](rust-lang/miri#3498 (comment)). <del>I’ve also removed Miri’s restriction to only work on bin crates as I don’t think this is necessary anymore.</del> Closes rust-lang#3758
- Loading branch information
Showing
8 changed files
with
140 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//@compile-flags: -Cpanic=abort | ||
//@error-in-other-file: `miri_start` must have the following signature: | ||
#![no_main] | ||
#![no_std] | ||
|
||
use core::fmt::Write; | ||
|
||
#[path = "../utils/mod.no_std.rs"] | ||
mod utils; | ||
|
||
#[no_mangle] | ||
fn miri_start() -> isize { | ||
//~^ ERROR: mismatched types | ||
writeln!(utils::MiriStdout, "Hello from miri_start!").unwrap(); | ||
0 | ||
} | ||
|
||
#[panic_handler] | ||
fn panic_handler(_: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/miri_start_wrong_sig.rs:LL:CC | ||
| | ||
LL | fn miri_start() -> isize { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters | ||
| | ||
= note: expected signature `fn(isize, *const *const u8) -> _` | ||
found signature `fn() -> _` | ||
|
||
error: `miri_start` must have the following signature: | ||
fn miri_start(argc: isize, argv: *const *const u8) -> isize | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
//@error-in-other-file: miri can only run programs that have a main function | ||
//@error-in-other-file: Miri can only run programs that have a main function. | ||
#![no_main] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
error: miri can only run programs that have a main function | ||
error: Miri can only run programs that have a main function. | ||
Alternatively, you can export a `miri_start` function: | ||
|
||
#[cfg(miri)] | ||
#[no_mangle] | ||
fn miri_start(argc: isize, argv: *const *const u8) -> isize { | ||
// Call the actual start function that your project implements, based on your target's conventions. | ||
} | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//@compile-flags: -Cpanic=abort | ||
#![no_main] | ||
#![no_std] | ||
|
||
use core::fmt::Write; | ||
|
||
#[path = "../utils/mod.no_std.rs"] | ||
mod utils; | ||
|
||
#[no_mangle] | ||
fn miri_start(_argc: isize, _argv: *const *const u8) -> isize { | ||
writeln!(utils::MiriStdout, "Hello from miri_start!").unwrap(); | ||
0 | ||
} | ||
|
||
#[panic_handler] | ||
fn panic_handler(_: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello from miri_start! |