forked from OSchip/llvm-project
[Sanitizers] Cleanup handling of stat64/statfs64
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 adresses it, allowing to specify presence/absence of stat64/statfs64 for each platform, in a single location. Also, it adresses the Android case which handles stat64, but not statfs64. Adding Vitaly as a reviewer since he seems to be actively working on sanitizers, perhaps can comment on the Android bit Differential Revision: https://reviews.llvm.org/D127343
This commit is contained in:
parent
353324eb14
commit
6d890a0fb8
|
@ -330,8 +330,7 @@
|
||||||
#define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
|
||||||
#define SANITIZER_INTERCEPT_STATFS \
|
#define SANITIZER_INTERCEPT_STATFS \
|
||||||
(SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
|
(SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
|
||||||
#define SANITIZER_INTERCEPT_STATFS64 \
|
#define SANITIZER_INTERCEPT_STATFS64 SANITIZER_HAS_STATFS64
|
||||||
(((SI_MAC && !TARGET_CPU_ARM64) && !SI_IOS) || SI_LINUX_NOT_ANDROID)
|
|
||||||
#define SANITIZER_INTERCEPT_STATVFS \
|
#define SANITIZER_INTERCEPT_STATVFS \
|
||||||
(SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
|
(SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
|
||||||
#define SANITIZER_INTERCEPT_STATVFS64 SI_LINUX_NOT_ANDROID
|
#define SANITIZER_INTERCEPT_STATVFS64 SI_LINUX_NOT_ANDROID
|
||||||
|
@ -468,7 +467,7 @@
|
||||||
#define SANITIZER_INTERCEPT_STAT \
|
#define SANITIZER_INTERCEPT_STAT \
|
||||||
(SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS || \
|
(SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS || \
|
||||||
SI_STAT_LINUX)
|
SI_STAT_LINUX)
|
||||||
#define SANITIZER_INTERCEPT_STAT64 SI_STAT_LINUX
|
#define SANITIZER_INTERCEPT_STAT64 SI_STAT_LINUX || SANITIZER_HAS_STAT64
|
||||||
#define SANITIZER_INTERCEPT_LSTAT (SI_NETBSD || SI_FREEBSD || SI_STAT_LINUX)
|
#define SANITIZER_INTERCEPT_LSTAT (SI_NETBSD || SI_FREEBSD || SI_STAT_LINUX)
|
||||||
#define SANITIZER_INTERCEPT___XSTAT \
|
#define SANITIZER_INTERCEPT___XSTAT \
|
||||||
((!SANITIZER_INTERCEPT_STAT && SI_POSIX) || SI_STAT_LINUX)
|
((!SANITIZER_INTERCEPT_STAT && SI_POSIX) || SI_STAT_LINUX)
|
||||||
|
|
|
@ -57,12 +57,6 @@
|
||||||
|
|
||||||
using namespace __sanitizer;
|
using namespace __sanitizer;
|
||||||
|
|
||||||
namespace __sanitizer {
|
|
||||||
#if !SANITIZER_ANDROID
|
|
||||||
unsigned struct_statfs64_sz = sizeof(struct statfs64);
|
|
||||||
#endif
|
|
||||||
} // namespace __sanitizer
|
|
||||||
|
|
||||||
# if !defined(__powerpc64__) && !defined(__x86_64__) && \
|
# if !defined(__powerpc64__) && !defined(__x86_64__) && \
|
||||||
!defined(__aarch64__) && !defined(__mips__) && !defined(__s390__) && \
|
!defined(__aarch64__) && !defined(__mips__) && !defined(__s390__) && \
|
||||||
!defined(__sparc__) && !defined(__riscv) && !defined(__hexagon__)
|
!defined(__sparc__) && !defined(__riscv) && !defined(__hexagon__)
|
||||||
|
|
|
@ -181,9 +181,9 @@ typedef struct user_fpregs elf_fpregset_t;
|
||||||
namespace __sanitizer {
|
namespace __sanitizer {
|
||||||
unsigned struct_utsname_sz = sizeof(struct utsname);
|
unsigned struct_utsname_sz = sizeof(struct utsname);
|
||||||
unsigned struct_stat_sz = sizeof(struct stat);
|
unsigned struct_stat_sz = sizeof(struct stat);
|
||||||
#if !SANITIZER_IOS && !(SANITIZER_APPLE && TARGET_CPU_ARM64)
|
#if SANITIZER_HAS_STAT64
|
||||||
unsigned struct_stat64_sz = sizeof(struct stat64);
|
unsigned struct_stat64_sz = sizeof(struct stat64);
|
||||||
#endif // !SANITIZER_IOS && !(SANITIZER_APPLE && TARGET_CPU_ARM64)
|
#endif // SANITIZER_HAS_STAT64
|
||||||
unsigned struct_rusage_sz = sizeof(struct rusage);
|
unsigned struct_rusage_sz = sizeof(struct rusage);
|
||||||
unsigned struct_tm_sz = sizeof(struct tm);
|
unsigned struct_tm_sz = sizeof(struct tm);
|
||||||
unsigned struct_passwd_sz = sizeof(struct passwd);
|
unsigned struct_passwd_sz = sizeof(struct passwd);
|
||||||
|
@ -208,9 +208,9 @@ namespace __sanitizer {
|
||||||
unsigned struct_regex_sz = sizeof(regex_t);
|
unsigned struct_regex_sz = sizeof(regex_t);
|
||||||
unsigned struct_regmatch_sz = sizeof(regmatch_t);
|
unsigned struct_regmatch_sz = sizeof(regmatch_t);
|
||||||
|
|
||||||
#if (SANITIZER_APPLE && !TARGET_CPU_ARM64) && !SANITIZER_IOS
|
#if SANITIZER_HAS_STATFS64
|
||||||
unsigned struct_statfs64_sz = sizeof(struct statfs64);
|
unsigned struct_statfs64_sz = sizeof(struct statfs64);
|
||||||
#endif // (SANITIZER_APPLE && !TARGET_CPU_ARM64) && !SANITIZER_IOS
|
#endif // SANITIZER_HAS_STATFS64
|
||||||
|
|
||||||
#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_APPLE
|
#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_APPLE
|
||||||
unsigned struct_fstab_sz = sizeof(struct fstab);
|
unsigned struct_fstab_sz = sizeof(struct fstab);
|
||||||
|
|
|
@ -19,6 +19,25 @@
|
||||||
#include "sanitizer_internal_defs.h"
|
#include "sanitizer_internal_defs.h"
|
||||||
#include "sanitizer_platform.h"
|
#include "sanitizer_platform.h"
|
||||||
|
|
||||||
|
#if SANITIZER_APPLE
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#if !__DARWIN_ONLY_64_BIT_INO_T
|
||||||
|
#define SANITIZER_HAS_STAT64 1
|
||||||
|
#define SANITIZER_HAS_STATFS64 1
|
||||||
|
#else
|
||||||
|
#define SANITIZER_HAS_STAT64 0
|
||||||
|
#define SANITIZER_HAS_STATFS64 0
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
// Must be SANITIZER_LINUX then
|
||||||
|
#define SANITIZER_HAS_STAT64 1
|
||||||
|
#if SANITIZER_ANDROID
|
||||||
|
#define SANITIZER_HAS_STATFS64 0 // Intercepting statfs64 seems to be broken on Android
|
||||||
|
#else
|
||||||
|
#define SANITIZER_HAS_STATFS64 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__sparc__)
|
#if defined(__sparc__)
|
||||||
// FIXME: This can't be included from tsan which does not support sparc yet.
|
// FIXME: This can't be included from tsan which does not support sparc yet.
|
||||||
#include "sanitizer_glibc_version.h"
|
#include "sanitizer_glibc_version.h"
|
||||||
|
@ -29,7 +48,7 @@
|
||||||
namespace __sanitizer {
|
namespace __sanitizer {
|
||||||
extern unsigned struct_utsname_sz;
|
extern unsigned struct_utsname_sz;
|
||||||
extern unsigned struct_stat_sz;
|
extern unsigned struct_stat_sz;
|
||||||
#if !SANITIZER_IOS
|
#if SANITIZER_HAS_STAT64
|
||||||
extern unsigned struct_stat64_sz;
|
extern unsigned struct_stat64_sz;
|
||||||
#endif
|
#endif
|
||||||
extern unsigned struct_rusage_sz;
|
extern unsigned struct_rusage_sz;
|
||||||
|
@ -49,7 +68,9 @@ extern unsigned struct_itimerspec_sz;
|
||||||
extern unsigned struct_sigevent_sz;
|
extern unsigned struct_sigevent_sz;
|
||||||
extern unsigned struct_stack_t_sz;
|
extern unsigned struct_stack_t_sz;
|
||||||
extern unsigned struct_sched_param_sz;
|
extern unsigned struct_sched_param_sz;
|
||||||
|
#if SANITIZER_HAS_STATFS64
|
||||||
extern unsigned struct_statfs64_sz;
|
extern unsigned struct_statfs64_sz;
|
||||||
|
#endif
|
||||||
extern unsigned struct_regex_sz;
|
extern unsigned struct_regex_sz;
|
||||||
extern unsigned struct_regmatch_sz;
|
extern unsigned struct_regmatch_sz;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue