Description
Libstd does some extra work in addition to what the libc startup does like setting up a stack guard, adding a handler for SIGSEGV to give a nice error message on stack overflows, storing the program arguments in a static and running the main function within std::panic::catch_unwind
to ensure that panicking doesn't immediately abort due to a missing unwind catcher. For reference the main shim calls https://github.com/rust-lang/rust/blob/a2cd91ceb0f156cb442d75e12dc77c3d064cdde4/library/std/src/rt.rs#L60 with the main function as first argument when using libstd. There are also a few other (unstable) options like marking a function with #[start]
, in which case argc and argv are directly passed to that function without any additional arguments: https://github.com/bjorn3/rustc_codegen_cranelift/blob/3ea8915d4a247b5b3c4cfb3424c230ccd2645b17/example/alloc_example.rs#L30
Originally posted by @bjorn3 in #137 (comment)