aboutsummaryrefslogtreecommitdiff
path: root/gcc/asan.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2012-11-12 16:51:34 +0100
committerDodji Seketeli <dodji@gcc.gnu.org>2012-11-12 16:51:34 +0100
commitdfe06d3e7f7719d2fc8ef7b7c7ca88e7277e7593 (patch)
tree4f0f7a2a85c05539f589338ab08d8fab607d18d7 /gcc/asan.c
parent37d6f666cae62d9d44c5aef4b2185e43635d5091 (diff)
downloadgcc-dfe06d3e7f7719d2fc8ef7b7c7ca88e7277e7593.zip
gcc-dfe06d3e7f7719d2fc8ef7b7c7ca88e7277e7593.tar.gz
gcc-dfe06d3e7f7719d2fc8ef7b7c7ca88e7277e7593.tar.bz2
Initial asan cleanups
This patch defines a new asan_shadow_offset target macro, instead of having a mere macro in the asan.c file. It becomes thus cleaner to define the target macro for targets that supports asan, namely x86 for now. The ASAN_SHADOW_SHIFT (which, along with the asan_shadow_offset constant, is used to compute the address of the shadow memory byte for a given memory address) is defined in asan.h. gcc/ChangeLog * toplev.c (process_options): Warn and turn off -faddress-sanitizer if not supported by target. * asan.c: Include target.h. (asan_scale, asan_offset_log_32, asan_offset_log_64, asan_offset_log): Removed. (build_check_stmt): Use ASAN_SHADOW_SHIFT and targetm.asan_shadow_offset (). (asan_instrument): Don't initialize asan_offset_log. * asan.h (ASAN_SHADOW_SHIFT): Define. * target.def (TARGET_ASAN_SHADOW_OFFSET): New hook. * doc/tm.texi.in (TARGET_ASAN_SHADOW_OFFSET): Add it. * doc/tm.texi: Regenerated. * Makefile.in (asan.o): Depend on $(TARGET_H). * config/i386/i386.c (ix86_asan_shadow_offset): New function. (TARGET_ASAN_SHADOW_OFFSET): Define. From-SVN: r193433
Diffstat (limited to 'gcc/asan.c')
-rw-r--r--gcc/asan.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/gcc/asan.c b/gcc/asan.c
index 4b07c9646..9655b11 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1,5 +1,5 @@
/* AddressSanitizer, a fast memory error detector.
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2012 Free Software Foundation, Inc.
Contributed by Kostya Serebryany <kcc@google.com>
This file is part of GCC.
@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3. If not see
#include "gimple.h"
#include "asan.h"
#include "gimple-pretty-print.h"
+#include "target.h"
/*
AddressSanitizer finds out-of-bounds and use-after-free bugs
@@ -78,15 +79,6 @@ along with GCC; see the file COPYING3. If not see
to create redzones for stack and global object and poison them.
*/
-/* The shadow address is computed as (X>>asan_scale) + (1<<asan_offset_log).
- We may want to add command line flags to change these values. */
-
-static const int asan_scale = 3;
-static const int asan_offset_log_32 = 29;
-static const int asan_offset_log_64 = 44;
-static int asan_offset_log;
-
-
/* Construct a function tree for __asan_report_{load,store}{1,2,4,8,16}.
IS_STORE is either 1 (for a store) or 0 (for a load).
SIZE_IN_BYTES is one of 1, 2, 4, 8, 16. */
@@ -202,15 +194,13 @@ build_check_stmt (tree base,
gimple_set_location (g, location);
gimple_seq_add_stmt (&seq, g);
- /* Build (base_addr >> asan_scale) + (1 << asan_offset_log). */
+ /* Build
+ (base_addr >> ASAN_SHADOW_SHIFT) | targetm.asan_shadow_offset (). */
t = build2 (RSHIFT_EXPR, uintptr_type, base_addr,
- build_int_cst (uintptr_type, asan_scale));
+ build_int_cst (uintptr_type, ASAN_SHADOW_SHIFT));
t = build2 (PLUS_EXPR, uintptr_type, t,
- build2 (LSHIFT_EXPR, uintptr_type,
- build_int_cst (uintptr_type, 1),
- build_int_cst (uintptr_type, asan_offset_log)
- ));
+ build_int_cst (uintptr_type, targetm.asan_shadow_offset ()));
t = build1 (INDIRECT_REF, shadow_type,
build1 (VIEW_CONVERT_EXPR, shadow_ptr_type, t));
t = force_gimple_operand (t, &stmts, false, NULL_TREE);
@@ -367,9 +357,6 @@ static unsigned int
asan_instrument (void)
{
struct gimplify_ctx gctx;
- tree uintptr_type = lang_hooks.types.type_for_mode (ptr_mode, true);
- int is_64 = tree_low_cst (TYPE_SIZE (uintptr_type), 0) == 64;
- asan_offset_log = is_64 ? asan_offset_log_64 : asan_offset_log_32;
push_gimplify_context (&gctx);
transform_statements ();
pop_gimplify_context (NULL);