diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp --- a/compiler-rt/lib/msan/msan_interceptors.cpp +++ b/compiler-rt/lib/msan/msan_interceptors.cpp @@ -765,17 +765,24 @@ #define MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED #endif +#define INTERCEPTOR_GETRLIMIT_BODY(func, resource, rlim) \ + if (msan_init_is_running) \ + return REAL(getrlimit)(resource, rlim); \ + ENSURE_MSAN_INITED(); \ + int res = REAL(func)(resource, rlim); \ + if (!res) \ + __msan_unpoison(rlim, __sanitizer::struct_rlimit_sz); \ + return res + INTERCEPTOR(int, getrlimit, int resource, void *rlim) { - if (msan_init_is_running) - return REAL(getrlimit)(resource, rlim); - ENSURE_MSAN_INITED(); - int res = REAL(getrlimit)(resource, rlim); - if (!res) - __msan_unpoison(rlim, __sanitizer::struct_rlimit_sz); - return res; + INTERCEPTOR_GETRLIMIT_BODY(getrlimit, resource, rlim); } #if !SANITIZER_FREEBSD && !SANITIZER_NETBSD +INTERCEPTOR(int, __getrlimit, int resource, void *rlim) { + INTERCEPTOR_GETRLIMIT_BODY(__getrlimit, resource, rlim); +} + INTERCEPTOR(int, getrlimit64, int resource, void *rlim) { if (msan_init_is_running) return REAL(getrlimit64)(resource, rlim); ENSURE_MSAN_INITED(); @@ -806,10 +813,12 @@ return res; } +#define MSAN_MAYBE_INTERCEPT___GETRLIMIT INTERCEPT_FUNCTION(__getrlimit) #define MSAN_MAYBE_INTERCEPT_GETRLIMIT64 INTERCEPT_FUNCTION(getrlimit64) #define MSAN_MAYBE_INTERCEPT_PRLIMIT INTERCEPT_FUNCTION(prlimit) #define MSAN_MAYBE_INTERCEPT_PRLIMIT64 INTERCEPT_FUNCTION(prlimit64) #else +#define MSAN_MAYBE_INTERCEPT___GETRLIMIT #define MSAN_MAYBE_INTERCEPT_GETRLIMIT64 #define MSAN_MAYBE_INTERCEPT_PRLIMIT #define MSAN_MAYBE_INTERCEPT_PRLIMIT64 @@ -1678,6 +1687,7 @@ INTERCEPT_FUNCTION(socketpair); MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED; INTERCEPT_FUNCTION(getrlimit); + MSAN_MAYBE_INTERCEPT___GETRLIMIT; MSAN_MAYBE_INTERCEPT_GETRLIMIT64; MSAN_MAYBE_INTERCEPT_PRLIMIT; MSAN_MAYBE_INTERCEPT_PRLIMIT64; diff --git a/compiler-rt/test/msan/preinit_array.cpp b/compiler-rt/test/msan/preinit_array.cpp new file mode 100644 --- /dev/null +++ b/compiler-rt/test/msan/preinit_array.cpp @@ -0,0 +1,16 @@ +// RUN: %clangxx_msan -O0 %s -o %t && %run %t + +#include + +volatile int global; +static void pre_ctor() { + volatile int local; + global = 42; + local = 42; +} + +__attribute__((section(".preinit_array"), used)) void(*__local_pre_ctor)(void) = pre_ctor; + +int main(void) { + return 0; +}