Revert libc time_t changes

This was based on a misunderstanding.

On musl, 64-bit time_t on 32-bit architectures was introduced in version 1.2.0,
by introducing new symbols. The old symbols still exist, to allow programs compiled against older versions
to keep running on 1.2.0+, preserving ABI-compatibility. (see musl commit 38143339646a4ccce8afe298c34467767c899f51)

Programs compiled against 1.2.0+ will get the new symbols, and will therefore think time_t is 64-bit.

Unfortunately, rust's libc crate uses its own definition of these types, and does not check for musl version.
Currently, it includes the pre-1.2.0 32-bit type.

That means:

- If you run on a 32-bit system like i686
- ... and compile against a C-library other than libc
- ... and pass it a time_t-containing struct like timespec or stat

... you need to arrange for that library to be built against musl <1.2.0.

Or, as https://github.com/ericonr/rust-time64 says:

> Therefore, for "old" 32-bit targets (riscv32 is supposed to default to time64),
> any Rust code that interacts with C code built on musl after 1.2.0,
> using types based on time_t (arguably, the main ones are struct timespec and struct stat) in their interface,
> will be completely miscompiled.

However, while fish runs on i686 and compiles against pcre2, we do not pass pcre2 a time_t.
Our only uses of time_t are confined to interactions with libc, in which case with musl we would simply use the legacy ABI.

I have compiled an i686 fish against musl to confirm and can find no issue.

This reverts commit 55196ee2a0.
This reverts commit 4992f88966.
This reverts commit 46c8ba2c9f.
This reverts commit 3a9b4149da.
This reverts commit 5f9e9cbe74.
This reverts commit 338579b78c.
This reverts commit d19e5508d7.
This reverts commit b64045dc18.

Closes #10634
This commit is contained in:
Fabian Boehm
2024-08-27 11:15:27 +02:00
parent 46c1f0e338
commit 7b7d16da48
13 changed files with 122 additions and 373 deletions

View File

@@ -17,8 +17,6 @@
use std::io::Write;
use std::time::{Duration, Instant};
use crate::libc::{getrusage64, rusage64};
enum Unit {
Minutes,
Seconds,
@@ -28,8 +26,8 @@ enum Unit {
struct TimerSnapshot {
wall_time: Instant,
cpu_fish: rusage64,
cpu_children: rusage64,
cpu_fish: libc::rusage,
cpu_children: libc::rusage,
}
/// Create a `TimerSnapshot` and return a `PrintElapsedOnDrop` object that will print upon
@@ -47,12 +45,24 @@ enum RUsage {
RChildren,
}
fn getrusage(resource: RUsage) -> rusage64 {
getrusage64(match resource {
RUsage::RSelf => libc::RUSAGE_SELF,
RUsage::RChildren => libc::RUSAGE_CHILDREN,
})
.unwrap_or(unsafe { std::mem::zeroed() })
/// A safe wrapper around `libc::getrusage()`
fn getrusage(resource: RUsage) -> libc::rusage {
let mut rusage = std::mem::MaybeUninit::uninit();
let result = unsafe {
match resource {
RUsage::RSelf => libc::getrusage(libc::RUSAGE_SELF, rusage.as_mut_ptr()),
RUsage::RChildren => libc::getrusage(libc::RUSAGE_CHILDREN, rusage.as_mut_ptr()),
}
};
// getrusage(2) says the syscall can only fail if the dest address is invalid (EFAULT) or if the
// requested resource type is invalid. Since we're in control of both, we can assume it won't
// fail. In case it does anyway (e.g. OS where the syscall isn't implemented), we can just
// return an empty value.
match result {
0 => unsafe { rusage.assume_init() },
_ => unsafe { std::mem::zeroed() },
}
}
impl TimerSnapshot {