From fb153d02da077fb18f52372dab68a8cc52ea3a54 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 6 Jan 2015 10:52:06 +0100 Subject: [PATCH] opts.c (common_handle_option): Add support for -fno-sanitize=all and -f{,no-}sanitize-recover=all. * opts.c (common_handle_option): Add support for -fno-sanitize=all and -f{,no-}sanitize-recover=all. * doc/invoke.texi: Document -fno-sanitize=all, -f{,no-}sanitize-recover=all. Document that -fsanitize=float-cast-overflow is not enabled by -fsanitize=undefined. Fix up documentation of -f{,no-}sanitize-recover. * c-c++-common/asan/sanitize-all-1.c: New test. * c-c++-common/ubsan/sanitize-all-1.c: New test. * c-c++-common/ubsan/sanitize-all-2.c: New test. * c-c++-common/ubsan/sanitize-all-3.c: New test. * c-c++-common/ubsan/sanitize-all-4.c: New test. From-SVN: r219241 --- gcc/ChangeLog | 10 +++++ gcc/doc/invoke.texi | 16 ++++++- gcc/opts.c | 11 ++++- gcc/testsuite/ChangeLog | 8 ++++ .../c-c++-common/asan/sanitize-all-1.c | 12 ++++++ .../c-c++-common/ubsan/sanitize-all-1.c | 8 ++++ .../c-c++-common/ubsan/sanitize-all-2.c | 41 ++++++++++++++++++ .../c-c++-common/ubsan/sanitize-all-3.c | 42 +++++++++++++++++++ .../c-c++-common/ubsan/sanitize-all-4.c | 42 +++++++++++++++++++ 9 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/asan/sanitize-all-1.c create mode 100644 gcc/testsuite/c-c++-common/ubsan/sanitize-all-1.c create mode 100644 gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c create mode 100644 gcc/testsuite/c-c++-common/ubsan/sanitize-all-3.c create mode 100644 gcc/testsuite/c-c++-common/ubsan/sanitize-all-4.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 812f980938b..daae241544f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2015-01-06 Jakub Jelinek + + * opts.c (common_handle_option): Add support for + -fno-sanitize=all and -f{,no-}sanitize-recover=all. + * doc/invoke.texi: Document -fno-sanitize=all, + -f{,no-}sanitize-recover=all. Document that + -fsanitize=float-cast-overflow is not enabled + by -fsanitize=undefined. Fix up documentation + of -f{,no-}sanitize-recover. + 2015-01-06 Eric Botcazou * config.gcc: Add Visium support. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 2e587f5d842..09706783a9a 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -5689,6 +5689,8 @@ be a legitimate way of obtaining infinities and NaNs. @opindex fsanitize=float-cast-overflow This option enables floating-point type to integer conversion checking. We check that the result of the conversion does not overflow. +Unlike other similar options, @option{-fsanitize=float-cast-overflow} is +not enabled by @option{-fsanitize=undefined}. This option does not work well with @code{FE_INVALID} exceptions enabled. @item -fsanitize=nonnull-attribute @@ -5724,6 +5726,13 @@ While @option{-ftrapv} causes traps for signed overflows to be emitted, @option{-fsanitize=undefined} gives a diagnostic message. This currently works only for the C family of languages. +@item -fno-sanitize=all +@opindex fno-sanitize=all + +This option disables all previously enabled sanitizers. +@option{-fsanitize=all} is not allowed, as some sanitizers cannot be used +together. + @item -fasan-shadow-offset=@var{number} @opindex fasan-shadow-offset This option forces GCC to use custom shadow offset in AddressSanitizer checks. @@ -5747,11 +5756,14 @@ Currently this feature only works for @option{-fsanitize=undefined} (and its sub except for @option{-fsanitize=unreachable} and @option{-fsanitize=return}), @option{-fsanitize=float-cast-overflow}, @option{-fsanitize=float-divide-by-zero} and @option{-fsanitize=kernel-address}. For these sanitizers error recovery is turned on by default. +@option{-fsanitize-recover=all} and @option{-fno-sanitize-recover=all} is also +accepted, the former enables recovery for all sanitizers that support it, +the latter disables recovery for all sanitizers that support it. Syntax without explicit @var{opts} parameter is deprecated. It is equivalent to -@option{-fsanitize-recover=undefined,float-cast-overflow,float-divide-by-zero,kernel-address}. +@option{-fsanitize-recover=undefined,float-cast-overflow,float-divide-by-zero}. Similarly @option{-fno-sanitize-recover} is equivalent to -@option{-fno-sanitize-recover=undefined,float-cast-overflow,float-divide-by-zero,kernel-address}. +@option{-fno-sanitize-recover=undefined,float-cast-overflow,float-divide-by-zero}. @item -fsanitize-undefined-trap-on-error @opindex fsanitize-undefined-trap-on-error diff --git a/gcc/opts.c b/gcc/opts.c index 1e7a2cc8710..8a16116665f 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -1588,6 +1588,7 @@ common_handle_option (struct gcc_options *opts, sizeof "returns-nonnull-attribute" - 1 }, { "object-size", SANITIZE_OBJECT_SIZE, sizeof "object-size" - 1 }, + { "all", ~0, sizeof "all" - 1 }, { NULL, 0, 0 } }; const char *comma; @@ -1611,7 +1612,15 @@ common_handle_option (struct gcc_options *opts, && memcmp (p, spec[i].name, len) == 0) { /* Handle both -fsanitize and -fno-sanitize cases. */ - if (value) + if (value && spec[i].flag == ~0U) + { + if (code == OPT_fsanitize_) + error_at (loc, "-fsanitize=all option is not valid"); + else + *flag |= ~(SANITIZE_USER_ADDRESS | SANITIZE_THREAD + | SANITIZE_LEAK); + } + else if (value) *flag |= spec[i].flag; else *flag &= ~spec[i].flag; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cbd491cc49d..634953cb0d5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2015-01-06 Jakub Jelinek + + * c-c++-common/asan/sanitize-all-1.c: New test. + * c-c++-common/ubsan/sanitize-all-1.c: New test. + * c-c++-common/ubsan/sanitize-all-2.c: New test. + * c-c++-common/ubsan/sanitize-all-3.c: New test. + * c-c++-common/ubsan/sanitize-all-4.c: New test. + 2015-01-06 Eric Botcazou * lib/target-supports.exp (check_profiling_available): Return 0 for diff --git a/gcc/testsuite/c-c++-common/asan/sanitize-all-1.c b/gcc/testsuite/c-c++-common/asan/sanitize-all-1.c new file mode 100644 index 00000000000..58e4079b0ee --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/sanitize-all-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fno-sanitize=all" } */ + +volatile int ten = 10; + +int main() { + volatile char x[10]; + x[ten]; + return 0; +} + +/* { dg-final { scan-assembler-not "__asan_load" } } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/sanitize-all-1.c b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-1.c new file mode 100644 index 00000000000..9ffba50443a --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-1.c @@ -0,0 +1,8 @@ +/* Test -f*sanitize*=all */ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */ +/* { dg-options "-fsanitize=all" } */ + +int i; + +/* { dg-error "-fsanitize=all option is not valid" "" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c new file mode 100644 index 00000000000..6ae6f3c233f --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c @@ -0,0 +1,41 @@ +/* Test -f*sanitize*=all */ +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */ +/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */ +/* { dg-options "-fsanitize=undefined,float-cast-overflow,float-divide-by-zero -fno-sanitize=all -fdump-tree-optimized" } */ + +int a[4]; + +int +f1 (int x, int y, int z) +{ + return a[x] + (1 << y) + (100 / z); +} + +char * +f2 (int x) +{ + char *p = (char *) __builtin_calloc (64, 1); + p[x] = 3; + return p; +} + +int +f3 (int x, int *y, double z, double w) +{ + int a[*y]; + if (x) + __builtin_unreachable (); + asm volatile ("" : : "r" (&a[0])); + return z / w; +} + +int +main () +{ + return 0; +} + +/* { dg-final { scan-tree-dump-not "__ubsan_" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "UBSAN_CHECK_" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/sanitize-all-3.c b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-3.c new file mode 100644 index 00000000000..9be62acdbe9 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-3.c @@ -0,0 +1,42 @@ +/* Test -f*sanitize*=all */ +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */ +/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */ +/* { dg-options "-fsanitize=undefined -fsanitize-recover=all -fdump-tree-optimized" } */ + +int a[4]; + +int +f1 (int x, int y, int z) +{ + return a[x] + (1 << y) + (100 / z); +} + +char * +f2 (int x) +{ + char *p = (char *) __builtin_calloc (64, 1); + p[x] = 3; + return p; +} + +int +f3 (int x, int *y, double z, double w) +{ + int a[*y]; + if (x) + __builtin_unreachable (); + asm volatile ("" : : "r" (&a[0])); + return z / w; +} + +int +main () +{ + return 0; +} + +/* { dg-final { scan-tree-dump "__ubsan_" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "__ubsan_\[a-z_\]*_abort" "optimized" } } */ +/* { dg-final { scan-tree-dump "UBSAN_CHECK_" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ diff --git a/gcc/testsuite/c-c++-common/ubsan/sanitize-all-4.c b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-4.c new file mode 100644 index 00000000000..1f7ec2b53f3 --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/sanitize-all-4.c @@ -0,0 +1,42 @@ +/* Test -f*sanitize*=all */ +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */ +/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */ +/* { dg-options "-fsanitize=undefined -fno-sanitize-recover=all -fdump-tree-optimized" } */ + +int a[4]; + +int +f1 (int x, int y, int z) +{ + return a[x] + (1 << y) + (100 / z); +} + +char * +f2 (int x) +{ + char *p = (char *) __builtin_calloc (64, 1); + p[x] = 3; + return p; +} + +int +f3 (int x, int *y, double z, double w) +{ + int a[*y]; + if (x) + __builtin_unreachable (); + asm volatile ("" : : "r" (&a[0])); + return z / w; +} + +int +main () +{ + return 0; +} + +/* { dg-final { scan-tree-dump "__ubsan_\[a-z_\]*_abort" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "__ubsan_\[a-z_\]*\[^et\] " "optimized" } } */ +/* { dg-final { scan-tree-dump "UBSAN_CHECK_" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ -- 2.30.2