Skip to content

Commit 6bb1197

Browse files
committed
docs
1 parent c4b7417 commit 6bb1197

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/tools/miri/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,19 @@ Miri provides some `extern` functions that programs can import to access
474474
Miri-specific functionality. They are declared in
475475
[/tests/utils/miri\_extern.rs](/tests/utils/miri_extern.rs).
476476

477+
## Entry point for no-std binaries
478+
479+
Binaries that do not use the standard library are expected to declare a function like this so that
480+
Miri knows where it is supposed to start execution:
481+
482+
```rust
483+
#[cfg(miri)]
484+
#[no_mangle]
485+
fn miri_start(argc: isize, argv: *const *const u8) -> isize {
486+
// Call the actual start function that your project implements, based on your target's conventions.
487+
}
488+
```
489+
477490
## Contributing and getting help
478491

479492
If you want to contribute to Miri, great! Please check out our

src/tools/miri/src/bin/miri.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ fn entry_fn(tcx: TyCtxt<'_>) -> (DefId, EntryFnType) {
358358
if let Some(entry_def) = tcx.entry_fn(()) {
359359
return entry_def;
360360
}
361-
// Look for a symbol in the local crate named `miri_start`, and threat that as the entry point.
361+
// Look for a symbol in the local crate named `miri_start`, and treat that as the entry point.
362362
let sym = tcx.exported_symbols(LOCAL_CRATE).iter().find_map(|(sym, _)| {
363363
if sym.symbol_name_for_local_instance(tcx).name == "miri_start" { Some(sym) } else { None }
364364
});
@@ -391,14 +391,16 @@ fn entry_fn(tcx: TyCtxt<'_>) -> (DefId, EntryFnType) {
391391
);
392392
}
393393
} else {
394-
tcx.dcx().fatal("Miri can only run programs that have a main function.\n\
395-
Alternatively, you can export a `miri_start` function:\n\
396-
\n\
397-
#[cfg(miri)]\n\
398-
#[no_mangle]\n\
399-
fn miri_start(argc: isize, argv: *const *const u8) -> isize {\
400-
\n // Call the actual start function that your project implements, based on your target's conventions.\n\
401-
}");
394+
tcx.dcx().fatal(
395+
"Miri can only run programs that have a main function.\n\
396+
Alternatively, you can export a `miri_start` function:\n\
397+
\n\
398+
#[cfg(miri)]\n\
399+
#[no_mangle]\n\
400+
fn miri_start(argc: isize, argv: *const *const u8) -> isize {\
401+
\n // Call the actual start function that your project implements, based on your target's conventions.\n\
402+
}"
403+
);
402404
}
403405
}
404406

0 commit comments

Comments
 (0)