OSDN Git Service

Merge branch 'master' of git://github.com/monaka/binutils
[pf3gnuchains/pf3gnuchains3x.git] / bfd / elflink.c
index c42c6e1..284bff1 100644 (file)
@@ -1,6 +1,6 @@
 /* ELF linking support for BFD.
    Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-   2005, 2006, 2007, 2008, 2009
+   2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -185,7 +185,7 @@ bfd_boolean
 _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
 {
   flagword flags;
-  register asection *s;
+  asection *s;
   const struct elf_backend_data *bed;
 
   if (! is_elf_hash_table (info->hash))
@@ -570,8 +570,7 @@ bfd_elf_record_link_assignment (bfd *output_bfd,
 
   if (provide && hidden)
     {
-      const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
-
+      bed = get_elf_backend_data (output_bfd);
       h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
       (*bed->elf_backend_hide_symbol) (info, h, TRUE);
     }
@@ -1184,9 +1183,8 @@ _bfd_elf_merge_symbol (bfd *abfd,
             was referenced before.  */
          if (h->ref_regular)
            {
-             const struct elf_backend_data *bed
-               = get_elf_backend_data (abfd);
              struct elf_link_hash_entry *vh = *sym_hash;
+
              vh->root.type = h->root.type;
              h->root.type = bfd_link_hash_indirect;
              (*bed->elf_backend_copy_indirect_symbol) (info, vh, h);
@@ -1548,7 +1546,6 @@ _bfd_elf_merge_symbol (bfd *abfd,
       /* Handle the case where we had a versioned symbol in a dynamic
         library and now find a definition in a normal object.  In this
         case, we make the versioned symbol point to the normal one.  */
-      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
       flip->root.type = h->root.type;
       flip->root.u.undef.abfd = h->root.u.undef.abfd;
       h->root.type = bfd_link_hash_indirect;
@@ -3234,6 +3231,8 @@ elf_finalize_dynstr (bfd *output_bfd, struct bfd_link_info *info)
        case DT_RUNPATH:
        case DT_FILTER:
        case DT_AUXILIARY:
+       case DT_AUDIT:
+       case DT_DEPAUDIT:
          dyn.d_un.d_val = _bfd_elf_strtab_offset (dynstr, dyn.d_un.d_val);
          break;
        default:
@@ -3525,6 +3524,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
     {
       asection *s;
       const char *soname = NULL;
+      char *audit = NULL;
       struct bfd_link_needed_list *rpath = NULL, *runpath = NULL;
       int ret;
 
@@ -3653,6 +3653,11 @@ error_free_dyn:
                    ;
                  *pn = n;
                }
+             if (dyn.d_tag == DT_AUDIT)
+               {
+                 unsigned int tagv = dyn.d_un.d_val;
+                 audit = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
+               }
            }
 
          free (dynbuf);
@@ -3705,6 +3710,9 @@ error_free_dyn:
         particular dynamic object more than once.  */
       if (ret > 0)
        return TRUE;
+
+      /* Save the DT_AUDIT entry for the linker emulation code. */
+      elf_dt_audit (abfd) = audit; 
     }
 
   /* If this is a dynamic object, we always link against the .dynsym
@@ -3866,6 +3874,7 @@ error_free_dyn:
       bfd_boolean common;
       unsigned int old_alignment;
       bfd *old_bfd;
+      bfd * undef_bfd = NULL;
 
       override = FALSE;
 
@@ -4097,6 +4106,20 @@ error_free_dyn:
              name = newname;
            }
 
+         /* If this is a definition of a previously undefined symbol
+            make a note of the bfd that contained the reference in
+            case we need to refer to it later on in error messages.  */
+         if (! bfd_is_und_section (sec))
+           {
+             h = elf_link_hash_lookup (elf_hash_table (info), name, FALSE, FALSE, FALSE);
+
+             if (h != NULL
+                 && (h->root.type == bfd_link_hash_undefined
+                     || h->root.type == bfd_link_hash_undefweak)
+                 && h->root.u.undef.abfd)
+               undef_bfd = h->root.u.undef.abfd;
+           }
+
          if (!_bfd_elf_merge_symbol (abfd, info, name, isym, &sec,
                                      &value, &old_alignment,
                                      sym_hash, &skip, &override,
@@ -4362,7 +4385,6 @@ error_free_dyn:
          if (definition && (sec->flags & SEC_DEBUGGING) && !info->relocatable)
            {
              /* We don't want to make debug symbol dynamic.  */
-             (*bed->elf_backend_hide_symbol) (info, h, TRUE);
              dynsym = FALSE;
            }
 
@@ -4437,9 +4459,12 @@ error_free_dyn:
              if ((elf_dyn_lib_class (abfd) & DYN_NO_NEEDED) != 0)
                {
                  (*_bfd_error_handler)
-                   (_("%s: invalid DSO for symbol `%s' definition"),
+                   (_("%B: undefined reference to symbol '%s'"),
+                    undef_bfd == NULL ? info->output_bfd : undef_bfd, name);
+                 (*_bfd_error_handler)
+                   (_("note: '%s' is defined in DSO %B so try adding it to the linker command line"),
                     abfd, name);
-                 bfd_set_error (bfd_error_bad_value);
+                 bfd_set_error (bfd_error_invalid_operation);
                  goto error_free_vers;
                }
 
@@ -5451,6 +5476,8 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
                               const char *soname,
                               const char *rpath,
                               const char *filter_shlib,
+                              const char *audit,
+                              const char *depaudit,
                               const char * const *auxiliary_filters,
                               struct bfd_link_info *info,
                               asection **sinterpptr,
@@ -5603,6 +5630,28 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
            }
        }
 
+      if (audit != NULL)
+       {
+         bfd_size_type indx;
+
+         indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, audit,
+                                     TRUE);
+         if (indx == (bfd_size_type) -1
+             || !_bfd_elf_add_dynamic_entry (info, DT_AUDIT, indx))
+           return FALSE;
+       }
+
+      if (depaudit != NULL)
+       {
+         bfd_size_type indx;
+
+         indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, depaudit,
+                                     TRUE);
+         if (indx == (bfd_size_type) -1
+             || !_bfd_elf_add_dynamic_entry (info, DT_DEPAUDIT, indx))
+           return FALSE;
+       }
+
       eif.info = info;
       eif.verdefs = verdefs;
       eif.failed = FALSE;
