Skip to content

Commit b449049

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 <ariadne@dereferenced.org>
1 parent 0bbac0c commit b449049

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

libc-test/build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3658,6 +3658,8 @@ fn test_linux(target: &str) {
36583658

36593659
let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_1_2_3").is_ok();
36603660

3661+
let old_musl = musl && !musl_v1_2_3;
3662+
36613663
let mut cfg = ctest_cfg();
36623664
if musl_v1_2_3 {
36633665
cfg.cfg("musl_v1_2_3", None);
@@ -4787,8 +4789,8 @@ fn test_linux(target: &str) {
47874789
(struct_ == "statvfs64" && field == "__f_spare") ||
47884790
// the `xsk_tx_metadata_union` field is an anonymous union
47894791
(struct_ == "xsk_tx_metadata" && field == "xsk_tx_metadata_union") ||
4790-
// FIXME(musl): After musl 1.2.0, the type becomes `int` instead of `long`.
4791-
(struct_ == "utmpx" && field == "ut_session")
4792+
// After musl 1.2.0, the type becomes `int` instead of `long`.
4793+
(old_musl && struct_ == "utmpx" && field == "ut_session")
47924794
});
47934795

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

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

Lines changed: 13 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,26 @@ 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+
// loongarch64 and ohos already use the new ABI
454+
#[cfg(not(any(target_arch = "loongarch64", target_env = "ohos", musl_v1_2_3)))]
455+
#[deprecated(
456+
since = "0.2.173",
457+
note = "The ABI of this field has changed from c_long to c_int with padding, \
458+
we'll follow that change in the future release as part of an effort to \
459+
update the musl API to reflect upstream. See #4443 for more info."
460+
)]
462461
pub ut_session: c_long,
463462

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")]
463+
#[cfg(any(target_arch = "loongarch64", target_env = "ohos", musl_v1_2_3))]
464+
#[cfg(not(target_endian = "little"))]
470465
__ut_pad2: c_int,
471466

472-
#[cfg(target_env = "ohos")]
473-
#[cfg(target_endian = "little")]
467+
#[cfg(any(target_arch = "loongarch64", target_env = "ohos", musl_v1_2_3))]
474468
pub ut_session: c_int,
475-
#[cfg(target_env = "ohos")]
476-
#[cfg(target_endian = "little")]
477-
__ut_pad2: c_int,
478469

479-
#[cfg(target_env = "ohos")]
480-
#[cfg(not(target_endian = "little"))]
470+
#[cfg(any(target_arch = "loongarch64", target_env = "ohos", musl_v1_2_3))]
471+
#[cfg(target_endian = "little")]
481472
__ut_pad2: c_int,
482-
#[cfg(target_env = "ohos")]
483-
#[cfg(not(target_endian = "little"))]
484-
pub ut_session: c_int,
485473

486474
pub ut_tv: crate::timeval,
487475
pub ut_addr_v6: [c_uint; 4],

0 commit comments

Comments
 (0)