From patchwork Wed Nov 21 07:14:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Mi X-Patchwork-Id: 200591 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 72B922C0085 for ; Wed, 21 Nov 2012 18:14:42 +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=1354086883; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:In-Reply-To:References:Date: Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=LfCnLylsPuqH0OfV9OqTiSsGf14=; b=qpVbLLTVI93JGAelL3VgJ/8+E2Fjmj7sG4U7LljbCM92nEJzjdKrmQt+e5bI7M K1umkpCdXvGqO1ygzpp0vmENKE0+SRxENs8Ia/TRhTBuJt2SFJNduFKlplUSAXdY 8WDVeK+jFQ7AI0Hg8io7zlxQemdaWxNy8eGjQts/pMFS8= 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:X-Google-DKIM-Signature:MIME-Version:Received:Received:In-Reply-To:References:Date:Message-ID:Subject:From:To:Cc:Content-Type:X-Gm-Message-State:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=eTkJciLyboyQTmDbd3EuSNOsrdQb9uiKYILmp7viGw2nIJLCCZu7DQo8KMNmWp 4DnOvO3cCOQ4gciU4DgG5l/xQo9ox/dn+WjLr5SwDlrH4rk2j12vilaWkr8JDKMi hQ/oFVYURiDrow6HI13K8QGmsDpGsYQEdK7gln3TPOR94=; Received: (qmail 22933 invoked by alias); 21 Nov 2012 07:14:35 -0000 Received: (qmail 22807 invoked by uid 22791); 21 Nov 2012 07:14:34 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_DB, TW_FD, TW_KC X-Spam-Check-By: sourceware.org Received: from mail-qc0-f175.google.com (HELO mail-qc0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 21 Nov 2012 07:14:28 +0000 Received: by mail-qc0-f175.google.com with SMTP id j3so4770914qcs.20 for ; Tue, 20 Nov 2012 23:14:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-gm-message-state; bh=K+cn923jFwQ60fRbyUSk8S2H/NIRMnhGOA2v7apSq8g=; b=IOsJIE4OOjYzdDFUog28vnRTvR/0gUJImjXy32wjVo2X5yLHIikMM9X7KR4VPJ2CMi eP+xz0pF22zHomzUMNmm5mSJRquyzpF74XgNv+kbb5l43ZVgwwBdEHjtCR+7A1X/pwDl FH8Nrx6Iac5cHUmrqYYYc+T5thJ53DFBjrg6Hj8SZk341SbfmW8OjpxCW6ZpirENOzSd 5vW/OWAvxuqL2vRBT1IzL4VTvkJaxcR1RJwE6ShLRBOiuWrX9HXPmvCO6vX76nuj+6l4 8X5qNxO09YLbPXodyA2bPMi9yS437z1TKs+Y7C9EZCC4coJP3sJdsnlfSsk+vx4JA2SG I8+w== MIME-Version: 1.0 Received: by 10.49.3.102 with SMTP id b6mr19861018qeb.26.1353482067700; Tue, 20 Nov 2012 23:14:27 -0800 (PST) Received: by 10.49.60.201 with HTTP; Tue, 20 Nov 2012 23:14:27 -0800 (PST) In-Reply-To: References: Date: Tue, 20 Nov 2012 23:14:27 -0800 Message-ID: Subject: Re: [PATCH] Change -faddress-sanitizer to -fsanitize=address From: Wei Mi To: Konstantin Serebryany Cc: Xinliang David Li , GCC Patches , Diego Novillo , Jakub Jelinek , Kostya Serebryany , Dodji Seketeli X-Gm-Message-State: ALoCoQlYg3rTa8PhvM4iiJ/JnYQd1Guhu2147YYprFTt8mWECK+iNxv9+Wk6xhhuzuylvM8zETeF6za6Xe23JR8hGl6a4cJod2whq2axEU5XJuZGbKv/4fPbyZKhF3zLP+0J8h/wMtIEv54eijL4mCiYIGDqeArXw0Wv47jNSkYboxnwZcwlJr5WkF1qQCVMdIrDBRpXskXX 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 I rewrite the patch according to Jakub's suggestion -- add the following option in common.opt and keep flag_asan. The patch is attached. Ok to checkin? fsanitize=address Common Report Var(flag_asan) Enable AddressSanitizer, a memory error detector 2012-11-21 Wei Mi * common.opt: Change faddress-sanitizer to fsanitize=address. * toplev.c (process_options): Likewise. * gcc.c (LINK_COMMAND_SPEC): Likewise. * testsuite/lib/asan-dg.exp (check_effective_target_faddress_sanitizer): Likewise. (asan_init): Likewise. * doc/invoke.texi (-fsanitize=[address|thread]): Document. Thanks, Wei. On Mon, Nov 19, 2012 at 9:09 PM, Konstantin Serebryany wrote: > On Mon, Nov 19, 2012 at 11:21 PM, Wei Mi wrote: >> I cannot remove RejectNegative and use -fno-sanitize=address, or else >> I will break an assertion (opts-common.c:614). The assertion requires >> -fxxx=var options set RejectNegative if var is of enumerater type. I >> see that all the other -fxxx=xxx options in common.opt set >> RejectNegative. >> >> Is it ok for me to checkin the current patch and submit another patch >> if there is a better way to do it? > > I would prefer to have the current patch earlier, rather then a more > comprehensive patch later. > Otherwise we may end up with too many uses of the old flag. > >> >> Thanks, >> Wei. >> >> On Mon, Nov 19, 2012 at 10:31 AM, Xinliang David Li wrote: >>> Questions: are -fsanitize=thread -fsanitize=address mutually exclusive >>> here? If yes, that will be wrong. >>> >>> How about -fsanitize=all option? >>> >>> As kcc mentioned, the -fno-.. form is not handled. >>> >>> David >>> >>> >>> On Mon, Nov 19, 2012 at 10:14 AM, Wei Mi wrote: >>>> Hi, >>>> >>>> This patch is to change -faddress-sanitizer to -fsanitize=address. Ok for trunk? >>>> >>>> 2012-11-19 Wei Mi >>>> >>>> * cfgexpand.c (partition_stack_vars): Change flag_asan to >>>> flag_sanitize. >>>> (expand_stack_vars): Likewise. >>>> (defer_stack_allocation): Likewise. >>>> (expand_used_vars): Likewise. >>>> * varasm.c (assemble_noswitch_variable): Likewise. >>>> (assemble_variable): Likewise. >>>> (place_block_symbol): Likewise. >>>> * asan.c (gate_asan): Likewise. >>>> (gate_asan_O0): Likewise. >>>> * toplev.c (compile_file): Likewise. >>>> (process_options): Likewise. >>>> * common.opt: Change faddress-sanitizer to fsanitize=address. >>>> * gcc.c (LINK_COMMAND_SPEC): Likewise. >>>> * testsuite/lib/asan-dg.exp >>>> (check_effective_target_faddress_sanitizer): Likewise. >>>> (asan_init): Likewise. >>>> * flag-types.h (sanitize_type): New enum type. >>>> * doc/invoke.texi (-fsanitize=[address|thread]): Document. >>>> >>>> Thanks, >>>> Wei. Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 193687) +++ gcc/common.opt (working copy) @@ -840,7 +840,7 @@ fargument-noalias-anything Common Ignore Does nothing. Preserved for backward compatibility. -faddress-sanitizer +fsanitize=address Common Report Var(flag_asan) Enable AddressSanitizer, a memory error detector Index: gcc/testsuite/lib/asan-dg.exp =================================================================== --- gcc/testsuite/lib/asan-dg.exp (revision 193687) +++ gcc/testsuite/lib/asan-dg.exp (working copy) @@ -14,13 +14,13 @@ # along with GCC; see the file COPYING3. If not see # . -# Return 1 if compilation with -faddress-sanitizer is error-free for trivial +# Return 1 if compilation with -fsanitize=address is error-free for trivial # code, 0 otherwise. proc check_effective_target_faddress_sanitizer {} { return [check_no_compiler_messages faddress_sanitizer object { void foo (void) { } - } "-faddress-sanitizer"] + } "-fsanitize=address"] } # @@ -83,12 +83,12 @@ proc asan_init { args } { } if [info exists ALWAYS_CXXFLAGS] { set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS] - set ALWAYS_CXXFLAGS [concat "{additional_flags=-faddress-sanitizer -g}" $ALWAYS_CXXFLAGS] + set ALWAYS_CXXFLAGS [concat "{additional_flags=-fsanitize=address -g}" $ALWAYS_CXXFLAGS] } else { if [info exists TEST_ALWAYS_FLAGS] { - set TEST_ALWAYS_FLAGS "$link_flags -faddress-sanitizer -g $TEST_ALWAYS_FLAGS" + set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=address -g $TEST_ALWAYS_FLAGS" } else { - set TEST_ALWAYS_FLAGS "$link_flags -faddress-sanitizer -g" + set TEST_ALWAYS_FLAGS "$link_flags -fsanitize=address -g" } } } Index: gcc/toplev.c =================================================================== --- gcc/toplev.c (revision 193687) +++ gcc/toplev.c (working copy) @@ -1549,7 +1549,7 @@ process_options (void) && (targetm.asan_shadow_offset == NULL || !FRAME_GROWS_DOWNWARD)) { - warning (0, "-faddress-sanitizer not supported for this target"); + warning (0, "-fsanitize=address not supported for this target"); flag_asan = 0; } Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 193687) +++ gcc/doc/invoke.texi (working copy) @@ -289,7 +289,8 @@ Objective-C and Objective-C++ Dialects}. @item Debugging Options @xref{Debugging Options,,Options for Debugging Your Program or GCC}. @gccoptlist{-d@var{letters} -dumpspecs -dumpmachine -dumpversion @gol --faddress-sanitizer -fdbg-cnt-list -fdbg-cnt=@var{counter-value-list} @gol +-fsanitize=@var{style} @gol +-fdbg-cnt-list -fdbg-cnt=@var{counter-value-list} @gol -fdisable-ipa-@var{pass_name} @gol -fdisable-rtl-@var{pass_name} @gol -fdisable-rtl-@var{pass-name}=@var{range-list} @gol @@ -6855,7 +6856,7 @@ assumptions based on that. The default is @option{-fzero-initialized-in-bss}. -@item -faddress-sanitizer +@item -fsanitize=address Enable AddressSanitizer, a fast memory error detector. Memory access instructions will be instrumented to detect out-of-bounds and use-after-free bugs. So far only heap bugs will be detected. @@ -9938,7 +9939,7 @@ for the languages used in the program, o @file{libgcc}. @item -static-libasan -When the @option{-faddress-sanitizer} option is used to link a program, +When the @option{-fsanitize=address} option is used to link a program, the GCC driver automatically links against @option{libasan}. If @file{libasan} is available as a shared library, and the @option{-static} option is not used, then this links against the shared version of Index: gcc/gcc.c =================================================================== --- gcc/gcc.c (revision 193687) +++ gcc/gcc.c (working copy) @@ -696,7 +696,7 @@ proper position among the other output f %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\ %(mflib) " STACK_SPLIT_SPEC "\ %{fprofile-arcs|fprofile-generate*|coverage:-lgcov}\ - %{faddress-sanitizer:" LIBASAN_SPEC "}\ + %{fsanitize=address:" LIBASAN_SPEC "}\ %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\ %{!nostdlib:%{!nostartfiles:%E}} %{T*} }}}}}}" #endif