Skip to content
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

Open
bjorn3 opened this issue Jan 11, 2021 · 5 comments
Open

Implement main shim #144

bjorn3 opened this issue Jan 11, 2021 · 5 comments

Comments

@bjorn3
Copy link

bjorn3 commented Jan 11, 2021

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)

@github-actions
Copy link

Thanks for your contribution fellow Rustacean

@bjorn3
Copy link
Author

bjorn3 commented Apr 13, 2021

@tschwinge
Copy link
Member

I think I know where/how to conceptually do such a thing in GCC; will provide details at some later point in time.

@philberty philberty removed this from the Imports and visibility milestone May 26, 2022
@P-E-P
Copy link
Member

P-E-P commented Mar 14, 2023

I've been reading the discussion about #[start] and I found no mention of envp ?

@bjorn3
Copy link
Author

bjorn3 commented Mar 14, 2023

Rust's standard library doesn't need envp (it uses libc functions and the global variable instead), so rustc doesn't expose this argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants