Skip to content

Commit 3b74966

Browse files
xbjfkDorianNiemiecSVRJS
authored 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 <ariadne@dereferenced.org> (backport <rust-lang#4443>) (cherry picked from commit 1038c7f)
1 parent bed5c8d commit 3b74966

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
@@ -4897,8 +4897,8 @@ fn test_linux(target: &str) {
48974897
(struct_ == "statvfs64" && field == "__f_spare") ||
48984898
// the `xsk_tx_metadata_union` field is an anonymous union
48994899
(struct_ == "xsk_tx_metadata" && field == "xsk_tx_metadata_union") ||
4900-
// FIXME(musl): After musl 1.2.0, the type becomes `int` instead of `long`.
4901-
(struct_ == "utmpx" && field == "ut_session")
4900+
// After musl 1.2.0, the type becomes `int` instead of `long`.
4901+
(old_musl && struct_ == "utmpx" && field == "ut_session")
49024902
});
49034903

49044904
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
@@ -438,13 +438,6 @@ s_no_extra_traits! {
438438
pub __reserved: [c_char; 256],
439439
}
440440

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

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

462-
#[cfg(target_env = "musl")]
463-
#[cfg(target_arch = "loongarch64")]
464-
pub ut_session: c_int,
465-
466-
#[cfg(target_env = "musl")]
467-
#[cfg(target_arch = "loongarch64")]
459+
#[cfg(musl_v1_2_3)]
460+
#[cfg(not(target_endian = "little"))]
468461
__ut_pad2: c_int,
469462

470-
#[cfg(target_env = "ohos")]
471-
#[cfg(target_endian = "little")]
463+
#[cfg(musl_v1_2_3)]
472464
pub ut_session: c_int,
473-
#[cfg(target_env = "ohos")]
474-
#[cfg(target_endian = "little")]
475-
__ut_pad2: c_int,
476465

477-
#[cfg(target_env = "ohos")]
478-
#[cfg(not(target_endian = "little"))]
466+
#[cfg(musl_v1_2_3)]
467+
#[cfg(target_endian = "little")]
479468
__ut_pad2: c_int,
480-
#[cfg(target_env = "ohos")]
481-
#[cfg(not(target_endian = "little"))]
482-
pub ut_session: c_int,
483469

484470
pub ut_tv: crate::timeval,
485471
pub ut_addr_v6: [c_uint; 4],
@@ -555,6 +541,7 @@ cfg_if! {
555541
}
556542

557543
impl PartialEq for utmpx {
544+
#[allow(deprecated)]
558545
fn eq(&self, other: &utmpx) -> bool {
559546
self.ut_type == other.ut_type
560547
//&& self.__ut_pad1 == other.__ut_pad1
@@ -579,6 +566,7 @@ cfg_if! {
579566
impl Eq for utmpx {}
580567

581568
impl fmt::Debug for utmpx {
569+
#[allow(deprecated)]
582570
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
583571
f.debug_struct("utmpx")
584572
.field("ut_type", &self.ut_type)
@@ -599,6 +587,7 @@ cfg_if! {
599587
}
600588

601589
impl hash::Hash for utmpx {
590+
#[allow(deprecated)]
602591
fn hash<H: hash::Hasher>(&self, state: &mut H) {
603592
self.ut_type.hash(state);
604593
//self.__ut_pad1.hash(state);

0 commit comments

Comments
 (0)