-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Technically unsafe behavior in safe rust using #![no_main] #47685
Comments
Whoops, missed those while searching (only searched for no_main). It should be noted though that the proposed solution in the other issues (errors on duplicate symbols) would not work in this case as |
Why does the compiler put the array of (effectively) bytes in |
The correct place for it to be would be |
I don't think this should result in a compilation error, since it might be useful occasionally. However I do think there should be a lint against it, or perhaps some kind of |
Triage: no change |
This is basically a duplicate of #28179, so closing in favor of that |
Using
#![no_main]
, and a#[no_mange] pub static main
array the linker will assume that the main array is actually the main function and execute whatever is in there. Outside of a warning for nonstandard naming this compiles fine on stable and nightly on both debug and release mode.Example
This example will print the text
Main is usually a function\n
on x64 linux and probably crash violently on anything else.It's rather hard to trigger this behavior without trying, but it should probably not compile without errors. Maybe add a check for
#![no_main]
crates that whatever's declared as#[no_mangle] main
is actually a function with the correct signature.Meta
The issue exists on
rustc 1.25.0-nightly
,rustc 1.23.0
and anything in between.The text was updated successfully, but these errors were encountered: