aboutsummaryrefslogtreecommitdiff
path: root/gcc/asan.h
AgeCommit message (Collapse)AuthorFilesLines
2016-01-04Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r232055
2015-04-17asan.c (set_sanitized_sections): New function.Yury Gribov1-0/+2
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
2015-01-05Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r219188
2014-11-04Makefile.in (OBJS): Add sanopt.o.Marek Polacek1-0/+1
* Makefile.in (OBJS): Add sanopt.o. (GTFILES): Add sanopt.c. * asan.h (asan_expand_check_ifn): Declare. * asan.c (asan_expand_check_ifn): No longer static. (class pass_sanopt, pass_sanopt::execute, make_pass_sanopt): Move... * sanopt.c: ...here. New file. testsuite/ * c-c++-common/ubsan/align-2.c: Remove dg-output. * c-c++-common/ubsan/align-4.c: Likewise. * g++.dg/ubsan/null-1.C: Likewise. * g++.dg/ubsan/null-2.C: Likewise. From-SVN: r217099
2014-10-28Don't inline GCC memory builtins if ASan is enabled.Max Ostapenko1-0/+24
gcc/ 2014-10-28 Max Ostapenko <m.ostapenko@partner.samsung.com> * asan.h (asan_intercepted_p): New function. * asan.c (asan_mem_ref_hasher::hash): Remove MEM_REF access size from hash value construction. Call iterative_hash_expr instead of explicit hash building. (asan_mem_ref_hasher::equal): Change condition. (has_mem_ref_been_instrumented): Likewise. (update_mem_ref_hash_table): Likewise. (maybe_update_mem_ref_hash_table): New function. (instrument_strlen_call): Removed. (get_mem_refs_of_builtin_call): Handle new parameter. (instrument_builtin_call): Call maybe_update_mem_ref_hash_table instead of instrument_mem_region_access if intercepted_p is true. (instrument_mem_region_access): Instrument only base with len instead of base and end with 1. (build_check_stmt): Remove start_instrumented and end_instrumented parameters. (enum asan_check_flags): Remove ASAN_CHECK_START_INSTRUMENTED and ASAN_CHECK_END_INSTRUMENTED. Change ASAN_CHECK_LAST. (asan_expand_check_ifn): Remove start_instrumented and end_instrumented. * builtins.c (expand_builtin): Include asan.h. Don't expand string/memory builtin functions that have interceptors if ASan is enabled. gcc/testsuite/ * c-c++-common/asan/no-redundant-instrumentation-1.c: Updated test. * c-c++-common/asan/no-redundant-instrumentation-4.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-5.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-6.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-7.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-8.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-2.c: Removed. * c-c++-common/asan/no-redundant-instrumentation-9.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-10.c: New test. * c-c++-common/asan/no-redundant-instrumentation-11.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-12.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-13.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-14.c: Likewise. * c-c++-common/asan/no-redundant-instrumentation-15.c: Likewise. * c-c++-common/asan/pr63638.c: Likewise. From-SVN: r216783
2014-10-28Allow to override Asan shadow offset.Yury Gribov1-1/+3
2014-10-28 Yury Gribov <y.gribov@samsung.com> gcc/ * asan.c (set_asan_shadow_offset): New function. (asan_shadow_offset): Likewise. (asan_emit_stack_protection): Call asan_shadow_offset. (build_shadow_mem_access): Likewise. * asan.h (set_asan_shadow_offset): Declare. * common.opt (fasan-shadow-offset): New option. (frandom-seed): Fixed parameter name. * doc/invoke.texi (fasan-shadow-offset): Describe new option. (frandom-seed): Fixed parameter name. * opts-global.c (handle_common_deferred_options): Handle -fasan-shadow-offset. * opts.c (common_handle_option): Likewise. gcc/testsuite/ * c-c++-common/asan/shadow-offset-1.c: New test. From-SVN: r216773
2014-08-19asan_emit_stack_protection returns an insnDavid Malcolm1-2/+2
2014-08-19 David Malcolm <dmalcolm@redhat.com> * asan.h (asan_emit_stack_protection): Strengthen return type from rtx to rtx_insn *. * asan.c (asan_emit_stack_protection): Likewise. Add local "insns" to hold the return value. From-SVN: r214189
2014-01-02Update copyright years in gcc/Richard Sandiford1-1/+1
From-SVN: r206289
2013-12-20ubsan.c: Include tree-ssanames.h, asan.h and gimplify-me.h.Jakub Jelinek1-0/+3
* ubsan.c: Include tree-ssanames.h, asan.h and gimplify-me.h. (ubsan_type_descriptor): Handle BOOLEAN_TYPE and ENUMERAL_TYPE like INTEGER_TYPE. (instrument_bool_enum_load): New function. (ubsan_pass): Call it. (gate_ubsan): Also enable for SANITIZE_BOOL or SANITIZE_ENUM. * asan.c (create_cond_insert_point): No longer static. * asan.h (create_cond_insert_point): Declare. * sanitizer.def (BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE): New built-in. * opts.c (common_handle_option): Handle -fsanitize=bool and -fsanitize=enum. * builtins.c (fold_builtin_memory_op): When sanitizing bool and enum loads, don't use enum or bool types for memcpy folding. * flag-types.h (SANITIZE_BOOL, SANITIZE_ENUM): New. (SANITIZE_UNDEFINED): Or these in. * c-c++-common/ubsan/load-bool-enum.c: New test. From-SVN: r206143
2013-11-28cfgexpand.c (struct stack_vars_data): Add asan_base and asan_alignb fields.Jakub Jelinek1-2/+5
* cfgexpand.c (struct stack_vars_data): Add asan_base and asan_alignb fields. (expand_stack_vars): For -fsanitize=address, use (and set initially) data->asan_base as base for vars and update asan_alignb. (expand_used_vars): Initialize data.asan_base and data.asan_alignb. Pass them to asan_emit_stack_protection. * asan.c (asan_detect_stack_use_after_return): New variable. (asan_emit_stack_protection): Add pbase and alignb arguments. Implement use after return sanitization. * asan.h (asan_emit_stack_protection): Adjust prototype. (ASAN_STACK_MAGIC_USE_AFTER_RET, ASAN_STACK_RETIRED_MAGIC): Define. From-SVN: r205476
2013-11-22sanitizer.def (BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT, [...]): New.Jakub Jelinek1-0/+1
* sanitizer.def (BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT, BUILT_IN_ASAN_AFTER_DYNAMIC_INIT): New. * asan.c (instrument_derefs): Handle also VAR_DECL loads/stores. Don't instrument accesses to VAR_DECLs which are known to fit into their bounds and the vars are known to have shadow bytes indicating allowed access. (asan_dynamic_init_call): New function. (asan_add_global): If vnode->dynamically_initialized, set __has_dynamic_init to 1 instead of 0. (initialize_sanitizer_builtins): Add BT_FN_VOID_CONST_PTR var. * asan.h (asan_dynamic_init_call): New prototype. * cgraph.h (varpool_node): Add dynamically_initialized bitfield. cp/ * decl2.c: Include asan.h. (one_static_initialization_or_destruction): If -fsanitize=address, init is non-NULL and guard is NULL, set vnode->dynamically_initialized. (do_static_initialization_or_destruction): Call __asan_{before,after}_dynamic_init around the static initialization. testsuite/ * c-c++-common/asan/no-redundant-instrumentation-1.c: Tweak to avoid optimizing away some __asan_report* calls. From-SVN: r205282
2013-11-04libsanitizer merge from upstream r191666Kostya Serebryany1-0/+1
This may break gcc-asan on Mac, will follow up separately. From-SVN: r204368
2013-01-10Update copyright years in gcc/Richard Sandiford1-1/+1
From-SVN: r195098
2012-12-03sanitizer.def: Add Address Sanitizer builtins.Jakub Jelinek1-0/+1
* sanitizer.def: Add Address Sanitizer builtins. Rename BUILT_IN_TSAN_READ_* to BUILT_IN_TSAN_READ* and BUILT_IN_TSAN_WRITE_* to BUILT_IN_TSAN_WRITE*. * Makefile.in (asan.o): Depend on langhooks.h. (tsan.o): Depend on asan.h. * asan.h (initialize_sanitizer_builtins): New prototype. * asan.c: Include langhooks.h. (report_error_func): Use builtin_decl_implicit of corresponding BUILT_IN_ASAN_REPORT_{LOAD,STORE}*. (asan_init_func): Removed. (initialize_sanitizer_builtins): New function. (asan_finish_file): Call it. Use builtin_decl_implicit on BUILT_IN_ASAN_{INIT,{,UN}REGISTER_GLOBALS}. (asan_instrument): Call initialize_sanitizer_builtins. * builtins.def (DEF_SANITIZER_BUILTIN): Change condition to (flag_asan || flag_tsan). * tsan.c: Include asan.h and tsan.h. (get_memory_access_decl): Rename BUILT_IN_TSAN_{READ,WRITE}_* to BUILT_IN_TSAN_{READ,WRITE}*. (tsan_pass): Call initialize_sanitizer_builtins. (tsan_gate, tsan_gate_O0): Don't check if builtin_decl_implicit_p (BUILT_IN_TSAN_INIT) is true. (tsan_finish_file): Call initialize_sanitizer_builtins. * builtin-types.def (BT_FN_VOID_PTR_PTRMODE): New fn type. From-SVN: r194103
2012-11-12Implement protection of global variablesJakub Jelinek1-0/+11
This patch implements the protection of global variables. See the comments appended to the beginning of the asan.c file. * varasm.c: Include asan.h. (assemble_noswitch_variable): Grow size by asan_red_zone_size if decl is asan protected. (place_block_symbol): Likewise. (assemble_variable): If decl is asan protected, increase DECL_ALIGN if needed, and for decls emitted using assemble_variable_contents append padding zeros after it. * Makefile.in (varasm.o): Depend on asan.h. * asan.c: Include output.h. (asan_pp, asan_pp_initialized, asan_ctor_statements): New variables. (asan_pp_initialize, asan_pp_string): New functions. (asan_emit_stack_protection): Use asan_pp{,_initialized} instead of local pp{,_initialized} vars, use asan_pp_initialize and asan_pp_string helpers. (asan_needs_local_alias, asan_protect_global, asan_global_struct, asan_add_global): New functions. (asan_finish_file): Protect global vars that can be protected. Use asan_ctor_statements instead of ctor_statements * asan.h (asan_protect_global): New prototype. (asan_red_zone_size): New inline function. Co-Authored-By: Wei Mi <wmi@google.com> From-SVN: r193437
2012-11-12Implement protection of stack variablesJakub Jelinek1-1/+30
This patch implements the protection of stack variables. It lays out stack variables as well as the different red zones, emits some prologue code to populate the shadow memory as to poison (mark as non-accessible) the regions of the red zones and mark the regions of stack variables as accessible, and emit some epilogue code to un-poison (mark as accessible) the regions of red zones right before the function exits. * Makefile.in (asan.o): Depend on $(EXPR_H) $(OPTABS_H). (cfgexpand.o): Depend on asan.h. * asan.c: Include expr.h and optabs.h. (asan_shadow_set): New variable. (asan_shadow_cst, asan_emit_stack_protection): New functions. (asan_init_shadow_ptr_types): Initialize also asan_shadow_set. * cfgexpand.c: Include asan.h. Define HOST_WIDE_INT heap vector. (partition_stack_vars): If i is large alignment and j small alignment or vice versa, break out of the loop instead of continue, and put the test earlier. If flag_asan, break out of the loop if for small alignment size is different. (struct stack_vars_data): New type. (expand_stack_vars): Add DATA argument. Change PRED type to function taking size_t argument instead of tree. Adjust pred calls. Fill DATA in and add needed padding in between variables if -faddress-sanitizer. (defer_stack_allocation): Defer everything for flag_asan. (stack_protect_decl_phase_1, stack_protect_decl_phase_2): Take size_t index into stack_vars array instead of the decl directly. (asan_decl_phase_3): New function. (expand_used_vars): Return var destruction sequence. Adjust expand_stack_vars calls, add another one for flag_asan. Call asan_emit_stack_protection if expand_stack_vars added anything to the vectors. (expand_gimple_basic_block): Add disable_tail_calls argument. (gimple_expand_cfg): Pass true to it if expand_used_vars returned non-NULL. Emit the sequence returned by expand_used_vars after return_label. * asan.h (asan_emit_stack_protection): New prototype. (asan_shadow_set): New decl. (ASAN_RED_ZONE_SIZE, ASAN_STACK_MAGIC_LEFT, ASAN_STACK_MAGIC_MIDDLE, ASAN_STACK_MAGIC_RIGHT, ASAN_STACK_FRAME_MAGIC): Define. (asan_protect_stack_decl): New inline. * toplev.c (process_options): Also disable -faddress-sanitizer on !FRAME_GROWS_DOWNWARDS targets. From-SVN: r193436
2012-11-12Emit GIMPLE directly instead of gimplifying GENERIC.Jakub Jelinek1-1/+1
This patch cleanups the instrumentation code generation by emitting GIMPLE directly, as opposed to emitting GENERIC tree and then gimplifying them. It also does some cleanups here and there * Makefile.in (GTFILES): Add $(srcdir)/asan.c. (asan.o): Update the dependencies of asan.o. * asan.c (tm.h, tree.h, tm_p.h, basic-block.h, flags.h function.h, tree-inline.h, tree-dump.h, diagnostic.h, demangle.h, langhooks.h, ggc.h, cgraph.h, gimple.h): Remove these unused but included headers. (shadow_ptr_types): New variable. (report_error_func): Change is_store argument to bool, don't append newline to function name. (PROB_VERY_UNLIKELY, PROB_ALWAYS): Define. (build_check_stmt): Change is_store argument to bool. Emit GIMPLE directly instead of creating trees and gimplifying them. Mark the error reporting function as very unlikely. (instrument_derefs): Change is_store argument to bool. Use int_size_in_bytes to compute size_in_bytes, simplify size check. Use build_fold_addr_expr instead of build_addr. (transform_statements): Adjust instrument_derefs caller. Use gimple_assign_single_p as stmt test. Don't look at MEM refs in rhs2. (asan_init_shadow_ptr_types): New function. (asan_instrument): Don't push/pop gimplify context. Call asan_init_shadow_ptr_types if not yet initialized. * asan.h (ASAN_SHADOW_SHIFT): Adjust comment. Co-Authored-By: Dodji Seketeli <dodji@redhat.com> Co-Authored-By: Xinliang David Li <davidxl@google.com> From-SVN: r193434
2012-11-12Initial asan cleanupsJakub Jelinek1-1/+5
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
2012-11-12Initial import of asan from the Google branchWei Mi1-0/+26
This patch imports the initial state of asan as it was in the Google branch. It provides basic infrastructure for asan to instrument memory accesses on the heap, at -O3. Note that it supports neither stack nor global variable protection. The rest of the patches of the set is intended to further improve this base. gcc/ChangeLog * Makefile.in: Add asan.c and its dependencies. * common.opt: Add -faddress-sanitizer option. * invoke.texi: Document the new flag. * passes.c: Add the asan pass. * toplev.c (compile_file): Call asan_finish_file. * asan.c: New file. * asan.h: New file. * tree-pass.h: Declare pass_asan. Co-Authored-By: Diego Novillo <dnovillo@google.com> Co-Authored-By: Dodji Seketeli <dodji@redhat.com> From-SVN: r193432