Patchwork Change -faddress-sanitizer to -fsanitize=address

login
register
mail settings
Submitter Wei Mi
Date Nov. 21, 2012, 7:14 a.m.
Message ID <CA+4CFy5mAKetjwe23JNChCz49ezvupfFS1ut1XXZxsX91YGdvg@mail.gmail.com>
Download mbox | patch
Permalink /patch/200591/
State New
Headers show

Comments

Wei Mi - Nov. 21, 2012, 7:14 a.m.
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  <wmi@google.com>

        * 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
<konstantin.s.serebryany@gmail.com> wrote:
> On Mon, Nov 19, 2012 at 11:21 PM, Wei Mi <wmi@google.com> 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 <davidxl@google.com> 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 <wmi@google.com> wrote:
>>>> Hi,
>>>>
>>>> This patch is to change -faddress-sanitizer to -fsanitize=address. Ok for trunk?
>>>>
>>>> 2012-11-19  Wei Mi  <wmi@google.com>
>>>>
>>>>         * 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.
Jakub Jelinek - Nov. 21, 2012, 7:57 a.m.
On Tue, Nov 20, 2012 at 11:14:27PM -0800, Wei Mi wrote:
> 2012-11-21  Wei Mi  <wmi@google.com>
> 
>         * 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.

Ok, thanks.

>         * doc/invoke.texi (-fsanitize=[address|thread]): Document.

Just change [address|thread] to address in the ChangeLog entry.

	Jakub
Wei Mi - Nov. 21, 2012, 5:46 p.m.
Thanks! Done.
Committed revision 193702.

Regards,
Wei.

On Tue, Nov 20, 2012 at 11:57 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Tue, Nov 20, 2012 at 11:14:27PM -0800, Wei Mi wrote:
>> 2012-11-21  Wei Mi  <wmi@google.com>
>>
>>         * 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.
>
> Ok, thanks.
>
>>         * doc/invoke.texi (-fsanitize=[address|thread]): Document.
>
> Just change [address|thread] to address in the ChangeLog entry.
>
>         Jakub

Patch

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
 # <http://www.gnu.org/licenses/>.
 
-# 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