From 0ce483917ffb79cf25d633e2dbe01a678437133e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 5 Sep 2016 21:43:57 +0200 Subject: [PATCH] re PR sanitizer/77396 (address sanitizer crashes if all static global variables are optimized) PR sanitizer/77396 * asan/asan_globals.cc: Cherry-pick upstream r280657. * g++.dg/asan/pr77396-2.C: New test. From-SVN: r239998 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/asan/pr77396-2.C | 12 ++++++++++++ libsanitizer/ChangeLog | 5 +++++ libsanitizer/asan/asan_globals.cc | 7 ++++--- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/asan/pr77396-2.C diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 87e88225382..d7640245e26 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-05 Jakub Jelinek + + PR sanitizer/77396 + * g++.dg/asan/pr77396-2.C: New test. + 2016-09-05 Uros Bizjak PR rtl-optimization/77452 diff --git a/gcc/testsuite/g++.dg/asan/pr77396-2.C b/gcc/testsuite/g++.dg/asan/pr77396-2.C new file mode 100644 index 00000000000..0570a14940e --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/pr77396-2.C @@ -0,0 +1,12 @@ +// PR sanitizer/77396 +// { dg-do run } +// { dg-set-target-env-var ASAN_OPTIONS "check_initialization_order=true" } + +struct S { S () { asm volatile ("" : : : "memory"); } }; +static S c; + +int +main () +{ + return 0; +} diff --git a/libsanitizer/ChangeLog b/libsanitizer/ChangeLog index d9eb7fa3bd2..a06ab4de7e7 100644 --- a/libsanitizer/ChangeLog +++ b/libsanitizer/ChangeLog @@ -1,3 +1,8 @@ +2016-09-05 Jakub Jelinek + + PR sanitizer/77396 + * asan/asan_globals.cc: Cherry-pick upstream r280657. + 2016-08-12 Jakub Jelinek PR sanitizer/71042 diff --git a/libsanitizer/asan/asan_globals.cc b/libsanitizer/asan/asan_globals.cc index 9c3588b8e08..f3531cbd133 100644 --- a/libsanitizer/asan/asan_globals.cc +++ b/libsanitizer/asan/asan_globals.cc @@ -248,10 +248,10 @@ void __asan_unregister_globals(__asan_global *globals, uptr n) { // initializer can only touch global variables in the same TU. void __asan_before_dynamic_init(const char *module_name) { if (!flags()->check_initialization_order || - !CanPoisonMemory()) + !CanPoisonMemory() || + !dynamic_init_globals) return; bool strict_init_order = flags()->strict_init_order; - CHECK(dynamic_init_globals); CHECK(module_name); CHECK(asan_inited); BlockingMutexLock lock(&mu_for_globals); @@ -274,7 +274,8 @@ void __asan_before_dynamic_init(const char *module_name) { // TU are poisoned. It simply unpoisons all dynamically initialized globals. void __asan_after_dynamic_init() { if (!flags()->check_initialization_order || - !CanPoisonMemory()) + !CanPoisonMemory() || + !dynamic_init_globals) return; CHECK(asan_inited); BlockingMutexLock lock(&mu_for_globals); -- 2.30.2