https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91287
--- Comment #29 from Xiong Hu XS Luo <luoxhu at cn dot ibm.com> ---
(In reply to Xiong Hu XS Luo from comment #28)
> (In reply to Richard Biener from comment #24)
> > Btw, this is controlled by symtab_node::output_to_lto_symbol_table_p which
> > has
> >
> > /* 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;
> >
> > we could try to do sth like
> >
> > if (TREE_CODE (decl) == FUNCTION_DECL
> > && (fndecl_built_in_p (decl, BUILT_IN_MD)
> > || (fndecl_built_in_p (decl, BUILT_IN_NORMAL)
> > && !associated_internal_fn (decl))))
> > return false;
> >
> > but that would still leave us with too many undefineds I guess
> > (gcc_unreachable for one).
> >
> > We do not currently track builtins that do have a library implementation
> > (whether that it is used in the end is another thing, but less important).
> >
> > What we definitely can do is put a whitelist above like via the following
> > which also catches the case of definitions of builtins.
> >
> > Index: gcc/symtab.c
> > ===================================================================
> > --- gcc/symtab.c (revision 273968)
> > +++ gcc/symtab.c (working copy)
> > @@ -2375,10 +2375,24 @@ symtab_node::output_to_lto_symbol_table_
> > 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 (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_ATAN2):
> > + CASE_FLT_FN (BUILT_IN_SIN):
> > + 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
>
> Hi Richard, no undefineds generated with below code, what's your opinion
> about the updated code, please? Thanks.
I mean "too many undefineds" here. with below modification, symbols will be
output to object file, then linker could link static library as expected.
>
> 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..ce74589b291 100644
> --- a/gcc/symtab.c
> +++ b/gcc/symtab.c
> @@ -2377,7 +2377,10 @@ 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))
> + if (TREE_CODE (decl) == FUNCTION_DECL
> + && (fndecl_built_in_p (decl, BUILT_IN_MD)
> + || (fndecl_built_in_p (decl, BUILT_IN_NORMAL)
> + && IFN_LAST == associated_internal_fn (decl))))
> return false;
>
> /* We have real symbol that should be in symbol table. However try to
> trim