-
Notifications
You must be signed in to change notification settings - Fork 1.2k
netbsd/riscv64.rs: make changes so that this builds again. #4886
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
Conversation
...to something which also passes the upstream automated checks. Pull request submitted at rust-lang/libc#4886
|
Not sure how those two failing CI jobs can be related to my proposed changes... |
This comment has been minimized.
This comment has been minimized.
…finition. This is already part of pull request rust-lang#4886 which is yet to be applied.
Evidently caused by what I had not done (merged upstream 'main' branch into mine). |
tgross35
left a comment
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.
Sorry for the breakage, thank you for the PR!
| s_no_extra_traits! { | ||
| pub union __fpreg { | ||
| pub u_u64: u64, | ||
| pub u_d: c_double, | ||
| impl core::cmp::PartialEq for __fpreg { | ||
| fn eq(&self, other: &__fpreg) -> bool { | ||
| unsafe { self.u_u64 == other.u_u64 || self.u_d == other.u_d } | ||
| } | ||
| } | ||
|
|
||
| cfg_if! { | ||
| if #[cfg(feature = "extra_traits")] { | ||
| impl PartialEq for __fpreg { | ||
| fn eq(&self, other: &Self) -> bool { | ||
| unsafe { self.u_u64 == other.u_u64 } | ||
| } | ||
| impl core::cmp::Eq for __fpreg {} | ||
| impl core::marker::Copy for __fpreg {} | ||
| impl core::clone::Clone for __fpreg { | ||
| fn clone(&self) -> __fpreg { | ||
| *self | ||
| } | ||
| } | ||
| impl hash::Hash for __fpreg { | ||
| fn hash<H: hash::Hasher>(&self, state: &mut H) { | ||
| unsafe { | ||
| self.u_u64.hash(state); | ||
| } | ||
| impl Eq for __fpreg {} | ||
| impl hash::Hash for __fpreg { | ||
| fn hash<H: hash::Hasher>(&self, state: &mut H) { | ||
| unsafe { self.u_u64.hash(state) }; | ||
| } | ||
| } | ||
| } | ||
| impl core::fmt::Debug for __fpreg { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| unsafe { | ||
| f.debug_struct("__fpreg") | ||
| .field("u_u64", &self.u_u64) | ||
| .field("u_d", &self.u_d) | ||
| .finish() |
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.
Could you add back the s_no_extra_traits and cfg wrappers for __fpreg? You can just make it match
libc/src/unix/linux_like/linux/gnu/b64/s390x.rs
Lines 218 to 241 in 0a5a8b6
| s_no_extra_traits! { | |
| pub union fpreg_t { | |
| pub d: c_double, | |
| pub f: c_float, | |
| } | |
| } | |
| cfg_if! { | |
| if #[cfg(feature = "extra_traits")] { | |
| impl PartialEq for fpreg_t { | |
| fn eq(&self, _other: &fpreg_t) -> bool { | |
| unimplemented!("traits") | |
| } | |
| } | |
| impl Eq for fpreg_t {} | |
| impl hash::Hash for fpreg_t { | |
| fn hash<H: hash::Hasher>(&self, _state: &mut H) { | |
| unimplemented!("traits") | |
| } | |
| } | |
| } | |
| } |
| pub(crate) const _ALIGNBYTES: usize = size_of::<c_long>() - 1; | ||
| pub(crate) const _ALIGNBYTES: usize = 0xf; |
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.
Do you have a source for this? Per https://github.com/NetBSD/src/blob/29216014b5d25ec3b457bbca2bb2bc6a80d7a1fd/sys/arch/riscv/include/cdefs.h#L6 it looks like the existing definition is correct.
(If you could add source links to the PR description for all changes here, that would be great)
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 could still use some context here
|
Reminder, once the PR becomes ready for a review, use |
| if #[cfg(feature = "extra_traits")] { | ||
| impl PartialEq for __fpreg { | ||
| fn eq(&self, other: &Self) -> bool { | ||
| unsafe { self.u_u64 == other.u_u64 } | ||
| impl core::cmp::PartialEq for __fpreg { | ||
| fn eq(&self, other: &__fpreg) -> bool { | ||
| unsafe { self.u_u64 == other.u_u64 || self.u_d == other.u_d } | ||
| } | ||
| } | ||
| impl core::cmp::Eq for __fpreg {} | ||
| impl core::marker::Copy for __fpreg {} | ||
| impl core::clone::Clone for __fpreg { | ||
| fn clone(&self) -> __fpreg { | ||
| *self | ||
| } | ||
| } | ||
| impl Eq for __fpreg {} | ||
| impl hash::Hash for __fpreg { | ||
| fn hash<H: hash::Hasher>(&self, state: &mut H) { | ||
| unsafe { self.u_u64.hash(state) }; | ||
| unsafe { | ||
| self.u_u64.hash(state); | ||
| } | ||
| } | ||
| } | ||
| impl core::fmt::Debug for __fpreg { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| unsafe { | ||
| f.debug_struct("__fpreg") | ||
| .field("u_u64", &self.u_u64) | ||
| .field("u_d", &self.u_d) | ||
| .finish() | ||
| } | ||
| } | ||
| } |
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.
You should verify this builds with --features extra_traits. s_no_extra_traits adds a Clone, Copy, and Debug impl so I suspect it will fail.
| impl core::cmp::PartialEq for __fpreg { | ||
| fn eq(&self, other: &__fpreg) -> bool { | ||
| unsafe { self.u_u64 == other.u_u64 || self.u_d == other.u_d } | ||
| } | ||
| } | ||
| impl core::cmp::Eq for __fpreg {} | ||
| impl core::marker::Copy for __fpreg {} | ||
| impl core::clone::Clone for __fpreg { |
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.
No need to add the core::cmp prefix, it's in libc's prelude
| impl PartialEq for __fpreg { | ||
| fn eq(&self, other: &Self) -> bool { | ||
| unsafe { self.u_u64 == other.u_u64 } | ||
| impl core::cmp::PartialEq for __fpreg { | ||
| fn eq(&self, other: &__fpreg) -> bool { | ||
| unsafe { self.u_u64 == other.u_u64 || self.u_d == other.u_d } | ||
| } | ||
| } |
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.
Leave this body as-is, not having a false positive for ints is more important than indicating the -0==0 case for floats. Also matches other similar impls.
Or replace it with unimplemented! like the source I linked, these traits exist to fit in API signatures but they're going away in 1.0.
| pub(crate) const _ALIGNBYTES: usize = size_of::<c_long>() - 1; | ||
| pub(crate) const _ALIGNBYTES: usize = 0xf; |
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 could still use some context here
Oh? I thought I quoted from the gcc sources to adequatly address this. But to repeat in another way: Gcc's riscv.h file (https://github.com/NetBSD/src/blob/trunk/external/gpl3/gcc/dist/gcc/config/riscv/riscv.h line 213) However, this is measured in bits, and gets converted to the predefined which ends up as 16. This results in an (from |
|
Did you mean the comment in 7b39a6f? I did see that but a source link still helps in case there's nuance to be aware of. Makes sense though, that's the same source I linked but I incorrectly assumed If you could instead change to pub(crate) const __BIGGEST_ALIGNMENT__: usize = 128;
pub(crate) const _ALIGNBYTES: usize = __BIGGEST_ALIGNMENT__ - 1;I think that would be best since it mirrors the source. |
Actually, no, that is wrong. Internally in gcc, I assume I don't need to comment the literal 8... |
tgross35
left a comment
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.
Forgot to mention the division but that's what I meant. Thanks for the updates, LGTM but could you please squash?
42f0450 to
ac428c7
Compare
This comment has been minimized.
This comment has been minimized.
OK. I tried, but not only am I a rust newbie, I'm evidently also a git newbie, so what I thought would be one commit ended up as two for some reason or other. Do you want me to make another stab at squashing them back to one? |
ac428c7 to
ef16e3e
Compare
* Use the same type names as used by the native libc, to allow
more self-tests to succeed
* Remove un-needed imports, uncovered by libc's "cargo test"
* Compute _ALIGNBYTES the same way gcc does.
Verified by
* Running (and passing) the libc self-tests "natively"
on an emulated NetBSD/riscv64 system.
* Cross-built rust 1.92.0 with this file in place for riscv64
in the vendored libc-0.2.17{5,6,7} versions, targeting
NetBSD/riscv64.
[ extracted this commit from the two in the PR - Trevor ]
ef16e3e to
8005136
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
No worries, I took care of it :) it looks like you squashed the __pthread_spin_t commit with one of this PR's commits then squashed the rest , but the pthread bit was already applied as d4dd6d8. For reference I just re-split the commits into pthread and the rest ( Thanks for the patch! |
Description
These are changes which appear to be required to get this file to build (and cross-build) again.
Admittedly, some of the additions are based on error messages emitted by the rustc compiler.
Sources
Checklist
libc-test/semverhave been updated*LASTor*MAXareincluded (see #3131)
cd libc-test && cargo test --target mytarget);especially relevant for platforms that may not be checked in CI