Ticket #3707: binutils_handle_more_than_one_plugin_at_a_time-1.patch

File binutils_handle_more_than_one_plugin_at_a_time-1.patch, 3.5 KB (added by Miklos Karacsony, 10 years ago)
  • bfd/plugin.c

    Submitted By:            Miklos Karacsony <mkaracsony81 at gmail dot com>
    Date:                    2014-11-06
    Initial Package Version: 2.24
    Upstream Status:         Applied
    Origin:                  Upstream
    Description:             Handle more than one plugin in /usr/lib/bfd-plugins
    
    diff --git a/bfd/plugin.c b/bfd/plugin.c
    index c9d53c89a61f..d336b6731116 100644
    a b bfd_plugin_set_program_name (const char *program_name)  
    156156}
    157157
    158158static int
    159 try_load_plugin (const char *pname)
     159try_claim (bfd *abfd)
    160160{
    161   static void *plugin_handle;
     161  int claimed = 0;
     162  struct ld_plugin_input_file file;
     163  bfd *iobfd;
     164
     165  file.name = abfd->filename;
     166
     167  if (abfd->my_archive)
     168    {
     169      iobfd = abfd->my_archive;
     170      file.offset = abfd->origin;
     171      file.filesize = arelt_size (abfd);
     172    }
     173  else
     174    {
     175      iobfd = abfd;
     176      file.offset = 0;
     177      file.filesize = 0;
     178    }
     179
     180  if (!iobfd->iostream && !bfd_open_file (iobfd))
     181    return 0;
     182
     183  file.fd = fileno ((FILE *) iobfd->iostream);
     184
     185  if (!abfd->my_archive)
     186    {
     187      struct stat stat_buf;
     188      if (fstat (file.fd, &stat_buf))
     189        return 0;
     190      file.filesize = stat_buf.st_size;
     191    }
     192
     193  file.handle = abfd;
     194  off_t cur_offset = lseek(file.fd, 0, SEEK_CUR);
     195  claim_file (&file, &claimed);
     196  lseek(file.fd, cur_offset, SEEK_SET);
     197  if (!claimed)
     198    return 0;
     199
     200  return 1;
     201}
     202
     203static int
     204try_load_plugin (const char *pname, bfd *abfd)
     205{
     206  void *plugin_handle;
    162207  int tv_size = 4;
    163208  struct ld_plugin_tv tv[tv_size];
    164209  int i;
    try_load_plugin (const char *pname)  
    200245  if (!claim_file)
    201246    goto err;
    202247
     248  if (!try_claim (abfd))
     249    goto err;
     250
    203251  return 1;
    204252
    205253 err:
    bfd_plugin_set_plugin (const char *p)  
    216264}
    217265
    218266static int
    219 load_plugin (void)
     267load_plugin (bfd *abfd)
    220268{
    221269  char *plugin_dir;
    222270  char *p;
    load_plugin (void)  
    225273  int found = 0;
    226274
    227275  if (plugin_name)
    228     return try_load_plugin (plugin_name);
     276    return try_load_plugin (plugin_name, abfd);
    229277
    230278  if (plugin_program_name == NULL)
    231279    return 0;
    load_plugin (void)  
    248296
    249297      full_name = concat (p, "/", ent->d_name, NULL);
    250298      if (stat(full_name, &s) == 0 && S_ISREG (s.st_mode))
    251         found = try_load_plugin (full_name);
     299        found = try_load_plugin (full_name, abfd);
    252300      free (full_name);
    253301      if (found)
    254302        break;
    load_plugin (void)  
    266314static const bfd_target *
    267315bfd_plugin_object_p (bfd *abfd)
    268316{
    269   int claimed = 0;
    270   struct ld_plugin_input_file file;
    271   bfd *iobfd;
    272   static int have_loaded = 0;
    273   static int have_plugin = 0;
    274 
    275   if (!have_loaded)
    276     {
    277       have_loaded = 1;
    278       have_plugin = load_plugin ();
    279     }
    280   if (!have_plugin)
    281     return NULL;
    282 
    283   file.name = abfd->filename;
    284 
    285   if (abfd->my_archive)
    286     {
    287       iobfd = abfd->my_archive;
    288       file.offset = abfd->origin;
    289       file.filesize = arelt_size (abfd);
    290     }
    291   else
    292     {
    293       iobfd = abfd;
    294       file.offset = 0;
    295       file.filesize = 0;
    296     }
    297 
    298   if (!iobfd->iostream && !bfd_open_file (iobfd))
    299     return NULL;
    300 
    301   file.fd = fileno ((FILE *) iobfd->iostream);
    302 
    303   if (!abfd->my_archive)
    304     {
    305       struct stat stat_buf;
    306       if (fstat (file.fd, &stat_buf))
    307         return NULL;
    308       file.filesize = stat_buf.st_size;
    309     }
    310 
    311   file.handle = abfd;
    312   off_t cur_offset = lseek(file.fd, 0, SEEK_CUR);
    313   claim_file (&file, &claimed);
    314   lseek(file.fd, cur_offset, SEEK_SET);
    315   if (!claimed)
     317  if (!load_plugin (abfd))
    316318    return NULL;
    317319
    318320  return abfd->xvec;