Build fails on 32-bit glibc (i686, armv7) with libc's `--cfg=libc_unstable_time64`: `tv_usec` is cast to `suseconds_t` (i32) for an i64 field

Ouverte Adaptée aux débutants
#684 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@omrzk y travaille déjà.

Depuis le 6/11/2026.

  • #686 par @omrzk — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
85/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
rust
Domaine
backend, networking

Piste de recherche

Lis src/sys/unix.rs à into_timeval, où l’issue signale le cast de tv_usec, et compare-le aux types des champs de timeval de libc avec la configuration time64. Le rapport suggère de laisser le champ de la structure inférer le type du cast ; vérifie que la compilation réussit pour i686 et armv7 avec et sans cfg, ainsi que pour x86_64. Le travail est terminé lorsque ces configurations compilent sans avertissements.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

socket2 does not compile for 32-bit glibc targets when libc's 64-bit time_t opt-in is on: RUSTFLAGS='--cfg=libc_unstable_time64' with libc ≥ 0.2.190 (earlier spellings of the same configuration: --cfg=libc_unstable_gnu_time_bits="64" from 0.2.187, RUST_LIBC_UNSTABLE_GNU_TIME_BITS=64 before that).

Under that configuration libc follows glibc's _TIME_BITS=64: timeval::tv_usec becomes __suseconds64_t (i64) while suseconds_t stays 32-bit, as it does in glibc. From libc 0.2.191, src/unix/mod.rs:71-79:

    pub struct timeval {
        pub tv_sec: time_t,
        #[cfg(not(gnu_time_bits64))]
        pub tv_usec: crate::suseconds_t,
        // For 64 bit time on 32 bit linux glibc, suseconds_t is still
        // a 32 bit type.  Use __suseconds64_t instead
        #[cfg(gnu_time_bits64)]
        pub tv_usec: __suseconds64_t,
    }

into_timeval casts to suseconds_t, so the struct literal gets an i32 where the field is i64. socket2 0.6.5, src/sys/unix.rs:1249-1262 (the same line is :1244 in 0.6.4, :1240 in 0.5.10 and :1318 on master):

fn into_timeval(duration: Option<Duration>) -> libc::timeval {
    match duration {
        // https://github.com/rust-lang/libc/issues/1848
        #[cfg_attr(target_env = "musl", allow(deprecated))]
        Some(duration) => libc::timeval {
            tv_sec: min(duration.as_secs(), libc::time_t::MAX as u64) as libc::time_t,
            tv_usec: duration.subsec_micros() as libc::suseconds_t,
        },
        None => libc::timeval {
            tv_sec: 0,
            tv_usec: 0,
        },
    }
}

Measured: socket2 0.5.10, 0.6.4 and 0.6.5 with libc 0.2.191, on i686-unknown-linux-gnu and armv7-unknown-linux-gnueabihf, rustc 1.98.1. Without the cfg all three build; with it each fails with this one error (0.6.5 on armv7; i686 is identical):

error[E0308]: mismatched types
    --> ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/socket2-0.6.5/src/sys/unix.rs:1255:22
     |
1255 |             tv_usec: duration.subsec_micros() as libc::suseconds_t,
     |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i64`, found `i32`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `socket2` (lib) due to 1 previous error

Reproduction: an empty library crate with

[dependencies]
socket2 = "=0.6.5"
libc = "=0.2.191"

and RUSTFLAGS='--cfg=libc_unstable_time64' cargo check --target i686-unknown-linux-gnu (or --target armv7-unknown-linux-gnueabihf).

A possible fix: tv_usec: duration.subsec_micros() as _, lets the field pick its type. With that one change 0.6.5 builds on i686, armv7 and x86_64, with and without the cfg, with no warnings.

The cast is private, so the change does not touch socket2's API. nix hits the same libc change in its public TimeVal API (nix-rust/nix#2778); libc's time64 tracking issue is rust-lang/libc#5507, and libc's 0.2.190 release notes ask for exactly this kind of report.

Langage dominant
Rust
Étoiles
885
Forks
328
Merge moyen
6 j 12 h
PR mergées (30 j)
2

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de rust-lang/socket2

Toutes les issues de rust-lang/socket2

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.