From 40ebe1fc2f136a454b0d5efa119bb516ad767c91 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Thu, 19 Dec 2019 11:03:48 +0100 Subject: [PATCH] Fix symver attribute with LTO * cgraph.c (cgraph_node_cannot_be_local_p_1): Prevent targets of symver attributes to be localized. * ipa-visibility.c (cgraph_externally_visible_p, varpool_node::externally_visible_p): Likewise. * symtab.c (symtab_node::verify_base): Check visibility of symbol versions. * lto-common.c (read_cgraph_and_symbols): Work around binutils PR25424 Co-Authored-By: Xi Ruoyao From-SVN: r279566 --- gcc/ChangeLog | 10 ++++++++++ gcc/cgraph.c | 3 +++ gcc/ipa-visibility.c | 21 ++++++++++++++------- gcc/lto/ChangeLog | 6 ++++++ gcc/lto/lto-common.c | 5 +++++ gcc/symtab.c | 16 ++++++++++++++++ 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3b703386ddd..5d938ae09d3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2019-12-19 Jan Hubicka + Xi Ruoyao + + * cgraph.c (cgraph_node_cannot_be_local_p_1): Prevent targets of + symver attributes to be localized. + * ipa-visibility.c (cgraph_externally_visible_p, + varpool_node::externally_visible_p): Likewise. + * symtab.c (symtab_node::verify_base): Check visibility of symbol + versions. + 2019-12-19 Jan Hubicka Luo Xiong Hu force_output && !node->ifunc_resolver + /* Limitation of gas requires us to output targets of symver aliases + as global symbols. This is binutils PR 25295. */ + && !node->symver && ((DECL_COMDAT (node->decl) && !node->forced_by_abi && !node->used_from_object_file_p () diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c index f470465f935..d216a54a7ab 100644 --- a/gcc/ipa-visibility.c +++ b/gcc/ipa-visibility.c @@ -220,6 +220,14 @@ cgraph_externally_visible_p (struct cgraph_node *node, && lookup_attribute ("dllexport", DECL_ATTRIBUTES (node->decl))) return true; + + /* Limitation of gas requires us to output targets of symver aliases as + global symbols. This is binutils PR 25295. */ + ipa_ref *ref; + FOR_EACH_ALIAS (node, ref) + if (ref->referring->symver) + return true; + if (node->resolution == LDPR_PREVAILING_DEF_IRONLY) return false; /* When doing LTO or whole program, we can bring COMDAT functoins static. @@ -284,14 +292,13 @@ varpool_node::externally_visible_p (void) DECL_ATTRIBUTES (decl))) return true; - /* See if we have linker information about symbol not being used or - if we need to make guess based on the declaration. + /* Limitation of gas requires us to output targets of symver aliases as + global symbols. This is binutils PR 25295. */ + ipa_ref *ref; + FOR_EACH_ALIAS (this, ref) + if (ref->referring->symver) + return true; - Even if the linker clams the symbol is unused, never bring internal - symbols that are declared by user as used or externally visible. - This is needed for i.e. references from asm statements. */ - if (used_from_object_file_p ()) - return true; if (resolution == LDPR_PREVAILING_DEF_IRONLY) return false; diff --git a/gcc/lto/ChangeLog b/gcc/lto/ChangeLog index 9f974afb123..d0b1dba740e 100644 --- a/gcc/lto/ChangeLog +++ b/gcc/lto/ChangeLog @@ -1,3 +1,9 @@ +2019-12-19 Jan Hubicka + Xi Ruoyao + + * lto-common.c (read_cgraph_and_symbols): Work around binutils + PR25424 + 2019-12-07 Jan Hubicka * lto-partition.c (lto_balanced_map): Fix printing of tp_first_run. diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c index 76a9d9383d5..ee07730a27d 100644 --- a/gcc/lto/lto-common.c +++ b/gcc/lto/lto-common.c @@ -2818,6 +2818,11 @@ read_cgraph_and_symbols (unsigned nfiles, const char **fnames) IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (snode->decl))); } + /* Symbol versions are always used externally, but linker does not + report that correctly. + This is binutils PR25924. */ + else if (snode->symver && *res == LDPR_PREVAILING_DEF_IRONLY) + snode->resolution = LDPR_PREVAILING_DEF_IRONLY_EXP; else snode->resolution = *res; } diff --git a/gcc/symtab.c b/gcc/symtab.c index 10b8ed1d178..9c52192fced 100644 --- a/gcc/symtab.c +++ b/gcc/symtab.c @@ -1156,6 +1156,22 @@ symtab_node::verify_base (void) error ("node is symver but not alias"); error_found = true; } + /* Limitation of gas requires us to output targets of symver aliases as + global symbols. This is binutils PR 25295. */ + if (symver + && (!TREE_PUBLIC (get_alias_target ()->decl) + || DECL_VISIBILITY (get_alias_target ()->decl) != VISIBILITY_DEFAULT)) + { + error ("symver target is not exported with default visibility"); + error_found = true; + } + if (symver + && (!TREE_PUBLIC (decl) + || DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT)) + { + error ("symver is not exported with default visibility"); + error_found = true; + } if (same_comdat_group) { symtab_node *n = same_comdat_group; -- 2.30.2