From: Mikhail Kashkarov Date: Mon, 17 Jun 2019 17:27:16 +0000 (+0300) Subject: New sanitizer option to disable dlclose processing X-Git-Tag: accepted/tizen/base/20191105.214104^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F90%2F216690%2F2;p=platform%2Fupstream%2Flinaro-gcc.git New sanitizer option to disable dlclose processing This is a simple workaround for https://github.com/google/sanitizers/issues/89: Avoid frames for functions from unloaded shared library. Rtld will unload dynamically loaded shared objects, we are not preventing unloading in this, just deferring it. This could hide potential bugs like accesing library range addressing after dlclose or some tricky cases for functions with __attribute__((__destructor__)) + code that relies on explicit call to dlclose. Change-Id: I14fb2b8846350e07040d6f9215b936d9b2956faa Signed-off-by: Mikhail Kashkarov --- diff --git a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc index e8cee58..f652db3 100644 --- a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc +++ b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc @@ -6016,6 +6016,10 @@ INTERCEPTOR(void*, dlopen, const char *filename, int flag) { } INTERCEPTOR(int, dlclose, void *handle) { + // Do not call dlclose to keep mapped memory ranges information to avoid + // frames. + if (common_flags()->no_dlclose) + return 0; void *ctx; MAYBE_FORWARD_TO_REAL(dlclose, handle); COMMON_INTERCEPTOR_ENTER_NOIGNORE(ctx, dlclose, handle); diff --git a/libsanitizer/sanitizer_common/sanitizer_flags.inc b/libsanitizer/sanitizer_common/sanitizer_flags.inc index a80c993..a1086a7 100644 --- a/libsanitizer/sanitizer_common/sanitizer_flags.inc +++ b/libsanitizer/sanitizer_common/sanitizer_flags.inc @@ -245,6 +245,9 @@ COMMON_FLAG(bool, intercept_stat, true, COMMON_FLAG(bool, intercept_send, true, "If set, uses custom wrappers for send* functions " "to find more errors.") +COMMON_FLAG(bool, no_dlclose, false, + "If set, dlclose will not be executed to avoid " + "frames.") COMMON_FLAG(bool, decorate_proc_maps, false, "If set, decorate sanitizer " "mappings in /proc/self/maps with " "user-readable names")