aboutsummaryrefslogtreecommitdiff
path: root/gcc/asan.h
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2018-11-30 15:25:15 +0100
committerMartin Liska <marxin@gcc.gnu.org>2018-11-30 14:25:15 +0000
commit6e644a50045f8032b6d6ff19eb70d8b33dfc4dae (patch)
treeb6ab18da4eaeb67ce5e78a93ed2b4b84bfa0b637 /gcc/asan.h
parentb49f1a7e7c85add83637cf7df46b8fc9b5b299e9 (diff)
downloadgcc-6e644a50045f8032b6d6ff19eb70d8b33dfc4dae.zip
gcc-6e644a50045f8032b6d6ff19eb70d8b33dfc4dae.tar.gz
gcc-6e644a50045f8032b6d6ff19eb70d8b33dfc4dae.tar.bz2
Make red zone size more flexible for stack variables (PR sanitizer/81715).
2018-11-30 Martin Liska <mliska@suse.cz> PR sanitizer/81715 * asan.c (asan_shadow_cst): Remove, partially transform into flush_redzone_payload. (RZ_BUFFER_SIZE): New. (struct asan_redzone_buffer): New. (asan_redzone_buffer::emit_redzone_byte): Likewise. (asan_redzone_buffer::flush_redzone_payload): Likewise. (asan_redzone_buffer::flush_if_full): Likewise. (asan_emit_stack_protection): Use asan_redzone_buffer class that is responsible for proper aligned stores and flushing of shadow memory payload. * asan.h (ASAN_MIN_RED_ZONE_SIZE): New. (asan_var_and_redzone_size): Likewise. * cfgexpand.c (expand_stack_vars): Use smaller alignment (ASAN_MIN_RED_ZONE_SIZE) in order to make shadow memory for automatic variables more compact. 2018-11-30 Martin Liska <mliska@suse.cz> PR sanitizer/81715 * c-c++-common/asan/asan-stack-small.c: New test. From-SVN: r266664
Diffstat (limited to 'gcc/asan.h')
-rw-r--r--gcc/asan.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/asan.h b/gcc/asan.h
index 2f431b4..e1b9b49 100644
--- a/gcc/asan.h
+++ b/gcc/asan.h
@@ -53,6 +53,11 @@ extern hash_set <tree> *asan_used_labels;
up to 2 * ASAN_RED_ZONE_SIZE - 1 bytes. */
#define ASAN_RED_ZONE_SIZE 32
+/* Stack variable use more compact red zones. The size includes also
+ size of variable itself. */
+
+#define ASAN_MIN_RED_ZONE_SIZE 16
+
/* Shadow memory values for stack protection. Left is below protected vars,
the first pointer in stack corresponding to that offset contains
ASAN_STACK_FRAME_MAGIC word, the second pointer to a string describing
@@ -102,6 +107,26 @@ asan_red_zone_size (unsigned int size)
return c ? 2 * ASAN_RED_ZONE_SIZE - c : ASAN_RED_ZONE_SIZE;
}
+/* Return how much a stack variable occupis on a stack
+ including a space for red zone. */
+
+static inline unsigned HOST_WIDE_INT
+asan_var_and_redzone_size (unsigned HOST_WIDE_INT size)
+{
+ if (size <= 4)
+ return 16;
+ else if (size <= 16)
+ return 32;
+ else if (size <= 128)
+ return size + 32;
+ else if (size <= 512)
+ return size + 64;
+ else if (size <= 4096)
+ return size + 128;
+ else
+ return size + 256;
+}
+
extern bool set_asan_shadow_offset (const char *);
extern void set_sanitized_sections (const char *);