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

Sam James sam@gentoo.org
Sat Jun 14 08:24:23 GMT 2025


"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.

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


More information about the Binutils mailing list