Skip to content

Resolve preadv/pwritev as weak symbols on Android - #5212

Merged
RalfJung merged 1 commit into
rust-lang:masterfrom
Joel-Wwalker:5080-android-fs
Jul 18, 2026
Merged

RalfJung merged 1 commit into
rust-lang:masterfrom
Joel-Wwalker:5080-android-fs

Conversation

@Joel-Wwalker

@Joel-Wwalker Joel-Wwalker commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

std on Android does vectored reads and writes at offsets through weak preadv/pwritev symbols with a raw syscall fallback (bionic gained them in API level 24). The weak symbols did not resolve under Miri, so these calls failed. Register them for Android so they land in the existing shims, and un-skip the Android case in the fs tests.

This is the vectored I/O half of #5080. The fs::hard_link half is being handled by rust-lang/rust#159346, which switches std to linkat on Android; Miri already supports linkat.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Jul 17, 2026
@RalfJung

Copy link
Copy Markdown
Member

Thanks!

Are you an Android expert? Maybe you can help with my question in rust-lang/rust#159346 (which would make the link part of this PR unnecessary).

@RalfJung RalfJung left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round of high-level comments.
@rustbot author

View changes since this review

Comment thread src/shims/unix/foreign_items.rs Outdated
let result = this.symlink(target, linkpath)?;
this.write_scalar(result, dest)?;
}
"link" => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this behaves different on different Unixes regarding how it deals with symlinks. On Linux it behaves like fs::hard_link but on other Unixes it may not. So please make this shim only available for "Linux-like" targets (Linux, Android), and add a comment also giving a citation for why this is the right symlink behavior.

That'll also fix the Solaris-related CI failure.

Comment thread src/shims/unix/android/foreign_items.rs Outdated
matches!(name, "gettid")
// `preadv`/`pwritev` are accessed via `weak!` linkage by std since bionic
// only gained them in API level 24.
matches!(name, "gettid" | "preadv" | "pwritev")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the "preadv" | "pwritev" cases into the is_dyn_sym function in the file that defines these symbols.

@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Jul 17, 2026
@rustbot

rustbot commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: Waiting for the PR author to address review comments label Jul 17, 2026
@RalfJung

Copy link
Copy Markdown
Member

Given the discussion in rust-lang/rust#159346, please remove the link support as it seems we'll start using linkat on Android reasonably soon.

@Joel-Wwalker Joel-Wwalker changed the title Add link shim and Android weak preadv/pwritev Resolve preadv/pwritev as weak symbols on Android Jul 17, 2026
@Joel-Wwalker

Copy link
Copy Markdown
Contributor Author

Done: removed the link shim and its test, and moved the preadv/pwritev cases into is_dyn_sym in unix/foreign_items.rs. The hard_link test stays skipped on Android until the linkat change reaches Miri's rustc pin; I left a comment in the test pointing at rust-lang/rust#159346.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Jul 17, 2026

@RalfJung RalfJung left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor nits, thanks :)
@rustbot author

View changes since this review

Comment thread src/shims/unix/foreign_items.rs Outdated
// `preadv`/`pwritev` are set up as weak symbols in `init_extern_statics` (on Android,
// where std uses them via `weak!` since bionic only gained them in API level 24), so
// we allow them here too.
"preadv" | "pwritev" => true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should exclude solaris where the functions do not exist

Comment thread tests/pass/shims/fs.rs Outdated
Comment on lines +54 to +55
// std uses `libc::link` on Android, which Miri does not implement;
// rust-lang/rust#159346 switches std to `linkat`, and then this cfg can go.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment will conflict with my PR where I am removing the cfg. ;)

So I think it's better to just not touch the hard_link parts here and avoid conflicts.

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Jul 17, 2026
@Joel-Wwalker

Copy link
Copy Markdown
Contributor Author

Both done: excluded Solaris from the preadv/pwritev dyn-syms, and reverted the test_hard_link changes so that part is untouched. Thanks!

@RalfJung

Copy link
Copy Markdown
Member

This looks great, thanks! Please squash the commits. You can squash manually if there are multiple independent commits you want to preserve, or use ./miri squash (make sure to pick a suitable commit message). Then write @rustbot ready after you force-pushed the squashed PR.

@rustbot author

std on Android does vectored I/O at offsets through weak
preadv/pwritev symbols with a raw syscall fallback (bionic gained
them in API level 24). The weak symbols did not resolve under Miri,
so these calls failed. Register them for Android so they land in the
existing shims, and un-skip the Android case in the fs tests.
@Joel-Wwalker

Copy link
Copy Markdown
Contributor Author

Squashed. @rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Jul 18, 2026
@RalfJung
RalfJung enabled auto-merge July 18, 2026 07:23
@RalfJung
RalfJung added this pull request to the merge queue Jul 18, 2026
Merged via the queue into rust-lang:master with commit 0fd5460 Jul 18, 2026
14 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Jul 18, 2026
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

Successfully merging this pull request may close these issues.

3 participants