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]

Re: [RFC] Enable math functions linking with static library for LTO


On Fri, Aug 9, 2019 at 10:13 AM Xiong Hu Luo <luoxhu@linux.vnet.ibm.com> wrote:
>
> In LTO mode, if static library and dynamic library contains same
> function and both libraries are passed as arguments, linker will link
> the function in dynamic library no matter the sequence.  This patch
> will output LTO symbol node as UNDEF if BUILT_IN_NORMAL function FNDECL
> is a math function, then the function in static library will be linked
> first if its sequence is ahead of the dynamic library.

Please factor the switch () to a new function in builtins.[ch] called
builtin_with_linkage_p () and use that in both places.  Please document
there that builtins with implementations in libgcc cannot be handled this
way.

Thanks,
Richard.

> gcc/ChangeLog
>
>         2019-08-09  Xiong Hu Luo  <luoxhu@linux.ibm.com>
>
>         PR lto/91287
>         * symtab.c (write_symbol): Check built_in function type.
>         * lto-streamer-out.c (symtab_node::output_to_lto_symbol_table_p):
>         Return true if built_in function is a math BUILT_IN_NORMAL function.
> ---
>  gcc/lto-streamer-out.c |  5 ++-
>  gcc/symtab.c           | 84 +++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 86 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
> index 47a9143ae26..9d42a57b4b6 100644
> --- a/gcc/lto-streamer-out.c
> +++ b/gcc/lto-streamer-out.c
> @@ -2644,7 +2644,10 @@ write_symbol (struct streamer_tree_cache_d *cache,
>
>    gcc_checking_assert (TREE_PUBLIC (t)
>                        && (TREE_CODE (t) != FUNCTION_DECL
> -                          || !fndecl_built_in_p (t))
> +                          || !fndecl_built_in_p (t, BUILT_IN_MD))
> +                      && (TREE_CODE (t) != FUNCTION_DECL
> +                          || !fndecl_built_in_p (t, BUILT_IN_NORMAL)
> +                          || associated_internal_fn (t) != IFN_LAST)
>                        && !DECL_ABSTRACT_P (t)
>                        && (!VAR_P (t) || !DECL_HARD_REGISTER (t)));
>
> diff --git a/gcc/symtab.c b/gcc/symtab.c
> index 63e2820eb93..34bdccd7f6e 100644
> --- a/gcc/symtab.c
> +++ b/gcc/symtab.c
> @@ -2377,8 +2377,88 @@ symtab_node::output_to_lto_symbol_table_p (void)
>      return false;
>    /* FIXME: Builtins corresponding to real functions probably should have
>       symbol table entries.  */
> -  if (TREE_CODE (decl) == FUNCTION_DECL && fndecl_built_in_p (decl))
> -    return false;
> +  if (TREE_CODE (decl) == FUNCTION_DECL && !definition
> +      && fndecl_built_in_p (decl))
> +    {
> +      if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
> +       switch (DECL_FUNCTION_CODE (decl))
> +         {
> +           CASE_FLT_FN (BUILT_IN_ACOS):
> +           CASE_FLT_FN (BUILT_IN_ACOSH):
> +           CASE_FLT_FN (BUILT_IN_ASIN):
> +           CASE_FLT_FN (BUILT_IN_ASINH):
> +           CASE_FLT_FN (BUILT_IN_ATAN):
> +           CASE_FLT_FN (BUILT_IN_ATANH):
> +           CASE_FLT_FN (BUILT_IN_ATAN2):
> +           CASE_FLT_FN (BUILT_IN_CBRT):
> +           CASE_FLT_FN (BUILT_IN_CEIL):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
> +           CASE_FLT_FN (BUILT_IN_COPYSIGN):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN):
> +           CASE_FLT_FN (BUILT_IN_COS):
> +           CASE_FLT_FN (BUILT_IN_COSH):
> +           CASE_FLT_FN (BUILT_IN_ERF):
> +           CASE_FLT_FN (BUILT_IN_ERFC):
> +           CASE_FLT_FN (BUILT_IN_EXP):
> +           CASE_FLT_FN (BUILT_IN_EXP2):
> +           CASE_FLT_FN (BUILT_IN_EXPM1):
> +           CASE_FLT_FN (BUILT_IN_FABS):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
> +           CASE_FLT_FN (BUILT_IN_FDIM):
> +           CASE_FLT_FN (BUILT_IN_FLOOR):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
> +           CASE_FLT_FN (BUILT_IN_FMA):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA):
> +           CASE_FLT_FN (BUILT_IN_FMAX):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMAX):
> +           CASE_FLT_FN (BUILT_IN_FMIN):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMIN):
> +           CASE_FLT_FN (BUILT_IN_FMOD):
> +           CASE_FLT_FN (BUILT_IN_FREXP):
> +           CASE_FLT_FN (BUILT_IN_HYPOT):
> +           CASE_FLT_FN (BUILT_IN_ILOGB):
> +           CASE_FLT_FN (BUILT_IN_LDEXP):
> +           CASE_FLT_FN (BUILT_IN_LGAMMA):
> +           CASE_FLT_FN (BUILT_IN_LLRINT):
> +           CASE_FLT_FN (BUILT_IN_LLROUND):
> +           CASE_FLT_FN (BUILT_IN_LOG):
> +           CASE_FLT_FN (BUILT_IN_LOG10):
> +           CASE_FLT_FN (BUILT_IN_LOG1P):
> +           CASE_FLT_FN (BUILT_IN_LOG2):
> +           CASE_FLT_FN (BUILT_IN_LOGB):
> +           CASE_FLT_FN (BUILT_IN_LRINT):
> +           CASE_FLT_FN (BUILT_IN_LROUND):
> +           CASE_FLT_FN (BUILT_IN_MODF):
> +           CASE_FLT_FN (BUILT_IN_NAN):
> +           CASE_FLT_FN (BUILT_IN_NEARBYINT):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
> +           CASE_FLT_FN (BUILT_IN_NEXTAFTER):
> +           CASE_FLT_FN (BUILT_IN_NEXTTOWARD):
> +           CASE_FLT_FN (BUILT_IN_POW):
> +           CASE_FLT_FN (BUILT_IN_REMAINDER):
> +           CASE_FLT_FN (BUILT_IN_REMQUO):
> +           CASE_FLT_FN (BUILT_IN_RINT):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
> +           CASE_FLT_FN (BUILT_IN_ROUND):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
> +           CASE_FLT_FN (BUILT_IN_SCALBLN):
> +           CASE_FLT_FN (BUILT_IN_SCALBN):
> +           CASE_FLT_FN (BUILT_IN_SIN):
> +           CASE_FLT_FN (BUILT_IN_SINH):
> +           CASE_FLT_FN (BUILT_IN_SINCOS):
> +           CASE_FLT_FN (BUILT_IN_SQRT):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT):
> +           CASE_FLT_FN (BUILT_IN_TAN):
> +           CASE_FLT_FN (BUILT_IN_TANH):
> +           CASE_FLT_FN (BUILT_IN_TGAMMA):
> +           CASE_FLT_FN (BUILT_IN_TRUNC):
> +           CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
> +             return true;
> +         default:
> +           break;
> +         }
> +      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
> --
> 2.21.0.777.g83232e3864
>


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