This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/8] PR ld/17878: Add bfd_maybe_object_p


On Sat, Feb 07, 2015 at 11:10:22AM -0800, H.J. Lu wrote:
> On Sat, Feb 07, 2015 at 04:50:27AM -0800, H.J. Lu wrote:
> > > I think you need to find a way of answering the question "is this a
> > > file accepted by a plugin?" in a more robust way.  One possibility is
> > > merging the linker handling of plugins into the bfd plugin support.
> > >
> > 
> > I have considered it before.  This approach has many implications.
> > If we do this, we need to add bfd_plugin_object and bfd_all_object.
> > bfd_all_object includes bfd_object and bfd_plugin_object.  We need
> > bfd_plugin_object so that we won't update dummy BFD info from the
> > LTO IR input.  Let me take another look.
> > 
> 
> We can extract a plugin_object_p out of plugin_maybe_claim for BFD.
> Here is the first patch.  I am checking it in.
> 
> H.J.

Here is a patch to add plugin_object_p.


H.J.
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index df34f03..6765d41 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -6428,6 +6428,13 @@ struct bfd
   /* Set if this is the linker output BFD.  */
   unsigned int is_linker_output : 1;
 
+  /* Set if this is claimed by a compiler plug-in library.  */
+  unsigned int claimed : 1;
+
+  /* Set to dummy BFD created when claimed by a compiler plug-in
+     library.  */
+  bfd *cbfd;
+
   /* Currently my_archive is tested before adding origin to
      anything. I believe that this can become always an add of
      origin, with origin set to 0 for non archive files.  */
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 29a7c5d..f579ab7 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -200,6 +200,13 @@ CODE_FRAGMENT
 .  {* Set if this is the linker output BFD.  *}
 .  unsigned int is_linker_output : 1;
 .
+.  {* Set if this is claimed by a compiler plug-in library.  *}
+.  unsigned int claimed : 1;
+.
+.  {* Set to dummy BFD created when claimed by a compiler plug-in
+.     library.  *}
+.  bfd *cbfd;
+.
 .  {* Currently my_archive is tested before adding origin to
 .     anything. I believe that this can become always an add of
 .     origin, with origin set to 0 for non archive files.  *}
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 5c4581f..a7b1273 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5869,7 +5869,7 @@ lang_check (void)
     {
 #ifdef ENABLE_PLUGINS
       /* Don't check format of files claimed by plugin.  */
-      if (file->input_statement.flags.claimed)
+      if (file->input_statement.the_bfd->claimed)
 	continue;
 #endif /* ENABLE_PLUGINS */
       input_bfd = file->input_statement.the_bfd;
@@ -6387,7 +6387,7 @@ lang_gc_sections (void)
 	{
 	  asection *sec;
 #ifdef ENABLE_PLUGINS
-	  if (f->flags.claimed)
+	  if (f->the_bfd->claimed)
 	    continue;
 #endif
 	  for (sec = f->the_bfd->sections; sec != NULL; sec = sec->next)
@@ -6553,7 +6553,7 @@ find_replacements_insert_point (void)
        claim1 != NULL;
        claim1 = &claim1->next->input_statement)
     {
-      if (claim1->flags.claimed)
+      if (claim1->the_bfd->claimed)
 	return claim1->flags.claim_archive ? lastobject : claim1;
       /* Update lastobject if this is a real object file.  */
       if (claim1->the_bfd && (claim1->the_bfd->my_archive == NULL))
diff --git a/ld/ldlang.h b/ld/ldlang.h
index 69d21a7..bb41f9c 100644
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -278,9 +278,6 @@ struct lang_input_statement_flags
   unsigned int reload : 1;
 
 #ifdef ENABLE_PLUGINS
-  /* Set if the file was claimed by a plugin.  */
-  unsigned int claimed : 1;
-
   /* Set if the file was claimed from an archive.  */
   unsigned int claim_archive : 1;
 #endif /* ENABLE_PLUGINS */
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 4b41288..7a6080f 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -793,7 +793,7 @@ add_archive_element (struct bfd_link_info *info,
     {
       /* We must offer this archive member to the plugins to claim.  */
       plugin_maybe_claim (input);
-      if (input->flags.claimed)
+      if (input->the_bfd->claimed)
 	{
 	  input->flags.claim_archive = TRUE;
 	  *subsbfd = input->the_bfd;
diff --git a/ld/plugin.c b/ld/plugin.c
index de91fa9..7d3ada9 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -1003,22 +1003,24 @@ plugin_strdup (bfd *abfd, const char *str)
   return copy;
 }
 
-void
-plugin_maybe_claim (lang_input_statement_type *entry)
+static const bfd_target *
+plugin_object_p (bfd *ibfd)
 {
   int claimed = 0;
   plugin_input_file_t *input;
   off_t offset, filesize;
   struct ld_plugin_input_file file;
   bfd *abfd;
-  bfd *ibfd = entry->the_bfd;
   bfd_boolean inarchive = bfd_my_archive (ibfd) != NULL;
   const char *name
     = inarchive ? bfd_my_archive (ibfd)->filename : ibfd->filename;
   int fd = open (name, O_RDONLY | O_BINARY);
 
+  if (ibfd->cbfd)
+    return ibfd->cbfd->xvec;
+
   if (fd < 0)
-    return;
+    return NULL;
 
   /* We create a dummy BFD, initially empty, to house whatever symbols
      the plugin may want to add.  */
@@ -1067,7 +1069,7 @@ plugin_maybe_claim (lang_input_statement_type *entry)
     einfo (_("%P%F: %s: plugin reported error claiming file\n"),
 	   plugin_error_plugin ());
 
-  if (input->fd != -1 && bfd_check_format (entry->the_bfd, bfd_object))
+  if (input->fd != -1 && bfd_check_format (ibfd, bfd_object))
     {
       /* FIXME: fd belongs to us, not the plugin.  IR for GCC plugin,
 	 which doesn't need fd after plugin_call_claim_file, is
@@ -1083,22 +1085,33 @@ plugin_maybe_claim (lang_input_statement_type *entry)
 
   if (claimed)
     {
-      /* Discard the real file's BFD and substitute the dummy one.  */
-
-      /* BFD archive handling caches elements so we can't call
-	 bfd_close for archives.  */
-      if (!inarchive)
-	bfd_close (ibfd);
+      ibfd->cbfd = abfd;
       bfd_make_readable (abfd);
-      entry->the_bfd = abfd;
-      entry->flags.claimed = TRUE;
+      abfd->claimed = 1;
+      return abfd->xvec;
     }
   else
     {
       /* If plugin didn't claim the file, we don't need the dummy bfd.
 	 Can't avoid speculatively creating it, alas.  */
       bfd_close_all_done (abfd);
-      entry->flags.claimed = FALSE;
+      return NULL;
+    }
+}
+
+void
+plugin_maybe_claim (lang_input_statement_type *entry)
+{
+  if (plugin_object_p (entry->the_bfd))
+    {
+      /* Discard the real file's BFD andsSubstitute the dummy one.  */
+      bfd *abfd = entry->the_bfd->cbfd;
+
+      /* BFD archive handling caches elements so we can't call
+	 bfd_close for archives.  */
+      if (entry->the_bfd->my_archive == NULL)
+	bfd_close (entry->the_bfd);
+      entry->the_bfd = abfd;
     }
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]