-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement main shim #144
Comments
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 rust-lang/rust#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 |
Rust's standard library doesn't need envp (it uses libc functions and the global variable instead), so rustc doesn't expose this argument. |
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#L30Originally posted by @bjorn3 in #137 (comment)
The text was updated successfully, but these errors were encountered: