Closed
Description
Consider the following simple program:
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
int
main()
{
int fd;
struct stat st;
fd = open("/etc/passwd", O_RDONLY);
if (fd < 0) {
printf("open failed: %s\n", strerror(errno));
return 1;
}
if (fstat(fd, &st) < 0) {
printf("fstat failed: %s\n", strerror(errno));
return 1;
}
close(fd);
}
When compiled on a POWER system (Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-83-generic ppc64le)
) with -fsanitize=thread
, regardless of the optimization level used, always fails with fstat failed: Invalid argument
. (i.e. the fstat
interceptor has returned EINVAL
)
This happens using either the Ubuntu-provided compiler (gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
) or a fresh build of llvm trunk. (with -DLLVM_ENABLE_PROJECTS='clang;compiler-rt;lld'
to be sure to build a fresh TSan library as well)
Running the binary under strace
shows no actual fstat
system call occurring.
This behaviour seems to be specific to TSan on POWER systems; the same test program run on amd64 or arm64 completes without errors.