<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/75346>75346</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            fstat TSan interceptor not behaving correctly on POWER
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dustanddreams
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzElV1v2zYUhn8NfXNgQaL8eeGLxI6HDl5SpGmLXRUUeSRxo0iBh4yXXuy3D6Ttpk2TAbuaYMgSz9F5Xz78EkS6s4gbNr9m891ExNA7v1GRgrBKeRQDTRqnnjZbZ0kr9BB6hNYZ447adkB6GA3C6F3nxcDqK1buWHnF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