Skip to content
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

cargo-miri panic's on no_main binaries #1452

Closed
ppannuto opened this issue Jun 17, 2020 · 1 comment · Fixed by #1473
Closed

cargo-miri panic's on no_main binaries #1452

ppannuto opened this issue Jun 17, 2020 · 1 comment · Fixed by #1473
Labels
A-interpreter Area: affects the core interpreter C-bug Category: This is a bug. E-good-first-issue A good way to start contributing, mentoring is available I-ICE Impact: makes Miri crash with some ICE

Comments

@ppannuto
Copy link

While there are many other questions about what miri should do for binaries with #![no_main], the current behavior is to panic. In the spirit of #1001, it would be nice explicitly indicate that miri doesn't support testing freestanding binaries at the moment.

An example backtrace
[-bash] Wed 17 Jun 16:40 [[master $] /Volumes/code/helena-project/tock/boards/hail]
$ cargo miri test
    Checking hail v0.1.0 (/Volumes/code/helena-project/tock/boards/hail)
warning: unused import: `core::panic::PanicInfo`
 --> boards/hail/src/io.rs:2:5
  |
2 | use core::panic::PanicInfo;
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: cortexm4
--> boards/hail/src/io.rs:4:5
|
4 | use cortexm4;
| ^^^^^^^^

warning: unused import: kernel::debug
--> boards/hail/src/io.rs:5:5
|
5 | use kernel::debug;
| ^^^^^^^^^^^^^

warning: unused import: kernel::hil::led
--> boards/hail/src/io.rs:7:5
|
7 | use kernel::hil::led;
| ^^^^^^^^^^^^^^^^

warning: unused import: crate::CHIP
--> boards/hail/src/io.rs:10:5
|
10 | use crate::CHIP;
| ^^^^^^^^^^^

warning: unused import: crate::PROCESSES
--> boards/hail/src/io.rs:11:5
|
11 | use crate::PROCESSES;
| ^^^^^^^^^^^^^^^^

warning: static is never used: WRITER
--> boards/hail/src/io.rs:17:1
|
17 | static mut WRITER: Writer = Writer { initialized: false };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default

thread 'rustc' panicked at 'no main function found!', src/tools/miri/src/bin/miri.rs:35:37
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

error: internal compiler error: unexpected panic

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.45.0-nightly (fe10f1a49 2020-06-02) running on x86_64-apple-darwin

note: compiler flags: -C opt-level=z -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on -C incremental

note: some of the compiler flags provided by cargo are hidden

warning: 7 warnings emitted

error: could not compile hail.

To learn more, run the command again with --verbose.

I've attached a backtrace, but any no_main binary will crash in a similar manner right now.

CC tock/tock#1713

@ppannuto ppannuto changed the title cargo-mini panic's on no_main binaries cargo-miri panic's on no_main binaries Jun 17, 2020
@RalfJung RalfJung added A-interpreter Area: affects the core interpreter C-bug Category: This is a bug. E-good-first-issue A good way to start contributing, mentoring is available labels Jun 18, 2020
@RalfJung
Copy link
Member

Thanks! I agree.

This is an easy bug to fix, well-suited as a first contribution. The panic arises here:

let (entry_def_id, _) = tcx.entry_fn(LOCAL_CRATE).expect("no main function found!");

And all it takes is replacing that by a better error message. rustc has some APIs for fatal errors; early_error might be suited here.

@RalfJung RalfJung added the I-ICE Impact: makes Miri crash with some ICE label Jun 24, 2020
@bors bors closed this as completed in ade99c3 Jul 9, 2020
@bors bors closed this as completed in #1473 Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-interpreter Area: affects the core interpreter C-bug Category: This is a bug. E-good-first-issue A good way to start contributing, mentoring is available I-ICE Impact: makes Miri crash with some ICE
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants