Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/gpl3/gcc/dist/libsanitizer Stop tracking atexit/__c...
details: https://anonhg.NetBSD.org/src/rev/dc53e00f12da
branches: trunk
changeset: 938545:dc53e00f12da
user: kamil <kamil%NetBSD.org@localhost>
date: Fri Sep 11 01:04:33 2020 +0000
description:
Stop tracking atexit/__cxa_atexit/pthread_atfork allocations in LSan/NetBSD
Cherry-pick and adapt:
commit 8827047551570b7ed7088765c3de2a8cce6823b8
Author: Kamil Rytarowski <n54%gmx.com@localhost>
Date: Sat Sep 21 07:30:42 2019 +0000
Stop tracking atexit/__cxa_atexit/pthread_atfork allocations in LSan/NetBSD
Summary:
The atexit(3) and __cxa_atexit() calls allocate internally memory and free on exit,
after executing all callback. This causes false positives as DoLeakCheck() is called
from the atexit handler. In the LSan/ASan tests there are strict checks triggering
false positives here.
Intercept all atexit(3) and __cxa_atexit() calls and disable LSan when calling the
real functions.
Stop tracing allocations in pthread_atfork(3) funtions, as there are performed
internal allocations that are not freed for the time of running StopTheWorld()
code. This avoids false-positives.
The same changes have to be replicated in the ASan and LSan runtime.
Non-NetBSD OSs are not tested and this code is restricted to NetBSD only.
Reviewers: dvyukov, joerg, mgorny, vitalybuka, eugenis
Reviewed By: vitalybuka
Subscribers: jfb, llvm-commits, #sanitizers
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D67331
llvm-svn: 372459
diffstat:
external/gpl3/gcc/dist/libsanitizer/asan/asan_interceptors.h | 12 ++
external/gpl3/gcc/dist/libsanitizer/lsan/lsan_interceptors.cc | 42 ++++++++++
external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h | 3 +
3 files changed, 57 insertions(+), 0 deletions(-)
diffs (99 lines):
diff -r ee8c1f816283 -r dc53e00f12da external/gpl3/gcc/dist/libsanitizer/asan/asan_interceptors.h
--- a/external/gpl3/gcc/dist/libsanitizer/asan/asan_interceptors.h Fri Sep 11 01:03:31 2020 +0000
+++ b/external/gpl3/gcc/dist/libsanitizer/asan/asan_interceptors.h Fri Sep 11 01:04:33 2020 +0000
@@ -103,12 +103,24 @@
# define ASAN_INTERCEPT___CXA_ATEXIT 0
#endif
+#if SANITIZER_NETBSD
+# define ASAN_INTERCEPT_ATEXIT 1
+#else
+# define ASAN_INTERCEPT_ATEXIT 0
+#endif
+
#if SANITIZER_LINUX && !SANITIZER_ANDROID
# define ASAN_INTERCEPT___STRDUP 1
#else
# define ASAN_INTERCEPT___STRDUP 0
#endif
+#if SANITIZER_NETBSD
+# define ASAN_INTERCEPT_PTHREAD_ATFORK 1
+#else
+# define ASAN_INTERCEPT_PTHREAD_ATFORK 0
+#endif
+
DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
DECLARE_REAL(char*, strchr, const char *str, int c)
DECLARE_REAL(SIZE_T, strlen, const char *s)
diff -r ee8c1f816283 -r dc53e00f12da external/gpl3/gcc/dist/libsanitizer/lsan/lsan_interceptors.cc
--- a/external/gpl3/gcc/dist/libsanitizer/lsan/lsan_interceptors.cc Fri Sep 11 01:03:31 2020 +0000
+++ b/external/gpl3/gcc/dist/libsanitizer/lsan/lsan_interceptors.cc Fri Sep 11 01:04:33 2020 +0000
@@ -348,6 +348,44 @@
#define LSAN_MAYBE_INTERCEPT_STRERROR
#endif
+#if SANITIZER_INTERCEPT___CXA_ATEXIT
+INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
+ void *dso_handle) {
+ __lsan::ScopedInterceptorDisabler disabler;
+ return REAL(__cxa_atexit)(func, arg, dso_handle);
+}
+#define LSAN_MAYBE_INTERCEPT___CXA_ATEXIT INTERCEPT_FUNCTION(__cxa_atexit)
+#else
+#define LSAN_MAYBE_INTERCEPT___CXA_ATEXIT
+#endif
+
+#if SANITIZER_INTERCEPT_ATEXIT
+INTERCEPTOR(int, atexit, void (*f)()) {
+ __lsan::ScopedInterceptorDisabler disabler;
+ return REAL(__cxa_atexit)((void (*)(void *a))f, 0, 0);
+}
+#define LSAN_MAYBE_INTERCEPT_ATEXIT INTERCEPT_FUNCTION(atexit)
+#else
+#define LSAN_MAYBE_INTERCEPT_ATEXIT
+#endif
+
+#if SANITIZER_INTERCEPT_PTHREAD_ATFORK
+extern "C" {
+extern int _pthread_atfork(void (*prepare)(), void (*parent)(),
+ void (*child)());
+};
+
+INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(),
+ void (*child)()) {
+ __lsan::ScopedInterceptorDisabler disabler;
+ // REAL(pthread_atfork) cannot be called due to symbol indirections at least on NetBSD
+ return _pthread_atfork(prepare, parent, child);
+}
+#define LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK INTERCEPT_FUNCTION(pthread_atfork)
+#else
+#define LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK
+#endif
+
struct ThreadParam {
void *(*callback)(void *arg);
void *param;
@@ -459,6 +497,10 @@
LSAN_MAYBE_INTERCEPT_STRERROR;
+ LSAN_MAYBE_INTERCEPT___CXA_ATEXIT;
+ LSAN_MAYBE_INTERCEPT_ATEXIT;
+ LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK;
+
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) {
Report("LeakSanitizer: failed to create thread key.\n");
diff -r ee8c1f816283 -r dc53e00f12da external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h
--- a/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h Fri Sep 11 01:03:31 2020 +0000
+++ b/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h Fri Sep 11 01:04:33 2020 +0000
@@ -508,5 +508,8 @@
#define SANITIZER_INTERCEPT_TTYENT SI_NETBSD
#define SANITIZER_INTERCEPT_PROTOENT SI_NETBSD
#define SANITIZER_INTERCEPT_NETENT SI_NETBSD
+#define SANITIZER_INTERCEPT___CXA_ATEXIT SI_NETBSD
+#define SANITIZER_INTERCEPT_ATEXIT SI_NETBSD
+#define SANITIZER_INTERCEPT_PTHREAD_ATFORK SI_NETBSD
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Home |
Main Index |
Thread Index |
Old Index