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

Rebase of "Upgrade musl supported version to 1.2.3" #3791

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

myl7
Copy link

@myl7 myl7 commented Aug 5, 2024

Also discussed in GSoC Zulip. Related: GSoC Idea OSPP Idea OSPP Zulip.

This PR is mainly the rebase of #3068 . So closes #3068 fixes #1848 closes #2088 .
Some other changes are made:

  • Fix warnings in CI by setting several #[allow(unused_imports)].

For the checklist for review or CI, as the original PR should have passed it, this PR only makes sure ci/style.sh and cd libc-test && cargo test pass

@rustbot
Copy link
Collaborator

rustbot commented Aug 5, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @JohnTitor (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot
Copy link
Collaborator

rustbot commented Aug 5, 2024

Some changes occurred in solarish module

cc @jclulow, @pfmooney

Some changes occurred in OpenBSD module

cc @semarie

Some changes occurred in OpenBSD module

cc @semarie

@semarie
Copy link
Contributor

semarie commented Aug 5, 2024

FYI, no problem on OpenBSD side

@myl7 myl7 force-pushed the musl branch 2 times, most recently from c45a829 to 0185395 Compare August 5, 2024 11:43
@myl7 myl7 changed the title Draft: Modernize the libc crate Rebase of "Upgrade musl supported version to 1.2.3" Aug 5, 2024
@tgross35
Copy link
Contributor

tgross35 commented Aug 12, 2024

Could you please rebase once #3797 lands? (Hopefully ~1 hour). You will need to drop 2852809 and eb4c4b2.

@bors
Copy link
Contributor

bors commented Aug 12, 2024

☔ The latest upstream changes (presumably #3797) made this pull request unmergeable. Please resolve the merge conflicts.

@tgross35
Copy link
Contributor

@rustbot author

danielframpton and others added 14 commits August 17, 2024 11:33
musl 1.1 maintenance has for all practical purposes ended.  Accordingly, there is
no point in supporting both 1.1 and 1.2 in the libc crate, so follow the
time_t type transition to 64-bit.
- add padding members for musl 1.2
- ensure the padding members have an appropriate type (always c_int)
Only some 32-bit targets use the time64 family of functions and that set
will not change going forward (new 32-bit targets added will use Y2038
compliant syscalls and types by default).

This patch introduces a cfg flag that controls when the time64 abi
related changes are enabled and sets that flag from libc and libc-tests'
build.rs files.
@myl7
Copy link
Author

myl7 commented Aug 17, 2024

Glad to see most pass!

The only failure of wasm32-unknown-emscripten is because some code generated by ctest2 does not add struct prefix to struct names.
However, it should be added according to:

t if is_struct => format!("struct {}", t),

Not sure how to resolve it.

@bors
Copy link
Contributor

bors commented Aug 27, 2024

☔ The latest upstream changes (presumably #3869) made this pull request unmergeable. Please resolve the merge conflicts.

@tgross35
Copy link
Contributor

Are you able to just skip the type with a fixme? I think we have emscripten-specific ignores already. Also not sure why this would be happening, but I am really hoping we don't need to block this on ctest changes.

@tgross35
Copy link
Contributor

Also @kaniini I think you had some ideas about how to do musl better here. If you get a chance, would you mind taking a look at this?

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

I didn't check all the types in depth yet but this looks good at first glance. Please address the feedback (specifically linux_time_bits64) and then I think we can get this in soon.

@@ -17,6 +17,7 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"libc_const_extern_fn",
"libc_const_extern_fn_unstable",
"libc_deny_warnings",
"musl_time64_abi",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be renamed to musl_redir_time64?

Musl uses _REDIR_TIME64 in their source, I think the name is a bit more intuitive because only 32-bit does these hacks (64-bit always has the 64-bit time interface).

Comment on lines +224 to +241
fn is_musl_time64_abi() -> bool {
match env::var("TARGET") {
Ok(target) => match &target[..] {
"arm-unknown-linux-musleabi"
| "arm-unknown-linux-musleabihf"
| "armv5te-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabihf"
| "i586-unknown-linux-musl"
| "i686-unknown-linux-musl"
| "mips-unknown-linux-musl"
| "mipsel-unknown-linux-musl"
| "powerpc-unknown-linux-musl" => true,
_ => false,
},
Err(_) => false,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably shouldn't match literal targets here since we only care about the prefix and the suffix. Instead could we:

  • Add const TARGET_PREFIXES_32BIT: &[&str] = &[/* ... */]; that contains arm-, i586-, etc
  • Add const MUSL_SUFFIXES : &[&str] = &[/* ... */]; with -musleabi, -musl, etc
  • Add fn target_is_32bit(target: &str) -> bool that checks if it starts if target starts with any of TARGET_PREFIXES_32BIT. Then we can reuse it with the GNU change.
  • Add fn target_is_musl(target: &str) -> bool that does the same with the suffixes
  • Add fn target_is_linux(target: &str) -> bool that checks if it contains -linux-
  • Check these three functions in order to set musl_redir_time64/musl_time64_abi

Comment on lines +3304 to +3320
// Some targets use time64 symbols so set the musl_time64_abi appropriately.
// See #2088 and #1848 for more information.
match target {
"arm-unknown-linux-musleabi"
| "arm-unknown-linux-musleabihf"
| "armv5te-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabi"
| "armv7-unknown-linux-musleabihf"
| "i586-unknown-linux-musl"
| "i686-unknown-linux-musl"
| "mips-unknown-linux-musl"
| "mipsel-unknown-linux-musl"
| "powerpc-unknown-linux-musl" => {
cfg.cfg("musl_time64_abi", None);
}
_ => {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this in build.rs if it's set automatically by our crate's build script?

// Some ABIs need to redirect time related symbols to their time64
// equivalents. See #2088 and #1848 for more information.
if is_musl_time64_abi() {
set_cfg("musl_time64_abi");
Copy link
Contributor

Choose a reason for hiding this comment

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

We should set two separate configs here:

  • musl_redir_time64 (musl_time64_abi) which corresponds to musl's _REDIR_TIME64
  • linux_time_bits64 which corresponds to __USE_TIME_BITS64 in uapi

We need this to be split because musl and glibc share the kernel uapi

Comment on lines +325 to 330
#[cfg(musl_time64_abi)]
pub input_event_sec: ::c_ulong,
#[cfg(musl_time64_abi)]
pub input_event_usec: ::c_ulong,
#[cfg(not(musl_time64_abi))]
pub time: ::timeval,
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned above this should make use of linux_time_bits64. Specifically to match https://github.com/torvalds/linux/blob/bf9aa14fc523d2763fc9a10672a709224e8fcaf4/include/uapi/linux/input.h#L29 it could be:

#[cfg(any(target_pointer_width = "64", not(linux_time_bits64))]
pub time: ::timeval,

#[cfg(not(any(target_pointer_width = "64", not(linux_time_bits64)))]
pub input_event_sec: ::c_ulong,
#[cfg(all(not(any(target_pointer_width = "64", not(linux_time_bits64))), target_arch = "sparc64")]
pub input_event_usec: ::c_uint,
#[cfg(all(not(any(target_pointer_width = "64", not(linux_time_bits64))), target_arch = "sparc64")]
pub __pad: ::c_uint,
#[cfg(all(not(any(target_pointer_width = "64", not(linux_time_bits64))), not(target_arch = "sparc64"))]
pub input_event_usec: ::c_ulong,

unfortunately a bit messy but I think that's accurate

Comment on lines -5431 to -5467
pub fn mq_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::mqd_t;
pub fn mq_close(mqd: ::mqd_t) -> ::c_int;
pub fn mq_unlink(name: *const ::c_char) -> ::c_int;
pub fn mq_receive(
mqd: ::mqd_t,
msg_ptr: *mut ::c_char,
msg_len: ::size_t,
msg_prio: *mut ::c_uint,
) -> ::ssize_t;
pub fn mq_timedreceive(
mqd: ::mqd_t,
msg_ptr: *mut ::c_char,
msg_len: ::size_t,
msg_prio: *mut ::c_uint,
abs_timeout: *const ::timespec,
) -> ::ssize_t;
pub fn mq_send(
mqd: ::mqd_t,
msg_ptr: *const ::c_char,
msg_len: ::size_t,
msg_prio: ::c_uint,
) -> ::c_int;
pub fn mq_timedsend(
mqd: ::mqd_t,
msg_ptr: *const ::c_char,
msg_len: ::size_t,
msg_prio: ::c_uint,
abs_timeout: *const ::timespec,
) -> ::c_int;
pub fn mq_getattr(mqd: ::mqd_t, attr: *mut ::mq_attr) -> ::c_int;
pub fn mq_setattr(
mqd: ::mqd_t,
newattr: *const ::mq_attr,
oldattr: *mut ::mq_attr
) -> ::c_int;

pub fn pthread_mutex_consistent(mutex: *mut pthread_mutex_t) -> ::c_int;
Copy link
Contributor

Choose a reason for hiding this comment

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

Did these functions move because they are now available on openharmony? If so, that should go in a different commit preferably.

@safinaskar
Copy link

Possible solution to "how to distinguish 32 and 64" problem: rust-lang/rfcs#3716 ("[RFC] Target Modifiers")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

musl: Change time_t definition on 32-bit targets according to "time64"
10 participants