aboutsummaryrefslogtreecommitdiff
path: root/gcc/varasm.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2012-12-10 12:14:36 +0000
committerJakub Jelinek <jakub@redhat.com>2012-12-10 12:14:36 +0000
commit3d1a5756aca18384ba57fbf1889a292d02f0de60 (patch)
tree3bd1c13134ce9fb42d46d64f6d4cfee4d5b21d3f /gcc/varasm.c
parent58772f5b90c3a053716113fc864853a6d1183f12 (diff)
* asan.c (asan_init_shadow_ptr_types): Move earlier in the file.
Call initialize_sanitizer_builtins at the end. (asan_pp_string): Use TREE_TYPE (shadow_ptr_types[0]) as character type instead of char_type_node. (asan_emit_stack_protection): Call asan_init_shadow_ptr_types if shadow_ptr_types isn't initialized. (asan_protect_global): Return true for STRING_CSTs except those created by asan_pp_string. (count_string_csts, add_string_csts): New functions. (struct asan_add_string_csts_data): New type. (asan_finish_file): Clear flag_asan at the beginning, restore at the end. Traverse constant_pool_htab () to look for protected STRING_CSTs. Don't call initialize_sanitizer_builtins, instead call asan_init_shadow_ptr_types if shadow_ptr_types isn't initialized yet. (asan_instrument): Don't call initialize_sanitizer_builtins. * varasm.c (output_constant_def_contents): If STRING_CST should be asan protected, align it sufficiently and emit padding after it. (categorize_decl_for_section): If flag_asan, don't put STRING_CSTs that should be asan protected into mergeable sections. For -fmerge-all-constants, ignore it for -fmudflap or if decl is asan protected. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@194355 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/varasm.c')
-rw-r--r--gcc/varasm.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/gcc/varasm.c b/gcc/varasm.c
index ee42afc8cbd..3c420c013d8 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -3249,11 +3249,23 @@ output_constant_def_contents (rtx symbol)
place_block_symbol (symbol);
else
{
+ bool asan_protected = false;
align = DECL_ALIGN (decl);
switch_to_section (get_constant_section (exp, align));
+ if (flag_asan && TREE_CODE (exp) == STRING_CST
+ && asan_protect_global (exp))
+ {
+ asan_protected = true;
+ align = MAX (align, ASAN_RED_ZONE_SIZE * BITS_PER_UNIT);
+ }
if (align > BITS_PER_UNIT)
ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
assemble_constant_contents (exp, XSTR (symbol, 0), align);
+ if (asan_protected)
+ {
+ HOST_WIDE_INT size = get_constant_size (exp);
+ assemble_zeros (asan_red_zone_size (size));
+ }
}
if (flag_mudflap)
mudflap_enqueue_constant (exp);
@@ -6157,7 +6169,9 @@ categorize_decl_for_section (const_tree decl, int reloc)
return SECCAT_TEXT;
else if (TREE_CODE (decl) == STRING_CST)
{
- if (flag_mudflap) /* or !flag_merge_constants */
+ if (flag_mudflap
+ || (flag_asan && asan_protect_global (CONST_CAST_TREE (decl))))
+ /* or !flag_merge_constants */
return SECCAT_RODATA;
else
return SECCAT_RODATA_MERGE_STR;
@@ -6181,7 +6195,8 @@ categorize_decl_for_section (const_tree decl, int reloc)
}
else if (reloc & targetm.asm_out.reloc_rw_mask ())
ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
- else if (reloc || flag_merge_constants < 2)
+ else if (reloc || flag_merge_constants < 2 || flag_mudflap
+ || (flag_asan && asan_protect_global (CONST_CAST_TREE (decl))))
/* C and C++ don't allow different variables to share the same
location. -fmerge-all-constants allows even that (at the
expense of not conforming). */