public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch] Fix some plugin API issues in BFD
@ 2011-02-09  3:17 Rafael Ávila de Espíndola
  2011-02-11 20:18 ` Rafael Avila de Espindola
  2011-02-20 19:55 ` Rafael Ávila de Espíndola
  0 siblings, 2 replies; 6+ messages in thread
From: Rafael Ávila de Espíndola @ 2011-02-09  3:17 UTC (permalink / raw)
  To: binutils; +Cc: iant

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

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

[-- Attachment #2: bfd.patch --]
[-- Type: text/x-patch, Size: 799 bytes --]

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;
 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] Fix some plugin API issues in BFD
  2011-02-09  3:17 [patch] Fix some plugin API issues in BFD Rafael Ávila de Espíndola
@ 2011-02-11 20:18 ` Rafael Avila de Espindola
  2011-02-20 19:55 ` Rafael Ávila de Espíndola
  1 sibling, 0 replies; 6+ messages in thread
From: Rafael Avila de Espindola @ 2011-02-11 20:18 UTC (permalink / raw)
  To: binutils; +Cc: iant, dave.korn.cygwin, ccoutant

ccing Dave and Cary.

On 11-02-08 10:17 PM, Rafael Ávila de Espíndola wrote:
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] Fix some plugin API issues in BFD
  2011-02-09  3:17 [patch] Fix some plugin API issues in BFD Rafael Ávila de Espíndola
  2011-02-11 20:18 ` Rafael Avila de Espindola
@ 2011-02-20 19:55 ` Rafael Ávila de Espíndola
  2011-02-20 21:17   ` Rafael Ávila de Espíndola
  1 sibling, 1 reply; 6+ messages in thread
From: Rafael Ávila de Espíndola @ 2011-02-20 19:55 UTC (permalink / raw)
  To: binutils; +Cc: iant, ccoutant

[-- Attachment #1: Type: text/plain, Size: 744 bytes --]

An updated patch is attached that also avoids calling onload multiple times.

2010-02-20  Rafael Ávila de Espíndola <respindola@mozilla.com>

        * plugin.c (bfd_plugin_object_p): Correctly set the filesize
	and handle claim_file seeking. Only try to load the plugin once.

On 2011-02-08 22:17, Rafael Ávila de Espíndola wrote:
> 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.

Cheers,
Rafael

[-- Attachment #2: bfd.patch --]
[-- Type: text/x-patch, Size: 1371 bytes --]

diff --git a/bfd/plugin.c b/bfd/plugin.c
index 30a4923..224d0e2 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -232,16 +232,21 @@ static const bfd_target *
 bfd_plugin_object_p (bfd *abfd)
 {
   int claimed = 0;
-  int t = load_plugin ();
   struct ld_plugin_input_file file;
   bfd *iobfd;
-
-  if (!t)
+  static int have_loaded = 0;
+  static int have_plugin = 0;
+  if (!have_loaded)
+    {
+      have_loaded = 1;
+      have_plugin = load_plugin ();
+    }
+  if (!have_plugin)
     return NULL;
 
   file.name = abfd->filename;
 
-  if (abfd->my_archive)
+  if (abfd->format == bfd_archive)
     {
       iobfd = abfd->my_archive;
       file.offset = abfd->origin;
@@ -251,7 +256,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 +264,18 @@ bfd_plugin_object_p (bfd *abfd)
 
   file.fd = fileno ((FILE *) iobfd->iostream);
 
+  if (abfd->format == bfd_object)
+    {
+      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;
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] Fix some plugin API issues in BFD
  2011-02-20 19:55 ` Rafael Ávila de Espíndola
@ 2011-02-20 21:17   ` Rafael Ávila de Espíndola
  2011-02-23 15:17     ` Dave Korn
  2011-02-25 20:58     ` DJ Delorie
  0 siblings, 2 replies; 6+ messages in thread
From: Rafael Ávila de Espíndola @ 2011-02-20 21:17 UTC (permalink / raw)
  To: binutils; +Cc: iant, ccoutant

[-- Attachment #1: Type: text/plain, Size: 192 bytes --]

On 2011-02-20 14:54, Rafael Ávila de Espíndola wrote:
> An updated patch is attached that also avoids calling onload multiple times.

Sorry, the correct one is now attached.

Cheers,
Rafael

[-- Attachment #2: bfd.patch --]
[-- Type: text/x-patch, Size: 1224 bytes --]

diff --git a/bfd/plugin.c b/bfd/plugin.c
index 30a4923..bba9548 100644
--- a/bfd/plugin.c
+++ b/bfd/plugin.c
@@ -232,11 +232,16 @@ static const bfd_target *
 bfd_plugin_object_p (bfd *abfd)
 {
   int claimed = 0;
-  int t = load_plugin ();
   struct ld_plugin_input_file file;
   bfd *iobfd;
-
-  if (!t)
+  static int have_loaded = 0;
+  static int have_plugin = 0;
+  if (!have_loaded)
+    {
+      have_loaded = 1;
+      have_plugin = load_plugin ();
+    }
+  if (!have_plugin)
     return NULL;
 
   file.name = abfd->filename;
@@ -251,7 +256,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 +264,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;
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] Fix some plugin API issues in BFD
  2011-02-20 21:17   ` Rafael Ávila de Espíndola
@ 2011-02-23 15:17     ` Dave Korn
  2011-02-25 20:58     ` DJ Delorie
  1 sibling, 0 replies; 6+ messages in thread
From: Dave Korn @ 2011-02-23 15:17 UTC (permalink / raw)
  To: Rafael Ávila de Espíndola; +Cc: binutils, iant, ccoutant

On 20/02/2011 21:17, Rafael Ávila de Espíndola wrote:
> On 2011-02-20 14:54, Rafael Ávila de Espíndola wrote:
>> An updated patch is attached that also avoids calling onload multiple times.
> 
> Sorry, the correct one is now attached.


  Sorry for not answering earlier.  I don't have formal approval rights over
this area, so we still need a maintainer, but I can review this patch based on
my experience working in the area.

  The parts about only loading the plugin once and setting the filesize in the
(!abfd->my_archive) case are clearly correct.  The bit about saving and
restoring the filepos, I had to refresh my memory on, but since we cleared up
the issues around the ownership of the fd passed to the plugin, that's the
right solution too.  So AFAIC the patch is OK.

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] Fix some plugin API issues in BFD
  2011-02-20 21:17   ` Rafael Ávila de Espíndola
  2011-02-23 15:17     ` Dave Korn
@ 2011-02-25 20:58     ` DJ Delorie
  1 sibling, 0 replies; 6+ messages in thread
From: DJ Delorie @ 2011-02-25 20:58 UTC (permalink / raw)
  To: Rafael Ávila de Espíndola; +Cc: binutils


> +  static int have_plugin = 0;
> +  if (!have_loaded)

Blank line between declarations and code, please.  Otherwise OK.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-02-25 20:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-09  3:17 [patch] Fix some plugin API issues in BFD Rafael Ávila de Espíndola
2011-02-11 20:18 ` Rafael Avila de Espindola
2011-02-20 19:55 ` Rafael Ávila de Espíndola
2011-02-20 21:17   ` Rafael Ávila de Espíndola
2011-02-23 15:17     ` Dave Korn
2011-02-25 20:58     ` DJ Delorie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).