[PATCH] objcopy: Correctly check archive element for LTO IR

H.J. Lu hjl.tools@gmail.com
Sat Jun 14 21:29:20 GMT 2025


On Sat, Jun 14, 2025 at 4:24 PM Sam James <sam@gentoo.org> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
> > On Fri, Jun 13, 2025 at 1:18 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>
> >> Pass archive element, instead of archive, to bfd_plugin_target_p to check
> >> for LTO IR in archive element.
> >>
> >> PR binutils/33078
> >> * objcopy.c (copy_archive): Correctly check archive element for
> >> LTO IR.
> >> * testsuite/binutils-all/objcopy.exp (strip_test_archive): New.
> >> Run strip_test_archive.
> >>
> >>
> >> --
> >> H.J.
> >
> > 717a38e9a02 strip: Add GCC LTO IR support
> >
> > added:
> >
> > @@ -3744,6 +3768,12 @@ copy_archive (bfd *ibfd, bfd *obfd, const char
> > *output_target,
> >      goto cleanup_and_exit;
> >    }
> >
> > +#if BFD_SUPPORTS_PLUGINS
> > +      /* Copy LTO IR file as unknown object.  */
> > +      if (bfd_plugin_target_p (ibfd->xvec))
> >                                               ^^^^^ This is a typo.
> > +  ok_object = false;
> > +      else
> > +#endif
> >        if (ok_object)
> >    {
> >      ok = copy_object (this_element, output_element, input_arch);
> >
> > to check if the archive element is a LTO IR file.   "ibfd" is the archive BFD.
> > "this_element" should be used for the archive element.   This simple change:
> >
> > diff --git a/binutils/objcopy.c b/binutils/objcopy.c
> > index a973789b1d5..366e1079d82 100644
> > --- a/binutils/objcopy.c
> > +++ b/binutils/objcopy.c
> > @@ -3770,7 +3770,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_tar
> > get,
> >
> >  #if BFD_SUPPORTS_PLUGINS
> >        /* Copy LTO IR file as unknown object.  */
> > -      if (bfd_plugin_target_p (ibfd->xvec))
> > +      if (bfd_plugin_target_p (this_element->xvec))
> >    ok_object = false;
> >        else
> >  #endif
> >
> > corrects the typo.
>
> Maybe it's even obvious. Surrounding code uses this_element too.

I am checking it in as an obvious fix.

> Anyway, it works for me. Thank you again H.J.



-- 
H.J.


More information about the Binutils mailing list