getrandom: Support `x86_64-unknown-linux-none`
The target was added in https://github.com/rust-lang/rust/pull/125023 and is available in the latest Nightly builds. Use cargo +nightly build --target=x86_64-unknown-linux-none -Zbuild-std.
The libc crate does NOT support this target, so libc::syscall and libc::getrandom cannot be used on this target.
I am planning to support this target in ring soon.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 32 (27 by maintainers)
I think it would be possible for the
linux-raw-syscrate to generate the syscall wrapper functions, as all their information is present in the various Linux headers, so they could (in theory) be auto-generated. For example:include/uapi/asm-generic/unistd.h(and arch-specific files) defines__NR_getrandomand referencessys_getrandominclude/linux/syscalls.hdefines the prototype forsys_getrandomlinux_raw_sys::general::__NR_getrandomwould still exist as a constantlinux_raw_sys::syscalls::sys_getrandomwould be a function whose implementation could be generated based on the “ABI” value in the syscall table:syscall()function. I agree with the above points that a function which can invoke any syscall is impossible to implement reliably.However, I definitely recognize that such auto-generation is quite complex, compared to what
linux-raw-syscurrently does.Zooming out, I think it would be fine for this crate to depend on
rustix/linux-raw-syson either all Linux targets or just thelinux-nonetargets, provided that adoption is sufficiently widespread. A good litmus test for this would belibstditself depending onrustix/linux-raw-syson some/all Linux targets.Until that point, having our own syscall wrapper seems like the least bad option. It will work with our without rustix, and we can always move to
rustix/linux-raw-syswhen there is consensus.In the PR, @morr0ne said that x86_64-unknown-linux-none won’t have libc, so it’s likely that many crates will use rustix for I/O on
*-linux-none, so rustix will often be in people’s dependency trees already. Perhaps that makes it feasible for getrandom to just userustix::rand::getrandom_uniniton x86_64-unknown-linux-none.If it were just getrandom it may seem ok to hard-code a little bit of
asm, but if other crates start following this example and we end up with many crates doing their own syscallasms, I think that would be unfortunate. And, it’s reasonable to anticipate morelinux-nonetargets than just x86_64.