From b297fd7974b282b66605547c7adb2eadbf82214f Mon Sep 17 00:00:00 2001 From: Sam James Date: Sun, 21 May 2023 02:06:14 +0100 Subject: [PATCH] [msan] Don't intercept LFS prlimit64/getrlimit64 on musl These are aliases on musl and as of 1.2.4, aren't visible by default (only with -D_LARGEFILE64_SOURCE), and will be removed entirely in a future release. This fixes a runtime failure with msan on musl-1.2.4: ``` $ echo 'int main(){}' | clang -x c - -fsanitize=memory -o /dev/null /usr/bin/x86_64-gentoo-linux-musl-ld.bfd: /usr/lib/llvm/16/bin/../../../../lib/clang/16/lib/linux/libclang_rt.msan-x86_64.a(msan_interceptors.cpp.o): in function `__interceptor_getrlimit64': [...] ``` Bug: https://bugs.gentoo.org/906603 Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D150925 --- compiler-rt/lib/msan/msan_interceptors.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp index 8cf724b..3ebcc7f 100644 --- a/compiler-rt/lib/msan/msan_interceptors.cpp +++ b/compiler-rt/lib/msan/msan_interceptors.cpp @@ -678,7 +678,7 @@ INTERCEPTOR(int, fstat, int fd, void *buf) { #define MSAN_MAYBE_INTERCEPT_FSTAT #endif -#if SANITIZER_STAT_LINUX +#if SANITIZER_GLIBC INTERCEPTOR(int, fstat64, int fd, void *buf) { ENSURE_MSAN_INITED(); int res = REAL(fstat64)(fd, buf); @@ -825,6 +825,7 @@ INTERCEPTOR(int, __getrlimit, int resource, void *rlim) { INTERCEPTOR_GETRLIMIT_BODY(__getrlimit, resource, rlim); } +#if SANITIZER_GLIBC INTERCEPTOR(int, getrlimit64, int resource, void *rlim) { if (msan_init_is_running) return REAL(getrlimit64)(resource, rlim); ENSURE_MSAN_INITED(); @@ -832,6 +833,9 @@ INTERCEPTOR(int, getrlimit64, int resource, void *rlim) { if (!res) __msan_unpoison(rlim, __sanitizer::struct_rlimit64_sz); return res; } +#else +#define MSAN_MAYBE_INTERCEPT_GETRLIMIT64 INTERCEPT_FUNCTION(getrlimit64) +#endif INTERCEPTOR(int, prlimit, int pid, int resource, void *new_rlimit, void *old_rlimit) { @@ -844,6 +848,7 @@ INTERCEPTOR(int, prlimit, int pid, int resource, void *new_rlimit, return res; } +#if SANITIZER_GLIBC INTERCEPTOR(int, prlimit64, int pid, int resource, void *new_rlimit, void *old_rlimit) { if (msan_init_is_running) @@ -854,6 +859,9 @@ INTERCEPTOR(int, prlimit64, int pid, int resource, void *new_rlimit, if (!res) __msan_unpoison(old_rlimit, __sanitizer::struct_rlimit64_sz); return res; } +#else +#define MSAN_MAYBE_INTERCEPT_PRLIMIT64 INTERCEPT_FUNCTION(prlimit64) +#endif #define MSAN_MAYBE_INTERCEPT___GETRLIMIT INTERCEPT_FUNCTION(__getrlimit) #define MSAN_MAYBE_INTERCEPT_GETRLIMIT64 INTERCEPT_FUNCTION(getrlimit64) @@ -1777,9 +1785,13 @@ void InitializeInterceptors() { MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED; INTERCEPT_FUNCTION(getrlimit); MSAN_MAYBE_INTERCEPT___GETRLIMIT; +#if SANITIZER_GLIBC MSAN_MAYBE_INTERCEPT_GETRLIMIT64; +#endif MSAN_MAYBE_INTERCEPT_PRLIMIT; +#if SANITIZER_GLIBC MSAN_MAYBE_INTERCEPT_PRLIMIT64; +#endif INTERCEPT_FUNCTION(gethostname); MSAN_MAYBE_INTERCEPT_EPOLL_WAIT; MSAN_MAYBE_INTERCEPT_EPOLL_PWAIT; -- 2.7.4