This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Don't unnecessarily create stack protector guard decls and MEMs (PR target/77957)
- From: Richard Biener <rguenther at suse dot de>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 13 Oct 2016 09:09:31 +0200 (CEST)
- Subject: Re: [PATCH] Don't unnecessarily create stack protector guard decls and MEMs (PR target/77957)
- Authentication-results: sourceware.org; auth=none
- References: <20161012233048.GZ7282@tucnak.redhat.com>
On Thu, 13 Oct 2016, Jakub Jelinek wrote:
> Hi!
>
> PR77957 is likely a rs6000 backend bug where a useless memory load causes
> .LCTOC0 undefined reference in the end at -O0 and as such should be fixed,
> but I think it is completely unnecessary to create those loads at all
> if we know we are going to ignore it in the stack_protect_{set,test}
> patterns because TARGET_THREAD_SSP_OFFSET is defined and we are going to
> load from ABI selected TLS word.
>
> So, this patch tweaks the -fstack-protector* expansion (both prologue and
> epilogue) so that if targetm.stack_protector_guard hook returns NULL it just
> passes a dummy const0_rtx down to the expander that is going to ignore it
> anyway, and adjusts the affected targets to return NULL in those cases.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Ok.
Thanks,
Richard.
> 2016-10-12 Jakub Jelinek <jakub@redhat.com>
>
> PR target/77957
> * hooks.h (hook_tree_void_null): Declare.
> * hooks.c (hook_tree_void_null): New function.
> * langhooks.c (lhd_return_null_tree_v): Remove.
> * langhooks-def.h (lhd_return_null_tree_v): Remove.
> * cfgexpand.c (stack_protect_prologue): If guard_decl is NULL,
> set y to const0_rtx.
> * function.c (stack_protect_epilogue): Likewise.
> * config/tilepro/tilepro.c (TARGET_STACK_PROTECT_GUARD): Redefine
> if TARGET_THREAD_SSP_OFFSET is defined.
> * config/s390/s390.c (TARGET_STACK_PROTECT_GUARD): Likewise.
> * config/sparc/sparc.c (TARGET_STACK_PROTECT_GUARD): Likewise.
> * config/tilegx/tilegx.c (TARGET_STACK_PROTECT_GUARD): Likewise.
> * config/rs6000/rs6000.c (TARGET_STACK_PROTECT_GUARD): Likewise.
> * config/i386/i386.c (TARGET_STACK_PROTECT_GUARD): Likewise.
> (ix86_stack_protect_guard): New function.
> c/
> * c-objc-common.h (LANG_HOOKS_GETDECLS): Use hook_tree_void_null
> instead of lhd_return_null_tree_v.
> ada/
> * gcc-interface/misc.c (LANG_HOOKS_GETDECLS): Use hook_tree_void_null
> instead of lhd_return_null_tree_v.
>
> --- gcc/config/tilepro/tilepro.c.jj 2016-09-27 20:12:45.000000000 +0200
> +++ gcc/config/tilepro/tilepro.c 2016-10-12 18:18:41.001998284 +0200
> @@ -4948,6 +4948,11 @@ tilepro_file_end (void)
> #undef TARGET_OPTION_OVERRIDE
> #define TARGET_OPTION_OVERRIDE tilepro_option_override
>
> +#ifdef TARGET_THREAD_SSP_OFFSET
> +#undef TARGET_STACK_PROTECT_GUARD
> +#define TARGET_STACK_PROTECT_GUARD hook_tree_void_null
> +#endif
> +
> #undef TARGET_SCALAR_MODE_SUPPORTED_P
> #define TARGET_SCALAR_MODE_SUPPORTED_P tilepro_scalar_mode_supported_p
>
> --- gcc/config/s390/s390.c.jj 2016-09-27 09:46:13.000000000 +0200
> +++ gcc/config/s390/s390.c 2016-10-12 18:17:24.873959377 +0200
> @@ -15124,6 +15124,11 @@ s390_invalid_binary_op (int op ATTRIBUTE
> #undef TARGET_OPTION_OVERRIDE
> #define TARGET_OPTION_OVERRIDE s390_option_override
>
> +#ifdef TARGET_THREAD_SSP_OFFSET
> +#undef TARGET_STACK_PROTECT_GUARD
> +#define TARGET_STACK_PROTECT_GUARD hook_tree_void_null
> +#endif
> +
> #undef TARGET_ENCODE_SECTION_INFO
> #define TARGET_ENCODE_SECTION_INFO s390_encode_section_info
>
> --- gcc/config/i386/i386.c.jj 2016-10-08 14:04:16.859911786 +0200
> +++ gcc/config/i386/i386.c 2016-10-12 18:10:00.344570177 +0200
> @@ -44023,6 +44023,18 @@ ix86_mangle_type (const_tree type)
> }
> }
>
> +#ifdef TARGET_THREAD_SSP_OFFSET
> +/* If using TLS guards, don't waste time creating and expanding
> + __stack_chk_guard decl and MEM as we are going to ignore it. */
> +static tree
> +ix86_stack_protect_guard (void)
> +{
> + if (TARGET_SSP_TLS_GUARD)
> + return NULL_TREE;
> + return default_stack_protect_guard ();
> +}
> +#endif
> +
> /* For 32-bit code we can save PIC register setup by using
> __stack_chk_fail_local hidden function instead of calling
> __stack_chk_fail directly. 64-bit code doesn't need to setup any PIC
> @@ -50614,6 +50626,11 @@ ix86_addr_space_zero_address_valid (addr
> #undef TARGET_MANGLE_TYPE
> #define TARGET_MANGLE_TYPE ix86_mangle_type
>
> +#ifdef TARGET_THREAD_SSP_OFFSET
> +#undef TARGET_STACK_PROTECT_GUARD
> +#define TARGET_STACK_PROTECT_GUARD ix86_stack_protect_guard
> +#endif
> +
> #if !TARGET_MACHO
> #undef TARGET_STACK_PROTECT_FAIL
> #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
> --- gcc/config/sparc/sparc.c.jj 2016-10-12 01:16:42.000000000 +0200
> +++ gcc/config/sparc/sparc.c 2016-10-12 18:17:44.595710443 +0200
> @@ -798,6 +798,11 @@ char sparc_hard_reg_printed[8];
> #undef TARGET_OPTION_OVERRIDE
> #define TARGET_OPTION_OVERRIDE sparc_option_override
>
> +#ifdef TARGET_THREAD_SSP_OFFSET
> +#undef TARGET_STACK_PROTECT_GUARD
> +#define TARGET_STACK_PROTECT_GUARD hook_tree_void_null
> +#endif
> +
> #if TARGET_GNU_TLS && defined(HAVE_AS_SPARC_UA_PCREL)
> #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
> #define TARGET_ASM_OUTPUT_DWARF_DTPREL sparc_output_dwarf_dtprel
> --- gcc/config/tilegx/tilegx.c.jj 2016-09-14 16:01:07.000000000 +0200
> +++ gcc/config/tilegx/tilegx.c 2016-10-12 18:18:20.952251422 +0200
> @@ -5544,6 +5544,11 @@ tilegx_file_end (void)
> #undef TARGET_OPTION_OVERRIDE
> #define TARGET_OPTION_OVERRIDE tilegx_option_override
>
> +#ifdef TARGET_THREAD_SSP_OFFSET
> +#undef TARGET_STACK_PROTECT_GUARD
> +#define TARGET_STACK_PROTECT_GUARD hook_tree_void_null
> +#endif
> +
> #undef TARGET_SCALAR_MODE_SUPPORTED_P
> #define TARGET_SCALAR_MODE_SUPPORTED_P tilegx_scalar_mode_supported_p
>
> --- gcc/config/rs6000/rs6000.c.jj 2016-10-11 20:51:04.000000000 +0200
> +++ gcc/config/rs6000/rs6000.c 2016-10-12 17:54:04.420635740 +0200
> @@ -1735,6 +1735,11 @@ static const struct attribute_spec rs600
> #define TARGET_VECTORIZE_BUILTIN_MD_VECTORIZED_FUNCTION \
> rs6000_builtin_md_vectorized_function
>
> +#ifdef TARGET_THREAD_SSP_OFFSET
> +#undef TARGET_STACK_PROTECT_GUARD
> +#define TARGET_STACK_PROTECT_GUARD hook_tree_void_null
> +#endif
> +
> #if !TARGET_MACHO
> #undef TARGET_STACK_PROTECT_FAIL
> #define TARGET_STACK_PROTECT_FAIL rs6000_stack_protect_fail
> --- gcc/ada/gcc-interface/misc.c.jj 2016-10-09 13:17:45.448639039 +0200
> +++ gcc/ada/gcc-interface/misc.c 2016-10-12 17:49:50.535840245 +0200
> @@ -1366,7 +1366,7 @@ get_lang_specific (tree node)
> #undef LANG_HOOKS_TYPE_HASH_EQ
> #define LANG_HOOKS_TYPE_HASH_EQ gnat_type_hash_eq
> #undef LANG_HOOKS_GETDECLS
> -#define LANG_HOOKS_GETDECLS lhd_return_null_tree_v
> +#define LANG_HOOKS_GETDECLS hook_tree_void_null
> #undef LANG_HOOKS_PUSHDECL
> #define LANG_HOOKS_PUSHDECL gnat_return_tree
> #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
> --- gcc/langhooks.c.jj 2016-10-09 13:19:09.000000000 +0200
> +++ gcc/langhooks.c 2016-10-12 17:46:49.135128824 +0200
> @@ -77,14 +77,6 @@ lhd_do_nothing_f (struct function * ARG_
> /* Do nothing (return NULL_TREE). */
>
> tree
> -lhd_return_null_tree_v (void)
> -{
> - return NULL_TREE;
> -}
> -
> -/* Do nothing (return NULL_TREE). */
> -
> -tree
> lhd_return_null_tree (tree ARG_UNUSED (t))
> {
> return NULL_TREE;
> --- gcc/function.c.jj 2016-10-09 13:19:09.000000000 +0200
> +++ gcc/function.c 2016-10-12 18:00:23.207854731 +0200
> @@ -5058,7 +5058,10 @@ stack_protect_epilogue (void)
> rtx_insn *seq;
>
> x = expand_normal (crtl->stack_protect_guard);
> - y = expand_normal (guard_decl);
> + if (guard_decl)
> + y = expand_normal (guard_decl);
> + else
> + y = const0_rtx;
>
> /* Allow the target to compare Y with X without leaking either into
> a register. */
> --- gcc/c/c-objc-common.h.jj 2016-09-02 20:36:22.744167412 +0200
> +++ gcc/c/c-objc-common.h 2016-10-12 17:49:11.089338134 +0200
> @@ -91,7 +91,7 @@ along with GCC; see the file COPYING3.
> This means it must also provide its own write_globals. */
>
> #undef LANG_HOOKS_GETDECLS
> -#define LANG_HOOKS_GETDECLS lhd_return_null_tree_v
> +#define LANG_HOOKS_GETDECLS hook_tree_void_null
>
> /* Hooks for tree gimplification. */
> #undef LANG_HOOKS_GIMPLIFY_EXPR
> --- gcc/hooks.h.jj 2016-09-23 11:57:28.000000000 +0200
> +++ gcc/hooks.h 2016-10-12 17:46:25.021432966 +0200
> @@ -89,6 +89,7 @@ extern int hook_int_rtx_mode_as_bool_0 (
> bool);
>
> extern tree hook_tree_const_tree_null (const_tree);
> +extern tree hook_tree_void_null (void);
>
> extern tree hook_tree_tree_tree_null (tree, tree);
> extern tree hook_tree_tree_tree_tree_null (tree, tree, tree);
> --- gcc/langhooks-def.h.jj 2016-09-13 10:43:59.000000000 +0200
> +++ gcc/langhooks-def.h 2016-10-12 17:47:10.522859065 +0200
> @@ -41,7 +41,6 @@ extern void lhd_do_nothing_f (struct fun
> extern tree lhd_pass_through_t (tree);
> extern bool lhd_post_options (const char **);
> extern alias_set_type lhd_get_alias_set (tree);
> -extern tree lhd_return_null_tree_v (void);
> extern tree lhd_return_null_tree (tree);
> extern tree lhd_return_null_const_tree (const_tree);
> extern tree lhd_do_nothing_iii_return_null_tree (int, int, int);
> --- gcc/cfgexpand.c.jj 2016-10-09 13:19:09.000000000 +0200
> +++ gcc/cfgexpand.c 2016-10-12 18:00:49.635521164 +0200
> @@ -6100,7 +6100,10 @@ stack_protect_prologue (void)
> rtx x, y;
>
> x = expand_normal (crtl->stack_protect_guard);
> - y = expand_normal (guard_decl);
> + if (guard_decl)
> + y = expand_normal (guard_decl);
> + else
> + y = const0_rtx;
>
> /* Allow the target to copy from Y to X without leaking Y into a
> register. */
> --- gcc/hooks.c.jj 2016-09-23 20:08:12.000000000 +0200
> +++ gcc/hooks.c 2016-10-12 17:58:21.523390618 +0200
> @@ -429,6 +429,13 @@ hook_tree_const_tree_null (const_tree)
> return NULL;
> }
>
> +/* Generic hook that takes no arguments and returns a NULL_TREE. */
> +tree
> +hook_tree_void_null (void)
> +{
> + return NULL;
> +}
> +
> /* Generic hook that takes a rtx_insn * and an int and returns a bool. */
>
> bool
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)