diff options
author | Maxim Ostapenko <m.ostapenko@samsung.com> | 2017-07-06 16:02:06 +0000 |
---|---|---|
committer | Maxim Ostapenko <chefmax@gcc.gnu.org> | 2017-07-06 19:02:06 +0300 |
commit | e3174bdf35c172f69daf08350401aa177f8f1498 (patch) | |
tree | e7632bf6f8c4e541f5dbf209ad90d807a7b79318 /gcc/builtins.c | |
parent | b6f4312871d39547c2e286b6eadac4408ab494ae (diff) | |
download | gcc-e3174bdf35c172f69daf08350401aa177f8f1498.zip gcc-e3174bdf35c172f69daf08350401aa177f8f1498.tar.gz gcc-e3174bdf35c172f69daf08350401aa177f8f1498.tar.bz2 |
ASAN: Implement dynamic allocas/VLAs sanitization.
gcc/
* asan.c: Include gimple-fold.h.
(get_last_alloca_addr): New function.
(handle_builtin_stackrestore): Likewise.
(handle_builtin_alloca): Likewise.
(asan_emit_allocas_unpoison): Likewise.
(get_mem_refs_of_builtin_call): Add new parameter, remove const
quallifier from first paramerer. Handle BUILT_IN_ALLOCA,
BUILT_IN_ALLOCA_WITH_ALIGN and BUILT_IN_STACK_RESTORE builtins.
(instrument_builtin_call): Pass gimple iterator to
get_mem_refs_of_builtin_call.
(last_alloca_addr): New global.
* asan.h (asan_emit_allocas_unpoison): Declare.
* builtins.c (expand_asan_emit_allocas_unpoison): New function.
(expand_builtin): Handle BUILT_IN_ASAN_ALLOCAS_UNPOISON.
* cfgexpand.c (expand_used_vars): Call asan_emit_allocas_unpoison
if function calls alloca.
* gimple-fold.c (replace_call_with_value): Remove static keyword.
* gimple-fold.h (replace_call_with_value): Declare.
* internal-fn.c: Include asan.h.
* sanitizer.def (BUILT_IN_ASAN_ALLOCA_POISON,
BUILT_IN_ASAN_ALLOCAS_UNPOISON): New builtins.
gcc/testsuite/
* c-c++-common/asan/alloca_big_alignment.c: New test.
* c-c++-common/asan/alloca_detect_custom_size.c: Likewise.
* c-c++-common/asan/alloca_instruments_all_paddings.c: Likewise.
* c-c++-common/asan/alloca_loop_unpoisoning.c: Likewise.
* c-c++-common/asan/alloca_overflow_partial.c: Likewise.
* c-c++-common/asan/alloca_overflow_right.c: Likewise.
* c-c++-common/asan/alloca_safe_access.c: Likewise.
* c-c++-common/asan/alloca_underflow_left.c: Likewise.
From-SVN: r250031
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 034ec2e..608993a 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4962,6 +4962,26 @@ expand_builtin_alloca (tree exp) return result; } +/* Emit a call to __asan_allocas_unpoison call in EXP. Replace second argument + of the call with virtual_stack_dynamic_rtx because in asan pass we emit a + dummy value into second parameter relying on this function to perform the + change. See motivation for this in comment to handle_builtin_stack_restore + function. */ + +static rtx +expand_asan_emit_allocas_unpoison (tree exp) +{ + tree arg0 = CALL_EXPR_ARG (exp, 0); + rtx top = expand_expr (arg0, NULL_RTX, GET_MODE (virtual_stack_dynamic_rtx), + EXPAND_NORMAL); + rtx ret = init_one_libfunc ("__asan_allocas_unpoison"); + ret = emit_library_call_value (ret, NULL_RTX, LCT_NORMAL, ptr_mode, 2, top, + TYPE_MODE (pointer_sized_int_node), + virtual_stack_dynamic_rtx, + TYPE_MODE (pointer_sized_int_node)); + return ret; +} + /* Expand a call to bswap builtin in EXP. Return NULL_RTX if a normal call should be emitted rather than expanding the function in-line. If convenient, the result should be placed in TARGET. @@ -6763,6 +6783,9 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, return target; break; + case BUILT_IN_ASAN_ALLOCAS_UNPOISON: + return expand_asan_emit_allocas_unpoison (exp); + case BUILT_IN_STACK_SAVE: return expand_stack_save (); |