From: Martin Liska Date: Fri, 15 Sep 2017 12:13:04 +0000 (+0200) Subject: Backport r249735 X-Git-Tag: releases/gcc-5.5.0~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29702edd6a6778e11fe05600ee6e99c786862443;p=thirdparty%2Fgcc.git Backport r249735 2017-09-15 Martin Liska Backport from mainline 2017-06-28 Martin Liska PR ipa/81128 * ipa-visibility.c (non_local_p): Handle visibility. 2017-09-15 Martin Liska Backport from mainline 2017-06-28 Martin Liska PR ipa/81128 * c-attribs.c (handle_alias_ifunc_attribute): Append ifunc alias to a function declaration. 2017-09-15 Martin Liska Backport from mainline 2017-06-28 Martin Liska PR ipa/81128 * gcc.target/i386/pr81128.c: New test. From-SVN: r252808 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c3115fc63eb3..a77bf9d2c514 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-09-15 Martin Liska + + Backport from mainline + 2017-06-28 Martin Liska + + PR ipa/81128 + * ipa-visibility.c (non_local_p): Handle visibility. + 2017-09-12 Bill Schmidt Backport from mainline diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 1a22975acefe..8c0e796f568a 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,12 @@ +2017-09-15 Martin Liska + + Backport from mainline + 2017-06-28 Martin Liska + + PR ipa/81128 + * c-attribs.c (handle_alias_ifunc_attribute): Append ifunc alias + to a function declaration. + 2017-09-11 Jonathan Wakely PR c++/81852 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 4a63c325d05a..e3e44518a646 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -7940,9 +7940,14 @@ handle_alias_ifunc_attribute (bool is_alias, tree *node, tree name, tree args, TREE_STATIC (decl) = 1; if (!is_alias) - /* ifuncs are also aliases, so set that attribute too. */ - DECL_ATTRIBUTES (decl) - = tree_cons (get_identifier ("alias"), args, DECL_ATTRIBUTES (decl)); + { + /* ifuncs are also aliases, so set that attribute too. */ + DECL_ATTRIBUTES (decl) + = tree_cons (get_identifier ("alias"), args, + DECL_ATTRIBUTES (decl)); + DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("ifunc"), + NULL, DECL_ATTRIBUTES (decl)); + } } else { diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c index 7614cfbee4b4..35e7423c4315 100644 --- a/gcc/ipa-visibility.c +++ b/gcc/ipa-visibility.c @@ -112,7 +112,8 @@ non_local_p (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED) && !DECL_EXTERNAL (node->decl) && !node->externally_visible && !node->used_from_other_partition - && !node->in_other_partition); + && !node->in_other_partition + && node->get_availability () >= AVAIL_AVAILABLE); } /* Return true when function can be marked local. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a3c1f6665b79..466a6e2581c1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2017-09-15 Martin Liska + + Backport from mainline + 2017-06-28 Martin Liska + + PR ipa/81128 + * gcc.target/i386/pr81128.c: New test. + 2017-09-12 Bill Schmidt Backport from mainline diff --git a/gcc/testsuite/gcc.target/i386/pr81128.c b/gcc/testsuite/gcc.target/i386/pr81128.c new file mode 100644 index 000000000000..90a567ad690d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr81128.c @@ -0,0 +1,65 @@ +/* PR ipa/81128 */ +/* { dg-do run } */ +/* { dg-options "-O3" } */ +/* { dg-require-ifunc "" } */ + + +#include +#include +#include + +int resolver_fn = 0; +int resolved_fn = 0; + +static inline void +do_it_right_at_runtime_A () +{ + resolved_fn++; +} + +static inline void +do_it_right_at_runtime_B () +{ + resolved_fn++; +} + +static inline void do_it_right_at_runtime (void); + +void do_it_right_at_runtime (void) + __attribute__ ((ifunc ("resolve_do_it_right_at_runtime"))); + +static void (*resolve_do_it_right_at_runtime (void)) (void) +{ + srand (time (NULL)); + int r = rand (); + resolver_fn++; + + /* Use intermediate variable to get a warning for non-matching + * prototype. */ + typeof(do_it_right_at_runtime) *func; + if (r & 1) + func = do_it_right_at_runtime_A; + else + func = do_it_right_at_runtime_B; + + return (void *) func; +} + +int +main (void) +{ + const unsigned int ITERS = 10; + + for (int i = ITERS; i > 0; i--) + { + do_it_right_at_runtime (); + } + + if (resolver_fn != 1) + __builtin_abort (); + + if (resolved_fn != 10) + __builtin_abort (); + + return 0; +}