hurd: clean up module#5242
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
I just saw the one thing then noticed the links, are you sure that's the most recent source? Per https://cgit.git.savannah.gnu.org/cgit/hurd/glibc.git/log/?h=t/sysvshm the branch you're linking hasn't been updated since 2021, and none of the branches at https://cgit.git.savannah.gnu.org/cgit/hurd/glibc.git/refs/heads are any newer.
There was a problem hiding this comment.
"hurd: remove duplicate routines": LGTM @ 62ccc91
| #[cfg(target_pointer_width = "32")] | ||
| pub l_type: c_int, | ||
| #[cfg(target_pointer_width = "32")] | ||
| pub l_whence: c_int, | ||
| #[cfg(target_pointer_width = "64")] | ||
| pub l_type: c_short, | ||
| #[cfg(target_pointer_width = "64")] | ||
| pub l_whence: c_short, | ||
| pub l_start: __off_t, | ||
| pub l_len: __off_t, | ||
| pub l_start: off_t, | ||
| pub l_len: off_t, | ||
| pub l_pid: __pid_t, | ||
| } | ||
|
|
||
| pub struct flock64 { | ||
| #[cfg(target_pointer_width = "32")] | ||
| pub l_type: c_int, | ||
| #[cfg(target_pointer_width = "32")] | ||
| pub l_whence: c_int, | ||
| #[cfg(target_pointer_width = "64")] | ||
| pub l_type: c_short, | ||
| #[cfg(target_pointer_width = "64")] | ||
| pub l_whence: c_short, | ||
| pub l_start: __off_t, | ||
| pub l_start: __off64_t, | ||
| pub l_len: __off64_t, | ||
| pub l_pid: __pid_t, |
There was a problem hiding this comment.
"hurd: use gnu_file_offset_bits64 to expose lfs": Is this accurate? Looking at https://github.com/bminor/glibc/blob/04e750e75b73957cf1c791535a3f4319534a52fc/sysdeps/mach/hurd/bits/types/struct_flock.h and https://github.com/bminor/glibc/blob/04e750e75b73957cf1c791535a3f4319534a52fc/sysdeps/mach/hurd/i386/bits/types/struct_flock.h, it looks like c_short is the right type on non-x86-32.
There was a problem hiding this comment.
just reviewed it with the updated glibc sources.
There was a problem hiding this comment.
yes, only i386 is to keep the non-posix-compatible int type for l_type/whence
|
Yeah - the author of #4127 is the lead Hurd developer as I understand it, and that PR links to the regular glibc sourceware repos. I assume that at some point the deviations were resolved and they just switched to developing upstream. @rustbot author since there's probably some things to revisit with that in mind. |
|
Reminder, once the PR becomes ready for a review, use |
There was a problem hiding this comment.
"hurd: deprecate lfs types and routines": Note that like the others, I am not comfortable deprecating the time bindings while users don't have a clean-cut solution.
There was a problem hiding this comment.
so, to a first approximation, how would a clean-cut solution look like?
There was a problem hiding this comment.
I think that what's at #4805 is the best bet, then we can find+replace these back once everything else is ready.
There was a problem hiding this comment.
I'm a bit surprised to see these deprecation warnings indeed, since the Linux port does not have them on its *64 variants.
There was a problem hiding this comment.
Claiming The definitions are equivalent when compiling on a 64bit target is wrong: yes on the 64b target they are equivalent, but then the programmer will migrate to the non-64 version and thusly break the 32bit builds unless gnu_file_offset_bits64 is used. So at most the warnings should be enabled only when the programmer did request for gnu_file_offset_bits64, in which case, yes, using the *64 variants is spurious.
There was a problem hiding this comment.
but again, better do this on all targets (Linux too notably) altogether rather than just Hurd
There was a problem hiding this comment.
those deprecations have now been replaced with comments. they were made before the plan in #4805 had been formulated. now they're just comments tagging some item for future deprecation.
also,
Claiming The definitions are equivalent when compiling on a 64bit target is wrong: yes on the 64b target they are equivalent, but then the programmer will migrate to the non-64 version and thusly break the 32bit builds unless gnu_file_offset_bits64 is used. So at most the warnings should be enabled only when the programmer did request for gnu_file_offset_bits64, in which case, yes, using the *64 variants is spurious.
aren't libc crate users just meant to take care of having the unsuffixed types be used on 64-bit targets, and of having gnu_file_offset_bits64 set on 32-bit targets?
if they're building for multiple targets, surely they must take into account platform differences.
This comment has been minimized.
This comment has been minimized.
6be7cc8 to
7159a66
Compare
|
@rustbot ready |
| pub type __squad_type = crate::__int64_t; | ||
| pub type __uquad_type = crate::__uint64_t; | ||
| pub type __squad_type = __int64_t; | ||
| pub type __uquad_type = __uint64_t; |
| pub struct fpos_t { | ||
| pub __pos: off_t, | ||
| pub __state: __mbstate_t, | ||
| } | ||
|
|
||
| pub struct __mbstate_t { | ||
| pub __count: c_int, | ||
| pub __value: __c_anonymous___mbstate_t___value, | ||
| } |
There was a problem hiding this comment.
"hurd: fill in definition for fpos_t": let's match linux-gnu and keep these fields private, similarly the union.
libc/src/unix/linux_like/linux/gnu/mod.rs
Line 343 in 328f309
There was a problem hiding this comment.
"hurd: add proper handling of lfs": looks pretty reasonable to me but I'd like the maintainer to ack
| cfg_if! { | ||
| if #[cfg(not(gnu_file_offset_bits64))] { | ||
| const STAT__SPARE_SIZE: usize = { | ||
| if size_of::<__fsid_t>() == size_of::<c_int>() { | ||
| 12 | ||
| } else { | ||
| 11 | ||
| } | ||
| }; | ||
| } else { | ||
| const STAT__SPARE_SIZE: usize = { | ||
| if size_of::<__fsid_t>() == size_of::<c_int>() { | ||
| 9 | ||
| } else { | ||
| 8 | ||
| } | ||
| }; | ||
| } | ||
| } |
There was a problem hiding this comment.
"hurd: add proper handling of lfs": nit, you can avoid the cfg-if here and instead do ... : usize = { if cfg!(gnu_file_offset_bits64) && size_of::<__fsid_t>() == size_of::<c_int>() { ... } to save a nesting.
Also, looks like there's an extra _ between STAT and SPARE (unless this is in the source?)
There was a problem hiding this comment.
done.
the identifier upstream is simply _SPARE_SIZE. i decided to add another underscore because there's already a "canonical" underscore used for separation between STAT and the actual identifier. considering this is not a public symbol, i decided to opt out of making it match upstream.
| pub st_spare: [c_int; 8usize], | ||
| st_spare: Padding< | ||
| [c_int; if size_of::<__fsid_t>() == size_of::<c_int>() { | ||
| 9 | ||
| } else { | ||
| 8 | ||
| }], | ||
| >, |
There was a problem hiding this comment.
"hurd: add proper handling of lfs": just put this in a const STAT64_SPARE_SIZE like the other, in case we need to reuse that value
| bits: [u32; 32], | ||
| #[cfg(not(all(target_pointer_width = "32", not(target_arch = "x86_64"))))] | ||
| bits: [u64; 16], | ||
| __bits: [__cpu_mask; 1024 / (8 * size_of::<__cpu_mask>())], |
There was a problem hiding this comment.
"hurd: adjust cpu_set_t definition": use __CPU_SETSIZE and __NCPUBITS intermediates like they do rather than hardcoding, just as nonpublic constants.
There was a problem hiding this comment.
decided i would make them public. __CPU_SETSIZE was already public before this pr so i made __NCPUBITS also public.
There was a problem hiding this comment.
"hurd: remove duplicate definitions": lgtm @ 8b36f4b
|
@rustbot author |
|
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, it's not.... The last commit there was 6 years ago... |
| pub st_fstype: c_int, | ||
| pub st_dev: __fsid_t, /* Actually st_fsid */ | ||
| pub st_ino: __ino_t, | ||
| pub st_fsid: __fsid_t, |
There was a problem hiding this comment.
No, we really want st_dev here, to match what the rest of the world expects. st_fsid is the real name in the structure, but st_dev is an alias for it, and that's what people expect. See #3785
|
|
||
| pub fn dirfd(dirp: *mut crate::DIR) -> c_int; | ||
|
|
||
| #[link_name = "__xpg_strerror_r"] |
There was a problem hiding this comment.
Why dropping this?
See https://sourceware.org/git/?p=glibc.git;a=blob;f=string/string.h;h=743395b3e3b2dd52194b1a6b8c34df4f8b56d8a1;hb=HEAD#l464 and linux does the same (except on musl, which is not ported to GNU/Hurd)
There was a problem hiding this comment.
did that because that one declaration exists when !__USE_GNU 1, but throughout the libc crate there's definitions affecting the hurd which assume __USE_GNU.
Footnotes
There was a problem hiding this comment.
assuming gnu functions are available is not the same as assuming that it's the gnu behavior that is desired.
Really, the linux crate does use the xpg redirection: https://github.com/rust-lang/libc/blob/main/src/unix/linux_like/linux_l4re_shared.rs#L1699 , and thus programs expect the xpg behavior, not the gnu behavior.
There was a problem hiding this comment.
i still don't get it. the linux definitions don't affect the hurd but i'm assuming you mean that as an example. why should we provide bindings to the non-gnu version if we have assumed otherwise in other parts of the codebase? granted, the current signature would have to change to that of the gnu version, but that can be readily done as we should be capable of breaking the api on tier 3 targets.
|
|
||
| #[cfg_attr( | ||
| all(gnu_time_bits64, not(gnu_file_offset_bits64)), | ||
| link_name = "__glob64_time64" |
There was a problem hiding this comment.
? this doesn't match the conditions of https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/glob.h;h=4c824eb0d30ec557f9c5d5e1d85d823e1a1900c6;hb=HEAD#l158
And note that GNU/Hurd doesn't define __USE_TIME64_REDIRECTS
There was a problem hiding this comment.
fixed. there's one thing to note, though: we recently made it so that our cfgs to handle redirects of time64 and fileoffset64 could not be set separately (though at present we only issue a warning at compile time.) this may conflict with the behavior in upstream glibc where you seem to be capable of opting into one or the other.
|
|
||
| #[cfg_attr( | ||
| all(gnu_time_bits64, not(gnu_file_offset_bits64)), | ||
| link_name = "__globfree64_time64" |
There was a problem hiding this comment.
|
|
||
| #[cfg_attr( | ||
| all(gnu_time_bits64, not(gnu_file_offset_bits64)), | ||
| link_name = "__glob64_time64" |
There was a problem hiding this comment.
| pub fn globfree64(pglob: *mut glob64_t); | ||
| #[cfg_attr( | ||
| all(gnu_time_bits64, not(gnu_file_offset_bits64)), | ||
| link_name = "__globfree64_time64" |
There was a problem hiding this comment.
|
Thanks for this work! I'd rather actually test this natively before letting it merged, unfortunately I won't have time to do this before at least tuesday. |
| pub type timezone; | ||
| } | ||
|
|
||
| const STAT__SPARE_SIZE: usize = { |
There was a problem hiding this comment.
it's a bit sad to make these far from the structure that uses it. Is it not possible to embed the condition in the structure itself? for instance by emitting several st_spare definitions, each conditioned appropriately. We don't really strictly need to define a STAT__SPARE_SIZE condition just to mimick what glibc uses, _SPARE_SIZE is not part of the API.
There was a problem hiding this comment.
those constants weren't public anyway. i've inlined the logic in the structure now.
i forgot to update the pr description, but i was also told about that little after submitting the patches so the current state should reflect upstream glibc. |
add gnu/hurd definition and skip the opaque type definition in the top-level unix module. the definition fits that of [^1]. [^1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=libio/bits/types/__fpos_t.h;h=bb04576651b9097b3027e4299cc30c88f334535f;hb=b5eecf35d91a3b29cff80b731bbc6bcce6863827
add uses of the gnu_file_offset_bits64 cfg to the hurd module. gnu/hurd systems use glibc and that includes both the file offset and time_t feature test macros. this patch ensures the right definition is exposed on 64-unsuffixed types. affected records don't directly use the cfg to define their fields conditionally. they instead use the types not prefixed with two underscores to define their fields. these types are themselves conditionally defined. this avoids cluttering both the type alias definition and the record definition.
modify definition of cpu_set_t to use the same constant expression as used upstream [^1]. this resolves to the same values as before but relies on the conditional definition of the type __cpu_mask is defined in terms of. [^1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/bits/cpu-set.h;h=ddb79cefc2e5d93003f8da84eca6302f99153a22;hb=b5eecf35d91a3b29cff80b731bbc6bcce6863827
remove routines bindings that were already present in the unix module. those in the top-level unix module were already outfit with the corresponding link name redirection under one of gnu_file_offset_bits64 or gnu_time_bits64. they have been preferred over those in the hurd submodule.
add deprecation notices to glob64_t and 64-suffixed routines. the bindings we expose have no difference whatsoever between glob_t and glob64_t. the fields that are different between those two we just have as void pointers.
add deprecation notice to fallocate64 because this routine is only exposed under linux in glibc [^1]. [^1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/fcntl-linux.h;h=587b815124318864320973b864899b19466e46b8;hb=HEAD#l450
add comments annotating file offset types and routines whose identifier is 64-suffixed as slated for deprecation and eventual removal. this holds only for 64-bit targets, so the comment adds a "parameter" to the comment that will be found+replaced with a deprecation attribute later on. these types otherwise provide redundant definitions.
Description
This PR consists of an overall clean up of the GNU Hurd module. It adds proper handling of types and routines when
_USE_FILE_OFFSET64is defined by using the existinggnu_file_offset_bits64cfg. It also fixes a type definition and more closely mirrors those of upstream.It also adds a number of future deprecation annotations. These apply only to 64-bit targets on type aliases. They apply to both 64-bit targets and any target with the afore mentioned
cfgset in the case of certain records.Finally, there were some routines that were duplicated in both the
unixmodule and theunix/hurdmodule. These have ben removed off of the latter. This decision was made because theunixmodule's definitions already included the right link name redirection for bindings where the actual identifier is the 64-bit suffixed one.Sources
Checklist
libc-test/semverhave been updated*LASTor*MAXare included (see #3131)cd libc-test && cargo test --target mytarget); especially relevant for platforms that may not be checked in CI@rustbot label +stable-nominated