Closed mattyclarkson closed 1 month ago
clock_gettime
was improved recently in the libc, and seems like superconfigure
releases haven't caught up yet.
Not sure about macOS x86_64
specifically, perhaps @jart can explain how debugging there can work.
@mattyclarkson can you try with the zstd
from the latest release https://github.com/ahgamut/superconfigure/releases/tag/z0.0.55
I can't reproduce this. Here's the code that zstd uses:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define PTime int64_t
typedef struct {
PTime t;
} UTIL_time_t;
UTIL_time_t UTIL_getTime(void) {
/* time must be initialized, othersize it may fail msan test.
* No good reason, likely a limitation of timespec_get() for some target */
struct timespec time = {0, 0};
if (clock_gettime(CLOCK_MONOTONIC, &time) != 0) {
perror("timefn::clock_gettime(CLOCK_MONOTONIC)");
abort();
}
{
UTIL_time_t r;
r.t = (PTime)time.tv_sec * 1000000000ULL + (PTime)time.tv_nsec;
return r;
}
}
int main(int argc, char *argv[]) {
printf("%ld\n", UTIL_getTime().t);
}
This works fine on MacOS x86-64 for me.
$?=1 jart@xnu:~$ uname -a
Darwin xnu.lan 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:27 PDT 2023; root:xnu-10002.41.9~6/RELEASE_X86_64 x86_64
jart@xnu:~$ ./wut
1719610618934733983
The implementation of clock_gettime
for XNU x86-64 is as follows:
int sys_clock_gettime_xnu(int clock, struct timespec *ts) {
long ax, dx;
if (clock == CLOCK_REALTIME) {
// invoke the system call
//
// int gettimeofday(struct timeval *tp,
// struct timezone *tzp,
// uint64_t *mach_absolute_time);
//
// as follows
//
// ax, dx = gettimeofday(&ts, 0, 0);
//
// to support multiple calling conventions
//
// 1. new xnu returns *ts in memory via rdi
// 2. old xnu returns *ts in rax:rdx regs
//
// we assume this system call always succeeds
asm volatile("syscall"
: "=a"(ax), "=d"(dx)
: "0"(0x2000000 | 116), "D"(ts), "S"(0), "1"(0)
: "rcx", "r8", "r9", "r10", "r11", "memory");
if (ax) {
ts->tv_sec = ax;
ts->tv_nsec = dx;
}
ts->tv_nsec *= 1000;
return 0;
} else if (clock == CLOCK_BOOTTIME || //
clock == CLOCK_MONOTONIC || //
clock == CLOCK_MONOTONIC_COARSE) {
return sys_clock_gettime_mono(ts);
} else {
return -EINVAL;
}
}
So unless the memory for clock
or CLOCK_MONOTONIC
is being corrupted somehow, I fail to see how it could EINVAL.
The only way I can imagine this happening would be if you've edited the zstd source code to redefine CLOCK_MONOTONIC
to be CLOCK_MONOTONIC_RAW
or something like that. The normal monotonic clock is guaranteed to work. Certifiably across fleet. The raw monotonic clock isn't supported by some systems like yours.
if you've edited the zstd source code to redefine
We use the prebuilt binaries from https://cosmo.zip/pub/cosmos/v/ in https://gitlab.arm.com/bazel/ape.
What is the correlation between superconfigure
releases and the versioned cosmo.zip
releases?
This works fine on MacOS x86-64 for me.
This may be something in the Bazel Central Registry MacOS x86_64 runner.
@mattyclarkson can you try with the zstd from the latest release https://github.com/ahgamut/superconfigure/releases/tag/z0.0.55
Yep, I can roll out a new Bazel toolchain using that binary.
This is not critical, we can workaround by using the built toolchain using the BCR zstd
package and building from source.
Leave it all with me, I'll do some debugging. Thanks for your prompt, and detailed, responses. 🙇
What is the correlation between superconfigure releases and the versioned cosmo.zip releases?
cosmo.zip
has nightly binaries built from the latest commit of Cosmopolitan Libc. They are more for our internal testing.
superconfigure
releases are more "stable" because I use Github Actions and a specific commit of Cosmpolitan, but the primary purpose is just to show how different third-party codebases can be built.
What is the correlation between superconfigure releases and the versioned cosmo.zip releases?
cosmo.zip
has nightly binaries built from the latest commit of Cosmopolitan Libc. They are more for our internal testing.
I was wondering about the versioned cosmo.zip
under https://cosmo.zip/pub/cosmos/v/
I added v0.0.55
to the rules_zstd
Bazel module.
It passed all tests on all BCR platforms and was added to the BCR in bazelbuild/bazel-central-registry#2792
Seems between cosmo.zip@3.7.1
and superconfigure@v0.0.55
solved this, thanks.
Caught as part of Bazel module testing that uses the APE binaries:
Should this be a upstream bug on
jart/cosmopolitan
? Seems like alibc
issue?