Hi,
This patch is to change -faddress-sanitizer to -fsanitize=address. Ok for trunk?
2012-11-19 Wei Mi <[email protected]>
* 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