PATCH: PR binutils/12004: "ar --plugin" doesn't work with more than 9 files

Rafael Espindola espindola@google.com
Wed Sep 15 16:10:00 GMT 2010


I think this is OK, but don't think I am qualified to actually approve
it. I probably never noticed this because ar is normally passed .o
files and the LLVM plugin uses the filename instead of fd when
handling them.

Thanks,
Rafael

On 15 September 2010 11:32, H.J. Lu <hongjiu.lu@intel.com> wrote:
> cache.c has
>
> #define BFD_CACHE_MAX_OPEN 10
> ...
>
> bfd_boolean
> bfd_cache_init (bfd *abfd)
> {
>  BFD_ASSERT (abfd->iostream != NULL);
>  if (open_files >= BFD_CACHE_MAX_OPEN)
>    {
>      if (! close_one ())
>        return FALSE;
>    }
>  abfd->iovec = &cache_iovec;
>  insert (abfd);
>  ++open_files;
>  return TRUE;
> }
>
> When you use AR with more than 9 files, one of them will be closed. But
> plugin isn't prepared to deal with it.  This patch calls bfd_open_file
> if iostream is NULL.  OK to install?
>
> Thanks.
>
>
> H.J.
> ---
> 2010-09-15  H.J. Lu  <hongjiu.lu@intel.com>
>
>        PR binutils/12004
>        * plugin.c (bfd_plugin_object_p): Handle NULL iostream.
>
> diff --git a/bfd/plugin.c b/bfd/plugin.c
> index 4c24a7f..a46bf90 100644
> --- a/bfd/plugin.c
> +++ b/bfd/plugin.c
> @@ -233,26 +233,31 @@ bfd_plugin_object_p (bfd *abfd)
>   int claimed = 0;
>   int t = load_plugin ();
>   struct ld_plugin_input_file file;
> +  bfd *iobfd;
> +
>   if (!t)
>     return NULL;
>
>   file.name = abfd->filename;
>
> -  if (abfd->iostream)
> +  if (abfd->my_archive)
>     {
> -      file.fd = fileno ((FILE *) abfd->iostream);
> -      file.offset = 0;
> -      file.filesize = 0; /*FIXME*/
> +      iobfd = abfd->my_archive;
> +      file.offset = abfd->origin;
> +      file.filesize = arelt_size (abfd);
>     }
>   else
>     {
> -      bfd *archive = abfd->my_archive;
> -      BFD_ASSERT (archive);
> -      file.fd = fileno ((FILE *) archive->iostream);
> -      file.offset = abfd->origin;
> -      file.filesize = arelt_size (abfd);
> -
> +      iobfd = abfd;
> +      file.offset = 0;
> +      file.filesize = 0; /*FIXME*/
>     }
> +
> +  if (!iobfd->iostream && !bfd_open_file (iobfd))
> +    return NULL;
> +
> +  file.fd = fileno ((FILE *) iobfd->iostream);
> +
>   file.handle = abfd;
>   claim_file (&file, &claimed);
>   if (!claimed)
>



-- 
Rafael Ávila de Espíndola



More information about the Binutils mailing list