about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/miri/README.md13
-rw-r--r--src/tools/miri/src/bin/miri.rs20
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 entry_fn(tcx: TyCtxt<'_>) -> (DefId, EntryFnType) {
             );
         }
     } 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\
+            }"
+        );
     }
 }