Skip to content

Commit f249092

Browse files
MaskRayllvmbot
authored andcommitted
[tsan] Refine fstat{,64} interceptors (#86625)
In glibc versions before 2.33. `libc_nonshared.a` defines `__fxstat/__fxstat64` but there is no `fstat/fstat64`. glibc 2.33 added `fstat/fstat64` and obsoleted `__fxstat/__fxstat64`. Ports added after 2.33 do not provide `__fxstat/__fxstat64`, so our `fstat/fstat64` interceptors using `__fxstat/__fxstat64` interceptors would lead to runtime failures on such ports (LoongArch and certain RISC-V ports). Similar to https://reviews.llvm.org/D118423, refine the conditions that we define fstat{,64} interceptors. `fstat` is supported by musl/*BSD while `fstat64` is glibc only. (cherry picked from commit d5224b7)
1 parent 76c7219 commit f249092

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

+18-25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "sanitizer_common/sanitizer_atomic.h"
1616
#include "sanitizer_common/sanitizer_errno.h"
17+
#include "sanitizer_common/sanitizer_glibc_version.h"
1718
#include "sanitizer_common/sanitizer_libc.h"
1819
#include "sanitizer_common/sanitizer_linux.h"
1920
#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
@@ -1613,47 +1614,40 @@ TSAN_INTERCEPTOR(int, __fxstat, int version, int fd, void *buf) {
16131614
FdAccess(thr, pc, fd);
16141615
return REAL(__fxstat)(version, fd, buf);
16151616
}
1616-
#define TSAN_MAYBE_INTERCEPT___FXSTAT TSAN_INTERCEPT(__fxstat)
1617+
1618+
TSAN_INTERCEPTOR(int, __fxstat64, int version, int fd, void *buf) {
1619+
SCOPED_TSAN_INTERCEPTOR(__fxstat64, version, fd, buf);
1620+
if (fd > 0)
1621+
FdAccess(thr, pc, fd);
1622+
return REAL(__fxstat64)(version, fd, buf);
1623+
}
1624+
#define TSAN_MAYBE_INTERCEPT___FXSTAT TSAN_INTERCEPT(__fxstat); TSAN_INTERCEPT(__fxstat64)
16171625
#else
16181626
#define TSAN_MAYBE_INTERCEPT___FXSTAT
16191627
#endif
16201628

1629+
#if !SANITIZER_GLIBC || __GLIBC_PREREQ(2, 33)
16211630
TSAN_INTERCEPTOR(int, fstat, int fd, void *buf) {
1622-
#if SANITIZER_GLIBC
1623-
SCOPED_TSAN_INTERCEPTOR(__fxstat, 0, fd, buf);
1624-
if (fd > 0)
1625-
FdAccess(thr, pc, fd);
1626-
return REAL(__fxstat)(0, fd, buf);
1627-
#else
16281631
SCOPED_TSAN_INTERCEPTOR(fstat, fd, buf);
16291632
if (fd > 0)
16301633
FdAccess(thr, pc, fd);
16311634
return REAL(fstat)(fd, buf);
1632-
#endif
1633-
}
1634-
1635-
#if SANITIZER_GLIBC
1636-
TSAN_INTERCEPTOR(int, __fxstat64, int version, int fd, void *buf) {
1637-
SCOPED_TSAN_INTERCEPTOR(__fxstat64, version, fd, buf);
1638-
if (fd > 0)
1639-
FdAccess(thr, pc, fd);
1640-
return REAL(__fxstat64)(version, fd, buf);
16411635
}
1642-
#define TSAN_MAYBE_INTERCEPT___FXSTAT64 TSAN_INTERCEPT(__fxstat64)
1636+
# define TSAN_MAYBE_INTERCEPT_FSTAT TSAN_INTERCEPT(fstat)
16431637
#else
1644-
#define TSAN_MAYBE_INTERCEPT___FXSTAT64
1638+
# define TSAN_MAYBE_INTERCEPT_FSTAT
16451639
#endif
16461640

1647-
#if SANITIZER_GLIBC
1641+
#if __GLIBC_PREREQ(2, 33)
16481642
TSAN_INTERCEPTOR(int, fstat64, int fd, void *buf) {
1649-
SCOPED_TSAN_INTERCEPTOR(__fxstat64, 0, fd, buf);
1643+
SCOPED_TSAN_INTERCEPTOR(fstat64, fd, buf);
16501644
if (fd > 0)
16511645
FdAccess(thr, pc, fd);
1652-
return REAL(__fxstat64)(0, fd, buf);
1646+
return REAL(fstat64)(fd, buf);
16531647
}
1654-
#define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64)
1648+
# define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64)
16551649
#else
1656-
#define TSAN_MAYBE_INTERCEPT_FSTAT64
1650+
# define TSAN_MAYBE_INTERCEPT_FSTAT64
16571651
#endif
16581652

16591653
TSAN_INTERCEPTOR(int, open, const char *name, int oflag, ...) {
@@ -2950,10 +2944,9 @@ void InitializeInterceptors() {
29502944

29512945
TSAN_INTERCEPT(pthread_once);
29522946

2953-
TSAN_INTERCEPT(fstat);
29542947
TSAN_MAYBE_INTERCEPT___FXSTAT;
2948+
TSAN_MAYBE_INTERCEPT_FSTAT;
29552949
TSAN_MAYBE_INTERCEPT_FSTAT64;
2956-
TSAN_MAYBE_INTERCEPT___FXSTAT64;
29572950
TSAN_INTERCEPT(open);
29582951
TSAN_MAYBE_INTERCEPT_OPEN64;
29592952
TSAN_INTERCEPT(creat);

0 commit comments

Comments
 (0)