[PATCH] ld: Keep indirect symbol from IR if referenced from shared object

H.J. Lu hjl.tools@gmail.com
Mon Feb 14 15:28:55 GMT 2022


On Sun, Feb 13, 2022 at 8:13 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Sun, Feb 13, 2022 at 06:58:48PM -0800, H.J. Lu wrote:
> > On Sun, Feb 13, 2022 at 6:47 PM Alan Modra <amodra@gmail.com> wrote:
> > >
> > > On Sun, Feb 13, 2022 at 04:16:35PM -0800, H.J. Lu wrote:
> > > > On Fri, Feb 11, 2022 at 3:19 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > > >
> > > > > Don't change indirect symbol defined in IR to undefined if it is
> > > > > referenced from shared object.
> > >
> > > The description above
> > >
> > > > > diff --git a/bfd/elflink.c b/bfd/elflink.c
> > > > > index 6fa18d92007..f8521426cad 100644
> > > > > --- a/bfd/elflink.c
> > > > > +++ b/bfd/elflink.c
> > > > > @@ -1294,9 +1294,8 @@ _bfd_elf_merge_symbol (bfd *abfd,
> > > > >           h->root.non_ir_ref_dynamic = true;
> > > > >           hi->root.non_ir_ref_dynamic = true;
> > > > >         }
> > > > > -
> > > > > -      if ((oldbfd->flags & BFD_PLUGIN) != 0
> > > > > -         && hi->root.type == bfd_link_hash_indirect)
> > > > > +      else if ((oldbfd->flags & BFD_PLUGIN) != 0
> > > > > +              && hi->root.type == bfd_link_hash_indirect)
> > > > >         {
> > > > >           /* Change indirect symbol from IR to undefined.  */
> > > > >           hi->root.type = bfd_link_hash_undefined;
> > >
> > > and the patch do not exactly match.  The code logic is old sym
> > > indirect in IR, new sym not IR, both in shared library *or both not*.
> > > Is that correct?
> > >
> >
> > The existing code is
> >
> >       if (newdyn != olddyn)
> >         {
> >           /* Handle a case where plugin_notice won't be called and thus
> >              won't set the non_ir_ref flags on the first pass over
> >              symbols.  */
> >           h->root.non_ir_ref_dynamic = true;
> >           hi->root.non_ir_ref_dynamic = true;
> >         }
> >
> > If an indirect symbol defined in IR is marked with
> > non_ir_ref_dynamic, we can't change it to undefined.
> > That is why I added "else" so that we don't get the
> > error of undefined reference from shared object.
>
> The patch is OK, I wasn't thinking clearly.

I checked it into master branch and will backport it to
2.38 branch later this week.

> >       if ((oldbfd->flags & BFD_PLUGIN) != 0
> >           && hi->root.type == bfd_link_hash_indirect)
> >         {
> >           /* Change indirect symbol from IR to undefined.  */
> >           hi->root.type = bfd_link_hash_undefined;
> >           hi->root.u.undef.abfd = oldbfd;
> >         }
> >
> >
> > --
> > H.J.
>
> --
> Alan Modra
> Australia Development Lab, IBM



-- 
H.J.


More information about the Binutils mailing list