+int
+bfd_plugin_open_input (bfd *ibfd, struct ld_plugin_input_file *file)
+{
+ bfd *iobfd;
+
+ iobfd = ibfd;
+ if (ibfd->my_archive && !bfd_is_thin_archive (ibfd->my_archive))
+ iobfd = ibfd->my_archive;
+ file->name = iobfd->filename;
+
+ if (!iobfd->iostream && !bfd_open_file (iobfd))
+ return 0;
+
+ file->fd = fileno ((FILE *) iobfd->iostream);
+
+ if (iobfd == ibfd)
+ {
+ struct stat stat_buf;
+ if (fstat (file->fd, &stat_buf))
+ return 0;
+ file->offset = 0;
+ file->filesize = stat_buf.st_size;
+ }
+ else
+ {
+ file->offset = ibfd->origin;
+ file->filesize = arelt_size (ibfd);
+ }
+ return 1;
+}
+
+static int
+try_claim (bfd *abfd)
+{
+ int claimed = 0;
+ struct ld_plugin_input_file file;
+
+ if (!bfd_plugin_open_input (abfd, &file))
+ return 0;
+ file.handle = abfd;
+ off_t cur_offset = lseek (file.fd, 0, SEEK_CUR);
+ claim_file (&file, &claimed);
+ lseek (file.fd, cur_offset, SEEK_SET);
+ return claimed;
+}
+