Skip to content

Commit b837ed9

Browse files
Mariusz Borsawrotki
authored andcommitted
[Sanitizers] Cleanup handling of stat64/statfs64
This is a follow up to <LLVM reviews>/D127343, which was reverted due to test failures. There are differences in handling of stat64/statfs64 calls by sanitizers between Linux and macOS. Versions of macOS starting with 10.6 drop the stat64/statfs64 APIs completely, relying on the linker to redirect stat/statfs to the appropriate 64 bit versions. Emitting variables needed by sanitizers is thus controlled by convoluted sets of conditions, involving Linux, IOS, macOS and Android, sprinkled around files. This change clarifies it a bit, allowing to specify presence/absence of stat64/statfs64 for each platform, in a single location. Please note that I wasn't able to test this change on platforms other than macOS and Linux Fedora 34. The previous attempt has caused test failures but couldn't figure out the context. I have a vague suspicion that they were Android and perhaps Fuchsia builds - and some build involving ppc64le, I don't have hardware handy to attempt a test there. Tried to tighten the conditions this time to clearly separate macOS from Linux, so Linux builds should behave same (sanitizerwise) as before the change. Will add people who reported the tests failing before as reviewers, so they can provide context should the change cause the test failures again. Differential Revision: https://reviews.llvm.org/D128476
1 parent 255411f commit b837ed9

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@
329329
#define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
330330
#define SANITIZER_INTERCEPT_STATFS \
331331
(SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
332-
#define SANITIZER_INTERCEPT_STATFS64 \
333-
(((SI_MAC && !TARGET_CPU_ARM64) && !SI_IOS) || SI_LINUX_NOT_ANDROID)
332+
#define SANITIZER_INTERCEPT_STATFS64 SI_LINUX_NOT_ANDROID && SANITIZER_HAS_STATFS64
334333
#define SANITIZER_INTERCEPT_STATVFS \
335334
(SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
336335
#define SANITIZER_INTERCEPT_STATVFS64 SI_LINUX_NOT_ANDROID
@@ -466,7 +465,7 @@
466465
#define SANITIZER_INTERCEPT_STAT \
467466
(SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS || \
468467
SI_STAT_LINUX)
469-
#define SANITIZER_INTERCEPT_STAT64 SI_STAT_LINUX
468+
#define SANITIZER_INTERCEPT_STAT64 SI_STAT_LINUX && SANITIZER_HAS_STAT64
470469
#define SANITIZER_INTERCEPT_LSTAT (SI_NETBSD || SI_FREEBSD || SI_STAT_LINUX)
471470
#define SANITIZER_INTERCEPT___XSTAT \
472471
((!SANITIZER_INTERCEPT_STAT && SI_POSIX) || SI_STAT_LINUX)

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_linux.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@
5757

5858
using namespace __sanitizer;
5959

60-
namespace __sanitizer {
61-
#if !SANITIZER_ANDROID
62-
unsigned struct_statfs64_sz = sizeof(struct statfs64);
63-
#endif
64-
} // namespace __sanitizer
65-
6660
# if !defined(__powerpc64__) && !defined(__x86_64__) && \
6761
!defined(__aarch64__) && !defined(__mips__) && !defined(__s390__) && \
6862
!defined(__sparc__) && !defined(__riscv) && !defined(__hexagon__)

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ typedef struct user_fpregs elf_fpregset_t;
177177
namespace __sanitizer {
178178
unsigned struct_utsname_sz = sizeof(struct utsname);
179179
unsigned struct_stat_sz = sizeof(struct stat);
180-
#if !SANITIZER_IOS && !(SANITIZER_APPLE && TARGET_CPU_ARM64)
180+
#if SANITIZER_HAS_STAT64
181181
unsigned struct_stat64_sz = sizeof(struct stat64);
182-
#endif // !SANITIZER_IOS && !(SANITIZER_APPLE && TARGET_CPU_ARM64)
182+
#endif // SANITIZER_HAS_STAT64
183183
unsigned struct_rusage_sz = sizeof(struct rusage);
184184
unsigned struct_tm_sz = sizeof(struct tm);
185185
unsigned struct_passwd_sz = sizeof(struct passwd);
@@ -204,9 +204,9 @@ namespace __sanitizer {
204204
unsigned struct_regex_sz = sizeof(regex_t);
205205
unsigned struct_regmatch_sz = sizeof(regmatch_t);
206206

207-
#if (SANITIZER_APPLE && !TARGET_CPU_ARM64) && !SANITIZER_IOS
207+
#if SANITIZER_HAS_STATFS64
208208
unsigned struct_statfs64_sz = sizeof(struct statfs64);
209-
#endif // (SANITIZER_APPLE && !TARGET_CPU_ARM64) && !SANITIZER_IOS
209+
#endif // SANITIZER_HAS_STATFS64
210210

211211
#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_APPLE
212212
unsigned struct_fstab_sz = sizeof(struct fstab);

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
#include "sanitizer_internal_defs.h"
2020
#include "sanitizer_platform.h"
2121

22+
#if SANITIZER_APPLE
23+
#include <sys/cdefs.h>
24+
#if !__DARWIN_ONLY_64_BIT_INO_T
25+
#define SANITIZER_HAS_STAT64 1
26+
#define SANITIZER_HAS_STATFS64 1
27+
#else
28+
#define SANITIZER_HAS_STAT64 0
29+
#define SANITIZER_HAS_STATFS64 0
30+
#endif
31+
#else
32+
// Must be SANITIZER_LINUX then
33+
#define SANITIZER_HAS_STAT64 1
34+
#define SANITIZER_HAS_STATFS64 1
35+
#endif
36+
2237
#if defined(__sparc__)
2338
// FIXME: This can't be included from tsan which does not support sparc yet.
2439
#include "sanitizer_glibc_version.h"
@@ -29,7 +44,7 @@
2944
namespace __sanitizer {
3045
extern unsigned struct_utsname_sz;
3146
extern unsigned struct_stat_sz;
32-
#if !SANITIZER_IOS
47+
#if SANITIZER_HAS_STAT64
3348
extern unsigned struct_stat64_sz;
3449
#endif
3550
extern unsigned struct_rusage_sz;
@@ -49,7 +64,9 @@ extern unsigned struct_itimerspec_sz;
4964
extern unsigned struct_sigevent_sz;
5065
extern unsigned struct_stack_t_sz;
5166
extern unsigned struct_sched_param_sz;
67+
#if SANITIZER_HAS_STATFS64
5268
extern unsigned struct_statfs64_sz;
69+
#endif
5370
extern unsigned struct_regex_sz;
5471
extern unsigned struct_regmatch_sz;
5572

0 commit comments

Comments
 (0)