daily update
[deliverable/binutils-gdb.git] / bfd / plugin.c
index 49395e8cb7cf5ec0c205bb93e45e91a8bd3e535e..dde61c883093cf43b8fda98994cdc0966c5b9dad 100644 (file)
    MA 02110-1301, USA.  */
 
 #include "config.h"
+#include "bfd.h"
+
+#if BFD_SUPPORTS_PLUGINS
+
 #include <assert.h>
 #include <dlfcn.h>
 #include <stdarg.h>
@@ -64,6 +68,7 @@
 #define bfd_plugin_bfd_discard_group                  bfd_generic_discard_group
 #define bfd_plugin_section_already_linked             _bfd_generic_section_already_linked
 #define bfd_plugin_bfd_define_common_symbol           bfd_generic_define_common_symbol
+#define bfd_plugin_bfd_copy_link_hash_symbol_type     _bfd_generic_copy_link_hash_symbol_type
 
 static enum ld_plugin_status
 message (int level ATTRIBUTE_UNUSED,
@@ -73,6 +78,7 @@ message (int level ATTRIBUTE_UNUSED,
   va_start (args, format);
   printf ("bfd plugin: ");
   vprintf (format, args);
+  putchar ('\n');
   va_end (args);
   return LDPS_OK;
 }
@@ -106,7 +112,13 @@ add_symbols (void * handle,
   return LDPS_OK;
 }
 
-extern char *program_name __attribute__ ((weak));
+static const char *plugin_program_name;
+
+void
+bfd_plugin_set_program_name (const char *program_name)
+{
+  plugin_program_name = program_name;
+}
 
 static int
 try_load_plugin (const char *pname)
@@ -180,11 +192,11 @@ load_plugin (void)
   if (plugin_name)
     return try_load_plugin (plugin_name);
 
-  if (!program_name)
+  if (plugin_program_name == NULL)
     return 0;
 
   plugin_dir = concat (BINDIR, "/../lib/bfd-plugins", NULL);
-  p = make_relative_prefix (program_name,
+  p = make_relative_prefix (plugin_program_name,
                            BINDIR,
                            plugin_dir);
   free (plugin_dir);
@@ -197,11 +209,11 @@ load_plugin (void)
   while ((ent = readdir (d)))
     {
       char *full_name;
-      if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
-       continue;
+      struct stat s;
 
       full_name = concat (p, "/", ent->d_name, NULL);
-      found = try_load_plugin (full_name);
+      if (stat(full_name, &s) == 0 && S_ISREG (s.st_mode))
+       found = try_load_plugin (full_name);
       free (full_name);
       if (found)
        break;
@@ -220,30 +232,51 @@ static const bfd_target *
 bfd_plugin_object_p (bfd *abfd)
 {
   int claimed = 0;
-  int t = load_plugin ();
   struct ld_plugin_input_file file;
-  if (!t)
+  bfd *iobfd;
+  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->iostream)
+  if (abfd->my_archive)
     {
-      file.fd = fileno (abfd->iostream);
-      file.offset = 0;
-      file.filesize = 0; /*FIXME*/
+      iobfd = abfd->my_archive;
+      file.offset = abfd->origin;
+      file.filesize = arelt_size (abfd);
     }
   else
     {
-      bfd *archive = abfd->my_archive;
-      BFD_ASSERT (archive);
-      file.fd = fileno (archive->iostream);
-      file.offset = abfd->origin;
-      file.filesize = arelt_size (abfd);
+      iobfd = abfd;
+      file.offset = 0;
+      file.filesize = 0;
+    }
+
+  if (!iobfd->iostream && !bfd_open_file (iobfd))
+    return NULL;
+
+  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;
 
@@ -308,6 +341,13 @@ bfd_plugin_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
   return 0;
 }
 
+static int
+bfd_plugin_core_file_pid (bfd *abfd ATTRIBUTE_UNUSED)
+{
+  BFD_ASSERT (0);
+  return 0;
+}
+
 static long
 bfd_plugin_get_symtab_upper_bound (bfd *abfd)
 {
@@ -409,11 +449,11 @@ bfd_plugin_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
 static asymbol *
 bfd_plugin_make_empty_symbol (bfd *abfd)
 {
-  asymbol *new = bfd_zalloc (abfd, sizeof (asymbol));
-  if (new == NULL)
-    return new;
-  new->the_bfd = abfd;
-  return new;
+  asymbol *new_symbol = bfd_zalloc (abfd, sizeof (asymbol));
+  if (new_symbol == NULL)
+    return new_symbol;
+  new_symbol->the_bfd = abfd;
+  return new_symbol;
 }
 
 static int
@@ -424,13 +464,6 @@ bfd_plugin_sizeof_headers (bfd *a ATTRIBUTE_UNUSED,
   return 0;
 }
 
-static bfd_boolean
-bfd_plugin_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
-{
-  BFD_ASSERT (0);
-  return 0;
-}
-
 const bfd_target plugin_vec =
 {
   "plugin",                    /* Name.  */
@@ -461,7 +494,7 @@ const bfd_target plugin_vec =
   },
   {                            /* bfd_set_format.  */
     bfd_false,
-    bfd_plugin_mkobject,
+    bfd_false,
     _bfd_generic_mkarchive,
     bfd_false,
   },
@@ -486,3 +519,4 @@ const bfd_target plugin_vec =
 
   NULL                         /* backend_data.  */
 };
+#endif /* BFD_SUPPORTS_PLUGIN */
This page took 0.025353 seconds and 4 git commands to generate.