Skip to content
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

use posix_memalign on almost all Unix targets #125271

Merged
merged 2 commits into from
May 25, 2024

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented May 19, 2024

Seems nice to be able to use a single common codepath for all of them. :) The libc crate says this symbol exists for all Unix targets. I did locally do check-builds to ensure this still builds, but I can't really test more than that.

  • For redox, I found indications posix_memalign really exists here
  • For esp-idf, I found indications here
  • For horizon and vita (these seem to be gaming console OSes? "Horizon OS" also has some hits for a Facebook product but that seems unrelated), they seem to be based on "newlib", where posix_memalign seems to exist. Turns out no, this 20-year-old standard POSIX function is unfortunately not supported here.

@rustbot
Copy link
Collaborator

rustbot commented May 19, 2024

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 19, 2024
@RalfJung
Copy link
Member Author

Pinging some of the people listed for these targets, just for awareness.
Cc @ivmarkov @Meziu @nikarh

@workingjubilee
Copy link
Contributor

For horizon and vita

"Horizon" is the name of the Nintendo Switch's system software.

The Vita is just the Vita.

@Meziu
Copy link
Contributor

Meziu commented May 19, 2024

"Horizon" is the name of the Nintendo Switch's system software.

Horizon also refers to the Nintendo 3DS' firmware/OS. This is actually what (almost) all references of target_os = "horizon" within std are related to, since (afaik) there are no Nintendo Switch targets with std support, but there is an armv6k-nintendo-3ds target with std support.

And yes, Meta did name their Android-VR operating system with the exact same name, but I guess the name wasn't ever marketed with regards to the consoles.

Edit: mentioning @ian-h-chamberlain @AzureMarker for good measure.

@nikarh
Copy link
Contributor

nikarh commented May 19, 2024

Hi, Vita target does not implement posix_memalign.

where posix_memalign seems to exist.

It's gated in the header under __POSIX_VISIBLE and implementation is per platform. Vita doesn't have an implementation for it. Same seems to be true for horizon.

See

@RalfJung
Copy link
Member Author

RalfJung commented May 19, 2024

Ah, damn. :/ Is there an issue tracker where one could ask for better POSIX coverage?

EDIT: I guess that's the mailing list mentioned here.

@RalfJung
Copy link
Member Author

RalfJung commented May 19, 2024

Ironically, "winsup" has posix_memalign.

Also ironically, it does have aligned_alloc. However, looking at the implementation, it seems to make non-power-of-two alignments be UB, which violates the C18 and C23 standards. So maybe we should stay away from that, who knows which other issues it has. (Also it's not supported by libc, so using memalign avoids us having to carry our own declaration.)

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label May 19, 2024
@rustbot

This comment was marked as resolved.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 19, 2024
@RalfJung RalfJung changed the title use posix_memalign on all Unix targets use posix_memalign on almost all Unix targets May 19, 2024
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 19, 2024
@workingjubilee
Copy link
Contributor

"Horizon" is the name of the Nintendo Switch's system software.

Horizon also refers to the Nintendo 3DS' firmware/OS. This is actually what (almost) all references of target_os = "horizon" within std are related to, since (afaik) there are no Nintendo Switch targets with std support, but there is an armv6k-nintendo-3ds target with std support.

Oh, right! We could probably use comments in our code or the platform support documentation to that effect. It is possible these already exist and I just missed it.

Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
@workingjubilee
Copy link
Contributor

To motivate requests like Ralf's somewhat for the target maintainers:

Ah, damn. :/ Is there an issue tracker where one could ask for better POSIX coverage?

People have been implementing more shims for Miri. The more the stdlib flows through standard, well-specified functions, the more Miri doesn't have to have a huge pile of ridiculous hacks. This allows even code for more... interesting platforms, that do basic interop with the system (we're not gonna be simulating games with full rendering to a framebuffer, here...) to benefit from Miri's ability to execute code on the Rust Abstract Machine, either simply as a (slow, but effective) virtual machine, or for its ability to detect violated invariants. Thus if you rely on an upstream C library, and that C library can be persuaded to gain (or simply PRed) extended support for "core" POSIX or Standard C functions... conformant support... this can reduce the amount of maintenance everyone has to do in the future, by making it easier to debug problems with your platform.

Correctly-aligned allocations are pretty important, since people can request arbitrary layouts are allocated with Rust code. They do use that to good effect, and it turns out that posix_memalign is the high-align alloc everyone actually supports pretty well.

@workingjubilee
Copy link
Contributor

Hm, aligned_alloc being UB on bad alignments was permitted by C11, apparently, but C17 corrected this and the return value must be the NULL pointer instead.

@workingjubilee
Copy link
Contributor

Okie-dokie, had been giving it a few days to see if any of the other pinged maintainers had something to say, but we have harder evidence for the Redox and Espressif changes being correct and tier 3 is alas tier 3. Rolling ahead with this.

@bors r+

@bors
Copy link
Contributor

bors commented May 24, 2024

📌 Commit 3c2d9c2 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 24, 2024
@workingjubilee
Copy link
Contributor

@bors rollup

workingjubilee added a commit to workingjubilee/rustc that referenced this pull request May 25, 2024
…jubilee

