Commit 18af8d16 by Yury Gribov Committed by Yury Gribov

asan.c (set_sanitized_sections): New function.

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.

From-SVN: r222168
parent d7cb230a
2015-04-17 Yury Gribov <y.gribov@samsung.com>
* 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.
2015-04-17 Jakub Jelinek <jakub@redhat.com> 2015-04-17 Jakub Jelinek <jakub@redhat.com>
PR debug/65771 PR debug/65771
......
...@@ -272,6 +272,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -272,6 +272,7 @@ along with GCC; see the file COPYING3. If not see
static unsigned HOST_WIDE_INT asan_shadow_offset_value; static unsigned HOST_WIDE_INT asan_shadow_offset_value;
static bool asan_shadow_offset_computed; static bool asan_shadow_offset_computed;
static const char *sanitized_sections;
/* Sets shadow offset to value in string VAL. */ /* Sets shadow offset to value in string VAL. */
...@@ -294,6 +295,33 @@ set_asan_shadow_offset (const char *val) ...@@ -294,6 +295,33 @@ set_asan_shadow_offset (const char *val)
return true; 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. */ /* Returns Asan shadow offset. */
static unsigned HOST_WIDE_INT static unsigned HOST_WIDE_INT
...@@ -1374,7 +1402,8 @@ asan_protect_global (tree decl) ...@@ -1374,7 +1402,8 @@ asan_protect_global (tree decl)
to be an array of such vars, putting padding in there to be an array of such vars, putting padding in there
breaks this assumption. */ breaks this assumption. */
|| (DECL_SECTION_NAME (decl) != NULL || (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 || DECL_SIZE (decl) == 0
|| ASAN_RED_ZONE_SIZE * BITS_PER_UNIT > MAX_OFILE_ALIGNMENT || ASAN_RED_ZONE_SIZE * BITS_PER_UNIT > MAX_OFILE_ALIGNMENT
|| !valid_constant_size_p (DECL_SIZE_UNIT (decl)) || !valid_constant_size_p (DECL_SIZE_UNIT (decl))
......
...@@ -79,6 +79,8 @@ asan_red_zone_size (unsigned int size) ...@@ -79,6 +79,8 @@ asan_red_zone_size (unsigned int size)
extern bool set_asan_shadow_offset (const char *); extern bool set_asan_shadow_offset (const char *);
extern void set_sanitized_sections (const char *);
/* Return TRUE if builtin with given FCODE will be intercepted by /* Return TRUE if builtin with given FCODE will be intercepted by
libasan. */ libasan. */
......
...@@ -897,6 +897,11 @@ fasan-shadow-offset= ...@@ -897,6 +897,11 @@ fasan-shadow-offset=
Common Joined RejectNegative Var(common_deferred_options) Defer Common Joined RejectNegative Var(common_deferred_options) Defer
-fasan-shadow-offset=<number> Use custom shadow memory offset. -fasan-shadow-offset=<number> Use custom shadow memory offset.
fsanitize-sections=
Common Joined RejectNegative Var(common_deferred_options) Defer
-fsanitize-sections=<sec1,sec2,...> Sanitize global variables
in user-defined sections.
fsanitize-recover= fsanitize-recover=
Common Report Joined Common Report Joined
After diagnosing undefined behavior attempt to continue execution After diagnosing undefined behavior attempt to continue execution
......
...@@ -301,7 +301,8 @@ Objective-C and Objective-C++ Dialects}. ...@@ -301,7 +301,8 @@ Objective-C and Objective-C++ Dialects}.
@xref{Debugging Options,,Options for Debugging Your Program or GCC}. @xref{Debugging Options,,Options for Debugging Your Program or GCC}.
@gccoptlist{-d@var{letters} -dumpspecs -dumpmachine -dumpversion @gol @gccoptlist{-d@var{letters} -dumpspecs -dumpmachine -dumpversion @gol
-fsanitize=@var{style} -fsanitize-recover -fsanitize-recover=@var{style} @gol -fsanitize=@var{style} -fsanitize-recover -fsanitize-recover=@var{style} @gol
-fasan-shadow-offset=@var{number} -fsanitize-undefined-trap-on-error @gol -fasan-shadow-offset=@var{number} -fsanitize-sections=@var{s1,s2,...} @gol
-fsanitize-undefined-trap-on-error @gol
-fcheck-pointer-bounds -fchkp-check-incomplete-type @gol -fcheck-pointer-bounds -fchkp-check-incomplete-type @gol
-fchkp-first-field-has-own-bounds -fchkp-narrow-bounds @gol -fchkp-first-field-has-own-bounds -fchkp-narrow-bounds @gol
-fchkp-narrow-to-innermost-array -fchkp-optimize @gol -fchkp-narrow-to-innermost-array -fchkp-optimize @gol
...@@ -5803,6 +5804,10 @@ This option forces GCC to use custom shadow offset in AddressSanitizer checks. ...@@ -5803,6 +5804,10 @@ This option forces GCC to use custom shadow offset in AddressSanitizer checks.
It is useful for experimenting with different shadow memory layouts in It is useful for experimenting with different shadow memory layouts in
Kernel AddressSanitizer. Kernel AddressSanitizer.
@item -fsanitize-sections=@var{s1,s2,...}
@opindex fsanitize-sections
Sanitize global variables in selected user-defined sections.
@item -fsanitize-recover@r{[}=@var{opts}@r{]} @item -fsanitize-recover@r{[}=@var{opts}@r{]}
@opindex fsanitize-recover @opindex fsanitize-recover
@opindex fno-sanitize-recover @opindex fno-sanitize-recover
......
...@@ -458,6 +458,10 @@ handle_common_deferred_options (void) ...@@ -458,6 +458,10 @@ handle_common_deferred_options (void)
error ("unrecognized shadow offset %qs", opt->arg); error ("unrecognized shadow offset %qs", opt->arg);
break; break;
case OPT_fsanitize_sections_:
set_sanitized_sections (opt->arg);
break;
default: default:
gcc_unreachable (); gcc_unreachable ();
} }
......
2015-04-17 Yury Gribov <y.gribov@samsung.com>
* c-c++-common/asan/user-section-1.c: New test.
2015-04-17 Jakub Jelinek <jakub@redhat.com> 2015-04-17 Jakub Jelinek <jakub@redhat.com>
PR debug/65771 PR debug/65771
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment