4 ms·
It is. I haven’t checked the complete source code. What I know for sure is that a program using Rust’s std still requires the C runtime to link and run, and fro
by codeflo 5y ago
It is. I haven’t checked the complete source code. What I know for sure is that a program using Rust’s std still requires the C runtime to link and run, and from that perspective, it doesn’t really matter if some or even many parts of the std don’t actually use it.
- deleted 5y ago[deleted]
- sanxiyn 5y agoI see. I wonder where Rust's std is using libc on Windows. I know for a fact filesystem portion of std doesn't call libc at all on Windows.
- ChrisSD 5y agoRust needs the C runtime for startup/shutdown code (and vcruntime for panics). It also needs basic memory functions such as memcpy and stack probes. There is no way round this except rewriting those in Rust.
- sanxiyn 5y agoRust already ships with its own memcpy, so it should be possible: https://github.com/rust-lang/compiler-builtins/blob/master/src/mem/impls.rs https://github.com/rust-lang/compiler-builtins/blob/master/s...
- ectopod 5y agoThe startup/shutdown code is for the C runtime. If you avoid the C runtime you don't need it.
- ChrisSD 5y agoAt a minimum Rust would have to run the C initializers as these are used even in pure Rust code. It might also make use of the security cookie but I'm uncertain about that. Also the C runtime is needed by the SEH handling code (in vcruntime) so Rust would have to replace that before it can replace the C startup/shutdown. To be clear, this is feasible but it'll require someone knowledgable to put in the work of rewriting this in Rust.
- steveklabnik 5y agohttps://crates.io/crates/r0 https://crates.io/crates/r0 exists (not everything you're talking about but like, there's some of this stuff around, in some contexts. We'll see if the whole pile of stuff needed ever gets ported or not, I'm guessing yes but on a long timeframe.)
- pjmlp 5y agoSEH doesn't need the C runtime, they are only required when using the C language extensions for frame-based Exception Handling, with the new vectored Exception Handling, plain Win32 calls will do, https://docs.microsoft.com/en-us/windows/win32/debug/vectored-exception-handling https://docs.microsoft.com/en-us/windows/win32/debug/vectore... Granted, they are more cumbersome to use and probably not worth the effort to try to avoid them other than special cases.
- ChrisSD 5y agoSure. I did not mean to imply that SEH itsef requires the C runtime. However, the __CxxFrameHandler3 that Rust/llvm uses would need to be rewritten. IIRC llvm itself generates calls to __CxxFrameHandler3 when SEH is being used, making it awkward to replace with something that's not compatible.