Hi. Sending GCC 6 branch backports. Patches can bootstrap on ppc64le-redhat-linux and survives regression tests. I'm going to install the patches.
Martin
>From e65a740ebed1d27132352c4a55e0a2554eb34820 Mon Sep 17 00:00:00 2001 From: hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Fri, 13 Oct 2017 13:44:05 +0000 Subject: [PATCH 01/15] Backport r253729 gcc/lto/ChangeLog: 2017-10-13 Jan Hubicka <hubi...@ucw.cz> * lto-lang.c (lto_post_options): Clean shlib flag when not doing PIC. --- gcc/lto/lto-lang.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c index ebe908a3e17..0b0db619562 100644 --- a/gcc/lto/lto-lang.c +++ b/gcc/lto/lto-lang.c @@ -837,11 +837,13 @@ lto_post_options (const char **pfilename ATTRIBUTE_UNUSED) flag_pie is 2. */ flag_pie = MAX (flag_pie, flag_pic); flag_pic = flag_pie; + flag_shlib = 0; break; case LTO_LINKER_OUTPUT_EXEC: /* Normal executable */ flag_pic = 0; flag_pie = 0; + flag_shlib = 0; break; case LTO_LINKER_OUTPUT_UNKNOWN: -- 2.16.2
>From ced3b528c81165680c7b60bedefe2fa640210f91 Mon Sep 17 00:00:00 2001 From: hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Tue, 30 Jan 2018 13:17:40 +0000 Subject: [PATCH 02/15] Backport r257183 gcc/lto/ChangeLog: 2018-01-30 Jan Hubicka <hubi...@ucw.cz> PR lto/83954 * lto-symtab.c (warn_type_compatibility_p): Silence false positive for type match warning on arrays of pointers. gcc/testsuite/ChangeLog: 2018-01-30 Jan Hubicka <hubi...@ucw.cz> PR lto/83954 * gcc.dg/lto/pr83954.h: New testcase. * gcc.dg/lto/pr83954_0.c: New testcase. * gcc.dg/lto/pr83954_1.c: New testcase. --- gcc/lto/lto-symtab.c | 19 +++++++++++++++---- gcc/testsuite/gcc.dg/lto/pr83954.h | 3 +++ gcc/testsuite/gcc.dg/lto/pr83954_0.c | 8 ++++++++ gcc/testsuite/gcc.dg/lto/pr83954_1.c | 7 +++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/lto/pr83954.h create mode 100644 gcc/testsuite/gcc.dg/lto/pr83954_0.c create mode 100644 gcc/testsuite/gcc.dg/lto/pr83954_1.c diff --git a/gcc/lto/lto-symtab.c b/gcc/lto/lto-symtab.c index 94b919b53e6..395dca47929 100644 --- a/gcc/lto/lto-symtab.c +++ b/gcc/lto/lto-symtab.c @@ -280,11 +280,22 @@ warn_type_compatibility_p (tree prevailing_type, tree type, alias_set_type set1 = get_alias_set (type); alias_set_type set2 = get_alias_set (prevailing_type); - if (set1 && set2 && set1 != set2 - && (!POINTER_TYPE_P (type) || !POINTER_TYPE_P (prevailing_type) + if (set1 && set2 && set1 != set2) + { + tree t1 = type, t2 = prevailing_type; + + /* Alias sets of arrays are the same as alias sets of the inner + types. */ + while (TREE_CODE (t1) == ARRAY_TYPE && TREE_CODE (t2) == ARRAY_TYPE) + { + t1 = TREE_TYPE (t1); + t2 = TREE_TYPE (t2); + } + if ((!POINTER_TYPE_P (t1) || !POINTER_TYPE_P (t2)) || (set1 != TYPE_ALIAS_SET (ptr_type_node) - && set2 != TYPE_ALIAS_SET (ptr_type_node)))) - lev |= 5; + && set2 != TYPE_ALIAS_SET (ptr_type_node))) + lev |= 5; + } } return lev; diff --git a/gcc/testsuite/gcc.dg/lto/pr83954.h b/gcc/testsuite/gcc.dg/lto/pr83954.h new file mode 100644 index 00000000000..e0155402504 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr83954.h @@ -0,0 +1,3 @@ +struct foo; +extern struct foo *FOO_PTR_ARR[1]; + diff --git a/gcc/testsuite/gcc.dg/lto/pr83954_0.c b/gcc/testsuite/gcc.dg/lto/pr83954_0.c new file mode 100644 index 00000000000..065a31dab80 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr83954_0.c @@ -0,0 +1,8 @@ +/* { dg-lto-do link } */ +#include "pr83954.h" + +int main() { + // just to prevent symbol removal + FOO_PTR_ARR[1] = 0; + return 0; +} diff --git a/gcc/testsuite/gcc.dg/lto/pr83954_1.c b/gcc/testsuite/gcc.dg/lto/pr83954_1.c new file mode 100644 index 00000000000..61b40fc7759 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr83954_1.c @@ -0,0 +1,7 @@ +#include "pr83954.h" + +struct foo { + int x; +}; +struct foo *FOO_PTR_ARR[1] = { 0 }; + -- 2.16.2
>From e3ff25c3be1c1767b987c0280c67173d179341ee Mon Sep 17 00:00:00 2001 From: ebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Fri, 2 Feb 2018 18:09:32 +0000 Subject: [PATCH 03/15] Backport r257343 gcc/lto/ChangeLog: 2018-02-02 Eric Botcazou <ebotca...@adacore.com> PR lto/83954 * lto-symtab.c (warn_type_compatibility_p): Do not recurse into the component type of array types with non-aliased component. --- gcc/lto/lto-symtab.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gcc/lto/lto-symtab.c b/gcc/lto/lto-symtab.c index 395dca47929..e6fb95fe372 100644 --- a/gcc/lto/lto-symtab.c +++ b/gcc/lto/lto-symtab.c @@ -284,9 +284,12 @@ warn_type_compatibility_p (tree prevailing_type, tree type, { tree t1 = type, t2 = prevailing_type; - /* Alias sets of arrays are the same as alias sets of the inner - types. */ - while (TREE_CODE (t1) == ARRAY_TYPE && TREE_CODE (t2) == ARRAY_TYPE) + /* Alias sets of arrays with aliased components are the same as alias + sets of the inner types. */ + while (TREE_CODE (t1) == ARRAY_TYPE + && !TYPE_NONALIASED_COMPONENT (t1) + && TREE_CODE (t2) == ARRAY_TYPE + && !TYPE_NONALIASED_COMPONENT (t2)) { t1 = TREE_TYPE (t1); t2 = TREE_TYPE (t2); -- 2.16.2
>From af294e424e681168fe3537e1c6090edd75a853dc Mon Sep 17 00:00:00 2001 From: hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Tue, 6 Feb 2018 13:27:04 +0000 Subject: [PATCH 04/15] Backport r257412 gcc/lto/ChangeLog: 2018-01-30 Jan Hubicka <hubi...@ucw.cz> PR lto/81004 * lto.c: Include builtins.h (register_resolution): Merge resolutions in case trees was merged across units. (lto_maybe_register_decl): Break out from ... (lto_read_decls): ... here. (unify_scc): Also register decls here. (read_cgraph_and_symbols): Sanity check that all resolutions was read. --- gcc/lto/lto.c | 57 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c index b661e4f411f..d218b4c55f1 100644 --- a/gcc/lto/lto.c +++ b/gcc/lto/lto.c @@ -52,6 +52,7 @@ along with GCC; see the file COPYING3. If not see #include "lto-symtab.h" #include "stringpool.h" #include "fold-const.h" +#include "builtins.h" /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver. */ @@ -828,12 +829,20 @@ static void register_resolution (struct lto_file_decl_data *file_data, tree decl, enum ld_plugin_symbol_resolution resolution) { + bool existed; if (resolution == LDPR_UNKNOWN) return; if (!file_data->resolution_map) file_data->resolution_map = new hash_map<tree, ld_plugin_symbol_resolution>; - file_data->resolution_map->put (decl, resolution); + ld_plugin_symbol_resolution_t &res + = file_data->resolution_map->get_or_insert (decl, &existed); + gcc_assert (!existed || res == resolution); + if (!existed + || resolution == LDPR_PREVAILING_DEF_IRONLY + || resolution == LDPR_PREVAILING_DEF + || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP) + res = resolution; } /* Register DECL with the global symbol table and change its @@ -876,6 +885,18 @@ lto_register_function_decl_in_symtab (struct data_in *data_in, tree decl, decl, get_resolution (data_in, ix)); } +/* Check if T is a decl and needs register its resolution info. */ + +static void +lto_maybe_register_decl (struct data_in *data_in, tree t, unsigned ix) +{ + if (TREE_CODE (t) == VAR_DECL) + lto_register_var_decl_in_symtab (data_in, t, ix); + else if (TREE_CODE (t) == FUNCTION_DECL + && !DECL_BUILT_IN (t)) + lto_register_function_decl_in_symtab (data_in, t, ix); +} + /* For the type T re-materialize it in the type variant list and the pointer/reference-to chains. */ @@ -1611,7 +1632,10 @@ unify_scc (struct data_in *data_in, unsigned from, /* Fixup the streamer cache with the prevailing nodes according to the tree node mapping computed by compare_tree_sccs. */ if (len == 1) - streamer_tree_cache_replace_tree (cache, pscc->entries[0], from); + { + lto_maybe_register_decl (data_in, pscc->entries[0], from); + streamer_tree_cache_replace_tree (cache, pscc->entries[0], from); + } else { tree *map2 = XALLOCAVEC (tree, 2 * len); @@ -1619,6 +1643,7 @@ unify_scc (struct data_in *data_in, unsigned from, { map2[i*2] = (tree)(uintptr_t)(from + i); map2[i*2+1] = scc->entries[i]; + lto_maybe_register_decl (data_in, scc->entries[i], from + i); } qsort (map2, len, 2 * sizeof (tree), cmp_tree); qsort (map, len, 2 * sizeof (tree), cmp_tree); @@ -1764,13 +1789,7 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data, } if (!flag_ltrans) { - /* Register variables and functions with the - symbol table. */ - if (TREE_CODE (t) == VAR_DECL) - lto_register_var_decl_in_symtab (data_in, t, from + i); - else if (TREE_CODE (t) == FUNCTION_DECL - && !DECL_BUILT_IN (t)) - lto_register_function_decl_in_symtab (data_in, t, from + i); + lto_maybe_register_decl (data_in, t, from + i); /* Scan the tree for references to global functions or variables and record those for later fixup. */ if (mentions_vars_p (t)) @@ -2861,13 +2880,21 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames) /* Store resolutions into the symbol table. */ - ld_plugin_symbol_resolution_t *res; FOR_EACH_SYMBOL (snode) - if (snode->real_symbol_p () - && snode->lto_file_data - && snode->lto_file_data->resolution_map - && (res = snode->lto_file_data->resolution_map->get (snode->decl))) - snode->resolution = *res; + if (snode->externally_visible && snode->real_symbol_p () + && snode->lto_file_data && snode->lto_file_data->resolution_map + && !is_builtin_fn (snode->decl) + && !(VAR_P (snode->decl) && DECL_HARD_REGISTER (snode->decl))) + { + ld_plugin_symbol_resolution_t *res; + + res = snode->lto_file_data->resolution_map->get (snode->decl); + if (!res || *res == LDPR_UNKNOWN) + fatal_error (input_location, "missing resolution data for %s", + IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (snode->decl))); + else + snode->resolution = *res; + } for (i = 0; all_file_decl_data[i]; i++) if (all_file_decl_data[i]->resolution_map) { -- 2.16.2
>From 0111b33fafd9e8563d8f3248ecfcadf51a97069d Mon Sep 17 00:00:00 2001 From: hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Wed, 7 Feb 2018 10:20:03 +0000 Subject: [PATCH 05/15] Backport r257442 gcc/lto/ChangeLog: 2018-01-30 Jan Hubicka <hubi...@ucw.cz> * lto.c (register_resolution): Remove forgotten sanity check. --- gcc/lto/lto.c | 1 - 1 file changed, 1 deletion(-) diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c index d218b4c55f1..2809917cd61 100644 --- a/gcc/lto/lto.c +++ b/gcc/lto/lto.c @@ -837,7 +837,6 @@ register_resolution (struct lto_file_decl_data *file_data, tree decl, = new hash_map<tree, ld_plugin_symbol_resolution>; ld_plugin_symbol_resolution_t &res = file_data->resolution_map->get_or_insert (decl, &existed); - gcc_assert (!existed || res == resolution); if (!existed || resolution == LDPR_PREVAILING_DEF_IRONLY || resolution == LDPR_PREVAILING_DEF -- 2.16.2
>From e89f8e20aa3f94ca1a3458f0d0710c4f6c156d41 Mon Sep 17 00:00:00 2001 From: hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Thu, 8 Feb 2018 14:51:51 +0000 Subject: [PATCH 06/15] Backport r257490 gcc/ChangeLog: 2018-02-08 Jan Hubicka <hubi...@ucw.cz> PR ipa/81360 * cgraph.h (symtab_node::output_to_lto_symbol_table_p): Declare * symtab.c: Include builtins.h (symtab_node::output_to_lto_symbol_table_p): Move here from lto-streamer-out.c:output_symbol_p. * lto-streamer-out.c (write_symbol): Turn early exit to assert. (output_symbol_p): Move all logic to symtab.c (produce_symtab): Update. gcc/lto/ChangeLog: 2018-02-08 Jan Hubicka <hubi...@ucw.cz> PR ipa/81360 * lto.c (unify_scc): Register prevailing trees, not trees to be freed. (read_cgraph_and_symbols): Use symtab_node::output_to_lto_symbol_table_p. --- gcc/cgraph.h | 3 +++ gcc/lto-streamer-out.c | 55 ++++++------------------------------------------- gcc/lto/lto.c | 17 ++++++++++----- gcc/symtab.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/tree.c | 7 ++++--- 5 files changed, 81 insertions(+), 57 deletions(-) diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 958cc4c5d21..5a81b48d300 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -315,6 +315,9 @@ public: or abstract function kept for debug info purposes only. */ bool real_symbol_p (void); + /* Return true when the symbol needs to be output to the LTO symbol table. */ + bool output_to_lto_symbol_table_p (void); + /* Determine if symbol declaration is needed. That is, visible to something either outside this translation unit, something magic in the system configury. This function is used just during symbol creation. */ diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c index 6703d4106de..57d946d15fa 100644 --- a/gcc/lto-streamer-out.c +++ b/gcc/lto-streamer-out.c @@ -2517,14 +2517,10 @@ write_symbol (struct streamer_tree_cache_d *cache, const char *comdat; unsigned char c; - /* None of the following kinds of symbols are needed in the - symbol table. */ - if (!TREE_PUBLIC (t) - || is_builtin_fn (t) - || DECL_ABSTRACT_P (t) - || (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))) - return; - gcc_assert (TREE_CODE (t) != RESULT_DECL); + gcc_checking_assert (TREE_PUBLIC (t) + && !is_builtin_fn (t) + && !DECL_ABSTRACT_P (t) + && (!VAR_P (t) || !DECL_HARD_REGISTER (t))); gcc_assert (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == FUNCTION_DECL); @@ -2614,45 +2610,6 @@ write_symbol (struct streamer_tree_cache_d *cache, lto_write_data (&slot_num, 4); } -/* Return true if NODE should appear in the plugin symbol table. */ - -bool -output_symbol_p (symtab_node *node) -{ - struct cgraph_node *cnode; - if (!node->real_symbol_p ()) - return false; - /* We keep external functions in symtab for sake of inlining - and devirtualization. We do not want to see them in symbol table as - references unless they are really used. */ - cnode = dyn_cast <cgraph_node *> (node); - if (cnode && (!node->definition || DECL_EXTERNAL (cnode->decl)) - && cnode->callers) - return true; - - /* Ignore all references from external vars initializers - they are not really - part of the compilation unit until they are used by folding. Some symbols, - like references to external construction vtables can not be referred to at all. - We decide this at can_refer_decl_in_current_unit_p. */ - if (!node->definition || DECL_EXTERNAL (node->decl)) - { - int i; - struct ipa_ref *ref; - for (i = 0; node->iterate_referring (i, ref); i++) - { - if (ref->use == IPA_REF_ALIAS) - continue; - if (is_a <cgraph_node *> (ref->referring)) - return true; - if (!DECL_EXTERNAL (ref->referring->decl)) - return true; - } - return false; - } - return true; -} - - /* Write an IL symbol table to OB. SET and VSET are cgraph/varpool node sets we are outputting. */ @@ -2677,7 +2634,7 @@ produce_symtab (struct output_block *ob) { symtab_node *node = lsei_node (lsei); - if (!output_symbol_p (node) || DECL_EXTERNAL (node->decl)) + if (DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ()) continue; write_symbol (cache, node->decl, &seen, false); } @@ -2686,7 +2643,7 @@ produce_symtab (struct output_block *ob) { symtab_node *node = lsei_node (lsei); - if (!output_symbol_p (node) || !DECL_EXTERNAL (node->decl)) + if (!DECL_EXTERNAL (node->decl) || !node->output_to_lto_symbol_table_p ()) continue; write_symbol (cache, node->decl, &seen, false); } diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c index 2809917cd61..5012cc1b45c 100644 --- a/gcc/lto/lto.c +++ b/gcc/lto/lto.c @@ -1642,13 +1642,16 @@ unify_scc (struct data_in *data_in, unsigned from, { map2[i*2] = (tree)(uintptr_t)(from + i); map2[i*2+1] = scc->entries[i]; - lto_maybe_register_decl (data_in, scc->entries[i], from + i); } qsort (map2, len, 2 * sizeof (tree), cmp_tree); qsort (map, len, 2 * sizeof (tree), cmp_tree); for (unsigned i = 0; i < len; ++i) - streamer_tree_cache_replace_tree (cache, map[2*i], - (uintptr_t)map2[2*i]); + { + lto_maybe_register_decl (data_in, map[2*i], + (uintptr_t)map2[2*i]); + streamer_tree_cache_replace_tree (cache, map[2*i], + (uintptr_t)map2[2*i]); + } } /* Free the tree nodes from the read SCC. */ @@ -2889,8 +2892,12 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames) res = snode->lto_file_data->resolution_map->get (snode->decl); if (!res || *res == LDPR_UNKNOWN) - fatal_error (input_location, "missing resolution data for %s", - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (snode->decl))); + { + if (snode->output_to_lto_symbol_table_p ()) + fatal_error (input_location, "missing resolution data for %s", + IDENTIFIER_POINTER + (DECL_ASSEMBLER_NAME (snode->decl))); + } else snode->resolution = *res; } diff --git a/gcc/symtab.c b/gcc/symtab.c index ef2524ba642..b867000c354 100644 --- a/gcc/symtab.c +++ b/gcc/symtab.c @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "output.h" #include "ipa-utils.h" #include "calls.h" +#include "builtins.h" static const char *ipa_ref_use_name[] = {"read","write","addr","alias","chkp"}; @@ -2207,3 +2208,58 @@ symbol_table::symbol_suffix_separator () return '_'; #endif } + +/* Return true if symbol should be output to the symbol table. */ + +bool +symtab_node::output_to_lto_symbol_table_p (void) +{ + /* Only externally visible symbols matter. */ + if (!TREE_PUBLIC (decl)) + return false; + if (!real_symbol_p ()) + return false; + /* FIXME: variables probably should not be considered as real symbols at + first place. */ + if (VAR_P (decl) && DECL_HARD_REGISTER (decl)) + return false; + /* FIXME: Builtins corresponding to real functions probably should have + symbol table entries. */ + if (is_builtin_fn (decl)) + return false; + + /* We have real symbol that should be in symbol table. However try to trim + down the refernces to libraries bit more because linker will otherwise + bring unnecesary object files into the final link. + FIXME: The following checks can easily be confused i.e. by self recursive + function or self-referring variable. */ + + /* We keep external functions in symtab for sake of inlining + and devirtualization. We do not want to see them in symbol table as + references unless they are really used. */ + cgraph_node *cnode = dyn_cast <cgraph_node *> (this); + if (cnode && (!definition || DECL_EXTERNAL (decl)) + && cnode->callers) + return true; + + /* Ignore all references from external vars initializers - they are not really + part of the compilation unit until they are used by folding. Some symbols, + like references to external construction vtables can not be referred to at + all. We decide this at can_refer_decl_in_current_unit_p. */ + if (!definition || DECL_EXTERNAL (decl)) + { + int i; + struct ipa_ref *ref; + for (i = 0; iterate_referring (i, ref); i++) + { + if (ref->use == IPA_REF_ALIAS) + continue; + if (is_a <cgraph_node *> (ref->referring)) + return true; + if (!DECL_EXTERNAL (ref->referring->decl)) + return true; + } + return false; + } + return true; +} diff --git a/gcc/tree.c b/gcc/tree.c index fa39842e767..84f324f03f1 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -5445,9 +5445,10 @@ free_lang_data_in_decl (tree decl) At this point, it is not needed anymore. */ DECL_SAVED_TREE (decl) = NULL_TREE; - /* Clear the abstract origin if it refers to a method. Otherwise - dwarf2out.c will ICE as we clear TYPE_METHODS and thus the - origin will not be output correctly. */ + /* Clear the abstract origin if it refers to a method. + Otherwise dwarf2out.c will ICE as we splice functions out of + TYPE_FIELDS and thus the origin will not be output + correctly. */ if (DECL_ABSTRACT_ORIGIN (decl) && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl)) && RECORD_OR_UNION_TYPE_P -- 2.16.2
>From d7d02d4e0cef414b07fecae227e283697cc15cf9 Mon Sep 17 00:00:00 2001 From: hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Wed, 21 Feb 2018 19:05:30 +0000 Subject: [PATCH 07/15] Backport r257877 gcc/ChangeLog: 2018-02-21 Jan Hubicka <hubi...@ucw.cz> PR c/84229 * ipa-cp.c (determine_versionability): Do not version functions caling va_arg_pack. --- gcc/ipa-cp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 98bb9514777..caa346f7016 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -544,6 +544,24 @@ determine_versionability (struct cgraph_node *node, reason = "calls comdat-local function"; } + /* Functions calling BUILT_IN_VA_ARG_PACK and BUILT_IN_VA_ARG_PACK_LEN + works only when inlined. Cloning them may still lead to better code + becuase ipa-cp will not give up on cloning further. If the function is + external this however leads to wrong code becuase we may end up producing + offline copy of the function. */ + if (DECL_EXTERNAL (node->decl)) + for (cgraph_edge *edge = node->callees; !reason && edge; + edge = edge->next_callee) + if (DECL_BUILT_IN (edge->callee->decl) + && DECL_BUILT_IN_CLASS (edge->callee->decl) == BUILT_IN_NORMAL) + { + if (DECL_FUNCTION_CODE (edge->callee->decl) == BUILT_IN_VA_ARG_PACK) + reason = "external function which calls va_arg_pack"; + if (DECL_FUNCTION_CODE (edge->callee->decl) + == BUILT_IN_VA_ARG_PACK_LEN) + reason = "external function which calls va_arg_pack_len"; + } + if (reason && dump_file && !node->alias && !node->thunk.thunk_p) fprintf (dump_file, "Function %s/%i is not versionable, reason: %s.\n", node->name (), node->order, reason); -- 2.16.2
>From f533d84a959efef19715110145a5c9e8a674a6d2 Mon Sep 17 00:00:00 2001 From: hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Fri, 23 Feb 2018 18:18:07 +0000 Subject: [PATCH 08/15] Backport r257939 gcc/lto/ChangeLog: 2018-02-08 Jan Hubicka <hubi...@ucw.cz> * lto-partition.c (lto_balanced_map): Watch overflow. --- gcc/lto/lto-partition.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c index 051b98771fc..cffec8e4bcf 100644 --- a/gcc/lto/lto-partition.c +++ b/gcc/lto/lto-partition.c @@ -751,7 +751,8 @@ lto_balanced_map (int n_lto_partitions) if (npartitions < n_lto_partitions) partition_size = total_size / (n_lto_partitions - npartitions); else - partition_size = INT_MAX; + /* Watch for overflow. */ + partition_size = INT_MAX / 16; if (partition_size < PARAM_VALUE (MIN_PARTITION_SIZE)) partition_size = PARAM_VALUE (MIN_PARTITION_SIZE); -- 2.16.2
>From e6b41bc39805626df837f275a13a417745bee73d Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Mon, 5 Mar 2018 15:30:47 +0100 Subject: [PATCH 09/15] Fix IPA profile merging, fixed in trunk with r253910. gcc/ChangeLog: 2018-03-05 Martin Liska <mli...@suse.cz> * ipa-utils.c (ipa_merge_profiles): Do not merge alias or a function without profile. --- gcc/ipa-utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/ipa-utils.c b/gcc/ipa-utils.c index 5eb7d5f31aa..cee0c6c95d0 100644 --- a/gcc/ipa-utils.c +++ b/gcc/ipa-utils.c @@ -403,6 +403,8 @@ ipa_merge_profiles (struct cgraph_node *dst, if (!dst->count) return; + if (!src->count || src->alias) + return; if (symtab->dump_file) { fprintf (symtab->dump_file, "Merging profiles of %s/%i to %s/%i\n", -- 2.16.2
>From c3c98155914e4848c17639a29bf7fab19951fe6c Mon Sep 17 00:00:00 2001 From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Tue, 19 Dec 2017 13:20:07 +0000 Subject: [PATCH 10/15] Backport r255818 gcc/ChangeLog: 2017-12-19 Martin Liska <mli...@suse.cz> PR rtl-optimization/82675 * loop-unroll.c (unroll_loop_constant_iterations): Allocate one more element in sbitmap. --- gcc/loop-unroll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/loop-unroll.c b/gcc/loop-unroll.c index 4d26e2f7cd1..c68cbc54892 100644 --- a/gcc/loop-unroll.c +++ b/gcc/loop-unroll.c @@ -477,7 +477,7 @@ unroll_loop_constant_iterations (struct loop *loop) exit_mod = niter % (max_unroll + 1); - wont_exit = sbitmap_alloc (max_unroll + 1); + wont_exit = sbitmap_alloc (max_unroll + 2); bitmap_ones (wont_exit); auto_vec<edge> remove_edges; -- 2.16.2
>From b54bc9372c903831dc619ff72e4e7d82a395c10e Mon Sep 17 00:00:00 2001 From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Tue, 23 Jan 2018 15:46:02 +0000 Subject: [PATCH 11/15] Backport r256989 gcc/lto/ChangeLog: 2018-01-23 Martin Liska <mli...@suse.cz> PR lto/81440 * lto-symtab.c (lto_symtab_merge): Handle and do not warn about trailing arrays at the end of a struct. gcc/testsuite/ChangeLog: 2018-01-23 Martin Liska <mli...@suse.cz> PR lto/81440 * gcc.dg/lto/pr81440.h: New test. * gcc.dg/lto/pr81440_0.c: New test. * gcc.dg/lto/pr81440_1.c: New test. --- gcc/lto/lto-symtab.c | 25 +++++++++++++++++++------ gcc/testsuite/gcc.dg/lto/pr81440.h | 4 ++++ gcc/testsuite/gcc.dg/lto/pr81440_0.c | 9 +++++++++ gcc/testsuite/gcc.dg/lto/pr81440_1.c | 6 ++++++ 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/lto/pr81440.h create mode 100644 gcc/testsuite/gcc.dg/lto/pr81440_0.c create mode 100644 gcc/testsuite/gcc.dg/lto/pr81440_1.c diff --git a/gcc/lto/lto-symtab.c b/gcc/lto/lto-symtab.c index e6fb95fe372..6b3b785b674 100644 --- a/gcc/lto/lto-symtab.c +++ b/gcc/lto/lto-symtab.c @@ -362,18 +362,31 @@ lto_symtab_merge (symtab_node *prevailing, symtab_node *entry) return false; if (DECL_SIZE (decl) && DECL_SIZE (prevailing_decl) - && !tree_int_cst_equal (DECL_SIZE (decl), DECL_SIZE (prevailing_decl)) + && !tree_int_cst_equal (DECL_SIZE (decl), DECL_SIZE (prevailing_decl))) + { + if (!DECL_COMMON (decl) && !DECL_EXTERNAL (decl)) + return false; + + tree type = TREE_TYPE (decl); + + /* For record type, check for array at the end of the structure. */ + if (TREE_CODE (type) == RECORD_TYPE) + { + tree field = TYPE_FIELDS (type); + while (DECL_CHAIN (field) != NULL_TREE) + field = DECL_CHAIN (field); + + return TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE; + } /* As a special case do not warn about merging int a[]; and int a[]={1,2,3}; here the first declaration is COMMON and sizeof(a) == sizeof (int). */ - && ((!DECL_COMMON (decl) && !DECL_EXTERNAL (decl)) - || TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE - || TYPE_SIZE (TREE_TYPE (decl)) - != TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))))) - return false; + else if (TREE_CODE (type) == ARRAY_TYPE) + return (TYPE_SIZE (decl) == TYPE_SIZE (TREE_TYPE (type))); + } return true; } diff --git a/gcc/testsuite/gcc.dg/lto/pr81440.h b/gcc/testsuite/gcc.dg/lto/pr81440.h new file mode 100644 index 00000000000..d9e6c3da645 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr81440.h @@ -0,0 +1,4 @@ +typedef struct { + int i; + int ints[]; +} struct_t; diff --git a/gcc/testsuite/gcc.dg/lto/pr81440_0.c b/gcc/testsuite/gcc.dg/lto/pr81440_0.c new file mode 100644 index 00000000000..07f2a87da21 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr81440_0.c @@ -0,0 +1,9 @@ +/* { dg-lto-do link } */ + +#include "pr81440.h" + +extern struct_t my_struct; + +int main() { + return my_struct.ints[0]; +} diff --git a/gcc/testsuite/gcc.dg/lto/pr81440_1.c b/gcc/testsuite/gcc.dg/lto/pr81440_1.c new file mode 100644 index 00000000000..d03533029c1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr81440_1.c @@ -0,0 +1,6 @@ +#include "pr81440.h" + +struct_t my_struct = { + 20, + { 1, 2 } +}; -- 2.16.2
>From a8674ec9e72a5a7c64342d890db8d1eb5e7755d6 Mon Sep 17 00:00:00 2001 From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Mon, 5 Feb 2018 09:19:18 +0000 Subject: [PATCH 12/15] Backport r257383 gcc/ChangeLog: 2018-02-05 Martin Liska <mli...@suse.cz> PR gcov-profile/83879 * doc/gcov.texi: Document necessity of --dynamic-list-data when using dlopen functionality. --- gcc/doc/gcov.texi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi index 8e1ef5cdba8..54a1172cb94 100644 --- a/gcc/doc/gcov.texi +++ b/gcc/doc/gcov.texi @@ -604,6 +604,8 @@ facilities to restrict profile collection to the program region of interest. Calling @code{_gcov_reset(void)} will clear all profile counters to zero, and calling @code{_gcov_dump(void)} will cause the profile information collected at that point to be dumped to @file{.gcda} output files. +If an executable loads a dynamic shared object via dlopen functionality, +@option{-Wl,--dynamic-list-data} is needed to dump all profile data. @c man end -- 2.16.2
>From ac932abe6ce63c4f100f36bc3e4e44b5c5451605 Mon Sep 17 00:00:00 2001 From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Mon, 5 Feb 2018 09:59:16 +0000 Subject: [PATCH 13/15] Backport r257384 gcc/ChangeLog: 2018-02-05 Martin Liska <mli...@suse.cz> PR gcov-profile/84137 * doc/gcov.texi: Fix typo in documentation. --- gcc/doc/gcov.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi index 54a1172cb94..ff1eca714b1 100644 --- a/gcc/doc/gcov.texi +++ b/gcc/doc/gcov.texi @@ -321,7 +321,7 @@ program source code. The format is Additional block information may succeed each line, when requested by command line option. The @var{execution_count} is @samp{-} for lines containing no code. Unexecuted lines are marked @samp{#####} or -@samp{====}, depending on whether they are reachable by +@samp{=====}, depending on whether they are reachable by non-exceptional paths or only exceptional paths such as C++ exception handlers, respectively. Given @samp{-a} option, unexecuted blocks are marked @samp{$$$$$} or @samp{%%%%%}, depending on whether a basic block -- 2.16.2
>From 8b4949bb7e0c3511d8568cb2c8e04200c0f33197 Mon Sep 17 00:00:00 2001 From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Mon, 19 Feb 2018 09:54:09 +0000 Subject: [PATCH 14/15] Backport r257803 gcc/ChangeLog: 2018-02-19 Martin Liska <mli...@suse.cz> PR other/80589 * doc/invoke.texi: Fix typo. * params.def (PARAM_MAX_LOOP_HEADER_INSNS): Likewise. --- gcc/doc/invoke.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b066f7bd419..dbd019f2c79 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -7278,7 +7278,7 @@ This flag is enabled by default at @option{-O2} and higher and depends on @item -fisolate-erroneous-paths-attribute @opindex fisolate-erroneous-paths-attribute -Detect paths that trigger erroneous or undefined behavior due a null value +Detect paths that trigger erroneous or undefined behavior due to a null value being used in a way forbidden by a @code{returns_nonnull} or @code{nonnull} attribute. Isolate those paths from the main control flow and turn the statement with erroneous or undefined behavior into a trap. This is not -- 2.16.2
>From f447d7447bf9804c4673fbf19f6163dd9918f004 Mon Sep 17 00:00:00 2001 From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Tue, 20 Feb 2018 10:04:13 +0000 Subject: [PATCH 15/15] Backport r257842 gcc/ChangeLog: 2018-02-20 Martin Liska <mli...@suse.cz> PR c/84310 PR target/79747 * final.c (shorten_branches): Build align_tab array with one more element. * opts.c (finish_options): Add alignment option limit check. (MAX_CODE_ALIGN): Likewise. (MAX_CODE_ALIGN_VALUE): Likewise. * doc/invoke.texi: Document maximum allowed option value for all -falign-* options. gcc/testsuite/ChangeLog: 2018-02-20 Martin Liska <mli...@suse.cz> PR c/84310 PR target/79747 * gcc.target/i386/pr84310.c: New test. * gcc.target/i386/pr84310-2.c: Likewise. --- gcc/doc/invoke.texi | 4 ++++ gcc/final.c | 4 ++-- gcc/opts.c | 20 ++++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr84310-2.c | 10 ++++++++++ gcc/testsuite/gcc.target/i386/pr84310.c | 8 ++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr84310-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr84310.c diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index dbd019f2c79..df4f5bd17d8 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -7822,6 +7822,7 @@ Some assemblers only support this flag when @var{n} is a power of two; in that case, it is rounded up. If @var{n} is not specified or is zero, use a machine-dependent default. +The maximum allowed @var{n} option value is 65536. Enabled at levels @option{-O2}, @option{-O3}. @@ -7841,6 +7842,7 @@ are greater than this value, then their values are used instead. If @var{n} is not specified or is zero, use a machine-dependent default which is very likely to be @samp{1}, meaning no alignment. +The maximum allowed @var{n} option value is 65536. Enabled at levels @option{-O2}, @option{-O3}. @@ -7854,6 +7856,7 @@ operations. @option{-fno-align-loops} and @option{-falign-loops=1} are equivalent and mean that loops are not aligned. +The maximum allowed @var{n} option value is 65536. If @var{n} is not specified or is zero, use a machine-dependent default. @@ -7871,6 +7874,7 @@ need be executed. equivalent and mean that loops are not aligned. If @var{n} is not specified or is zero, use a machine-dependent default. +The maximum allowed @var{n} option value is 65536. Enabled at levels @option{-O2}, @option{-O3}. diff --git a/gcc/final.c b/gcc/final.c index 55cf509611f..c07764e02e2 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -901,7 +901,7 @@ shorten_branches (rtx_insn *first) char *varying_length; rtx body; int uid; - rtx align_tab[MAX_CODE_ALIGN]; + rtx align_tab[MAX_CODE_ALIGN + 1]; /* Compute maximum UID and allocate label_align / uid_shuid. */ max_uid = get_max_uid (); @@ -1010,7 +1010,7 @@ shorten_branches (rtx_insn *first) alignment of n. */ uid_align = XCNEWVEC (rtx, max_uid); - for (i = MAX_CODE_ALIGN; --i >= 0;) + for (i = MAX_CODE_ALIGN + 1; --i >= 0;) align_tab[i] = NULL_RTX; seq = get_last_insn (); for (; seq; seq = PREV_INSN (seq)) diff --git a/gcc/opts.c b/gcc/opts.c index 8f9862db57c..1467782bc3a 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -972,6 +972,26 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, opts->x_flag_aggressive_loop_optimizations = 0; opts->x_flag_strict_overflow = 0; } + + /* Comes from final.c -- no real reason to change it. */ +#define MAX_CODE_ALIGN 16 +#define MAX_CODE_ALIGN_VALUE (1 << MAX_CODE_ALIGN) + + if (opts->x_align_loops > MAX_CODE_ALIGN_VALUE) + error_at (loc, "-falign-loops=%d is not between 0 and %d", + opts->x_align_loops, MAX_CODE_ALIGN_VALUE); + + if (opts->x_align_jumps > MAX_CODE_ALIGN_VALUE) + error_at (loc, "-falign-jumps=%d is not between 0 and %d", + opts->x_align_jumps, MAX_CODE_ALIGN_VALUE); + + if (opts->x_align_functions > MAX_CODE_ALIGN_VALUE) + error_at (loc, "-falign-functions=%d is not between 0 and %d", + opts->x_align_functions, MAX_CODE_ALIGN_VALUE); + + if (opts->x_align_labels > MAX_CODE_ALIGN_VALUE) + error_at (loc, "-falign-labels=%d is not between 0 and %d", + opts->x_align_labels, MAX_CODE_ALIGN_VALUE); } #define LEFT_COLUMN 27 diff --git a/gcc/testsuite/gcc.target/i386/pr84310-2.c b/gcc/testsuite/gcc.target/i386/pr84310-2.c new file mode 100644 index 00000000000..dbf5db6ff87 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr84310-2.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -malign-loops=16" } */ +/* { dg-warning "is obsolete" "" { target *-*-* } 0 } */ + +void +c (void) +{ + for (;;) + ; +} diff --git a/gcc/testsuite/gcc.target/i386/pr84310.c b/gcc/testsuite/gcc.target/i386/pr84310.c new file mode 100644 index 00000000000..f82327e45f3 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr84310.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -falign-functions=100000" } */ +/* { dg-error "is not between 0 and 65536" "" { target *-*-* } 0 } */ + +void +test_func (void) +{ +} -- 2.16.2