[klibc] mips64el stat/time/…? problem

Thorsten Glaser
Tue, 03 Jan 2023 16:47:18 -0000

Hi,

I noticed a failure of mksh built with klibc on mips64el.

The failing test, on a high level, is this:

	:>a
	sleep 2
	:>b
	test a -nt b
	echo $?

This is supposed to echo 1 (false) because a is not newer than b.

The test code is roughly:

// const char *opnd1 = "a";
// const char *opnd2 = "b";
// struct stat b1, b2;
// int s;

	return (test_stat(opnd1, &b1) == 0 &&
	    (((s = test_stat(opnd2, &b2)) == 0 &&
	    mtimecmp(&b1, &b2) > 0) || s < 0));

// #define st_mtimensec st_mtim.tv_nsec
// #define HAVE_ST_MTIMENSEC 1

static int
mtimecmp(const struct stat *sb1, const struct stat *sb2)
{
	if (sb1->st_mtime < sb2->st_mtime)
		return (-1);
	if (sb1->st_mtime > sb2->st_mtime)
		return (1);
#if HAVE_ST_MTIMENSEC
	if (sb1->st_mtimensec < sb2->st_mtimensec)
		return (-1);
	if (sb1->st_mtimensec > sb2->st_mtimensec)
		return (1);
#endif
	return (0);
}

The build+test was on mipsel-osuosl-03.debian.org with uname
-a:
> Linux mipsel-osuosl-03 5.10.0-20-loongson-3 #1 SMP PREEMPT Debian
5.10.158-2 (2022-12-13) mips64 GNU/Linux

On the same machine and during the same build, the test passed
with glibc, musl and dietlibc.

Does this suffice to begin debugging?

Thanks,
//mirabilos
--
?It is inappropriate to require that a time represented as
 seconds since the Epoch precisely represent the number of
 seconds between the referenced time and the Epoch.?
	-- IEEE Std 1003.1b-1993 (POSIX) Section B.2.2.2