diff options
author | Martin Liska <mliska@suse.cz> | 2017-06-30 10:51:00 +0200 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2017-06-30 08:51:00 +0000 |
commit | c497284c371acf3861754365b1f4d1800378e690 (patch) | |
tree | bc8710aa85afaf74385085ba3f7dc7a14c9f7f3b | |
parent | 516fa8946459e29b26035d1d273e8fafbaaa95ce (diff) | |
download | gcc-c497284c371acf3861754365b1f4d1800378e690.zip gcc-c497284c371acf3861754365b1f4d1800378e690.tar.gz gcc-c497284c371acf3861754365b1f4d1800378e690.tar.bz2 |
Call BUILT_IN_ASAN_HANDLE_NO_RETURN before BUILT_IN_UNWIND_RESUME (PR sanitizer/81021).
2017-06-30 Martin Liska <mliska@suse.cz>
PR sanitizer/81021
* g++.dg/asan/pr81021.C: New test.
2017-06-30 Martin Liska <mliska@suse.cz>
PR sanitizer/81021
* tree-eh.c (lower_resx): Call BUILT_IN_ASAN_HANDLE_NO_RETURN
before BUILT_IN_UNWIND_RESUME when ASAN is used.
From-SVN: r249833
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/asan/pr81021.C | 33 | ||||
-rw-r--r-- | gcc/tree-eh.c | 13 |
4 files changed, 57 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e5f699d..5401bda 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-06-30 Martin Liska <mliska@suse.cz> + + PR sanitizer/81021 + * tree-eh.c (lower_resx): Call BUILT_IN_ASAN_HANDLE_NO_RETURN + before BUILT_IN_UNWIND_RESUME when ASAN is used. + 2017-06-30 Yvan Roux <yvan.roux@linaro.org> * doc/invoke.texi (AArch64): Add missing options and remove redundant diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9b92e44..274fced 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-30 Martin Liska <mliska@suse.cz> + + PR sanitizer/81021 + * g++.dg/asan/pr81021.C: New test. + 2017-06-30 Richard Biener <rguenther@suse.de> PR tree-optimization/81249 diff --git a/gcc/testsuite/g++.dg/asan/pr81021.C b/gcc/testsuite/g++.dg/asan/pr81021.C new file mode 100644 index 0000000..daa0525 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/pr81021.C @@ -0,0 +1,33 @@ +// { dg-do run } + +#include <string> + +struct ConfigFile { + ConfigFile(std::string filename, std::string delimiter) { throw "error"; } + ConfigFile(std::string filename) {} +}; + +struct Configuration { + ConfigFile _configFile; + + Configuration(const std::string &root, const char *baseName) + : _configFile(root + baseName, "=") { } + Configuration(const std::string &root, const char *a, const char *b) + : _configFile(root + a + b) { } +}; + + +void test() { + std::string root("etc"); + try { + Configuration config(root, "notthere"); + } + catch (...) { + // exception is thrown, caught here and ignored... + } + Configuration config(root, "a", "b"); // ASAN error during constructor here +} + +int main(int argc, const char *argv[]) { + test(); +} diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c index 34c223d..79d02ad 100644 --- a/gcc/tree-eh.c +++ b/gcc/tree-eh.c @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "cfgloop.h" #include "gimple-low.h" +#include "asan.h" /* In some instances a tree and a gimple need to be stored in a same table, i.e. in hash tables. This is a structure to do this. */ @@ -3302,6 +3303,18 @@ lower_resx (basic_block bb, gresx *stmt, gimple_call_set_lhs (x, var); gsi_insert_before (&gsi, x, GSI_SAME_STMT); + /* When exception handling is delegated to a caller function, we + have to guarantee that shadow memory variables living on stack + will be cleaner before control is given to a parent function. */ + if (sanitize_flags_p (SANITIZE_ADDRESS)) + { + tree decl + = builtin_decl_implicit (BUILT_IN_ASAN_HANDLE_NO_RETURN); + gimple *g = gimple_build_call (decl, 0); + gimple_set_location (g, gimple_location (stmt)); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + } + fn = builtin_decl_implicit (BUILT_IN_UNWIND_RESUME); x = gimple_build_call (fn, 1, var); gsi_insert_before (&gsi, x, GSI_SAME_STMT); |