LTO: Restore the wrapper symbol check before reference

Message ID 20240802112505.190542-1-hjl.tools@gmail.com
State Superseded
Headers
Series LTO: Restore the wrapper symbol check before reference |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

H.J. Lu Aug. 2, 2024, 11:25 a.m. UTC
  Call unwrap_hash_lookup to check for the wrapper symbol before the wrapped
reference.  The testcase is hard to create since for simple tests, GCC 14
always outputs the wrapped reference first.

	PR ld/31956
	* plugin.c (get_symbols): Restore the wrapper symbol check before
	the wrapped reference.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 ld/plugin.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
  

Comments

H.J. Lu Aug. 2, 2024, 11:30 a.m. UTC | #1
On Fri, Aug 2, 2024 at 4:25 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Call unwrap_hash_lookup to check for the wrapper symbol before the wrapped
> reference.  The testcase is hard to create since for simple tests, GCC 14
> always outputs the wrapped reference first.
>
>         PR ld/31956
>         * plugin.c (get_symbols): Restore the wrapper symbol check before
>         the wrapped reference.
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  ld/plugin.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/ld/plugin.c b/ld/plugin.c
> index 03ee9880d10..51c4765cc5b 100644
> --- a/ld/plugin.c
> +++ b/ld/plugin.c
> @@ -778,8 +778,18 @@ get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms,
>         {
>           blhe = h;
>           /* Check if a symbol is a wrapper symbol.  */
> -         if (blhe && blhe->wrapper_symbol)
> -           wrap_status = wrapper;
> +         if (blhe)
> +           {
> +             if (blhe->wrapper_symbol)
> +               wrap_status = wrapper;
> +             else if (link_info.wrap_hash != NULL)
> +               {
> +                 struct bfd_link_hash_entry *unwrap
> +                   = unwrap_hash_lookup (&link_info, (bfd *) abfd, blhe);
> +                 if (unwrap != NULL && unwrap != h)
> +                   wrap_status = wrapper;

This patch works for pcp,  but may not be the best.

> +               }
> +           }
>         }
>        else
>         {
> --
> 2.45.2
>
  
H.J. Lu Aug. 2, 2024, 11:41 a.m. UTC | #2
On Fri, Aug 2, 2024 at 4:30 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Aug 2, 2024 at 4:25 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > Call unwrap_hash_lookup to check for the wrapper symbol before the wrapped
> > reference.  The testcase is hard to create since for simple tests, GCC 14
> > always outputs the wrapped reference first.
> >
> >         PR ld/31956
> >         * plugin.c (get_symbols): Restore the wrapper symbol check before
> >         the wrapped reference.
> >
> > Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> > ---
> >  ld/plugin.c | 14 ++++++++++++--
> >  1 file changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/ld/plugin.c b/ld/plugin.c
> > index 03ee9880d10..51c4765cc5b 100644
> > --- a/ld/plugin.c
> > +++ b/ld/plugin.c
> > @@ -778,8 +778,18 @@ get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms,
> >         {
> >           blhe = h;
> >           /* Check if a symbol is a wrapper symbol.  */
> > -         if (blhe && blhe->wrapper_symbol)
> > -           wrap_status = wrapper;
> > +         if (blhe)
> > +           {
> > +             if (blhe->wrapper_symbol)
> > +               wrap_status = wrapper;
> > +             else if (link_info.wrap_hash != NULL)
> > +               {
> > +                 struct bfd_link_hash_entry *unwrap
> > +                   = unwrap_hash_lookup (&link_info, (bfd *) abfd, blhe);
> > +                 if (unwrap != NULL && unwrap != h)
> > +                   wrap_status = wrapper;
>
> This patch works for pcp,  but may not be the best.

I sent v2 with the updated commit log.   I will add a testcase later.

>
> > +               }
> > +           }
> >         }
> >        else
> >         {
> > --
> > 2.45.2
> >
>
>
> --
> H.J.
  
H.J. Lu Aug. 2, 2024, 5:20 p.m. UTC | #3
On Fri, Aug 2, 2024 at 4:41 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Aug 2, 2024 at 4:30 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Fri, Aug 2, 2024 at 4:25 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > Call unwrap_hash_lookup to check for the wrapper symbol before the wrapped
> > > reference.  The testcase is hard to create since for simple tests, GCC 14
> > > always outputs the wrapped reference first.
> > >
> > >         PR ld/31956
> > >         * plugin.c (get_symbols): Restore the wrapper symbol check before
> > >         the wrapped reference.
> > >
> > > Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> > > ---
> > >  ld/plugin.c | 14 ++++++++++++--
> > >  1 file changed, 12 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/ld/plugin.c b/ld/plugin.c
> > > index 03ee9880d10..51c4765cc5b 100644
> > > --- a/ld/plugin.c
> > > +++ b/ld/plugin.c
> > > @@ -778,8 +778,18 @@ get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms,
> > >         {
> > >           blhe = h;
> > >           /* Check if a symbol is a wrapper symbol.  */
> > > -         if (blhe && blhe->wrapper_symbol)
> > > -           wrap_status = wrapper;
> > > +         if (blhe)
> > > +           {
> > > +             if (blhe->wrapper_symbol)
> > > +               wrap_status = wrapper;
> > > +             else if (link_info.wrap_hash != NULL)
> > > +               {
> > > +                 struct bfd_link_hash_entry *unwrap
> > > +                   = unwrap_hash_lookup (&link_info, (bfd *) abfd, blhe);
> > > +                 if (unwrap != NULL && unwrap != h)
> > > +                   wrap_status = wrapper;
> >
> > This patch works for pcp,  but may not be the best.
>
> I sent v2 with the updated commit log.   I will add a testcase later.
>

I sent v3 with a testcase.
  

Patch

diff --git a/ld/plugin.c b/ld/plugin.c
index 03ee9880d10..51c4765cc5b 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -778,8 +778,18 @@  get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms,
 	{
 	  blhe = h;
 	  /* Check if a symbol is a wrapper symbol.  */
-	  if (blhe && blhe->wrapper_symbol)
-	    wrap_status = wrapper;
+	  if (blhe)
+	    {
+	      if (blhe->wrapper_symbol)
+		wrap_status = wrapper;
+	      else if (link_info.wrap_hash != NULL)
+		{
+		  struct bfd_link_hash_entry *unwrap
+		    = unwrap_hash_lookup (&link_info, (bfd *) abfd, blhe);
+		  if (unwrap != NULL && unwrap != h)
+		    wrap_status = wrapper;
+		}
+	    }
 	}
       else
 	{