-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix watchOS and visionOS for pread64 and pwrite64 calls #124089
Fix watchOS and visionOS for pread64 and pwrite64 calls #124089
Conversation
rustbot has assigned @workingjubilee. Use |
This comment has been minimized.
This comment has been minimized.
Hmm, I don't think E.g. the following fails even on the newest version of macOS: extern "C" {
fn preadv64(w: libc::c_int, z: *const libc::iovec, y: libc::c_int, x: libc::off_t) -> isize;
}
fn main() {
unsafe { preadv64(0, std::ptr::null(), 0, 0) };
} Only the |
824d00c
to
4477be0
Compare
Yeah, I'm confused how it's not broken for other apple targets in it's current setup? More so, it looks like the |
Me neither, tagging original implementor @a1phyr |
library/std/src/sys/pal/unix/fd.rs
Outdated
// We support old MacOS, iOS, watchOS, tvOS and visionOS versions that do not have `preadv`. | ||
// There is no `syscall` possible in these platform for following apple versions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not certain this comment (or the one one about pwritev
) is accurate anymore. Went about looking into the apple SDKs and they all have:
ssize_t preadv(int, const struct iovec *, int, off_t) __DARWIN_NOCANCEL(preadv) __API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0));
ssize_t pwritev(int, const struct iovec *, int, off_t) __DARWIN_NOCANCEL(pwritev) __API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0));
Here's the iOS SDK header but they all look the same on my local SDK's. I found preadv
/pwritev
in the VisionOS tbd ("text-based stub" libraries)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that it's the same in the headers for each SDK, can be checked using:
for sdk in macosx appletvos iphoneos watchos xros
do
cat $(xcrun --show-sdk-path --sdk $sdk)/usr/include/sys/uio.h | grep API_AVAILABLE
done
That said, the comment is indeed correct that we still support e.g. macOS 10.12, while the API has only added in macOS 11. So we still need to do weak linking here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's so much easier to think clearly about this now, thank you so much!
I notice we've had to re-answer the question of "what appleOS versions do we actually support" a few times here. Could we write down the answers, so that we can explicitly encode the version we're assuming we support, and thus that requires this weak linking? I can't find them actually documented (placed in an easily-findable location and an explicit note that this is the intentional version we support, like the platform support docs) for anything except macOS. I think it's reasonable to not want to sift through CI files, somewhat randomly located *_DEPLOYMENT_TARGET
variables, or other random PRs for an answer.
library/std/src/sys/pal/unix/fd.rs
Outdated
// ios 14.0 | ||
// tvos 14.0 | ||
// macos 11.0 | ||
// watchos 7.0 | ||
// visionos 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this... do we support visionOS before 1.0? I would think not? We could strong-link on visionOS if we don't. Arguably it makes the implementation messier, I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to double check myself. Looks like visionOS 1.0 is the first version. In #121419, the default was set to 1.0. This should be something easier to check though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about this more, I think that this comment is not to say "this is the minimum supported version", I think the original comment I paraphrased and amended meant "The following Operating system versions have this syscall: iOS 14.0, tvOS 14.0, macOS 11.0, watchOS 7.1".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated code comments to reflect my understanding of things and better describe it.
#[cfg(target_vendor = "apple")] | ||
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> { | ||
super::weak::weak!(fn preadv(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super weak!
I also am willing to accept this if you instead decide to open an issue to clarify the version situation here, fwiw! This is good enough for me. |
I've been wanting to add that to the platform support docs too, will try to do so (in a way that doesn't conflict too much with #120745). |
I authored #124215 to keep this PR small. |
Excellent! r=me with the format commits squished! @bors delegate+ |
✌️ @simlay, you can now approve this pull request! If @workingjubilee told you to " |
* Refactor apple OSs to use pwritev and preadv rather pwritev64 and preadv64 * Updated the comments for preadv and pwritev
b411fb7
to
fa53b9f
Compare
…llaumeGomez Rollup of 4 pull requests Successful merges: - rust-lang#124069 (enable clippy for bootstrap on CI PRs (in `mingw-check` image)) - rust-lang#124089 (Fix watchOS and visionOS for pread64 and pwrite64 calls) - rust-lang#124184 (Suggest using `unsigned_abs` in `abs` documentation) - rust-lang#124198 (Flip spans for precise capturing syntax not capturing a ty/const param, and for implicit captures of lifetime params) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#124089 - simlay:fix-preadv64-and-pwritev64-link-for-watchos-and-visionos, r=workingjubilee Fix watchOS and visionOS for pread64 and pwrite64 calls In rust-lang#122880, links to `preadv64` and `pwritev64` were added for `watchOS` however the underlying [`weak!` macro did not include `target_os = "watchos"`](https://github.com/rust-lang/rust/blob/c45dee5efd0c042e9d1e24559ebd0d6424d8aa70/library/std/src/sys/pal/unix/weak.rs#L30-L74). This resulted in an `xcodebuild` error when targeting `watchOS`: ``` Undefined symbols for architecture arm64: "_preadv64", referenced from: __rust_extern_with_linkage_preadv64 in libliveview_native_core.a[274](std-324fdd8d31e8eaa2.std.e18cf7e8d0336778-cgu.08.rcgu.o) "_pwritev64", referenced from: __rust_extern_with_linkage_pwritev64 in libliveview_native_core.a[274](std-324fdd8d31e8eaa2.std.e18cf7e8d0336778-cgu.08.rcgu.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` So I added them. I also went ahead and added the same for visionOS because it's bound to create the same issue.
In #122880, links to
preadv64
andpwritev64
were added forwatchOS
however the underlyingweak!
macro did not includetarget_os = "watchos"
.This resulted in an
xcodebuild
error when targetingwatchOS
:So I added them. I also went ahead and added the same for visionOS because it's bound to create the same issue.