Open bjia56 opened 1 month ago
Can reproduce with
zig cc a.c --target=arm-linux-gnueabihf
zig cc a.c --target=arm-linux-gnueabihf
Works with
zig cc a.c --target=arm-linux-gnueabihf
the program to test this:
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
int main() {
struct stat st;
int ret = stat("/tmp/", &st);
printf("%d %d", ret, errno);
return 0;
}
Zig Version
0.13.0-dev.260+fb88cfdf6
Steps to Reproduce and Observed Behavior
tl;dr: Compiling with arm32 glibc 2.31 target pulls in incorrect _STAT_VER constants, causing
fstatat
function to returnEINVAL
.Issue
Cross compiling the following code with
zig cc -target arm-linux-gnueabihf.2.31 fstatat.c -o fstatat
, creating an empty file/tmp/test.txt
, and running the code will printfstatat: Invalid argument
:Findings from debugging
Debugging this on a Raspberry Pi 3B+ armv7l running Debian Bullseye shows that the program enters
__GI___fxstatat
which then calls__xstat32_conv
. Disassembling__xstat32_conv
shows a suspicious comparison with the constant "3":which matches the value of
_STAT_VER_LINUX
:However, Zig's
fstatat
function passes in the constant "0":Expected Behavior
fstatat
should not returnEINVAL
. In the sample program, there should be no output.