This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[patch] Fix some plugin API issues in BFD
- From: Rafael Ávila de Espíndola <respindola at mozilla dot com>
- To: binutils at sourceware dot org
- Cc: iant at google dot com
- Date: Tue, 08 Feb 2011 22:17:02 -0500
- Subject: [patch] Fix some plugin API issues in BFD
I recently updated a plugin to use the file descriptor directly. This
worked fine in gold, but had two issues using bfd (nm and ar):
*) The filesize was not being set.
*) The code expected the claim_file callback to not seek.
That is not my understanding from reading the api documentation in
http://gcc.gnu.org/wiki/whopr/driver, so the attached patch fixes both
issues.
2010-02-08 Rafael Ávila de Espíndola <respindola@mozilla.com>
* plugin.c (bfd_plugin_object_p): Correctly set the filesize
and handle claim_file seeking.
Cheers,
Rafael
diff --git a/bfd/plugin.c b/bfd/plugin.c
index 30a4923..319ef50 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -251,7 +251,7 @@ bfd_plugin_object_p (bfd *abfd)
{
iobfd = abfd;
file.offset = 0;
- file.filesize = 0; /*FIXME*/
+ file.filesize = 0;
}
if (!iobfd->iostream && !bfd_open_file (iobfd))
@@ -259,8 +259,18 @@ bfd_plugin_object_p (bfd *abfd)
file.fd = fileno ((FILE *) iobfd->iostream);
+ if (!abfd->my_archive)
+ {
+ struct stat stat_buf;
+ if (fstat (file.fd, &stat_buf))
+ return NULL;
+ file.filesize = stat_buf.st_size;
+ }
+
file.handle = abfd;
+ off_t cur_offset = lseek(file.fd, 0, SEEK_CUR);
claim_file (&file, &claimed);
+ lseek(file.fd, cur_offset, SEEK_SET);
if (!claimed)
return NULL;