use posix_memalign on almost all Unix targets

Seems nice to be able to use a single common codepath for all of them. :) The `libc` crate says this symbol exists for all Unix targets. I did locally do check-builds to ensure this still builds, but I can't really test more than that.

- For redox, I found indications posix_memalign really exists [here](https://gitlab.redox-os.org/redox-os/relibc/-/merge_requests/271)
- For esp-idf, I found indications [here](playable-tech/esp-idf@c5b297a)
- ~~For horizon and vita (these seem to be gaming console OSes? "Horizon OS" also has some hits for a Facebook product but that seems unrelated), they seem to be based on "newlib", where posix_memalign [seems to exist](https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=3ba2c39fb2a12cd7332ef16b1b3e3df994f7c6f5).~~ Turns out no, this 20-year-old standard POSIX function is unfortunately [not supported](rust-lang#125271 (comment)) here.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 25, 2024
…kingjubilee

Rollup of 9 pull requests

Successful merges:

 - rust-lang#124080 (Some unstable changes to where opaque types get defined)
 - rust-lang#125271 (use posix_memalign on almost all Unix targets)
 - rust-lang#125433 (A small diagnostic improvement for dropping_copy_types)
 - rust-lang#125498 (Stop using the avx512er and avx512pf x86 target features)
 - rust-lang#125510 (remove proof tree formatting, make em shallow)
 - rust-lang#125513 (Don't eagerly monomorphize drop for types that are impossible to instantiate)
 - rust-lang#125514 (Structurally resolve before `builtin_index` in EUV)
 - rust-lang#125515 ( bootstrap: support target specific config overrides )
 - rust-lang#125527 (Add manual Sync impl for ReentrantLockGuard)

r? `@ghost`
`@rustbot` modify labels: rollup
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request May 25, 2024
…jubilee

use posix_memalign on almost all Unix targets

Seems nice to be able to use a single common codepath for all of them. :) The `libc` crate says this symbol exists for all Unix targets. I did locally do check-builds to ensure this still builds, but I can't really test more than that.

- For redox, I found indications posix_memalign really exists [here](https://gitlab.redox-os.org/redox-os/relibc/-/merge_requests/271)
- For esp-idf, I found indications [here](playable-tech/esp-idf@c5b297a)
- ~~For horizon and vita (these seem to be gaming console OSes? "Horizon OS" also has some hits for a Facebook product but that seems unrelated), they seem to be based on "newlib", where posix_memalign [seems to exist](https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=3ba2c39fb2a12cd7332ef16b1b3e3df994f7c6f5).~~ Turns out no, this 20-year-old standard POSIX function is unfortunately [not supported](rust-lang#125271 (comment)) here.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 25, 2024
…kingjubilee

Rollup of 7 pull requests

Successful merges:

 - rust-lang#125271 (use posix_memalign on almost all Unix targets)
 - rust-lang#125433 (A small diagnostic improvement for dropping_copy_types)
 - rust-lang#125498 (Stop using the avx512er and avx512pf x86 target features)
 - rust-lang#125510 (remove proof tree formatting, make em shallow)
 - rust-lang#125513 (Don't eagerly monomorphize drop for types that are impossible to instantiate)
 - rust-lang#125514 (Structurally resolve before `builtin_index` in EUV)
 - rust-lang#125527 (Add manual Sync impl for ReentrantLockGuard)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request May 25, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#125271 (use posix_memalign on almost all Unix targets)
 - rust-lang#125451 (Fail relating constants of different types)
 - rust-lang#125478 (Bump bootstrap compiler to the latest beta compiler)
 - rust-lang#125498 (Stop using the avx512er and avx512pf x86 target features)
 - rust-lang#125510 (remove proof tree formatting, make em shallow)
 - rust-lang#125513 (Don't eagerly monomorphize drop for types that are impossible to instantiate)
 - rust-lang#125514 (Structurally resolve before `builtin_index` in EUV)
 - rust-lang#125527 (Add manual Sync impl for ReentrantLockGuard)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f28d368 into rust-lang:master May 25, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 25, 2024
Rollup merge of rust-lang#125271 - RalfJung:posix_memalign, r=workingjubilee

use posix_memalign on almost all Unix targets

Seems nice to be able to use a single common codepath for all of them. :) The `libc` crate says this symbol exists for all Unix targets. I did locally do check-builds to ensure this still builds, but I can't really test more than that.

- For redox, I found indications posix_memalign really exists [here](https://gitlab.redox-os.org/redox-os/relibc/-/merge_requests/271)
- For esp-idf, I found indications [here](playable-tech/esp-idf@c5b297a)
- ~~For horizon and vita (these seem to be gaming console OSes? "Horizon OS" also has some hits for a Facebook product but that seems unrelated), they seem to be based on "newlib", where posix_memalign [seems to exist](https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=3ba2c39fb2a12cd7332ef16b1b3e3df994f7c6f5).~~ Turns out no, this 20-year-old standard POSIX function is unfortunately [not supported](rust-lang#125271 (comment)) here.
@RalfJung RalfJung deleted the posix_memalign branch May 28, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix Operating system: Unix-like S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants