Skip to content

#![no_std] seems quite difficult to use in practice #18172

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

Closed
jgallagher opened this issue Oct 20, 2014 · 11 comments
Closed

#![no_std] seems quite difficult to use in practice #18172

jgallagher opened this issue Oct 20, 2014 · 11 comments

Comments

@jgallagher
Copy link

I've had a few conversations on IRC about using #![no_std] in Rust libraries. There are comments around (such as here in html5ever) that using #![no_std] should be used if one wants to write a Rust library that is going to be used from other languages. It's not really clear to me how accurate that recommendation still is currently / will be at 1.0 with the changes to std that have happened over the past months; however, assuming it's still true, I think there are a couple of problems that don't seem to have easy solutions:

@alexcrichton
Copy link
Member

Note that for the second point you don't actually need to define any lang items so long as your'e compiled as an rlib. If you compile as a dylib, staticlib, or an executable you'll be required to provide an impl for all the lang items.

@jgallagher
Copy link
Author

Ahh, that helps a lot. I worry more about the first point though. If no_std is a recommended practice for "crates that support use from other languages", will that end up creating a sort of split where some (probably large) percentage of rust crates - the one that do use std - can't be used as dependencies?

@alexcrichton
Copy link
Member

I'm not sure I would classify no_std as "recommended practice" per se. Currently no_std serves as a way to disable extern crate std injection, but not a whole lot beyond that in terms of an "official recommendation".

@thehydroimpulse
Copy link
Contributor

/cc me

@arielb1
Copy link
Contributor

arielb1 commented Oct 20, 2014

There should be an option to make eh_personality and stack_exhausted weak symbols, so that if no rust library is linked, then they would be null, and jumping to them would segfault the program.

@thestinger
Copy link
Contributor

@arielb1: There is absolutely no guarantee of a segfault when dereferencing a null pointer. It only causes that on a subset of platforms due to the zero page being mapped as PROT_NONE. The use case for #![no_std] includes use cases like a kernel where it is not common for this to result in a deterministic crash. It's dangerous undefined behaviour and can be exploited as a memory corruption vulnerability.

@thestinger
Copy link
Contributor

Weak symbols also don't work properly with static linking.

@mahkoh
Copy link
Contributor

mahkoh commented Oct 22, 2014

Would it be possible for the compiler to provide these functions in a hosted environment with a sane default behavior? E.g., if the the programmer doesn't provide his own functions, they simply abort the process.

@thestinger
Copy link
Contributor

@mahkoh: It can provide the abort behaviour everywhere, because it's provided by an LLVM intrinsic mapping down to a single instruction.

@arielb1
Copy link
Contributor

arielb1 commented Oct 25, 2014

Kernels will of course have to supply their own version of the failure function, which should be something like linux's panic. I was worried about libraries, which don't want to export a non-weak stack_exhausted etc. symbols (as these will conflict with symbols with the same name from other libraries).

@steveklabnik
Copy link
Member

This ticket isn't really actionable, and with changes to the runtime, the details are (somewhat) different overall anyway.

lnicola pushed a commit to lnicola/rust that referenced this issue Sep 25, 2024
…vidbarsky

fix: Support expect in attribute completion and hover

Fixes rust-lang#18171
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

7 participants