-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
This naked function SIGSEGVs #32490
Comments
Naked functions that contain anything other than an asm blocks are at the very least unspecified behavior. |
@arielb1 I do not disagree, however the RFC does not have any such requirements, and the RFC discussion seemed to imply it “just works”. |
At the very least we should forbid non-single-asm-statement naked functions. |
cc #32408 |
Would it make sense to allow non-single-asm-statement naked parameterless functions?
|
Right, both of these must make rustc fail, but doesn’t currently. On Sun, 27 Mar, 2016 at 5:49 PM, Kai Noda [email protected]
|
I don't think that we should prevent random undefined uses of naked functions from compiling unless we have a good set of rules. Maybe lint against them. |
Asm-only naked functions are a very large potential footgun, mentioned as an unresolved question in the RFC since there wasn't consensus on what a reasonable approach is. Opinions tend to be split between those who are okay with the correctness of their code being at the whims of the code generator (allowing Rust code in naked functions, trading safety guarantees for improved efficiency) and those who prefer to ensure it is impossible to generate wrong code by accident. The compromise solution is requiring the body of a naked function be unsafe (#32489), but that means (if made unsafe), I don't think the code sample in OP is a Rust bug. The actual correctness of non-asm code in naked functions depends on the optimizer and code generator, which in general we cannot make any guarantees about what it will do. A rule like "no parameters allowed" is not sufficient to ensure generated code is correct. I believe the only way to properly check for implied stack allocations is to perform some kind of checking pass after codegen, which would at the least require some significant compiler complexity. A lint against non-asm code in naked functions sounds like a reasonable approach to further help avoid foot-shooting to me. |
I've hit an issue here too. I had a naked function as the entry point to some baremetal code. The first thing the function does is set up the stack pointer with some asm! then it has some rust code with automatic variables. I expected this to work but when I had a look at the llvm-ir the alloca for the automatic variable was placed before my asm!, not after. I have gone with the pure asm! in the naked function which branches to another function with the rust code. This is fine but it is a little annoying needing the unnecessary branch. |
The core::intrinsics::unreachable() we used at the end of every naked function is essentially pointless, as #[naked] implies that intrinsic at the end of the function. rustc currently does not implement that behavior (rust-lang/rust#32487), but it is a bug. On top of that, anything except a single asm!() in naked functions is likely to be disallowed in the future (rust-lang/rust#32490). A nice side effect is that we avoid the core_intrinsics feature, which will be never stabilized, though neither asm nor naked_functions are likely to be stabilized soon.
The core::intrinsics::unreachable() we used at the end of every naked function is essentially pointless, as #[naked] implies that intrinsic at the end of the function. rustc currently does not implement that behavior (rust-lang/rust#32487), but it is a bug. On top of that, anything except a single asm!() in naked functions is likely to be disallowed in the future (rust-lang/rust#32490). A nice side effect is that we avoid the core_intrinsics feature, which will be never stabilized, though neither asm nor naked_functions are likely to be stabilized soon.
…nctions, r=Amanieu Reject unsupported naked functions Transition unsupported naked functions future incompatibility lint into an error: * Naked functions must contain a single inline assembly block. Introduced as future incompatibility lint in 1.50 rust-lang#79653. Change into an error fixes a soundness issue described in rust-lang#32489. * Naked functions must not use any forms of inline attribute. Introduced as future incompatibility lint in 1.56 rust-lang#87652. Closes rust-lang#32490. Closes rust-lang#32489. r? `@Amanieu` `@npmccallum` `@joshtriplett`
…nctions, r=Amanieu Reject unsupported naked functions Transition unsupported naked functions future incompatibility lint into an error: * Naked functions must contain a single inline assembly block. Introduced as future incompatibility lint in 1.50 rust-lang#79653. Change into an error fixes a soundness issue described in rust-lang#32489. * Naked functions must not use any forms of inline attribute. Introduced as future incompatibility lint in 1.56 rust-lang#87652. Closes rust-lang#32490. Closes rust-lang#32489. r? ``@Amanieu`` ``@npmccallum`` ``@joshtriplett``
SIGSEGVs on my system, but it only happens in builds without
-O
or-g
flags, making it hard to debug.The text was updated successfully, but these errors were encountered: