Skip to content

Commit 1313f6d

Browse files
MaskRaySixWeining
authored andcommitted
[tsan] Refine fstat{,64} interceptors (llvm#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) Change-Id: Icf805b4795870414d77b221f7f514769d296f8aa
1 parent 4021d30 commit 1313f6d

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

Lines changed: 18 additions & 25 deletions
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"
@@ -1595,47 +1596,40 @@ TSAN_INTERCEPTOR(int, __fxstat, int version, int fd, void *buf) {
15951596
FdAccess(thr, pc, fd);
15961597
return REAL(__fxstat)(version, fd, buf);
15971598
}
1598-
#define TSAN_MAYBE_INTERCEPT___FXSTAT TSAN_INTERCEPT(__fxstat)
1599+
1600+
TSAN_INTERCEPTOR(int, __fxstat64, int version, int fd, void *buf) {
1601+
SCOPED_TSAN_INTERCEPTOR(__fxstat64, version, fd, buf);
1602+
if (fd > 0)
1603+
FdAccess(thr, pc, fd);
1604+
return REAL(__fxstat64)(version, fd, buf);
1605+
}
1606+
#define TSAN_MAYBE_INTERCEPT___FXSTAT TSAN_INTERCEPT(__fxstat); TSAN_INTERCEPT(__fxstat64)
15991607
#else
16001608
#define TSAN_MAYBE_INTERCEPT___FXSTAT
16011609
#endif
16021610

1611+
#if !SANITIZER_GLIBC || __GLIBC_PREREQ(2, 33)
16031612
TSAN_INTERCEPTOR(int, fstat, int fd, void *buf) {
1604-
#if SANITIZER_GLIBC
1605-
SCOPED_TSAN_INTERCEPTOR(__fxstat, 0, fd, buf);
1606-
if (fd > 0)
1607-
FdAccess(thr, pc, fd);
1608-
return REAL(__fxstat)(0, fd, buf);
1609-
#else
16101613
SCOPED_TSAN_INTERCEPTOR(fstat, fd, buf);
16111614
if (fd > 0)
16121615
FdAccess(thr, pc, fd);
16131616
return REAL(fstat)(fd, buf);
1614-
#endif
1615-
}
1616-
1617-
#if SANITIZER_GLIBC
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);
16231617
}
1624-
#define TSAN_MAYBE_INTERCEPT___FXSTAT64 TSAN_INTERCEPT(__fxstat64)
1618+
# define TSAN_MAYBE_INTERCEPT_FSTAT TSAN_INTERCEPT(fstat)
16251619
#else
1626-
#define TSAN_MAYBE_INTERCEPT___FXSTAT64
1620+
# define TSAN_MAYBE_INTERCEPT_FSTAT
16271621
#endif
16281622

1629-
#if SANITIZER_GLIBC
1623+
#if __GLIBC_PREREQ(2, 33)
16301624
TSAN_INTERCEPTOR(int, fstat64, int fd, void *buf) {
1631-
SCOPED_TSAN_INTERCEPTOR(__fxstat64, 0, fd, buf);
1625+
SCOPED_TSAN_INTERCEPTOR(fstat64, fd, buf);
16321626
if (fd > 0)
16331627
FdAccess(thr, pc, fd);
1634-
return REAL(__fxstat64)(0, fd, buf);
1628+
return REAL(fstat64)(fd, buf);
16351629
}
1636-
#define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64)
1630+
# define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64)
16371631
#else
1638-
#define TSAN_MAYBE_INTERCEPT_FSTAT64
1632+
# define TSAN_MAYBE_INTERCEPT_FSTAT64
16391633
#endif
16401634

16411635
TSAN_INTERCEPTOR(int, open, const char *name, int oflag, ...) {
@@ -2929,10 +2923,9 @@ void InitializeInterceptors() {
29292923

29302924
TSAN_INTERCEPT(pthread_once);
29312925

2932-
TSAN_INTERCEPT(fstat);
29332926
TSAN_MAYBE_INTERCEPT___FXSTAT;
2927+
TSAN_MAYBE_INTERCEPT_FSTAT;
29342928
TSAN_MAYBE_INTERCEPT_FSTAT64;
2935-
TSAN_MAYBE_INTERCEPT___FXSTAT64;
29362929
TSAN_INTERCEPT(open);
29372930
TSAN_MAYBE_INTERCEPT_OPEN64;
29382931
TSAN_INTERCEPT(creat);

0 commit comments

Comments
 (0)