diff options
author | ygribov <ygribov@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-04-17 07:51:02 +0000 |
---|---|---|
committer | ygribov <ygribov@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-04-17 07:51:02 +0000 |
commit | 4d3c996bee3c03fff2211781d78f5b1f42f55974 (patch) | |
tree | 09b053c21952ec3a007be7fb313cc8b3d5295944 /gcc/asan.c | |
parent | 06065ecc5011a9a0ab8be1800bf43813ebb71c15 (diff) | |
download | gcc-4d3c996bee3c03fff2211781d78f5b1f42f55974.tar.gz |
2015-04-17 Yury Gribov <y.gribov@samsung.com>
gcc/
* asan.c (set_sanitized_sections): New function.
(section_sanitized_p): Ditto.
(asan_protect_global): Optionally sanitize user-defined
sections.
* asan.h (set_sanitized_sections): Declare new function.
* common.opt (fsanitize-sections): New option.
* doc/invoke.texi (-fsanitize-sections): Document new option.
* opts-global.c (handle_common_deferred_options): Handle new
option.
gcc/testsuite/
* c-c++-common/asan/user-section-1.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@222168 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/asan.c')
-rw-r--r-- | gcc/asan.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/gcc/asan.c b/gcc/asan.c index 9e4a6299817..6706af7008c 100644 --- a/gcc/asan.c +++ b/gcc/asan.c @@ -272,6 +272,7 @@ along with GCC; see the file COPYING3. If not see static unsigned HOST_WIDE_INT asan_shadow_offset_value; static bool asan_shadow_offset_computed; +static const char *sanitized_sections; /* Sets shadow offset to value in string VAL. */ @@ -294,6 +295,33 @@ set_asan_shadow_offset (const char *val) return true; } +/* Set list of user-defined sections that need to be sanitized. */ + +void +set_sanitized_sections (const char *secs) +{ + sanitized_sections = secs; +} + +/* Checks whether section SEC should be sanitized. */ + +static bool +section_sanitized_p (const char *sec) +{ + if (!sanitized_sections) + return false; + size_t len = strlen (sec); + const char *p = sanitized_sections; + while ((p = strstr (p, sec))) + { + if ((p == sanitized_sections || p[-1] == ',') + && (p[len] == 0 || p[len] == ',')) + return true; + ++p; + } + return false; +} + /* Returns Asan shadow offset. */ static unsigned HOST_WIDE_INT @@ -1374,7 +1402,8 @@ asan_protect_global (tree decl) to be an array of such vars, putting padding in there breaks this assumption. */ || (DECL_SECTION_NAME (decl) != NULL - && !symtab_node::get (decl)->implicit_section) + && !symtab_node::get (decl)->implicit_section + && !section_sanitized_p (DECL_SECTION_NAME (decl))) || DECL_SIZE (decl) == 0 || ASAN_RED_ZONE_SIZE * BITS_PER_UNIT > MAX_OFILE_ALIGNMENT || !valid_constant_size_p (DECL_SIZE_UNIT (decl)) |