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
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 85/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust
- 领域
- backend, networking
调研方向
阅读 src/sys/unix.rs 中的 into_timeval,issue 在此指出了 tv_usec 的 cast;将其与 time64 配置下 libc 的 timeval 字段类型进行比较。报告建议让结构体字段推断 cast 类型;检查 i686 和 armv7 在有无 cfg 时,以及 x86_64 上的构建是否成功。这些配置均能无警告地编译即表示完成。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Rust
- 星标
- 885
- 派生
- 328
- 平均合并
- 6 天 12 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/socket2 的其他 Issue
-
Commit lockfile未关闭
难度 2/5 1-3 小时 新手友好度 65/100
rust-lang/socket2#703 · 1 条评论 ·
维护者通常 1 天内回复
-
windows-sys 0.101.0可能已有人在做 @xtqqczze 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
SockAddr::path_len doesn't bound the length by sun_path: as_pathname panics since #691, as_abstract_namespace slices past it可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
`from_timeval` overflows on a non-normalised `tv_usec`可能已有人在做 @pederbe 于 18 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
rust-lang/socket2#683 · 2 条评论 ·
维护者通常 1 天内回复
查看 rust-lang/socket2 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
infra
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
available bug good first issue tooling
难度 2/5 1-3 小时 新手友好度 78/100
Nixitov/Riptide-Native#817 ·
维护者通常 1 天内回复