Skip to content

Commit 9b6d421

Browse files
xbjfkkaniini
andcommitted
musl: fix utmpx struct layout
This ut_session has changed from long to int + padding in newer versions. This was already reflected on loongarch64 and ohos - this commit adds this change, and re-enables the test when musl_v1_2_3 is set. Co-authored-by: Ariadne Conill <[email protected]>
1 parent 7ec6d14 commit 9b6d421

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed

libc-test/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4818,8 +4818,8 @@ fn test_linux(target: &str) {
48184818
(struct_ == "statvfs64" && field == "__f_spare") ||
48194819
// the `xsk_tx_metadata_union` field is an anonymous union
48204820
(struct_ == "xsk_tx_metadata" && field == "xsk_tx_metadata_union") ||
4821-
// FIXME(musl): After musl 1.2.0, the type becomes `int` instead of `long`.
4822-
(struct_ == "utmpx" && field == "ut_session")
4821+
// After musl 1.2.0, the type becomes `int` instead of `long`.
4822+
(old_musl && struct_ == "utmpx" && field == "ut_session")
48234823
});
48244824

48254825
cfg.skip_roundtrip(move |s| match s {

src/unix/linux_like/linux/musl/mod.rs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,6 @@ s_no_extra_traits! {
440440
pub __reserved: [c_char; 256],
441441
}
442442

443-
// FIXME(musl): musl added paddings and adjusted
444-
// layout in 1.2.0 but our CI is still 1.1.24.
445-
// So, I'm leaving some fields as cfg for now.
446-
// ref. https://github.com/bminor/musl/commit/
447-
// 1e7f0fcd7ff2096904fd93a2ee6d12a2392be392
448-
//
449-
// OpenHarmony uses the musl 1.2 layout.
450443
pub struct utmpx {
451444
pub ut_type: c_short,
452445
__ut_pad1: c_short,
@@ -457,31 +450,24 @@ s_no_extra_traits! {
457450
pub ut_host: [c_char; 256],
458451
pub ut_exit: __exit_status,
459452

460-
#[cfg(target_env = "musl")]
461-
#[cfg(not(target_arch = "loongarch64"))]
453+
#[cfg(not(musl_v1_2_3))]
454+
#[deprecated(
455+
since = "0.2.173",
456+
note = "The ABI of this field has changed from c_long to c_int with padding, \
457+
we'll follow that change in the future release. See #4443 for more info."
458+
)]
462459
pub ut_session: c_long,
463460

464-
#[cfg(target_env = "musl")]
465-
#[cfg(target_arch = "loongarch64")]
466-
pub ut_session: c_int,
467-
468-
#[cfg(target_env = "musl")]
469-
#[cfg(target_arch = "loongarch64")]
461+
#[cfg(musl_v1_2_3)]
462+
#[cfg(not(target_endian = "little"))]
470463
__ut_pad2: c_int,
471464

472-
#[cfg(target_env = "ohos")]
473-
#[cfg(target_endian = "little")]
465+
#[cfg(musl_v1_2_3)]
474466
pub ut_session: c_int,
475-
#[cfg(target_env = "ohos")]
476-
#[cfg(target_endian = "little")]
477-
__ut_pad2: c_int,
478467

479-
#[cfg(target_env = "ohos")]
480-
#[cfg(not(target_endian = "little"))]
468+
#[cfg(musl_v1_2_3)]
469+
#[cfg(target_endian = "little")]
481470
__ut_pad2: c_int,
482-
#[cfg(target_env = "ohos")]
483-
#[cfg(not(target_endian = "little"))]
484-
pub ut_session: c_int,
485471

486472
pub ut_tv: crate::timeval,
487473
pub ut_addr_v6: [c_uint; 4],
@@ -557,6 +543,7 @@ cfg_if! {
557543
}
558544

559545
impl PartialEq for utmpx {
546+
#![allow(deprecated)]
560547
fn eq(&self, other: &utmpx) -> bool {
561548
self.ut_type == other.ut_type
562549
//&& self.__ut_pad1 == other.__ut_pad1
@@ -581,6 +568,7 @@ cfg_if! {
581568
impl Eq for utmpx {}
582569

583570
impl fmt::Debug for utmpx {
571+
#![allow(deprecated)]
584572
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
585573
f.debug_struct("utmpx")
586574
.field("ut_type", &self.ut_type)
@@ -601,6 +589,7 @@ cfg_if! {
601589
}
602590

603591
impl hash::Hash for utmpx {
592+
#![allow(deprecated)]
604593
fn hash<H: hash::Hasher>(&self, state: &mut H) {
605594
self.ut_type.hash(state);
606595
//self.__ut_pad1.hash(state);

0 commit comments

Comments
 (0)