From: "Rafael Ávila de Espíndola" <respindola@mozilla.com>
To: binutils@sourceware.org
Cc: iant@google.com, ccoutant@google.com
Subject: Re: [patch] Fix some plugin API issues in BFD
Date: Sun, 20 Feb 2011 19:55:00 -0000 [thread overview]
Message-ID: <4D61718E.20003@mozilla.com> (raw)
In-Reply-To: <4D52072E.20908@mozilla.com>
[-- 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;
next prev parent reply other threads:[~2011-02-20 19:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2011-02-20 21:17 ` Rafael Ávila de Espíndola
2011-02-23 15:17 ` Dave Korn
2011-02-25 20:58 ` DJ Delorie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D61718E.20003@mozilla.com \
--to=respindola@mozilla.com \
--cc=binutils@sourceware.org \
--cc=ccoutant@google.com \
--cc=iant@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).