-
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
Make rust_stack_exhausted a lang item #11922
Comments
The morestack-based stack overflow checking doesn't work at all in a kernel. I think this would just hide the issue. Rust can also only generate position-independent code and is unable to easily define I've been tagging these as |
Why doesn't morestack work in a kernel? |
That is not true. I have written a kernel that makes use of morestack checks. It is just a little more difficult to set up the state of the world such that the stack checking works. |
@alexcrichton: That's exactly what I mean though. It's broken out-of-the-box and will be a silent hazard in a freestanding project like a Linux kernel module. |
The problem is that, without doing some setup, the morestack checks will trip incorrectly? |
Is it true that this incorrect trip only happens in kernel space? Does userpace always initialize our morestack TCB slot to zero for us? (ISTR it doesn't in some cases) |
@brson: That issue along with the possibility of setting it up not being an option if you're integrating with an existing kernel like Linux. I don't know if it's ever a problem in userland, as I haven't seen it go wrong yet. |
We could probably provide portable routines for initializing morestack. If this is only a problem for kernelspace it doesn't seem too burdensome to ask them to call an init function. Of course, having an option to disable morestack generation would also be useful. As long as we are using morestack, I'd like to make it as convenient as we can. |
Could we just have this have normal lang-item detection? If there is any function that will require the split-stack header, emit a "requires stack_exhausted" error, which at least means we don't get linking errors. |
As long as it's still possible to build with without marking every function as |
This commit is part of the ongoing libstd facade efforts (cc rust-lang#13851). The compiler now recognizes some language items as "extern { fn foo(...); }" and will automatically perform the following actions: 1. The foreign function has a pre-defined name. 2. The crate and downstream crates can only be built as rlibs until a crate defines the lang item itself. 3. The actual lang item has a pre-defined name. This is essentially nicer compiler support for the hokey core-depends-on-std-failure scheme today, but it is implemented the same way. The details are a little more hidden under the covers. In addition to failure, this commit promotes the eh_personality and rust_stack_exhausted functions to official lang items. The compiler can generate calls to these functions, causing linkage errors if they are left undefined. The checking for these items is not as precise as it could be. Crates compiling with `-Z no-landing-pads` will not need the eh_personality lang item, and crates compiling with no split stacks won't need the stack exhausted lang item. For ease, however, these items are checked for presence in all final outputs of the compiler. It is quite easy to define dummy versions of the functions necessary: #[lang = "stack_exhausted"] extern fn stack_exhausted() { /* ... */ } #[lang = "eh_personality"] extern fn eh_personality() { /* ... */ } cc rust-lang#11922, rust_stack_exhausted is now a lang item cc rust-lang#13851, libcollections is blocked on eh_personality becoming weak
This commit is part of the ongoing libstd facade efforts (cc #13851). The compiler now recognizes some language items as "extern { fn foo(...); }" and will automatically perform the following actions: 1. The foreign function has a pre-defined name. 2. The crate and downstream crates can only be built as rlibs until a crate defines the lang item itself. 3. The actual lang item has a pre-defined name. This is essentially nicer compiler support for the hokey core-depends-on-std-failure scheme today, but it is implemented the same way. The details are a little more hidden under the covers. In addition to failure, this commit promotes the eh_personality and rust_stack_exhausted functions to official lang items. The compiler can generate calls to these functions, causing linkage errors if they are left undefined. The checking for these items is not as precise as it could be. Crates compiling with `-Z no-landing-pads` will not need the eh_personality lang item, and crates compiling with no split stacks won't need the stack exhausted lang item. For ease, however, these items are checked for presence in all final outputs of the compiler. It is quite easy to define dummy versions of the functions necessary: #[lang = "stack_exhausted"] extern fn stack_exhausted() { /* ... */ } #[lang = "eh_personality"] extern fn eh_personality() { /* ... */ } cc #11922, rust_stack_exhausted is now a lang item cc #13851, libcollections is blocked on eh_personality becoming weak
Closing, this was done in #14293 |
cc #9839. Right now if you don't link to the standard library you get a link error because
__morestack
expects a symbol calledrust_stack_exhausted
to exist.Add a "stack_exhausted" lang item. For every compilation unit, if the lang item doesn't exist, emit the code
If it does exist, emit the same function, but call the lang item.
This would work in our current scheme where std defines what happens when the stack runs out, but not if we refactored std like #11828, so that the lowest levels of the crate hierarchy don't know the failure policy.
The text was updated successfully, but these errors were encountered: