[compiler-rt] [compiler-rt] [libtsan] fix fstat{, 64} interceptors on glibc (PR #75578)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 01:24:15 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: Miod Vallat (dustanddreams)
<details>
<summary>Changes</summary>
When targeting a glibc environment, the `fstat` and `fstat64` interceptors directly invoke `__fxstat64` rather than `fstat` and `fstat64`.
Unfortunately, the `__fxstat64` Linux interface is not machine-independent, as it takes a "`struct stat` version number" argument, which values vary across architectures and do not seem to be exposed in userland headers, as reported and analyzed in issue #<!-- -->75346.
This PR implements the suggested fix in the issue by invoking `fstat` and `fstat64` as expected, and letting them invoke `__fxstat64` with the proper, machine-specific, arguments.
---
Full diff: https://github.com/llvm/llvm-project/pull/75578.diff
1 Files Affected:
- (modified) compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp (+2-9)
``````````diff
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index 80f86ca98ed9cd..28f6ccffcc4420 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -1603,17 +1603,10 @@ TSAN_INTERCEPTOR(int, __fxstat, int version, int fd, void *buf) {
#endif
TSAN_INTERCEPTOR(int, fstat, int fd, void *buf) {
-#if SANITIZER_GLIBC
- SCOPED_TSAN_INTERCEPTOR(__fxstat, 0, fd, buf);
- if (fd > 0)
- FdAccess(thr, pc, fd);
- return REAL(__fxstat)(0, fd, buf);
-#else
SCOPED_TSAN_INTERCEPTOR(fstat, fd, buf);
if (fd > 0)
FdAccess(thr, pc, fd);
return REAL(fstat)(fd, buf);
-#endif
}
#if SANITIZER_GLIBC
@@ -1630,10 +1623,10 @@ TSAN_INTERCEPTOR(int, __fxstat64, int version, int fd, void *buf) {
#if SANITIZER_GLIBC
TSAN_INTERCEPTOR(int, fstat64, int fd, void *buf) {
- SCOPED_TSAN_INTERCEPTOR(__fxstat64, 0, fd, buf);
+ SCOPED_TSAN_INTERCEPTOR(fstat64, fd, buf);
if (fd > 0)
FdAccess(thr, pc, fd);
- return REAL(__fxstat64)(0, fd, buf);
+ return REAL(fstat64)(fd, buf);
}
#define TSAN_MAYBE_INTERCEPT_FSTAT64 TSAN_INTERCEPT(fstat64)
#else
``````````
</details>
https://github.com/llvm/llvm-project/pull/75578
More information about the llvm-commits
mailing list