diff mbox

Change -faddress-sanitizer to -fsanitize=address

Message ID CA+4CFy5cJHSuHhX7YgaekGA7oGejmcRs9FNDzs4DghytbX-vzQ@mail.gmail.com
State New
Headers show

Commit Message

Wei Mi Nov. 19, 2012, 6:14 p.m. UTC
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.

Comments

Jakub Jelinek Nov. 19, 2012, 6:23 p.m. UTC | #1
On Mon, Nov 19, 2012 at 10:14:21AM -0800, Wei Mi wrote:
> This patch is to change -faddress-sanitizer to -fsanitize=address. Ok for trunk?

Ok, thanks.

> 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.

	Jakub
Konstantin Serebryany Nov. 19, 2012, 6:26 p.m. UTC | #2
FYI
Clang also supports the no- form (-fno-sanitize=address).
We probably want it here too, but preferably as a separate patch.
(or is it automatically implemented via some internal magic?)

--kcc

On Mon, Nov 19, 2012 at 10:14 PM, 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.
Xinliang David Li Nov. 19, 2012, 6:31 p.m. UTC | #3
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. 19, 2012, 6:57 p.m. UTC | #4
On Mon, Nov 19, 2012 at 10:26:26PM +0400, Konstantin Serebryany wrote:
> FYI
> Clang also supports the no- form (-fno-sanitize=address).
> We probably want it here too, but preferably as a separate patch.
> (or is it automatically implemented via some internal magic?)

So, how does it work in clang?
Does -fsanitize=address -fsanitize=thread enable both asan and tsan,
or just tsan?  Does -fsanitize=thread -fno-sanitize=address enable tsan or
not?  If -fsanitize=thread doesn't disable ASAN, then you can't
use the same flag variable for both, you need flag_asan and flag_tsan
as before on the compiler side, and just fsanitize=address and
fsanitize=thread in common.opt, without RejectNegative, and with appropriate
Var(flag_asan) resp. Var(flag_tsan).

> On Mon, Nov 19, 2012 at 10:14 PM, 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
Xinliang David Li Nov. 19, 2012, 7:15 p.m. UTC | #5
On Mon, Nov 19, 2012 at 10:57 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Mon, Nov 19, 2012 at 10:26:26PM +0400, Konstantin Serebryany wrote:
>> FYI
>> Clang also supports the no- form (-fno-sanitize=address).
>> We probably want it here too, but preferably as a separate patch.
>> (or is it automatically implemented via some internal magic?)
>
> So, how does it work in clang?
> Does -fsanitize=address -fsanitize=thread enable both asan and tsan,
> or just tsan?

I have not looked at the spec, but I think it should enable both, same
as ' -faddress-sanitizer -fthread-sanitizer'.


>  Does -fsanitize=thread -fno-sanitize=address enable tsan or
> not?

Yes, I think. Kostya can clarify.

>If -fsanitize=thread doesn't disable ASAN, then you can't
> use the same flag variable for both, you need flag_asan and flag_tsan
> as before on the compiler side, and just fsanitize=address and
> fsanitize=thread in common.opt, without RejectNegative, and with appropriate
> Var(flag_asan) resp. Var(flag_tsan).


that will work.

thanks,

David

>
>> On Mon, Nov 19, 2012 at 10:14 PM, 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
Wei Mi Nov. 19, 2012, 7:21 p.m. UTC | #6
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?

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. 19, 2012, 7:28 p.m. UTC | #7
On Mon, Nov 19, 2012 at 11:21:27AM -0800, 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?

If the two options are independent, then please don't commit the current
patch, rewrite it not to use enumerated type, use two different variables
etc.

fsanitize=address
Common Report Var(flag_asan)
Enable AddressSanitizer, a memory error detector

fsanitize=thread
Common Report Var(flag_tsan)
Enable ThreadSanitizer, a thread race detector

or something similar in common.opt, and no changes to places that use
flag_asan internally.  If this works, the patch for trunk right now
shouldn't include fsanitize=thread bits though, that should be moved over
into the tsan patch.

	Jakub
Konstantin Serebryany Nov. 20, 2012, 5:07 a.m. UTC | #8
On Mon, Nov 19, 2012 at 10:31 PM, 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?

asan and tsan can not coexist in the same process.
Until recently, using both flags with clang was causing a failure at
program startup, now it produces a build failure.

--kcc


>
> 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.
Konstantin Serebryany Nov. 20, 2012, 5:09 a.m. UTC | #9
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.
Xinliang David Li Nov. 20, 2012, 5:16 a.m. UTC | #10
If that is a limitation, the compiler should give a warning about it
instead of making them silently suppress each other. Think about some
other sanitizer options that can co-exist with asan or tsan in the
future.

David

On Mon, Nov 19, 2012 at 9:07 PM, Konstantin Serebryany
<konstantin.s.serebryany@gmail.com> wrote:
> On Mon, Nov 19, 2012 at 10:31 PM, 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?
>
> asan and tsan can not coexist in the same process.
> Until recently, using both flags with clang was causing a failure at
> program startup, now it produces a build failure.
>
> --kcc
>
>
>>
>> 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.
Konstantin Serebryany Nov. 20, 2012, 5:22 a.m. UTC | #11
On Tue, Nov 20, 2012 at 9:16 AM, Xinliang David Li <davidxl@google.com> wrote:
> If that is a limitation, the compiler should give a warning about it
> instead of making them silently suppress each other. Think about some
> other sanitizer options that can co-exist with asan or tsan in the
> future.

Yes, that's what we are moving to in clang (e.g. "ubsan" can co-exist
with tsan/tsan/msan).


>
> David
>
> On Mon, Nov 19, 2012 at 9:07 PM, Konstantin Serebryany
> <konstantin.s.serebryany@gmail.com> wrote:
>> On Mon, Nov 19, 2012 at 10:31 PM, 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?
>>
>> asan and tsan can not coexist in the same process.
>> Until recently, using both flags with clang was causing a failure at
>> program startup, now it produces a build failure.
>>
>> --kcc
>>
>>
>>>
>>> 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.
diff mbox

Patch

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