From owner-svn-src-all@freebsd.org Mon Feb 13 18:39:23 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 70558CDDCCE; Mon, 13 Feb 2017 18:39:23 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2E6711506; Mon, 13 Feb 2017 18:39:23 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v1DIdMre085134; Mon, 13 Feb 2017 18:39:22 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1DIdL8M085130; Mon, 13 Feb 2017 18:39:21 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201702131839.v1DIdL8M085130@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Mon, 13 Feb 2017 18:39:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r313702 - in stable/11/contrib/compiler-rt/lib: asan lsan sanitizer_common X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Feb 2017 18:39:23 -0000 Author: dim Date: Mon Feb 13 18:39:21 2017 New Revision: 313702 URL: https://svnweb.freebsd.org/changeset/base/313702 Log: MFC r313052: Pull in r293536 from upstream compiler-rt trunk: Recommit: Stop intercepting some malloc-related functions on FreeBSD and macOS Summary: In https://bugs.freebsd.org/215125 I was notified that some configure scripts attempt to test for the Linux-specific `mallinfo` and `mallopt` functions by compiling and linking small programs which references the functions, and observing whether that results in errors. FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so normally these tests would fail, but when sanitizers are enabled, they incorrectly succeed, because the sanitizers define interceptors for these functions. This also applies to some other malloc-related functions, such as `memalign`, `pvalloc` and `cfree`. Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`, `pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers. Also delete the non-functional `cfree` wrapper for Windows, to fix the test cases on that platform. Reviewers: emaste, kcc, rnk Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D27654 This prevents autoconf scripts from incorrectly detecting that functions like mallinfo, mallopt, memalign, pvalloc and cfree are supported. PR: 215125, 215455 Modified: stable/11/contrib/compiler-rt/lib/asan/asan_malloc_linux.cc stable/11/contrib/compiler-rt/lib/asan/asan_malloc_win.cc stable/11/contrib/compiler-rt/lib/lsan/lsan_interceptors.cc stable/11/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h Directory Properties: stable/11/ (props changed) Modified: stable/11/contrib/compiler-rt/lib/asan/asan_malloc_linux.cc ============================================================================== --- stable/11/contrib/compiler-rt/lib/asan/asan_malloc_linux.cc Mon Feb 13 17:44:07 2017 (r313701) +++ stable/11/contrib/compiler-rt/lib/asan/asan_malloc_linux.cc Mon Feb 13 18:39:21 2017 (r313702) @@ -50,12 +50,14 @@ INTERCEPTOR(void, free, void *ptr) { asan_free(ptr, &stack, FROM_MALLOC); } +#if SANITIZER_INTERCEPT_CFREE INTERCEPTOR(void, cfree, void *ptr) { GET_STACK_TRACE_FREE; if (UNLIKELY(IsInDlsymAllocPool(ptr))) return; asan_free(ptr, &stack, FROM_MALLOC); } +#endif // SANITIZER_INTERCEPT_CFREE INTERCEPTOR(void*, malloc, uptr size) { if (UNLIKELY(!asan_inited)) @@ -85,22 +87,24 @@ INTERCEPTOR(void*, realloc, void *ptr, u return asan_realloc(ptr, size, &stack); } +#if SANITIZER_INTERCEPT_MEMALIGN INTERCEPTOR(void*, memalign, uptr boundary, uptr size) { GET_STACK_TRACE_MALLOC; return asan_memalign(boundary, size, &stack, FROM_MALLOC); } -INTERCEPTOR(void*, aligned_alloc, uptr boundary, uptr size) { - GET_STACK_TRACE_MALLOC; - return asan_memalign(boundary, size, &stack, FROM_MALLOC); -} - INTERCEPTOR(void*, __libc_memalign, uptr boundary, uptr size) { GET_STACK_TRACE_MALLOC; void *res = asan_memalign(boundary, size, &stack, FROM_MALLOC); DTLS_on_libc_memalign(res, size); return res; } +#endif // SANITIZER_INTERCEPT_MEMALIGN + +INTERCEPTOR(void*, aligned_alloc, uptr boundary, uptr size) { + GET_STACK_TRACE_MALLOC; + return asan_memalign(boundary, size, &stack, FROM_MALLOC); +} INTERCEPTOR(uptr, malloc_usable_size, void *ptr) { GET_CURRENT_PC_BP_SP; @@ -108,6 +112,7 @@ INTERCEPTOR(uptr, malloc_usable_size, vo return asan_malloc_usable_size(ptr, pc, bp); } +#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO // We avoid including malloc.h for portability reasons. // man mallinfo says the fields are "long", but the implementation uses int. // It doesn't matter much -- we just need to make sure that the libc's mallinfo @@ -125,6 +130,7 @@ INTERCEPTOR(struct fake_mallinfo, mallin INTERCEPTOR(int, mallopt, int cmd, int value) { return -1; } +#endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) { GET_STACK_TRACE_MALLOC; @@ -137,10 +143,12 @@ INTERCEPTOR(void*, valloc, uptr size) { return asan_valloc(size, &stack); } +#if SANITIZER_INTERCEPT_PVALLOC INTERCEPTOR(void*, pvalloc, uptr size) { GET_STACK_TRACE_MALLOC; return asan_pvalloc(size, &stack); } +#endif // SANITIZER_INTERCEPT_PVALLOC INTERCEPTOR(void, malloc_stats, void) { __asan_print_accumulated_stats(); Modified: stable/11/contrib/compiler-rt/lib/asan/asan_malloc_win.cc ============================================================================== --- stable/11/contrib/compiler-rt/lib/asan/asan_malloc_win.cc Mon Feb 13 17:44:07 2017 (r313701) +++ stable/11/contrib/compiler-rt/lib/asan/asan_malloc_win.cc Mon Feb 13 18:39:21 2017 (r313702) @@ -56,11 +56,6 @@ void _free_base(void *ptr) { } ALLOCATION_FUNCTION_ATTRIBUTE -void cfree(void *ptr) { - CHECK(!"cfree() should not be used on Windows"); -} - -ALLOCATION_FUNCTION_ATTRIBUTE void *malloc(size_t size) { GET_STACK_TRACE_MALLOC; return asan_malloc(size, &stack); Modified: stable/11/contrib/compiler-rt/lib/lsan/lsan_interceptors.cc ============================================================================== --- stable/11/contrib/compiler-rt/lib/lsan/lsan_interceptors.cc Mon Feb 13 17:44:07 2017 (r313701) +++ stable/11/contrib/compiler-rt/lib/lsan/lsan_interceptors.cc Mon Feb 13 18:39:21 2017 (r313702) @@ -19,6 +19,7 @@ #include "sanitizer_common/sanitizer_flags.h" #include "sanitizer_common/sanitizer_internal_defs.h" #include "sanitizer_common/sanitizer_linux.h" +#include "sanitizer_common/sanitizer_platform_interceptors.h" #include "sanitizer_common/sanitizer_platform_limits_posix.h" #include "sanitizer_common/sanitizer_tls_get_addr.h" #include "lsan.h" @@ -86,11 +87,26 @@ INTERCEPTOR(void*, realloc, void *q, upt return Reallocate(stack, q, size, 1); } +#if SANITIZER_INTERCEPT_MEMALIGN INTERCEPTOR(void*, memalign, uptr alignment, uptr size) { ENSURE_LSAN_INITED; GET_STACK_TRACE_MALLOC; return Allocate(stack, size, alignment, kAlwaysClearMemory); } +#define LSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign) + +INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) { + ENSURE_LSAN_INITED; + GET_STACK_TRACE_MALLOC; + void *res = Allocate(stack, size, alignment, kAlwaysClearMemory); + DTLS_on_libc_memalign(res, size); + return res; +} +#define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign) +#else +#define LSAN_MAYBE_INTERCEPT_MEMALIGN +#define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN +#endif // SANITIZER_INTERCEPT_MEMALIGN INTERCEPTOR(void*, aligned_alloc, uptr alignment, uptr size) { ENSURE_LSAN_INITED; @@ -106,14 +122,6 @@ INTERCEPTOR(int, posix_memalign, void ** return 0; } -INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) { - ENSURE_LSAN_INITED; - GET_STACK_TRACE_MALLOC; - void *res = Allocate(stack, size, alignment, kAlwaysClearMemory); - DTLS_on_libc_memalign(res, size); - return res; -} - INTERCEPTOR(void*, valloc, uptr size) { ENSURE_LSAN_INITED; GET_STACK_TRACE_MALLOC; @@ -127,6 +135,7 @@ INTERCEPTOR(uptr, malloc_usable_size, vo return GetMallocUsableSize(ptr); } +#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO struct fake_mallinfo { int x[10]; }; @@ -136,11 +145,18 @@ INTERCEPTOR(struct fake_mallinfo, mallin internal_memset(&res, 0, sizeof(res)); return res; } +#define LSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo) INTERCEPTOR(int, mallopt, int cmd, int value) { return -1; } +#define LSAN_MAYBE_INTERCEPT_MALLOPT INTERCEPT_FUNCTION(mallopt) +#else +#define LSAN_MAYBE_INTERCEPT_MALLINFO +#define LSAN_MAYBE_INTERCEPT_MALLOPT +#endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO +#if SANITIZER_INTERCEPT_PVALLOC INTERCEPTOR(void*, pvalloc, uptr size) { ENSURE_LSAN_INITED; GET_STACK_TRACE_MALLOC; @@ -152,8 +168,17 @@ INTERCEPTOR(void*, pvalloc, uptr size) { } return Allocate(stack, size, GetPageSizeCached(), kAlwaysClearMemory); } +#define LSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc) +#else +#define LSAN_MAYBE_INTERCEPT_PVALLOC +#endif // SANITIZER_INTERCEPT_PVALLOC +#if SANITIZER_INTERCEPT_CFREE INTERCEPTOR(void, cfree, void *p) ALIAS(WRAPPER_NAME(free)); +#define LSAN_MAYBE_INTERCEPT_CFREE INTERCEPT_FUNCTION(cfree) +#else +#define LSAN_MAYBE_INTERCEPT_CFREE +#endif // SANITIZER_INTERCEPT_CFREE #define OPERATOR_NEW_BODY \ ENSURE_LSAN_INITED; \ @@ -277,17 +302,18 @@ namespace __lsan { void InitializeInterceptors() { INTERCEPT_FUNCTION(malloc); INTERCEPT_FUNCTION(free); - INTERCEPT_FUNCTION(cfree); + LSAN_MAYBE_INTERCEPT_CFREE; INTERCEPT_FUNCTION(calloc); INTERCEPT_FUNCTION(realloc); - INTERCEPT_FUNCTION(memalign); + LSAN_MAYBE_INTERCEPT_MEMALIGN; + LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN; + INTERCEPT_FUNCTION(aligned_alloc); INTERCEPT_FUNCTION(posix_memalign); - INTERCEPT_FUNCTION(__libc_memalign); INTERCEPT_FUNCTION(valloc); - INTERCEPT_FUNCTION(pvalloc); + LSAN_MAYBE_INTERCEPT_PVALLOC; INTERCEPT_FUNCTION(malloc_usable_size); - INTERCEPT_FUNCTION(mallinfo); - INTERCEPT_FUNCTION(mallopt); + LSAN_MAYBE_INTERCEPT_MALLINFO; + LSAN_MAYBE_INTERCEPT_MALLOPT; INTERCEPT_FUNCTION(pthread_create); INTERCEPT_FUNCTION(pthread_join); Modified: stable/11/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h ============================================================================== --- stable/11/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h Mon Feb 13 17:44:07 2017 (r313701) +++ stable/11/contrib/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h Mon Feb 13 18:39:21 2017 (r313702) @@ -318,4 +318,10 @@ #define SANITIZER_INTERCEPT___XSTAT64 SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT___LXSTAT SANITIZER_INTERCEPT___XSTAT #define SANITIZER_INTERCEPT___LXSTAT64 SI_LINUX_NOT_ANDROID + +#define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (!SI_FREEBSD && !SI_MAC) +#define SANITIZER_INTERCEPT_MEMALIGN (!SI_FREEBSD && !SI_MAC) +#define SANITIZER_INTERCEPT_PVALLOC (!SI_FREEBSD && !SI_MAC) +#define SANITIZER_INTERCEPT_CFREE (!SI_FREEBSD && !SI_MAC) + #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H