[compiler-rt] r372461 - Add __lsan::ScopedInterceptorDisabler for strerror(3)
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 21 00:45:03 PDT 2019
Author: kamil
Date: Sat Sep 21 00:45:02 2019
New Revision: 372461
URL: http://llvm.org/viewvc/llvm-project?rev=372461&view=rev
Log:
Add __lsan::ScopedInterceptorDisabler for strerror(3)
Summary:
strerror(3) on NetBSD uses internally TSD with a destructor that is never
fired for exit(3). It's correctly called for pthread_exit(3) scenarios.
This is a case when a leak on exit(3) is expected, unavoidable and harmless.
Reviewers: joerg, vitalybuka, dvyukov, mgorny
Reviewed By: vitalybuka
Subscribers: dmgreen, kristof.beyls, jfb, llvm-commits, #sanitizers
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D67337
Modified:
compiler-rt/trunk/lib/asan/asan_interceptors.cpp
compiler-rt/trunk/lib/lsan/lsan_interceptors.cpp
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cpp?rev=372461&r1=372460&r2=372461&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cpp (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cpp Sat Sep 21 00:45:02 2019
@@ -164,6 +164,11 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free,
ASAN_MEMSET_IMPL(ctx, block, c, size); \
} while (false)
+#if CAN_SANITIZE_LEAKS
+#define COMMON_INTERCEPTOR_STRERROR() \
+ __lsan::ScopedInterceptorDisabler disabler
+#endif
+
#include "sanitizer_common/sanitizer_common_interceptors.inc"
#include "sanitizer_common/sanitizer_signal_interceptors.inc"
Modified: compiler-rt/trunk/lib/lsan/lsan_interceptors.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_interceptors.cpp?rev=372461&r1=372460&r2=372461&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_interceptors.cpp (original)
+++ compiler-rt/trunk/lib/lsan/lsan_interceptors.cpp Sat Sep 21 00:45:02 2019
@@ -383,6 +383,16 @@ INTERCEPTOR(int, pthread_atfork, void (*
#define LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK
#endif
+#if SANITIZER_INTERCEPT_STRERROR
+INTERCEPTOR(char *, strerror, int errnum) {
+ __lsan::ScopedInterceptorDisabler disabler;
+ return REAL(strerror)(errnum);
+}
+#define LSAN_MAYBE_INTERCEPT_STRERROR INTERCEPT_FUNCTION(strerror)
+#else
+#define LSAN_MAYBE_INTERCEPT_STRERROR
+#endif
+
struct ThreadParam {
void *(*callback)(void *arg);
void *param;
@@ -496,6 +506,8 @@ void InitializeInterceptors() {
LSAN_MAYBE_INTERCEPT_ATEXIT;
LSAN_MAYBE_INTERCEPT_PTHREAD_ATFORK;
+ LSAN_MAYBE_INTERCEPT_STRERROR;
+
#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) {
Report("LeakSanitizer: failed to create thread key.\n");
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=372461&r1=372460&r2=372461&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Sat Sep 21 00:45:02 2019
@@ -36,6 +36,7 @@
// COMMON_INTERCEPTOR_MMAP_IMPL
// COMMON_INTERCEPTOR_COPY_STRING
// COMMON_INTERCEPTOR_STRNDUP_IMPL
+// COMMON_INTERCEPTOR_STRERROR
//===----------------------------------------------------------------------===//
#include "interception/interception.h"
@@ -301,6 +302,10 @@ bool PlatformHasDifferentMemcpyAndMemmov
return new_mem;
#endif
+#ifndef COMMON_INTERCEPTOR_STRERROR
+#define COMMON_INTERCEPTOR_STRERROR() {}
+#endif
+
struct FileMetadata {
// For open_memstream().
char **addr;
@@ -3677,6 +3682,7 @@ INTERCEPTOR(int, sched_getparam, int pid
INTERCEPTOR(char *, strerror, int errnum) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, strerror, errnum);
+ COMMON_INTERCEPTOR_STRERROR();
char *res = REAL(strerror)(errnum);
if (res) COMMON_INTERCEPTOR_INITIALIZE_RANGE(res, REAL(strlen)(res) + 1);
return res;
More information about the llvm-commits
mailing list