This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, MPX, 2/X] Pointers Checker pass


Hi,

Here is the second patch in MPX series. This patch adds pointer
checker instrumentation (-fcheck-pointers) pass and its support in
i386 target. See
http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler
for more details.

Thanks,
Ilya
--

2013-08-20  Ilya Enkovich <ilya.enkovich@intel.com>

        * Makefile.in (OBJS): Add tree-chkp.o.
        (GTFILES): Add tree-chkp.c.
        (tree-chkp.o): New.
        * builtin-types.def (BT_FN_VOID_CONST_PTR): New.
        (BT_FN_PTR_CONST_PTR): New.
        (BT_FN_CONST_PTR_CONST_PTR): New.
        (BT_FN_PTR_CONST_PTR_SIZE): New.
        (BT_FN_PTR_CONST_PTR_CONST_PTR): New.
        (BT_FN_VOID_PTRPTR_CONST_PTR): New.
        (BT_FN_VOID_CONST_PTR_SIZE): New.
        (BT_FN_PTR_CONST_PTR_CONST_PTR_SIZE); New.
        * builtins.c (expand_builtin_mempcpy_args): Add original
        expr as a new arg and support NOBND_NOCHK string functions.
        (expand_builtin_stpcpy): Likewise.
        (expand_builtin_cexpi): Add bound args to generated call.
        (expand_builtin_va_copy): Add bounds initialization.
        (expand_builtin): Support checker builtins.  Support calls
        with bound args.  Disable string functions inlining when
        pointers checker is on.
        (fold_builtin_next_arg): Support bound args for next_arg.
        * builtins.def (DEF_CHKP_BUILTIN): New.
        (BUILT_IN_CHKP_BNDMK): New.
        (BUILT_IN_CHKP_BNDSTX): New.
        (BUILT_IN_CHKP_BNDCL): New.
        (BUILT_IN_CHKP_BNDCU): New.
        (BUILT_IN_CHKP_BNDLDX): New.
        (BUILT_IN_CHKP_BNDRET): New.
        (BUILT_IN_CHKP_INTERSECT): New.
        (BUILT_IN_CHKP_ARG_BND): New.
        (BUILT_IN_CHKP_SIZEOF): New.
        (BUILT_IN_CHKP_EXTRACT_LOWER): New.
        (BUILT_IN_CHKP_EXTRACT_UPPER): New.
        (BUILT_IN_CHKP_NARROW): New.
        (BUILT_IN_CHKP_SET_PTR_BOUNDS): New.
        (BUILT_IN_CHKP_INIT_PTR_BOUNDS): New.
        (BUILT_IN_CHKP_NULL_PTR_BOUNDS): New.
        (BUILT_IN_CHKP_COPY_PTR_BOUNDS): New.
        (BUILT_IN_CHKP_NARROW_PTR_BOUNDS): New.
        (BUILT_IN_CHKP_STORE_PTR_BOUNDS): New.
        (BUILT_IN_CHKP_CHECK_PTR_LBOUNDS): New.
        (BUILT_IN_CHKP_CHECK_PTR_UBOUNDS): New.
        (BUILT_IN_CHKP_CHECK_PTR_BOUNDS): New.
        (BUILT_IN_CHKP_GET_PTR_LBOUND): New.
        (BUILT_IN_CHKP_GET_PTR_UBOUND): New.
        (BUILT_IN_CHKP_MEMCPY_NOBND): New.
        (BUILT_IN_CHKP_MEMCPY_NOCHK): New.
        (BUILT_IN_CHKP_MEMCPY_NOBND_NOCHK): New.
        (BUILT_IN_CHKP_MEMMOVE_NOBND): New.
        (BUILT_IN_CHKP_MEMMOVE_NOCHK): New.
        (BUILT_IN_CHKP_MEMMOVE_NOBND_NOCHK): New.
        (BUILT_IN_CHKP_MEMPCPY_NOBND): New.
        (BUILT_IN_CHKP_MEMPCPY_NOCHK): New.
        (BUILT_IN_CHKP_MEMPCPY_NOBND_NOCHK): New.
        (BUILT_IN_CHKP_MEMSET_NOBND): New.
        (BUILT_IN_CHKP_MEMSET_NOCHK): New.
        (BUILT_IN_CHKP_MEMSET_NOBND_NOCHK): New.
        * c-family/c-common.c (handle_bnd_variable_size_attribute): New.
        (handle_bnd_legacy): New.
        (c_common_attribute_table): Add bnd_variable_size and bnd_legacy.
        * common.opt (fcheck-pointers): New.
        (fchkp-check-incomplete-type): New.
        (fchkp-zero-input-bounds-for-main): New.
        (fchkp-zero-input-bounds-for-main): New.
        (fchkp-narrow-to-innermost-array): New.
        (fchkp-optimize): New.
        (fchkp-use-fast-string-functions): New.
        (fchkp-use-nochk-string-functions): New.
        (fchkp-use-static-bounds): New.
        (fchkp-use-static-const-bounds): New.
        (fchkp-treat-zero-size-reloc-as-infinite): New.
        (fchkp-check-read): New.
        (fchkp-check-write): New.
        * c/c-parser.c (c_parser_declaration_or_fndef): Register all
        statically initialized variables in pointers checker.
        * calls.c (arg_data): Add bounds related fields.
        (precompute_register_parameters): Add bounds expand.
        (initialize_argument_information): Initialize bounds_value and
        bounds slot for each arg.
        (load_register_parameters): Handle arg bounds.
        (expand_call): Handle bound args and returned bounds.
        (emit_library_call_value_1): Handle returned bounds slot
        and store pushed arg value.
        (store_one_arg): Store bounds for arg.
        * cfgexpand.c (expand_gimple_stmt_1): Fix expand_return call.
        * config/elfos.h (ASM_DECLARE_OBJECT_NAME): Fix size emitted for
        object.
        (ASM_FINISH_DECLARE_OBJECT) Likewise.
        * config/i386/cpuid.h (bit_MPX): New.
        * config/i386/i386-builtin-types.def (BND): New.
        (ULONG): New.
        (BND_FTYPE_PCVOID_ULONG): New.
        (VOID_FTYPE_BND_PCVOID): New.
        (VOID_FTYPE_PCVOID_PCVOID_BND): New.
        (BND_FTYPE_PCVOID_PCVOID): New.
        (BND_FTYPE_INT): New.
        (BND_FTYPE_VOID): New.
        (BND_FTYPE_BND_BND): New.
        (PVOID_FTYPE_PVOID_PVOID): New.
        (PVOID_FTYPE_PVOID_PVOID_ULONG): New.
        (PVOID_FTYPE_PCVOID_BND_ULONG): New.
        (ULONG_FTYPE_VOID): New.
        (PVOID_FTYPE_BND): New.
        * config/i386/i386.c (X86_64_BOUNDED_INTEGER_CLASS): New.
        (X86_64_BOUNDED_INTEGERSI_CLASS): New.
        (ix86_return_pops_args): Call aggregate_value_p with function
        type when function decl is not available.
        (init_cumulative_args): Initialize bound regs info.
        (merge_classes): Handle bounded classes.
        (classify_argument): Add stdarg argument.  Produce bounded classes
        for bounded types.  Handle bound modes.
        (examine_argument): Add bnd_nregs and stdarg arguments.  Fix-up
        classify_argument calls.  Handle bounded classes.
        (construct_container): Likewise.
        (function_arg_advance_32): Update bound regs info.
        (function_arg_advance_64): Likewise.
        (function_arg_32): Handle bounded args for instrumented code.
        (function_arg_64): Fix-up construct_container call.
        (ix86_function_value_regno_p): Handle FIRST_BND_REG.
        (function_value_32): Handle bounded returned value.
        (function_value_ms_64): Likewise.
        (function_value_64): Fix-up construct_container call.
        (return_in_memory_64): Fix-up examine_argument call.
        (setup_incoming_varargs_64): Store bounds when required.
        (ix86_va_start): Reset bounds for va_list and pointers inside it.
        (ix86_gimplify_va_arg): Fix-up construct_container and
        examine_argument calls.  Handle bounds in container.
        (output_pic_addr_const): Support UNSPEC_SIZEOF.
        (i386_asm_output_addr_const_extra): Support UNSPEC_SIZEOF.
        (ix86_expand_call): Add bound registers for calls with retval.
        (IX86_BUILTIN_BNDMK): New.
        (IX86_BUILTIN_BNDSTX): New.
        (IX86_BUILTIN_BNDLDX): New.
        (IX86_BUILTIN_BNDCL): New.
        (IX86_BUILTIN_BNDCU): New.
        (IX86_BUILTIN_BNDRET): New.
        (IX86_BUILTIN_BNDSET): New.
        (IX86_BUILTIN_BNDNARROW): New.
        (IX86_BUILTIN_BNDINT): New.
        (IX86_BUILTIN_ARG_BND): New.
        (IX86_BUILTIN_SIZEOF): New.
        (IX86_BUILTIN_BNDLOWER): New.
        (IX86_BUILTIN_BNDUPPER): New.
        (builtin_isa): Add leaf_p field to mark leaf attribute presence.
        (def_builtin): Initilaize leaf_p field.
        (ix86_add_new_builtins): Handle leaf_p field.
        (bdesc_mpx): New.
        (bdesc_mpx_const): New.
        (ix86_init_mpx_builtins): New.
        (ix86_init_builtins): Call ix86_init_mpx_builtins.
        (ix86_expand_builtin): Add support for IX86_BUILTIN_BNDMK,
        IX86_BUILTIN_BNDSTX, IX86_BUILTIN_BNDLDX, IX86_BUILTIN_BNDCL,
        IX86_BUILTIN_BNDCU, IX86_BUILTIN_BNDRET, IX86_BUILTIN_BNDSET,
        IX86_BUILTIN_BNDNARROW, IX86_BUILTIN_BNDINT, IX86_BUILTIN_ARG_BND,
        IX86_BUILTIN_SIZEOF, IX86_BUILTIN_BNDLOWER, IX86_BUILTIN_BNDUPPER.
        (ix86_builtin_mpx_function): New.
        (ix86_load_bounds): New.
        (ix86_store_bounds): New.
        (ix86_init_returned_bounds): New.
        (ix86_bnd_prefixed_insn_p): Check MPX flags and legacy attribute.
        (ix86_fn_abi_va_list_bounds_size): New.
        (ix86_mpx_bound_type): New.
        (ix86_mpx_bound_mode): New.
        (TARGET_LOAD_BOUNDS_FOR_ARG): New.
        (TARGET_STORE_BOUNDS_FOR_ARG): New.
        (TARGET_INIT_RETURNED_BOUNDS): New.
        (TARGET_FN_ABI_VA_LIST_BOUNDS_SIZE): New.
        (TARGET_CHKP_BOUND_TYPE): New.
        (TARGET_CHKP_BOUND_MODE): New.
        (TARGET_BUILTIN_CHKP_FUNCTION): New.
        * config/i386/i386.h (ix86_args): Add bound regs info and stdarg flag.
        * config/i386/i386.md (UNSPEC_SIZEOF): New.
        (UNSPEC_BNDRET): New.
        (*call_value): Add bound regs.
        (*sibcall_value): Likewise.
        (*call_value_rex64_ms_sysv): Likewise.
        (*call_value_pop): Likewise.
        (*sibcall_value_pop): Likewise.
        (*move_size_reloc_<mode>): New.
        * config/i386/predicates.md (size_relocation): New.
        (x86_64_zext_immediate_operand): Support UNSPEC_SIZEOF.
        (call_rex64_ms_sysv_operation): Fix due to clobbered bound regs.
        * cp/decl.c (cp_finish_decl): Register static initializer in
        instrumentation pass.
        * cppbuiltin.c (define_builtin_macros_for_compilation_flags): Add
        __CHKP__ macro definition when compiled with -fcheck-pointers.
        * dbxout.c (dbxout_type): Handle BOUND_TYPE with no output.
        * doc/tm.texi.in (TARGET_FN_ABI_VA_LIST_BOUNDS_SIZE): New.
        (TARGET_LOAD_BOUNDS_FOR_ARG): New.
        (TARGET_STORE_BOUNDS_FOR_ARG): New.
        (TARGET_INIT_RETURNED_BOUNDS): New.
        (TARGET_BUILTIN_CHKP_FUNCTION): New.
        (TARGET_CHKP_BOUND_TYPE): New.
        (TARGET_CHKP_BOUND_MODE): New.
        * doc/tm.texi: Regenerate.
        * dwarf2out.c (gen_subprogram_die): Skip bound args.
        * emit-rtl.c (immed_double_const): Add MODE_BOUND class.
        * except.c (expand_builtin_eh_pointer): Initialize bounds for
        returned pointer.
        * explow.c (trunc_int_for_mode): Allow bound mode.
        (hard_function_value): Handle returned bounds.
        * expr.c (emit_block_move_via_libcall): Add bound args to library
        call if required.
        (expand_assignment): Handle returned bounds.
        (store_expr): Likewise.
        * function.c (instantiate_virtual_regs_in_insn): Add PLUS expr.
        (aggregate_value_p): Handle returned bounds.
        (use_register_for_decl): Do not use register for aggregates having
        pointers when pointers checker is on.
        (assign_parm_data_one): Add bound_parm field to hold arg bounds.
        (assign_parm_find_data_types): Take bound args into account when
        checking for variadric args.
        (assign_parm_find_entry_rtl): Split parm into value and bounds parts.
        (assign_parm_is_stack_parm): Check bound parm.
        (assign_parm_setup_block): Store bounds if any.
        (assign_parm_setup_stack): Likewise.
        (assign_parms): Load bounds and associate them with parm.
        (expand_function_start): Handle returned bounds.
        (diddle_return_value_1): New.
        (diddle_return_value): Handle returned bounds.
        (expand_function_end): Likewise.
        * function.h (rtl_data): Add return_bnd to hold bound register
        holding returned bounds.
        * gimple-pretty-print.c (dump_gimple_assign): Dump returned bounds.
        * gimple.c (gimple_build_return): Add new operand to hold returned
        bounds.
        * gimple.h (gimple_return_retbnd): New.
        (gimple_return_set_retbnd): New.
        * gimplify.c (gimplify_init_constructor): Do not generate initializer
        image in the memory when handling chkp constructor.  Register created
        statically initialized vars.
        * hooks.c (hook_tree_void_null): New.
        (hook_tree_uint_null): New.
        * hooks.h (hook_tree_void_null): New.
        (hook_tree_uint_null): New.
        * ipa.c (cgraph_build_static_cdtor_1) Add 'P' and 'B' constructor types.
        * optabs.c (expand_unop): Handle returned bounds.
        * passes.def: Add pass_chkp, pass_copy_prop_chkp, pass_chkp_opt,
        pass_dce_chkp.
        * stmt.c (expand_return): Add bounds arg.  Handle returned bounds.
        * target.def (builtin_chkp_function): New.
        (chkp_bound_type): New.
        (chkp_bound_mode): New.
        (fn_abi_va_list_bounds_size): New.
        (load_bounds_for_arg): New.
        (store_bounds_for_arg): New.
        (init_returned_bounds): New.
        * targhooks.c (default_load_bounds_for_arg): New.
        (default_store_bounds_for_arg): New.
        (default_init_returned_bounds): New.
        (default_fn_abi_va_list_bounds_size): New.
        (default_chkp_bound_mode): New.
        (default_builtin_chkp_function): New.
        * targhooks.h (default_load_bounds_for_arg): New.
        (default_store_bounds_for_arg): New.
        (default_fn_abi_va_list_bounds_size): New.
        (default_init_returned_bounds): New.
        (default_chkp_bound_mode): New.
        (default_builtin_chkp_function): New.
        * toplev.c (compile_file): Add chkp_finish_file call.
        (process_options): Check front-end support.  Check for
        pointers checker and lto usage.
        * tree-chkp.c: New.
        * tree-pass.h (make_pass_chkp): New.
        (make_pass_copy_prop_chkp): New.
        (make_pass_chkp_opt): New.
        (make_pass_dce_chkp): New.
        * tree-ssa-copy.c (gate_copy_prop_chkp): New.
        (pass_copy_prop_chkp): New.
        (make_pass_copy_prop_chkp): New.
        * tree-ssa-dce.c (gate_dce_chkp): New.
        (pass_dce_chkp): New.
        (make_pass_dce_chkp): New.
        * tree-ssa-loop.c (gate_tree_ssa_loop_ivopts): Disable ivopts when
        pointers checker is on.
        * tree.c (build_common_tree_nodes): Add bound_type_node creation.
        * tree.h (BOUNDED_TYPE_P): New.
        (BOUNDED_P): New.
        (DECL_BOUNDS_RTL): New.
        (SET_DECL_BOUNDS_RTL): New.
        (TI_BOUND_TYPE): New.
        (bound_type_node): New.
        (expand_return): Add arg.
        (chkp_get_rtl_bounds): New.
        (chkp_set_rtl_bounds): New.
        (chkp_register_var_initializer): New.
        (chkp_finish_file): New.
        (chkp_get_registered_bounds): New.
        (chkp_get_arg_bounds): New.
        (chkp_split_slot): New.
        (chkp_join_splitted_slot): New.
        (chkp_get_value_with_offs): New.
        (chkp_copy_bounds_for_stack_parm): New.
        (chkp_type_has_pointer): New.
        (chkp_emit_bounds_store): New.
        (chkp_make_bounds_for_struct_addr): New.
        (chkp_get_zero_bounds): New.
        (chkp_variable_size_type): New.
        (chkp_build_make_bounds_call): New.
        (chkp_build_bndstx_call): New.
        (chkp_expand_bounds_reset_for_mem): New.
        (chkp_put_regs_to_expr_list): New.
        * langhooks.h (lang_hooks): Add chkp_supported field.
        * langhooks-def.h (LANG_HOOKS_CHKP_SUPPORTED): New.
        (LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_CHKP_SUPPORTED.
        * c/c-lang.c (LANG_HOOKS_CHKP_SUPPORTED): New.
        * cp/cp-lang.c (LANG_HOOKS_CHKP_SUPPORTED): New.
        * objc/objc-lang.c (LANG_HOOKS_CHKP_SUPPORTED): New.
        * objcp/objcp-lang.c (LANG_HOOKS_CHKP_SUPPORTED): New.

Attachment: mpx-pass.patch.tgz
Description: GNU Zip compressed data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]