Implement main shim
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 https://github.com/Rust-GCC/gccrs/pull/137#discussion_r555210692
Thanks for your contribution fellow Rustacean
The main shim is codegened at https://github.com/rust-lang/rust/blob/015d2bc3fec48cef3cbfaec71c54fa31ce420853/compiler/rustc_codegen_ssa/src/base.rs#L345-L439. Note that https://github.com/rust-lang/rust/pull/84062 will change the logic a bit.
I think I know where/how to conceptually do such a thing in GCC; will provide details at some later point in time.
I've been reading the discussion about #[start] and I found no mention of envp ?
Rust's standard library doesn't need envp (it uses libc functions and the global variable instead), so rustc doesn't expose this argument.