@@ -8587,9 +8636,11 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
     strip = FALSE;
 
   /* If we're stripping it, and it's not a dynamic symbol, there's
-     nothing else to do unless it is a forced local symbol.  */
+     nothing else to do unless it is a forced local symbol or a
+     STT_GNU_IFUNC symbol.  */
   if (strip
       && h->dynindx == -1
+      && h->type != STT_GNU_IFUNC
       && !h->forced_local)
     return TRUE;
 
@@ -8597,7 +8648,11 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
   sym.st_size = h->size;
   sym.st_other = h->other;
   if (h->forced_local)
-    sym.st_info = ELF_ST_INFO (STB_LOCAL, h->type);
+    {
+      sym.st_info = ELF_ST_INFO (STB_LOCAL, h->type);
+      /* Turn off visibility on local symbol.  */
+      sym.st_other &= ~ELF_ST_VISIBILITY (-1);
+    }
   else if (h->unique_global)
     sym.st_info = ELF_ST_INFO (STB_GNU_UNIQUE, h->type);
   else if (h->root.type == bfd_link_hash_undefweak
@@ -10053,9 +10108,9 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
   bfd_boolean emit_relocs;
   bfd *dynobj;
   struct elf_final_link_info finfo;
-  register asection *o;
-  register struct bfd_link_order *p;
-  register bfd *sub;
+  asection *o;
+  struct bfd_link_order *p;
+  bfd *sub;
   bfd_size_type max_contents_size;
   bfd_size_type max_external_reloc_size;
   bfd_size_type max_internal_reloc_count;
@@ -10504,9 +10559,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
          if (size == 0
              && (sec->flags & SEC_HAS_CONTENTS) == 0)
            {
-             struct bfd_link_order *o = sec->map_tail.link_order;
-             if (o != NULL)
-               size = o->offset + o->size;
+             struct bfd_link_order *ord = sec->map_tail.link_order;
+
+             if (ord != NULL)
+               size = ord->offset + ord->size;
            }
          end = sec->vma + size;
        }
@@ -10669,13 +10725,11 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
              asection *s;
              bfd_byte *dest;
 
-             sym.st_size = e->isym.st_size;
-             sym.st_other = e->isym.st_other;
-
-             /* Copy the internal symbol as is.
+             /* Copy the internal symbol and turn off visibility.
                 Note that we saved a word of storage and overwrote
                 the original st_name with the dynstr_index.  */
              sym = e->isym;
+             sym.st_other &= ~ELF_ST_VISIBILITY (-1);
 
              s = bfd_section_from_elf_index (e->input_bfd,
                                              e->isym.st_shndx);
@@ -11473,9 +11527,10 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
              o->gc_mark = first->gc_mark;
            }
          else if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0
-                  || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)
+                  || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0
+                  || elf_section_data (o)->this_hdr.sh_type == SHT_NOTE)
            {
-             /* Keep debug and special sections.  */
+             /* Keep debug, special and SHT_NOTE sections.  */
              o->gc_mark = 1;
            }
 
@@ -12495,7 +12550,7 @@ _bfd_elf_get_dynamic_reloc_section (bfd *       abfd,
    section does not exist it is created and attached to the DYNOBJ
    bfd and stored in the SRELOC field of SEC's elf_section_data
    structure.
-   
+
    ALIGNMENT is the alignment for the newly created section and
    IS_RELA defines whether the name should be .rela.<SEC's name>
    or .rel.<SEC's name>.  The section name is looked up in the
@@ -12540,3 +12595,15 @@ _bfd_elf_make_dynamic_reloc_section (asection *         sec,
 
   return reloc_sec;
 }
+
+/* Copy the ELF symbol type associated with a linker hash entry.  */
+void
+_bfd_elf_copy_link_hash_symbol_type (bfd *abfd ATTRIBUTE_UNUSED,
+    struct bfd_link_hash_entry * hdest,
+    struct bfd_link_hash_entry * hsrc)
+{
+  struct elf_link_hash_entry *ehdest = (struct elf_link_hash_entry *)hdest;
+  struct elf_link_hash_entry *ehsrc = (struct elf_link_hash_entry *)hsrc;
+
+  ehdest->type = ehsrc->type;
+}