* elflink.c (_bfd_elf_merge_symbol): Revert previous patch.
[deliverable/binutils-gdb.git] / bfd / linker.c
index 1c22beb99057214e549862557af83ac7c3f249a6..1163a5591c1436800ce233a0a6e958d37afa9f3b 100644 (file)
@@ -1,6 +1,6 @@
 /* linker.c -- BFD linker routines
    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-   2003, 2004, 2005, 2006, 2007, 2008
+   2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support
 
@@ -444,7 +444,8 @@ _bfd_link_hash_newfunc (struct bfd_hash_entry *entry,
      subclass.  */
   if (entry == NULL)
     {
-      entry = bfd_hash_allocate (table, sizeof (struct bfd_link_hash_entry));
+      entry = (struct bfd_hash_entry *)
+          bfd_hash_allocate (table, sizeof (struct bfd_link_hash_entry));
       if (entry == NULL)
        return entry;
     }
@@ -548,7 +549,7 @@ bfd_wrapped_link_hash_lookup (bfd *abfd,
              references to SYM with references to __wrap_SYM.  */
 
          amt = strlen (l) + sizeof WRAP + 1;
-         n = bfd_malloc (amt);
+         n = (char *) bfd_malloc (amt);
          if (n == NULL)
            return NULL;
 
@@ -579,7 +580,7 @@ bfd_wrapped_link_hash_lookup (bfd *abfd,
              with references to SYM.  */
 
          amt = strlen (l + sizeof REAL - 1) + 2;
-         n = bfd_malloc (amt);
+         n = (char *) bfd_malloc (amt);
          if (n == NULL)
            return NULL;
 
@@ -678,7 +679,7 @@ _bfd_generic_link_hash_newfunc (struct bfd_hash_entry *entry,
      subclass.  */
   if (entry == NULL)
     {
-      entry =
+      entry = (struct bfd_hash_entry *)
        bfd_hash_allocate (table, sizeof (struct generic_link_hash_entry));
       if (entry == NULL)
        return entry;
@@ -707,7 +708,7 @@ _bfd_generic_link_hash_table_create (bfd *abfd)
   struct generic_link_hash_table *ret;
   bfd_size_type amt = sizeof (struct generic_link_hash_table);
 
-  ret = bfd_malloc (amt);
+  ret = (struct generic_link_hash_table *) bfd_malloc (amt);
   if (ret == NULL)
     return NULL;
   if (! _bfd_link_hash_table_init (&ret->root, abfd,
@@ -748,7 +749,8 @@ bfd_generic_link_read_symbols (bfd *abfd)
       symsize = bfd_get_symtab_upper_bound (abfd);
       if (symsize < 0)
        return FALSE;
-      bfd_get_outsymbols (abfd) = bfd_alloc (abfd, symsize);
+      bfd_get_outsymbols (abfd) = (struct bfd_symbol **) bfd_alloc (abfd,
+                                                                    symsize);
       if (bfd_get_outsymbols (abfd) == NULL && symsize != 0)
        return FALSE;
       symcount = bfd_canonicalize_symtab (abfd, bfd_get_outsymbols (abfd));
@@ -880,7 +882,8 @@ archive_hash_newfunc (struct bfd_hash_entry *entry,
   /* Allocate the structure if it has not already been allocated by a
      subclass.  */
   if (ret == NULL)
-    ret = bfd_hash_allocate (table, sizeof (struct archive_hash_entry));
+    ret = (struct archive_hash_entry *)
+        bfd_hash_allocate (table, sizeof (struct archive_hash_entry));
   if (ret == NULL)
     return NULL;
 
@@ -1051,7 +1054,7 @@ _bfd_generic_link_add_archive_symbols
          if (info->pei386_auto_import)
            {
              bfd_size_type amt = strlen (h->root.string) + 10;
-             char *buf = bfd_malloc (amt);
+             char *buf = (char *) bfd_malloc (amt);
              if (buf == NULL)
                return FALSE;
 
@@ -1242,7 +1245,7 @@ generic_link_check_archive_element (bfd *abfd,
             attached to symbfd to ensure that it is in a BFD which
             will be linked in.  */
          h->type = bfd_link_hash_common;
-         h->u.c.p =
+         h->u.c.p = (struct bfd_link_hash_common_entry *)
            bfd_hash_allocate (&info->hash->table,
                               sizeof (struct bfd_link_hash_common_entry));
          if (h->u.c.p == NULL)
@@ -1691,7 +1694,7 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
          if (h->type == bfd_link_hash_new)
            bfd_link_add_undef (info->hash, h);
          h->type = bfd_link_hash_common;
-         h->u.c.p =
+         h->u.c.p = (struct bfd_link_hash_common_entry *)
            bfd_hash_allocate (&info->hash->table,
                               sizeof (struct bfd_link_hash_common_entry));
          if (h->u.c.p == NULL)
@@ -1972,7 +1975,7 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info,
                char *w;
                size_t len = strlen (string) + 1;
 
-               w = bfd_hash_allocate (&info->hash->table, len);
+               w = (char *) bfd_hash_allocate (&info->hash->table, len);
                if (w == NULL)
                  return FALSE;
                memcpy (w, string, len);
@@ -2059,7 +2062,7 @@ _bfd_generic_final_link (bfd *abfd, struct bfd_link_info *info)
                                                       input_section);
                  if (relsize < 0)
                    return FALSE;
-                 relocs = bfd_malloc (relsize);
+                 relocs = (arelent **) bfd_malloc (relsize);
                  if (!relocs && relsize != 0)
                    return FALSE;
                  symbols = _bfd_generic_link_get_symbols (input_bfd);
@@ -2081,7 +2084,7 @@ _bfd_generic_final_link (bfd *abfd, struct bfd_link_info *info)
 
              amt = o->reloc_count;
              amt *= sizeof (arelent *);
-             o->orelocation = bfd_alloc (abfd, amt);
+             o->orelocation = (struct reloc_cache_entry **) bfd_alloc (abfd, amt);
              if (!o->orelocation)
                return FALSE;
              o->flags |= SEC_RELOC;
@@ -2135,7 +2138,7 @@ generic_add_output_symbol (bfd *output_bfd, size_t *psymalloc, asymbol *sym)
        *psymalloc *= 2;
       amt = *psymalloc;
       amt *= sizeof (asymbol *);
-      newsyms = bfd_realloc (bfd_get_outsymbols (output_bfd), amt);
+      newsyms = (asymbol **) bfd_realloc (bfd_get_outsymbols (output_bfd), amt);
       if (newsyms == NULL)
        return FALSE;
       bfd_get_outsymbols (output_bfd) = newsyms;
@@ -2212,7 +2215,7 @@ _bfd_generic_link_output_symbols (bfd *output_bfd,
          || bfd_is_ind_section (bfd_get_section (sym)))
        {
          if (sym->udata.p != NULL)
-           h = sym->udata.p;
+           h = (struct generic_link_hash_entry *) sym->udata.p;
          else if ((sym->flags & BSF_CONSTRUCTOR) != 0)
            {
              /* This case normally means that the main linker code
@@ -2451,7 +2454,8 @@ bfd_boolean
 _bfd_generic_link_write_global_symbol (struct generic_link_hash_entry *h,
                                       void *data)
 {
-  struct generic_write_global_symbol_info *wginfo = data;
+  struct generic_write_global_symbol_info *wginfo =
+      (struct generic_write_global_symbol_info *) data;
   asymbol *sym;
 
   if (h->root.type == bfd_link_hash_warning)
@@ -2508,7 +2512,7 @@ _bfd_generic_reloc_link_order (bfd *abfd,
   if (sec->orelocation == NULL)
     abort ();
 
-  r = bfd_alloc (abfd, sizeof (arelent));
+  r = (arelent *) bfd_alloc (abfd, sizeof (arelent));
   if (r == NULL)
     return FALSE;
 
@@ -2556,7 +2560,7 @@ _bfd_generic_reloc_link_order (bfd *abfd,
       file_ptr loc;
 
       size = bfd_get_reloc_size (r->howto);
-      buf = bfd_zmalloc (size);
+      buf = (bfd_byte *) bfd_zmalloc (size);
       if (buf == NULL)
        return FALSE;
       rstat = _bfd_relocate_contents (r->howto, abfd,
@@ -2604,21 +2608,21 @@ struct bfd_link_order *
 bfd_new_link_order (bfd *abfd, asection *section)
 {
   bfd_size_type amt = sizeof (struct bfd_link_order);
-  struct bfd_link_order *new;
+  struct bfd_link_order *new_lo;
 
-  new = bfd_zalloc (abfd, amt);
-  if (!new)
+  new_lo = (struct bfd_link_order *) bfd_zalloc (abfd, amt);
+  if (!new_lo)
     return NULL;
 
-  new->type = bfd_undefined_link_order;
+  new_lo->type = bfd_undefined_link_order;
 
   if (section->map_tail.link_order != NULL)
-    section->map_tail.link_order->next = new;
+    section->map_tail.link_order->next = new_lo;
   else
-    section->map_head.link_order = new;
-  section->map_tail.link_order = new;
+    section->map_head.link_order = new_lo;
+  section->map_tail.link_order = new_lo;
 
-  return new;
+  return new_lo;
 }
 
 /* Default link order processing routine.  Note that we can not handle
@@ -2671,7 +2675,7 @@ default_data_link_order (bfd *abfd,
   if (fill_size != 0 && fill_size < size)
     {
       bfd_byte *p;
-      fill = bfd_malloc (size);
+      fill = (bfd_byte *) bfd_malloc (size);
       if (fill == NULL)
        return FALSE;
       p = fill;
@@ -2781,7 +2785,7 @@ default_indirect_link_order (bfd *output_bfd,
              /* sym->udata may have been set by
                 generic_link_add_symbol_list.  */
              if (sym->udata.p != NULL)
-               h = sym->udata.p;
+               h = (struct bfd_link_hash_entry *) sym->udata.p;
              else if (bfd_is_und_section (bfd_get_section (sym)))
                h = bfd_wrapped_link_hash_lookup (output_bfd, info,
                                                  bfd_asymbol_name (sym),
@@ -2816,7 +2820,7 @@ default_indirect_link_order (bfd *output_bfd,
       sec_size = (input_section->rawsize > input_section->size
                  ? input_section->rawsize
                  : input_section->size);
-      contents = bfd_malloc (sec_size);
+      contents = (bfd_byte *) bfd_malloc (sec_size);
       if (contents == NULL && sec_size != 0)
        goto error_return;
       new_contents = (bfd_get_relocated_section_contents
@@ -2949,7 +2953,8 @@ bfd_section_already_linked_table_insert
 
   /* Allocate the memory from the same obstack as the hash table is
      kept in.  */
-  l = bfd_hash_allocate (&_bfd_section_already_linked_table, sizeof *l);
+  l = (struct bfd_section_already_linked *)
+      bfd_hash_allocate (&_bfd_section_already_linked_table, sizeof *l);
   if (l == NULL)
     return FALSE;
   l->sec = sec;
@@ -2964,7 +2969,8 @@ already_linked_newfunc (struct bfd_hash_entry *entry ATTRIBUTE_UNUSED,
                        const char *string ATTRIBUTE_UNUSED)
 {
   struct bfd_section_already_linked_hash_entry *ret =
-    bfd_hash_allocate (table, sizeof *ret);
+    (struct bfd_section_already_linked_hash_entry *)
+      bfd_hash_allocate (table, sizeof *ret);
 
   if (ret == NULL)
     return NULL;
@@ -3271,14 +3277,17 @@ DESCRIPTION
 
 struct bfd_elf_version_tree *
 bfd_find_version_for_sym (struct bfd_elf_version_tree *verdefs,
-                     const char *sym_name,
-                     bfd_boolean *hide)
+                         const char *sym_name,
+                         bfd_boolean *hide)
 {
   struct bfd_elf_version_tree *t;
   struct bfd_elf_version_tree *local_ver, *global_ver, *exist_ver;
+  struct bfd_elf_version_tree *star_local_ver, *star_global_ver;
 
   local_ver = NULL;
   global_ver = NULL;
+  star_local_ver = NULL;
+  star_global_ver = NULL;
   exist_ver = NULL;
   for (t = verdefs; t != NULL; t = t->next)
     {
@@ -3288,7 +3297,10 @@ bfd_find_version_for_sym (struct bfd_elf_version_tree *verdefs,
 
          while ((d = (*t->match) (&t->globals, d, sym_name)) != NULL)
            {
-             global_ver = t;
+             if (d->literal || strcmp (d->pattern, "*") != 0)
+               global_ver = t;
+             else
+               star_global_ver = t;
              if (d->symver)
                exist_ver = t;
              d->script = 1;
@@ -3308,13 +3320,17 @@ bfd_find_version_for_sym (struct bfd_elf_version_tree *verdefs,
 
          while ((d = (*t->match) (&t->locals, d, sym_name)) != NULL)
            {
-             local_ver = t;
+             if (d->literal || strcmp (d->pattern, "*") != 0)
+               local_ver = t;
+             else
+               star_local_ver = t;
              /* If the match is a wildcard pattern, keep looking for
                 a more explicit, perhaps even global, match.  */
              if (d->literal)
                {
                  /* An exact match overrides a global wildcard.  */
                  global_ver = NULL;
+                 star_global_ver = NULL;
                  break;
                }
            }
@@ -3324,6 +3340,9 @@ bfd_find_version_for_sym (struct bfd_elf_version_tree *verdefs,
        }
     }
 
+  if (global_ver == NULL && local_ver == NULL)
+    global_ver = star_global_ver;
+
   if (global_ver != NULL)
     {
       /* If we already have a versioned symbol that matches the
@@ -3334,6 +3353,9 @@ bfd_find_version_for_sym (struct bfd_elf_version_tree *verdefs,
       return global_ver;
     }
 
+  if (local_ver == NULL)
+    local_ver = star_local_ver;
+
   if (local_ver != NULL)
     {
       *hide = TRUE;
@@ -3342,4 +3364,3 @@ bfd_find_version_for_sym (struct bfd_elf_version_tree *verdefs,
 
   return NULL;
 }
-
This page took 0.027513 seconds and 4 git commands to generate.