From patchwork Mon Nov 19 18:14:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Mi X-Patchwork-Id: 200056 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 634BF2C0093 for ; Tue, 20 Nov 2012 05:14:45 +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=1353953685; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received: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=zN1XH96 WYQnxa5Cg68wlxn9NQpY=; b=tBaQTEksw+yLKLTmfKE4GpRt9+b7Ze7z6rCHsTX c6pqK0saZVuVD+s/Zn2aHDIbRf5I4232xHuOsz+GpZeoBV2yQF4hIIYX9wqA6P0+ sLOKv0EiyK0xvCxH7yS093GvbKlRAhZAUJertAQpt3P37zmmGTcmEyExp/sX1Y+V aKT0= 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: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=CxfXSFHKa555rlR+5aOL+uFH4Y5Mkk4cwuGSe201/PfKKiryn6jrvwsVxTUXv2 7TBoFeF8rdrro5vE89VqZEcUdvMIEqD8pxNb7zAazfkuh/9GwkwEk57sQVMSXFXM C4YvTheF74VtZwag3gmSV1mZvmc1tY7VT24qFLvMcPtyA=; Received: (qmail 23531 invoked by alias); 19 Nov 2012 18:14:31 -0000 Received: (qmail 23523 invoked by uid 22791); 19 Nov 2012 18:14:30 -0000 X-SWARE-Spam-Status: No, hits=-4.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KAM_STOCKGEN, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_DB, TW_FD 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; Mon, 19 Nov 2012 18:14:22 +0000 Received: by mail-qc0-f175.google.com with SMTP id j3so3543063qcs.20 for ; Mon, 19 Nov 2012 10:14:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=jUmU4kDCkHpWDnYpWg2VTVqnPMxVbPo2hF0dQ94rgoc=; b=GpLaAY7tvb3jWfCcW7WjRZLlNuX+VYe4rHjAdQ3yH9Qd6XD+rbYSkQIDsDx59d6nLx UexRAxAbRnwYWFQb1rY9a6gGuWQIE8e3hoJrUx3PAePqUqZVTXCKh8SmLfRCbUEiAD/U tx9nLbzvoJGUEHTJA6SzGzveyM+q7ejWXdbMeRedaKWpPAu3WFN69jhf5Zv4zKhTqDie QGjQ+unIJ6ooqVEOG5QelPDNhjQse7ZB5OmE0AvVWbcKbgbUGs26JBWtnvax3x3azViz Iip2KTvqFON+nWJv+BPHZbGCr2iuxaTmOjRAgnmaISw+gSZ9JWlkR3fE0UoMayDkAoa2 YPrA== MIME-Version: 1.0 Received: by 10.224.179.212 with SMTP id br20mr12301895qab.51.1353348861567; Mon, 19 Nov 2012 10:14:21 -0800 (PST) Received: by 10.49.60.201 with HTTP; Mon, 19 Nov 2012 10:14:21 -0800 (PST) Date: Mon, 19 Nov 2012 10:14:21 -0800 Message-ID: Subject: [PATCH] Change -faddress-sanitizer to -fsanitize=address From: Wei Mi To: GCC Patches Cc: David Li , Diego Novillo , Jakub Jelinek , Kostya Serebryany , Dodji Seketeli X-Gm-Message-State: ALoCoQnZYFyHk98AYwrSDxnu/KN7qohKh94DVFFOefO+Ek/qnAmmnSzcBSFKpiLIPkKs50J7vEuF8r+E3z8Nj36VMeePEUKe0bfUIJAMMXw6dajaqRn1ETpyZl4+/2+JLxQen2qTkQK+CbDTYLTKT9i3nyPoFOf90+zB2bPx+1tLsEqqpv10zJA89cYnIkN4YVVEcT3vbtld 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 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/cfgexpand.c =================================================================== --- gcc/cfgexpand.c (revision 193614) +++ gcc/cfgexpand.c (working copy) @@ -765,7 +765,7 @@ partition_stack_vars (void) sizes, as the shorter vars wouldn't be adequately protected. Don't do that for "large" (unsupported) alignment objects, those aren't protected anyway. */ - if (flag_asan && isize != jsize + if (flag_sanitize == SANITIZE_ADDRESS && isize != jsize && ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT) break; @@ -941,7 +941,7 @@ expand_stack_vars (bool (*pred) (size_t) alignb = stack_vars[i].alignb; if (alignb * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT) { - if (flag_asan && pred) + if (flag_sanitize == SANITIZE_ADDRESS && pred) { HOST_WIDE_INT prev_offset = frame_offset; tree repr_decl = NULL_TREE; @@ -1111,7 +1111,7 @@ defer_stack_allocation (tree var, bool t /* If stack protection is enabled, *all* stack variables must be deferred, so that we can re-order the strings to the top of the frame. Similarly for Address Sanitizer. */ - if (flag_stack_protect || flag_asan) + if (flag_stack_protect || flag_sanitize == SANITIZE_ADDRESS) return true; /* We handle "large" alignment via dynamic allocation. We want to handle @@ -1693,7 +1693,7 @@ expand_used_vars (void) expand_stack_vars (stack_protect_decl_phase_2, &data); } - if (flag_asan) + if (flag_sanitize == SANITIZE_ADDRESS) /* Phase 3, any partitions that need asan protection in addition to phase 1 and 2. */ expand_stack_vars (asan_decl_phase_3, &data); Index: gcc/testsuite/lib/asan-dg.exp =================================================================== --- gcc/testsuite/lib/asan-dg.exp (revision 193614) +++ gcc/testsuite/lib/asan-dg.exp (working copy) @@ -20,7 +20,7 @@ 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/varasm.c =================================================================== --- gcc/varasm.c (revision 193614) +++ gcc/varasm.c (working copy) @@ -1832,7 +1832,7 @@ assemble_noswitch_variable (tree decl, c size = tree_low_cst (DECL_SIZE_UNIT (decl), 1); rounded = size; - if (flag_asan && asan_protect_global (decl)) + if (flag_sanitize == SANITIZE_ADDRESS && asan_protect_global (decl)) size += asan_red_zone_size (size); /* Don't allocate zero bytes of common, @@ -1990,7 +1990,7 @@ assemble_variable (tree decl, int top_le align_variable (decl, dont_output_data); - if (flag_asan + if (flag_sanitize == SANITIZE_ADDRESS && asan_protect_global (decl)) { asan_protected = true; @@ -6942,7 +6942,8 @@ place_block_symbol (rtx symbol) decl = SYMBOL_REF_DECL (symbol); alignment = DECL_ALIGN (decl); size = tree_low_cst (DECL_SIZE_UNIT (decl), 1); - if (flag_asan && asan_protect_global (decl)) + if (flag_sanitize == SANITIZE_ADDRESS + && asan_protect_global (decl)) size += asan_red_zone_size (size); } Index: gcc/flag-types.h =================================================================== --- gcc/flag-types.h (revision 193614) +++ gcc/flag-types.h (working copy) @@ -200,4 +200,10 @@ enum fp_contract_mode { FP_CONTRACT_FAST = 2 }; +/* Sanitize mode */ +enum sanitize_type { + SANITIZE_OFF, + SANITIZE_ADDRESS, + SANITIZE_THREAD +}; #endif /* ! GCC_FLAG_TYPES_H */ Index: gcc/asan.c =================================================================== --- gcc/asan.c (revision 193614) +++ gcc/asan.c (working copy) @@ -1587,7 +1587,7 @@ asan_instrument (void) static bool gate_asan (void) { - return flag_asan != 0; + return flag_sanitize == SANITIZE_ADDRESS; } struct gimple_opt_pass pass_asan = @@ -1614,7 +1614,7 @@ struct gimple_opt_pass pass_asan = static bool gate_asan_O0 (void) { - return flag_asan != 0 && !optimize; + return flag_sanitize == SANITIZE_ADDRESS && !optimize; } struct gimple_opt_pass pass_asan_O0 = Index: gcc/toplev.c =================================================================== --- gcc/toplev.c (revision 193614) +++ gcc/toplev.c (working copy) @@ -572,7 +572,7 @@ compile_file (void) mudflap_finish_file (); /* File-scope initialization for AddressSanitizer. */ - if (flag_asan) + if (flag_sanitize == SANITIZE_ADDRESS) asan_finish_file (); output_shared_constant_pool (); @@ -1545,12 +1545,12 @@ process_options (void) } /* Address Sanitizer needs porting to each target architecture. */ - if (flag_asan + if (flag_sanitize == SANITIZE_ADDRESS && (targetm.asan_shadow_offset == NULL || !FRAME_GROWS_DOWNWARD)) { warning (0, "-faddress-sanitizer not supported for this target"); - flag_asan = 0; + flag_sanitize = SANITIZE_OFF; } /* Enable -Werror=coverage-mismatch when -Werror and -Wno-error Index: gcc/gcc.c =================================================================== --- gcc/gcc.c (revision 193614) +++ 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 Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 193614) +++ gcc/common.opt (working copy) @@ -840,9 +840,18 @@ fargument-noalias-anything Common Ignore Does nothing. Preserved for backward compatibility. -faddress-sanitizer -Common Report Var(flag_asan) -Enable AddressSanitizer, a memory error detector +fsanitize= +Common Joined RejectNegative Enum(sanitize_type) Var(flag_sanitize) Init(SANITIZE_OFF) +-fsanitize=[address|thread] Specify to run a type of sanitize test + +Enum +Name(sanitize_type) Type(sanitize_type) UnknownError(unknown sanitize type %qs) + +EnumValue +Enum(sanitize_type) String(address) Value(SANITIZE_ADDRESS) + +EnumValue +Enum(sanitize_type) String(thread) Value(SANITIZE_THREAD) fasynchronous-unwind-tables Common Report Var(flag_asynchronous_unwind_tables) Optimization Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 193614) +++ 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,11 +6856,14 @@ assumptions based on that. The default is @option{-fzero-initialized-in-bss}. -@item -faddress-sanitizer -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. -See @uref{http://code.google.com/p/address-sanitizer/} for more details. +@item -fsanitize=[address|thread] +Enable AddressSanitizer or ThreadSanitizer. AddressSanitizer is a fast +memory error detector. Memory access instructions will be instrumented +to detect out-of-bounds, use-after-free, stack overflow and global +overflow bugs. ThreadSanitizer is a fast data race detector. +See @uref{http://code.google.com/p/address-sanitizer/} and +@uref{http://code.google.com/p/data-race-test/wiki/ThreadSanitizer} +for more details. @item -fmudflap -fmudflapth -fmudflapir @opindex fmudflap @@ -9938,7 +9942,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