From 6bb119764b607d40be0a4f246643297f7ea36745 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 2 Aug 2024 14:16:36 +0200 Subject: [PATCH] docs --- src/tools/miri/README.md | 13 +++++++++++++ src/tools/miri/src/bin/miri.rs | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/tools/miri/README.md b/src/tools/miri/README.md index b1be596c006..4892f3824d9 100644 --- a/src/tools/miri/README.md +++ b/src/tools/miri/README.md @@ -474,6 +474,19 @@ Miri provides some `extern` functions that programs can import to access Miri-specific functionality. They are declared in [/tests/utils/miri\_extern.rs](/tests/utils/miri_extern.rs). +## Entry point for no-std binaries + +Binaries that do not use the standard library are expected to declare a function like this so that +Miri knows where it is supposed to start execution: + +```rust +#[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. +} +``` + ## Contributing and getting help If you want to contribute to Miri, great! Please check out our diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 2cea8e75117..42929bcb282 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -358,7 +358,7 @@ fn entry_fn(tcx: TyCtxt<'_>) -> (DefId, EntryFnType) { if let Some(entry_def) = tcx.entry_fn(()) { return entry_def; } - // Look for a symbol in the local crate named `miri_start`, and threat that as the entry point. + // Look for a symbol in the local crate named `miri_start`, and treat that as the entry point. let sym = tcx.exported_symbols(LOCAL_CRATE).iter().find_map(|(sym, _)| { if sym.symbol_name_for_local_instance(tcx).name == "miri_start" { Some(sym) } else { None } }); @@ -391,14 +391,16 @@ fn miri_start(argc: isize, argv: *const *const u8) -> isize", ); } } else { - tcx.dcx().fatal("Miri can only run programs that have a main function.\n\ - Alternatively, you can export a `miri_start` function:\n\ - \n\ - #[cfg(miri)]\n\ - #[no_mangle]\n\ - fn miri_start(argc: isize, argv: *const *const u8) -> isize {\ - \n // Call the actual start function that your project implements, based on your target's conventions.\n\ - }"); + tcx.dcx().fatal( + "Miri can only run programs that have a main function.\n\ + Alternatively, you can export a `miri_start` function:\n\ + \n\ + #[cfg(miri)]\n\ + #[no_mangle]\n\ + fn miri_start(argc: isize, argv: *const *const u8) -> isize {\ + \n // Call the actual start function that your project implements, based on your target's conventions.\n\ + }" + ); } }