From patchwork Sun Dec 2 02:43:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jack Howarth X-Patchwork-Id: 203177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 0D93D2C0086 for ; Sun, 2 Dec 2012 13:43:35 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1355021016; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=7DGtbLvPr5F1hXM3/UVZitoBow8=; b=KYzFS9nWBqDEmte F3lhiAUbFytrTgnG0FOG5Eb0EDWQkNZZjIsf3ZAd1XYKdQvPvh9ala66nIhJWacK 7N1IaRGtIYVG8KkHkHkMcPUZKtO4UrZdw0kb0Sb/3W80+aJgw8xmQdhMrApDW5aB PjFlhKH4ewvUFN3iDnDiA3F6Lry4= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=FJvwvmaZLlgYNLg2JHvNY1fG7dO+Au9Y+kI1QO/+uLjR0r4572ya2Z/X/1w7xj QFhj8nkfTyp6k+I+Ci6fK6uZxAp+sMIWRtEE7s4X7pAUapZuFgDxzzW2ucOKNL4m Nu0NaX3+6LmJnFCb6NGvxZvfgwyS1Og5nxrLwm2hvso8s=; Received: (qmail 30655 invoked by alias); 2 Dec 2012 02:43:20 -0000 Received: (qmail 30581 invoked by uid 22791); 2 Dec 2012 02:43:16 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, KHOP_SPAMHAUS_DROP, RP_MATCHES_RCVD, TW_LV X-Spam-Check-By: sourceware.org Received: from bromo.med.uc.edu (HELO bromo.med.uc.edu) (129.137.3.146) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 02 Dec 2012 02:43:05 +0000 Received: from bromo.med.uc.edu (localhost.localdomain [127.0.0.1]) by bromo.med.uc.edu (Postfix) with ESMTP id 17407B004B; Sat, 1 Dec 2012 21:43:04 -0500 (EST) Received: (from howarth@localhost) by bromo.med.uc.edu (8.14.3/8.14.3/Submit) id qB22h3lP000405; Sat, 1 Dec 2012 21:43:03 -0500 Date: Sat, 1 Dec 2012 21:43:03 -0500 From: Jack Howarth To: gcc-patches@gcc.gnu.org Cc: wmi@google.com, dodji@redhat.com, mikestump@comcast.net, iain@codesourcery.com, glider@google.com, konstantin.s.serebryany@gmail.com Subject: [PATCH] Fix PR55521 by switching libsanitizer from mach_override to mac interpose functions on darwin Message-ID: <20121202024303.GA32709@bromo.med.uc.edu> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The attached patch eliminates PR 55521/sanitizer by switching libasan on darwin from using mach_override to mac function interposition via the importation of the asan/dynamic/asan_interceptors_dynamic.cc file from llvm.org's compiler-rt svn. The changes involve defining USING_MAC_INTERPOSE in configure.ac rather than rather than USING_MACH_OVERRIDE, introduction of the use of USING_MAC_INTERPOSE in Makefile.am to avoid building the interception subdirectory, the passage of -DMAC_INTERPOSE_FUNCTIONS in asan/Makefile.am when USING_MAC_INTERPOSE as well as the introduction of a -DMISSING_BLOCKS_SUPPORT flag to disable code that requires blocks support which FSF gcc lacks. The depreciated usage of USING_MACH_OVERRIDE is also removed from interception/Makefile.am. Bootstrapped on x86_64-apple-darwin10, x86_64-apple-darwin11 and x86_64-apple-darwin12. Passes... make -k check RUNTESTFLAGS="asan.exp --target_board=unix'{-m32,-m64}'" and fixes the previously failing cond1.C test case from PR55521 on all three targets. Okay for gcc trunk? Jack 2012-12-01 Kostya Serebryany kcc@google.com Jack Howarth /libsanitizer PR 55521/sanitizer * configure.ac: Define USING_MAC_INTERPOSE when on darwin. * Makefile.am: Don't build interception subdir when USING_MAC_INTERPOSE defined. * asan/Makefile.am: Pass -DMAC_INTERPOSE_FUNCTIONS and -DMISSING_BLOCKS_SUPPORT when USING_MAC_INTERPOSE defined. Compile asan_interceptors_dynamic.cc but not libinterception when USING_MAC_INTERPOSE defined. * interception/Makefile.am: Remove usage of USING_MACH_OVERRIDE. * configure: Regenerated. * Makefile.in: Likewise. * asan/Makefile.in: Likewise. * interception/Makefile.in: Likewise. * asan/asan_intercepted_functions.h: Use MISSING_BLOCKS_SUPPORT. * asan/asan_mac.cc: Likewise. * asan/dynamic/asan_interceptors_dynamic.cc: Migrate from llvm and use MISSING_BLOCKS_SUPPORT. Index: libsanitizer/asan/asan_mac.cc =================================================================== --- libsanitizer/asan/asan_mac.cc (revision 194037) +++ libsanitizer/asan/asan_mac.cc (working copy) @@ -383,7 +383,7 @@ INTERCEPTOR(void, dispatch_group_async_f asan_dispatch_call_block_and_release); } -#if MAC_INTERPOSE_FUNCTIONS +#if defined(MAC_INTERPOSE_FUNCTIONS) && !defined(MISSING_BLOCKS_SUPPORT) // dispatch_async, dispatch_group_async and others tailcall the corresponding // dispatch_*_f functions. When wrapping functions with mach_override, those // dispatch_*_f are intercepted automatically. But with dylib interposition Index: libsanitizer/asan/asan_intercepted_functions.h =================================================================== --- libsanitizer/asan/asan_intercepted_functions.h (revision 194037) +++ libsanitizer/asan/asan_intercepted_functions.h (working copy) @@ -203,7 +203,7 @@ DECLARE_FUNCTION_AND_WRAPPER(void, __CFI DECLARE_FUNCTION_AND_WRAPPER(CFStringRef, CFStringCreateCopy, CFAllocatorRef alloc, CFStringRef str); DECLARE_FUNCTION_AND_WRAPPER(void, free, void* ptr); -#if MAC_INTERPOSE_FUNCTIONS +#if defined(MAC_INTERPOSE_FUNCTIONS) && !defined(MISSING_BLOCKS_SUPPORT) DECLARE_FUNCTION_AND_WRAPPER(void, dispatch_group_async, dispatch_group_t dg, dispatch_queue_t dq, void (^work)(void)); Index: libsanitizer/asan/Makefile.am =================================================================== --- libsanitizer/asan/Makefile.am (revision 194037) +++ libsanitizer/asan/Makefile.am (working copy) @@ -4,6 +4,9 @@ AM_CPPFLAGS = -I $(top_srcdir)/include - gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER) DEFS = -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DASAN_HAS_EXCEPTIONS=1 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 -DASAN_NEEDS_SEGV=1 +if USING_MAC_INTERPOSE +DEFS += -DMAC_INTERPOSE_FUNCTIONS -DMISSING_BLOCKS_SUPPORT +endif AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros -Wno-c99-extensions ACLOCAL_AMFLAGS = -I $(top_srcdir) -I $(top_srcdir)/config @@ -29,8 +32,14 @@ asan_files = \ asan_thread.cc \ asan_win.cc -libasan_la_SOURCES = $(asan_files) +libasan_la_SOURCES = $(asan_files) +if USING_MAC_INTERPOSE +libasan_la_SOURCES += dynamic/asan_interceptors_dynamic.cc +libasan_la_LIBADD = $(top_builddir)/sanitizer_common/libsanitizer_common.la $(top_builddir)/../libstdc++-v3/src/libstdc++.la +else libasan_la_LIBADD = $(top_builddir)/sanitizer_common/libsanitizer_common.la $(top_builddir)/interception/libinterception.la $(top_builddir)/../libstdc++-v3/src/libstdc++.la +endif + libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lpthread -ldl # Work around what appears to be a GNU make bug handling MAKEFLAGS Index: libsanitizer/interception/Makefile.am =================================================================== --- libsanitizer/interception/Makefile.am (revision 194037) +++ libsanitizer/interception/Makefile.am (working copy) @@ -14,11 +14,7 @@ interception_files = \ interception_mac.cc \ interception_win.cc -if USING_MACH_OVERRIDE -libinterception_la_SOURCES = $(interception_files) mach_override/mach_override.c -else libinterception_la_SOURCES = $(interception_files) -endif # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and Index: libsanitizer/configure.ac =================================================================== --- libsanitizer/configure.ac (revision 194037) +++ libsanitizer/configure.ac (working copy) @@ -81,10 +81,10 @@ unset TSAN_SUPPORTED AM_CONDITIONAL(TSAN_SUPPORTED, [test "x$TSAN_SUPPORTED" = "xyes"]) case "$host" in - *-*-darwin*) MACH_OVERRIDE=true ;; - *) MACH_OVERRIDE=false ;; + *-*-darwin*) MAC_INTERPOSE=true ;; + *) MAC_INTERPOSE=false ;; esac -AM_CONDITIONAL(USING_MACH_OVERRIDE, $MACH_OVERRIDE) +AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE) AC_CONFIG_FILES([Makefile]) Index: libsanitizer/Makefile.am =================================================================== --- libsanitizer/Makefile.am (revision 194037) +++ libsanitizer/Makefile.am (working copy) @@ -6,6 +6,10 @@ else SUBDIRS = interception sanitizer_common asan endif +if USING_MAC_INTERPOSE +SUBDIRS = sanitizer_common asan +endif + # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and # friends when we are called from the top level Makefile. --- /dev/null 2012-12-01 18:41:54.000000000 -0500 +++ libsanitizer/asan/dynamic/asan_interceptors_dynamic.cc 2012-12-01 18:37:57.000000000 -0500 @@ -0,0 +1,112 @@ +//===-- asan_interceptors_dynamic.cc --------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is a part of AddressSanitizer, an address sanity checker. +// +// __DATA,__interpose section of the dynamic runtime library for Mac OS. +//===----------------------------------------------------------------------===// + +#if defined(__APPLE__) + +#include "../asan_interceptors.h" +#include "../asan_intercepted_functions.h" + +namespace __asan { + +#if !MAC_INTERPOSE_FUNCTIONS +# error \ + Dynamic interposing library should be built with -DMAC_INTERPOSE_FUNCTIONS +#endif + +#define INTERPOSE_FUNCTION(function) \ + { reinterpret_cast(WRAP(function)), \ + reinterpret_cast(function) } + +#define INTERPOSE_FUNCTION_2(function, wrapper) \ + { reinterpret_cast(wrapper), \ + reinterpret_cast(function) } + +struct interpose_substitution { + const uptr replacement; + const uptr original; +}; + +__attribute__((used)) +const interpose_substitution substitutions[] + __attribute__((section("__DATA, __interpose"))) = { + INTERPOSE_FUNCTION(strlen), + INTERPOSE_FUNCTION(memcmp), + INTERPOSE_FUNCTION(memcpy), + INTERPOSE_FUNCTION(memmove), + INTERPOSE_FUNCTION(memset), + INTERPOSE_FUNCTION(strchr), + INTERPOSE_FUNCTION(strcat), + INTERPOSE_FUNCTION(strncat), + INTERPOSE_FUNCTION(strcpy), + INTERPOSE_FUNCTION(strncpy), + INTERPOSE_FUNCTION(pthread_create), + INTERPOSE_FUNCTION(longjmp), +#if ASAN_INTERCEPT__LONGJMP + INTERPOSE_FUNCTION(_longjmp), +#endif +#if ASAN_INTERCEPT_SIGLONGJMP + INTERPOSE_FUNCTION(siglongjmp), +#endif +#if ASAN_INTERCEPT_STRDUP + INTERPOSE_FUNCTION(strdup), +#endif +#if ASAN_INTERCEPT_STRNLEN + INTERPOSE_FUNCTION(strnlen), +#endif +#if ASAN_INTERCEPT_INDEX + INTERPOSE_FUNCTION_2(index, WRAP(strchr)), +#endif + INTERPOSE_FUNCTION(strcmp), + INTERPOSE_FUNCTION(strncmp), +#if ASAN_INTERCEPT_STRCASECMP_AND_STRNCASECMP + INTERPOSE_FUNCTION(strcasecmp), + INTERPOSE_FUNCTION(strncasecmp), +#endif + INTERPOSE_FUNCTION(atoi), + INTERPOSE_FUNCTION(atol), + INTERPOSE_FUNCTION(strtol), +#if ASAN_INTERCEPT_ATOLL_AND_STRTOLL + INTERPOSE_FUNCTION(atoll), + INTERPOSE_FUNCTION(strtoll), +#endif +#if ASAN_INTERCEPT_MLOCKX + INTERPOSE_FUNCTION(mlock), + INTERPOSE_FUNCTION(munlock), + INTERPOSE_FUNCTION(mlockall), + INTERPOSE_FUNCTION(munlockall), +#endif +#if defined(MAC_INTERPOSE_FUNCTIONS) && !defined(MISSING_BLOCKS_SUPPORT) + INTERPOSE_FUNCTION(dispatch_async_f), + INTERPOSE_FUNCTION(dispatch_sync_f), + INTERPOSE_FUNCTION(dispatch_after_f), + INTERPOSE_FUNCTION(dispatch_barrier_async_f), + INTERPOSE_FUNCTION(dispatch_group_async_f), + + INTERPOSE_FUNCTION(dispatch_group_async), + INTERPOSE_FUNCTION(dispatch_async), + INTERPOSE_FUNCTION(dispatch_after), + INTERPOSE_FUNCTION(dispatch_source_set_event_handler), + INTERPOSE_FUNCTION(dispatch_source_set_cancel_handler), +#endif + INTERPOSE_FUNCTION(signal), + INTERPOSE_FUNCTION(sigaction), + + INTERPOSE_FUNCTION(__CFInitialize), + INTERPOSE_FUNCTION(CFStringCreateCopy), + INTERPOSE_FUNCTION(free), +}; + +} // namespace __asan + +#endif // __APPLE__