* elf-bfd.h (enum elf_link_info_type): New.
[deliverable/binutils-gdb.git] / bfd / elflink.h
index 4455f01a5b7466dd24b0ccd7d479f7dceb5f710a..37ea63d4ecee797698e0941644db4e7ceebd759c 100644 (file)
@@ -39,9 +39,14 @@ static boolean elf_link_add_object_symbols
 static boolean elf_link_add_archive_symbols
   PARAMS ((bfd *, struct bfd_link_info *));
 static boolean elf_merge_symbol
-  PARAMS ((bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,
-          asection **, bfd_vma *, struct elf_link_hash_entry **,
-          boolean *, boolean *, boolean *, boolean));
+  PARAMS ((bfd *, struct bfd_link_info *, const char *,
+          Elf_Internal_Sym *, asection **, bfd_vma *,
+          struct elf_link_hash_entry **, boolean *, boolean *,
+          boolean *, boolean));
+static boolean elf_add_default_symbol
+  PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
+          const char *, Elf_Internal_Sym *, asection **, bfd_vma *,
+          boolean *, boolean, boolean));
 static boolean elf_export_symbol
   PARAMS ((struct elf_link_hash_entry *, PTR));
 static boolean elf_finalize_dynstr
@@ -894,6 +899,243 @@ elf_merge_symbol (abfd, info, name, sym, psec, pvalue, sym_hash,
   return true;
 }
 
+/* This function is called to create an indirect symbol from the
+   default for the symbol with the default version if needed. The
+   symbol is described by H, NAME, SYM, SEC, VALUE, and OVERRIDE.  We
+   set DYNSYM if the new indirect symbol is dynamic. DT_NEEDED
+   indicates if it comes from a DT_NEEDED entry of a shared object.  */
+
+static boolean
+elf_add_default_symbol (abfd, info, h, name, sym, sec, value,
+                       dynsym, override, dt_needed)
+     bfd *abfd;
+     struct bfd_link_info *info;
+     struct elf_link_hash_entry *h;
+     const char *name;
+     Elf_Internal_Sym *sym;
+     asection **sec;
+     bfd_vma *value;
+     boolean *dynsym;
+     boolean override;
+     boolean dt_needed;
+{
+  boolean type_change_ok;
+  boolean size_change_ok;
+  char *shortname;
+  struct elf_link_hash_entry *hi;
+  struct elf_backend_data *bed;
+  boolean collect;
+  boolean dynamic;
+  char *p;
+
+  /* If this symbol has a version, and it is the default version, we
+     create an indirect symbol from the default name to the fully
+     decorated name.  This will cause external references which do not
+     specify a version to be bound to this version of the symbol.  */
+  p = strchr (name, ELF_VER_CHR);
+  if (p == NULL || p[1] != ELF_VER_CHR)
+    return true;
+
+  if (override)
+    {
+      /* We are overridden by an old defition. We need to check if we
+        need to crreate the indirect symbol from the default name.  */
+      hi = elf_link_hash_lookup (elf_hash_table (info), name, true,
+                                false, false);
+      BFD_ASSERT (hi != NULL);
+      if (hi == h)
+       return true;
+      while (hi->root.type == bfd_link_hash_indirect
+            || hi->root.type == bfd_link_hash_warning)
+       {
+         hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
+         if (hi == h)
+           return true;
+       }
+    }
+
+  bed = get_elf_backend_data (abfd);
+  collect = bed->collect;
+  dynamic = (abfd->flags & DYNAMIC) != 0;
+
+  shortname = bfd_hash_allocate (&info->hash->table,
+                                (size_t) (p - name + 1));
+  if (shortname == NULL)
+    return false;
+  strncpy (shortname, name, (size_t) (p - name));
+  shortname [p - name] = '\0';
+
+  /* We are going to create a new symbol.  Merge it with any existing
+     symbol with this name.  For the purposes of the merge, act as
+     though we were defining the symbol we just defined, although we
+     actually going to define an indirect symbol.  */
+  type_change_ok = false;
+  size_change_ok = false;
+  if (! elf_merge_symbol (abfd, info, shortname, sym, sec, value,
+                         &hi, &override, &type_change_ok,
+                         &size_change_ok, dt_needed))
+    return false;
+
+  if (! override)
+    {
+      if (! (_bfd_generic_link_add_one_symbol
+            (info, abfd, shortname, BSF_INDIRECT, bfd_ind_section_ptr,
+             (bfd_vma) 0, name, false, collect,
+             (struct bfd_link_hash_entry **) &hi)))
+       return false;
+    }
+  else
+    {
+      /* In this case the symbol named SHORTNAME is overriding the
+        indirect symbol we want to add.  We were planning on making
+        SHORTNAME an indirect symbol referring to NAME.  SHORTNAME
+        is the name without a version.  NAME is the fully versioned
+        name, and it is the default version.
+
+        Overriding means that we already saw a definition for the
+        symbol SHORTNAME in a regular object, and it is overriding
+        the symbol defined in the dynamic object.
+
+        When this happens, we actually want to change NAME, the
+        symbol we just added, to refer to SHORTNAME.  This will cause
+        references to NAME in the shared object to become references
+        to SHORTNAME in the regular object.  This is what we expect
+        when we override a function in a shared object: that the
+        references in the shared object will be mapped to the
+        definition in the regular object.  */
+
+      while (hi->root.type == bfd_link_hash_indirect
+            || hi->root.type == bfd_link_hash_warning)
+       hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
+
+      h->root.type = bfd_link_hash_indirect;
+      h->root.u.i.link = (struct bfd_link_hash_entry *) hi;
+      if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
+       {
+         h->elf_link_hash_flags &=~ ELF_LINK_HASH_DEF_DYNAMIC;
+         hi->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
+         if (hi->elf_link_hash_flags
+             & (ELF_LINK_HASH_REF_REGULAR
+                | ELF_LINK_HASH_DEF_REGULAR))
+           {
+             if (! _bfd_elf_link_record_dynamic_symbol (info, hi))
+               return false;
+           }
+       }
+
+      /* Now set HI to H, so that the following code will set the
+         other fields correctly.  */
+      hi = h;
+    }
+
+  /* If there is a duplicate definition somewhere, then HI may not
+     point to an indirect symbol.  We will have reported an error to
+     the user in that case.  */
+
+  if (hi->root.type == bfd_link_hash_indirect)
+    {
+      struct elf_link_hash_entry *ht;
+
+      /* If the symbol became indirect, then we assume that we have
+        not seen a definition before.  */
+      BFD_ASSERT ((hi->elf_link_hash_flags
+                  & (ELF_LINK_HASH_DEF_DYNAMIC
+                     | ELF_LINK_HASH_DEF_REGULAR)) == 0);
+
+      ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
+      (*bed->elf_backend_copy_indirect_symbol) (ht, hi);
+
+      /* See if the new flags lead us to realize that the symbol must
+        be dynamic.  */
+      if (! *dynsym)
+       {
+         if (! dynamic)
+           {
+             if (info->shared
+                 || ((hi->elf_link_hash_flags
+                      & ELF_LINK_HASH_REF_DYNAMIC) != 0))
+               *dynsym = true;
+           }
+         else
+           {
+             if ((hi->elf_link_hash_flags
+                  & ELF_LINK_HASH_REF_REGULAR) != 0)
+               *dynsym = true;
+           }
+       }
+    }
+
+  /* We also need to define an indirection from the nondefault version
+     of the symbol.  */
+
+  shortname = bfd_hash_allocate (&info->hash->table, strlen (name));
+  if (shortname == NULL)
+    return false;
+  strncpy (shortname, name, (size_t) (p - name));
+  strcpy (shortname + (p - name), p + 1);
+
+  /* Once again, merge with any existing symbol.  */
+  type_change_ok = false;
+  size_change_ok = false;
+  if (! elf_merge_symbol (abfd, info, shortname, sym, sec, value,
+                         &hi, &override, &type_change_ok,
+                         &size_change_ok, dt_needed))
+    return false;
+
+  if (override)
+    {
+      /* Here SHORTNAME is a versioned name, so we don't expect to see
+        the type of override we do in the case above.  */
+      (*_bfd_error_handler)
+       (_("%s: warning: unexpected redefinition of `%s'"),
+        bfd_archive_filename (abfd), shortname);
+    }
+  else
+    {
+      if (! (_bfd_generic_link_add_one_symbol
+            (info, abfd, shortname, BSF_INDIRECT,
+             bfd_ind_section_ptr, (bfd_vma) 0, name, false,
+             collect, (struct bfd_link_hash_entry **) &hi)))
+       return false;
+
+      /* If there is a duplicate definition somewhere, then HI may not
+        point to an indirect symbol.  We will have reported an error
+        to the user in that case.  */
+
+      if (hi->root.type == bfd_link_hash_indirect)
+       {
+         /* If the symbol became indirect, then we assume that we have
+            not seen a definition before.  */
+         BFD_ASSERT ((hi->elf_link_hash_flags
+                      & (ELF_LINK_HASH_DEF_DYNAMIC
+                         | ELF_LINK_HASH_DEF_REGULAR)) == 0);
+
+          (*bed->elf_backend_copy_indirect_symbol) (h, hi);
+
+         /* See if the new flags lead us to realize that the symbol
+            must be dynamic.  */
+         if (! *dynsym)
+           {
+             if (! dynamic)
+               {
+                 if (info->shared
+                     || ((hi->elf_link_hash_flags
+                          & ELF_LINK_HASH_REF_DYNAMIC) != 0))
+                   *dynsym = true;
+               }
+             else
+               {
+                 if ((hi->elf_link_hash_flags
+                      & ELF_LINK_HASH_REF_REGULAR) != 0)
+                   *dynsym = true;
+               }
+           }
+       }
+    }
+
+  return true;
+}
+
 /* Add symbols from an ELF object file to the linker hash table.  */
 
 static boolean
@@ -1373,6 +1615,9 @@ elf_link_add_object_symbols (abfd, info)
       boolean size_change_ok, type_change_ok;
       boolean new_weakdef;
       unsigned int old_alignment;
+      boolean override;
+
+      override = false;
 
       elf_swap_symbol_in (abfd, esym, &sym);
 
@@ -1463,7 +1708,6 @@ elf_link_add_object_symbols (abfd, info)
        {
          Elf_Internal_Versym iver;
          unsigned int vernum = 0;
-         boolean override;
 
          if (ever != NULL)
            {
@@ -1735,217 +1979,13 @@ elf_link_add_object_symbols (abfd, info)
 
          h->elf_link_hash_flags |= new_flag;
 
-         /* If this symbol has a version, and it is the default
-             version, we create an indirect symbol from the default
-             name to the fully decorated name.  This will cause
-             external references which do not specify a version to be
-             bound to this version of the symbol.  */
+         /* Check to see if we need to add an indirect symbol for
+            the default name.  */
          if (definition || h->root.type == bfd_link_hash_common)
-           {
-             char *p;
-
-             p = strchr (name, ELF_VER_CHR);
-             if (p != NULL && p[1] == ELF_VER_CHR)
-               {
-                 char *shortname;
-                 struct elf_link_hash_entry *hi;
-                 boolean override;
-
-                 shortname = bfd_hash_allocate (&info->hash->table,
-                                                (size_t) (p - name + 1));
-                 if (shortname == NULL)
-                   goto error_return;
-                 strncpy (shortname, name, (size_t) (p - name));
-                 shortname[p - name] = '\0';
-
-                 /* We are going to create a new symbol.  Merge it
-                     with any existing symbol with this name.  For the
-                     purposes of the merge, act as though we were
-                     defining the symbol we just defined, although we
-                     actually going to define an indirect symbol.  */
-                 type_change_ok = false;
-                 size_change_ok = false;
-                 if (! elf_merge_symbol (abfd, info, shortname, &sym, &sec,
-                                         &value, &hi, &override,
-                                         &type_change_ok,
-                                         &size_change_ok, dt_needed))
-                   goto error_return;
-
-                 if (! override)
-                   {
-                     if (! (_bfd_generic_link_add_one_symbol
-                            (info, abfd, shortname, BSF_INDIRECT,
-                             bfd_ind_section_ptr, (bfd_vma) 0, name, false,
-                             collect, (struct bfd_link_hash_entry **) &hi)))
-                       goto error_return;
-                   }
-                 else
-                   {
-                     /* In this case the symbol named SHORTNAME is
-                         overriding the indirect symbol we want to
-                         add.  We were planning on making SHORTNAME an
-                         indirect symbol referring to NAME.  SHORTNAME
-                         is the name without a version.  NAME is the
-                         fully versioned name, and it is the default
-                         version.
-
-                        Overriding means that we already saw a
-                        definition for the symbol SHORTNAME in a
-                        regular object, and it is overriding the
-                        symbol defined in the dynamic object.
-
-                        When this happens, we actually want to change
-                        NAME, the symbol we just added, to refer to
-                        SHORTNAME.  This will cause references to
-                        NAME in the shared object to become
-                        references to SHORTNAME in the regular
-                        object.  This is what we expect when we
-                        override a function in a shared object: that
-                        the references in the shared object will be
-                        mapped to the definition in the regular
-                        object.  */
-
-                     while (hi->root.type == bfd_link_hash_indirect
-                            || hi->root.type == bfd_link_hash_warning)
-                       hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
-
-                     h->root.type = bfd_link_hash_indirect;
-                     h->root.u.i.link = (struct bfd_link_hash_entry *) hi;
-                     if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
-                       {
-                         h->elf_link_hash_flags &=~ ELF_LINK_HASH_DEF_DYNAMIC;
-                         hi->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
-                         if (hi->elf_link_hash_flags
-                             & (ELF_LINK_HASH_REF_REGULAR
-                                | ELF_LINK_HASH_DEF_REGULAR))
-                           {
-                             if (! _bfd_elf_link_record_dynamic_symbol (info,
-                                                                        hi))
-                               goto error_return;
-                           }
-                       }
-
-                     /* Now set HI to H, so that the following code
-                         will set the other fields correctly.  */
-                     hi = h;
-                   }
-
-                 /* If there is a duplicate definition somewhere,
-                    then HI may not point to an indirect symbol.  We
-                    will have reported an error to the user in that
-                    case.  */
-
-                 if (hi->root.type == bfd_link_hash_indirect)
-                   {
-                     struct elf_link_hash_entry *ht;
-
-                     /* If the symbol became indirect, then we assume
-                        that we have not seen a definition before.  */
-                     BFD_ASSERT ((hi->elf_link_hash_flags
-                                  & (ELF_LINK_HASH_DEF_DYNAMIC
-                                     | ELF_LINK_HASH_DEF_REGULAR))
-                                 == 0);
-
-                     ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
-                     (*bed->elf_backend_copy_indirect_symbol) (ht, hi);
-
-                     /* See if the new flags lead us to realize that
-                        the symbol must be dynamic.  */
-                     if (! dynsym)
-                       {
-                         if (! dynamic)
-                           {
-                             if (info->shared
-                                 || ((hi->elf_link_hash_flags
-                                      & ELF_LINK_HASH_REF_DYNAMIC)
-                                     != 0))
-                               dynsym = true;
-                           }
-                         else
-                           {
-                             if ((hi->elf_link_hash_flags
-                                  & ELF_LINK_HASH_REF_REGULAR) != 0)
-                               dynsym = true;
-                           }
-                       }
-                   }
-
-                 /* We also need to define an indirection from the
-                     nondefault version of the symbol.  */
-
-                 shortname = bfd_hash_allocate (&info->hash->table,
-                                                strlen (name));
-                 if (shortname == NULL)
-                   goto error_return;
-                 strncpy (shortname, name, (size_t) (p - name));
-                 strcpy (shortname + (p - name), p + 1);
-
-                 /* Once again, merge with any existing symbol.  */
-                 type_change_ok = false;
-                 size_change_ok = false;
-                 if (! elf_merge_symbol (abfd, info, shortname, &sym, &sec,
-                                         &value, &hi, &override,
-                                         &type_change_ok,
-                                         &size_change_ok, dt_needed))
-                   goto error_return;
-
-                 if (override)
-                   {
-                     /* Here SHORTNAME is a versioned name, so we
-                         don't expect to see the type of override we
-                         do in the case above.  */
-                     (*_bfd_error_handler)
-                       (_("%s: warning: unexpected redefinition of `%s'"),
-                        bfd_archive_filename (abfd), shortname);
-                   }
-                 else
-                   {
-                     if (! (_bfd_generic_link_add_one_symbol
-                            (info, abfd, shortname, BSF_INDIRECT,
-                             bfd_ind_section_ptr, (bfd_vma) 0, name, false,
-                             collect, (struct bfd_link_hash_entry **) &hi)))
-                       goto error_return;
-
-                     /* If there is a duplicate definition somewhere,
-                         then HI may not point to an indirect symbol.
-                         We will have reported an error to the user in
-                         that case.  */
-
-                     if (hi->root.type == bfd_link_hash_indirect)
-                       {
-                         /* If the symbol became indirect, then we
-                             assume that we have not seen a definition
-                             before.  */
-                         BFD_ASSERT ((hi->elf_link_hash_flags
-                                      & (ELF_LINK_HASH_DEF_DYNAMIC
-                                         | ELF_LINK_HASH_DEF_REGULAR))
-                                     == 0);
-
-                         (*bed->elf_backend_copy_indirect_symbol) (h, hi);
-
-                         /* See if the new flags lead us to realize
-                             that the symbol must be dynamic.  */
-                         if (! dynsym)
-                           {
-                             if (! dynamic)
-                               {
-                                 if (info->shared
-                                     || ((hi->elf_link_hash_flags
-                                          & ELF_LINK_HASH_REF_DYNAMIC)
-                                         != 0))
-                                   dynsym = true;
-                               }
-                             else
-                               {
-                                 if ((hi->elf_link_hash_flags
-                                      & ELF_LINK_HASH_REF_REGULAR) != 0)
-                                   dynsym = true;
-                               }
-                           }
-                       }
-                   }
-               }
-           }
+           if (! elf_add_default_symbol (abfd, info, h, name, &sym,
+                                         &sec, &value, &dynsym,
+                                         override, dt_needed))
+             goto error_return;
 
          if (dynsym && h->dynindx == -1)
            {
@@ -2174,7 +2214,7 @@ elf_link_add_object_symbols (abfd, info)
       asection *stab, *stabstr;
 
       stab = bfd_get_section_by_name (abfd, ".stab");
-      if (stab != NULL)
+      if (stab != NULL && !(stab->flags & SEC_MERGE))
        {
          stabstr = bfd_get_section_by_name (abfd, ".stabstr");
 
@@ -2186,8 +2226,10 @@ elf_link_add_object_symbols (abfd, info)
              if (! _bfd_link_section_stabs (abfd,
                                             & hash_table->stab_info,
                                             stab, stabstr,
-                                            &secdata->stab_info))
+                                            &secdata->sec_info))
                goto error_return;
+             if (secdata->sec_info)
+               secdata->sec_info_type = ELF_INFO_TYPE_STABS;
            }
        }
     }
@@ -2198,10 +2240,18 @@ elf_link_add_object_symbols (abfd, info)
       asection *s;
 
       for (s = abfd->sections; s != NULL; s = s->next)
-       if ((s->flags & SEC_MERGE)
-           && ! _bfd_merge_section (abfd, & hash_table->merge_info, s,
-                                    & elf_section_data (s)->merge_info))
-         goto error_return;
+       if (s->flags & SEC_MERGE)
+         {
+           struct bfd_elf_section_data *secdata;
+
+           secdata = elf_section_data (s);
+           if (! _bfd_merge_section (abfd,
+                                     & hash_table->merge_info,
+                                     s, &secdata->sec_info))
+             goto error_return;
+           else if (secdata->sec_info)
+             secdata->sec_info_type = ELF_INFO_TYPE_MERGE;
+         }
     }
 
   return true;
@@ -2260,6 +2310,16 @@ elf_link_create_dynamic_sections (abfd, info)
        return false;
     }
 
+  if (! info->traditional_format
+      && info->hash->creator->flavour == bfd_target_elf_flavour)
+    {
+      s = bfd_make_section (abfd, ".eh_frame_hdr");
+      if (s == NULL
+         || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
+         || ! bfd_set_section_alignment (abfd, s, 2))
+       return false;
+    }
+
   /* Create sections to hold version informations.  These are removed
      if they are not needed.  */
   s = bfd_make_section (abfd, ".gnu.version_d");
@@ -5482,6 +5542,19 @@ elf_bfd_final_link (abfd, info)
        goto error_return;
     }
 
+  if (info->eh_frame_hdr)
+    {
+      o = bfd_get_section_by_name (elf_hash_table (info)->dynobj,
+                                  ".eh_frame_hdr");
+      if (o
+         && (elf_section_data (o)->sec_info_type
+             == ELF_INFO_TYPE_EH_FRAME_HDR))
+       {
+         if (! _bfd_elf_write_section_eh_frame_hdr (abfd, o))
+           goto error_return;
+       }
+    }
+
   if (finfo.symstrtab != NULL)
     _bfd_stringtab_free (finfo.symstrtab);
   if (finfo.contents != NULL)
@@ -5631,14 +5704,14 @@ elf_link_sec_merge_syms (h, data)
   if ((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
       && ((sec = h->root.u.def.section)->flags & SEC_MERGE)
-      && elf_section_data (sec)->merge_info)
+      && elf_section_data (sec)->sec_info_type == ELF_INFO_TYPE_MERGE)
     {
       bfd *output_bfd = (bfd *) data;
 
       h->root.u.def.value =
        _bfd_merged_section_offset (output_bfd,
                                    &h->root.u.def.section,
-                                   elf_section_data (sec)->merge_info,
+                                   elf_section_data (sec)->sec_info,
                                    h->root.u.def.value, (bfd_vma) 0);
     }
 
@@ -6130,11 +6203,12 @@ elf_link_input_bfd (finfo, input_bfd)
       else if (isym->st_shndx > 0 && isym->st_shndx < SHN_LORESERVE)
        {
          isec = section_from_elf_index (input_bfd, isym->st_shndx);
-         if (isec && elf_section_data (isec)->merge_info
+         if (isec
+             && elf_section_data (isec)->sec_info_type == ELF_INFO_TYPE_MERGE
              && ELF_ST_TYPE (isym->st_info) != STT_SECTION)
            isym->st_value =
              _bfd_merged_section_offset (output_bfd, &isec,
-                                         elf_section_data (isec)->merge_info,
+                                         elf_section_data (isec)->sec_info,
                                          isym->st_value, (bfd_vma) 0);
        }
       else if (isym->st_shndx == SHN_ABS)
@@ -6317,7 +6391,9 @@ elf_link_input_bfd (finfo, input_bfd)
                           || h->root.type == bfd_link_hash_defweak)
                          && ! bfd_is_abs_section (h->root.u.def.section)
                          && bfd_is_abs_section (h->root.u.def.section
-                                                ->output_section))
+                                                ->output_section)
+                         && (elf_section_data (h->root.u.def.section)
+                             ->sec_info_type != ELF_INFO_TYPE_MERGE))
                        {
 #if BFD_VERSION_DATE < 20031005
                          if ((o->flags & SEC_DEBUGGING) != 0)
@@ -6328,6 +6404,7 @@ elf_link_input_bfd (finfo, input_bfd)
                                 _("warning: relocation against removed section; zeroing"),
                                 NULL, input_bfd, o, rel->r_offset);
 #endif
+                             BFD_ASSERT (r_symndx != 0);
                              memset (rel, 0, sizeof (*rel));
                            }
                          else
@@ -6343,53 +6420,52 @@ elf_link_input_bfd (finfo, input_bfd)
                    }
                  else
                    {
-                     isym = finfo->internal_syms + r_symndx;
-                     if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
-                       {
-                         asection *sec = finfo->sections[r_symndx];
+                     asection *sec = finfo->sections[r_symndx];
 
-                         if (sec != NULL
-                             && ! bfd_is_abs_section (sec)
-                             && bfd_is_abs_section (sec->output_section))
-                           {
+                     if (sec != NULL
+                         && ! bfd_is_abs_section (sec)
+                         && bfd_is_abs_section (sec->output_section)
+                         && (elf_section_data (sec)->sec_info_type
+                             != ELF_INFO_TYPE_MERGE))
+                       {
 #if BFD_VERSION_DATE < 20031005
-                             if ((o->flags & SEC_DEBUGGING) != 0
-                                 || (sec->flags & SEC_LINK_ONCE) != 0)
-                               {
+                         if ((o->flags & SEC_DEBUGGING) != 0
+                             || (sec->flags & SEC_LINK_ONCE) != 0)
+                           {
 #if BFD_VERSION_DATE > 20021005
-                                 (*finfo->info->callbacks->warning)
-                                   (finfo->info,
-                                    _("warning: relocation against removed section"),
-                                    NULL, input_bfd, o, rel->r_offset);
+                             (*finfo->info->callbacks->warning)
+                               (finfo->info,
+                                _("warning: relocation against removed section"),
+                                NULL, input_bfd, o, rel->r_offset);
 #endif
-                                 rel->r_info
-                                   = ELF_R_INFO (0, ELF_R_TYPE (rel->r_info));
-                                 rel->r_addend = 0;
-                               }
-                             else
+                             BFD_ASSERT (r_symndx != 0);
+                             rel->r_info
+                               = ELF_R_INFO (0, ELF_R_TYPE (rel->r_info));
+                             rel->r_addend = 0;
+                           }
+                         else
 #endif
-                               {
-                                 boolean ok;
-                                 const char *msg
-                                   = _("local symbols in discarded section %s");
-                                 bfd_size_type amt
-                                   = strlen (sec->name) + strlen (msg) - 1;
-                                 char *buf = (char *) bfd_malloc (amt);
-
-                                 if (buf != NULL)
-                                   sprintf (buf, msg, sec->name);
-                                 else
-                                   buf = (char *) sec->name;
-                                 ok = (*finfo->info->callbacks
-                                       ->undefined_symbol) (finfo->info, buf,
-                                                            input_bfd, o,
-                                                            rel->r_offset,
-                                                            true);
-                                 if (buf != sec->name)
-                                   free (buf);
-                                 if (!ok)
-                                   return false;
-                               }
+                           {
+                             boolean ok;
+                             const char *msg
+                               = _("local symbols in discarded section %s");
+                             bfd_size_type amt
+                               = strlen (sec->name) + strlen (msg) - 1;
+                             char *buf = (char *) bfd_malloc (amt);
+
+                             if (buf != NULL)
+                               sprintf (buf, msg, sec->name);
+                             else
+                               buf = (char *) sec->name;
+                             ok = (*finfo->info->callbacks
+                                   ->undefined_symbol) (finfo->info, buf,
+                                                        input_bfd, o,
+                                                        rel->r_offset,
+                                                        true);
+                             if (buf != sec->name)
+                               free (buf);
+                             if (!ok)
+                               return false;
                            }
                        }
                    }
@@ -6595,34 +6671,49 @@ elf_link_input_bfd (finfo, input_bfd)
 
       /* Write out the modified section contents.  */
       if (bed->elf_backend_write_section
-         && bed->elf_backend_write_section (output_bfd, o, contents))
+         && (*bed->elf_backend_write_section) (output_bfd, o, contents))
        {
          /* Section written out.  */
        }
-      else if (elf_section_data (o)->stab_info)
+      else switch (elf_section_data (o)->sec_info_type)
        {
+       case ELF_INFO_TYPE_STABS:
          if (! (_bfd_write_section_stabs
-                (output_bfd, &elf_hash_table (finfo->info)->stab_info,
-                 o, &elf_section_data (o)->stab_info, contents)))
+                (output_bfd,
+                 &elf_hash_table (finfo->info)->stab_info,
+                 o, &elf_section_data (o)->sec_info, contents)))
            return false;
-       }
-      else if (elf_section_data (o)->merge_info)
-       {
+         break;
+       case ELF_INFO_TYPE_MERGE:
          if (! (_bfd_write_merged_section
-                (output_bfd, o, elf_section_data (o)->merge_info)))
-           return false;
-       }
-      else
-       {
-         bfd_size_type sec_size;
-
-         sec_size = (o->_cooked_size != 0 ? o->_cooked_size : o->_raw_size);
-         if (! (o->flags & SEC_EXCLUDE)
-             && ! bfd_set_section_contents (output_bfd, o->output_section,
-                                            contents,
-                                            (file_ptr) o->output_offset,
-                                            sec_size))
+                (output_bfd, o, elf_section_data (o)->sec_info)))
            return false;
+         break;
+       case ELF_INFO_TYPE_EH_FRAME:
+         {
+           asection *ehdrsec;
+
+           ehdrsec
+             = bfd_get_section_by_name (elf_hash_table (finfo->info)->dynobj,
+                                        ".eh_frame_hdr");
+           if (! (_bfd_elf_write_section_eh_frame (output_bfd, o, ehdrsec,
+                                                   contents)))
+             return false;
+         }
+         break;
+       default:
+         {
+           bfd_size_type sec_size;
+
+           sec_size = (o->_cooked_size != 0 ? o->_cooked_size : o->_raw_size);
+           if (! (o->flags & SEC_EXCLUDE)
+               && ! bfd_set_section_contents (output_bfd, o->output_section,
+                                              contents,
+                                              (file_ptr) o->output_offset,
+                                              sec_size))
+             return false;
+         }
+         break;
        }
     }
 
@@ -7786,9 +7877,9 @@ elf_reloc_symbol_deleted_p (offset, cookie)
       if (rcookie->rel->r_offset != offset)
        continue;
 
-      if (rcookie->locsyms)
+      if (rcookie->locsyms && r_symndx < rcookie->locsymcount)
        elf_swap_symbol_in (rcookie->abfd,
-                           ((Elf_External_Sym *)rcookie->locsyms) + r_symndx,
+                           (Elf_External_Sym *) rcookie->locsyms + r_symndx,
                            &isym);
 
       if (r_symndx >= rcookie->locsymcount
@@ -7815,7 +7906,7 @@ elf_reloc_symbol_deleted_p (offset, cookie)
       else if (rcookie->locsyms)
        {
          /* It's not a relocation against a global symbol,
-            but it could be a relocation against a section
+            but it could be a relocation against a local
             symbol for a discarded section.  */
          asection *isec;
 
@@ -7824,7 +7915,6 @@ elf_reloc_symbol_deleted_p (offset, cookie)
            {
              isec = section_from_elf_index (rcookie->abfd, isym.st_shndx);
              if (isec != NULL
-                 && ELF_ST_TYPE (isym.st_info) == STT_SECTION
                  && ! bfd_is_abs_section (isec)
                  && bfd_is_abs_section (isec->output_section))
                return true;
@@ -7841,33 +7931,50 @@ elf_reloc_symbol_deleted_p (offset, cookie)
    which is true for all known assemblers.  */
 
 boolean
-elf_bfd_discard_info (info)
+elf_bfd_discard_info (output_bfd, info)
+     bfd *output_bfd;
      struct bfd_link_info *info;
 {
   struct elf_reloc_cookie cookie;
-  asection *o;
+  asection *stab, *eh, *ehdr;
   Elf_Internal_Shdr *symtab_hdr;
   Elf_External_Sym *freesyms;
   struct elf_backend_data *bed;
   bfd *abfd;
   boolean ret = false;
+  boolean strip = info->strip == strip_all || info->strip == strip_debugger;
 
   if (info->relocateable
       || info->traditional_format
       || info->hash->creator->flavour != bfd_target_elf_flavour
-      || ! is_elf_hash_table (info)
-      || info->strip == strip_all
-      || info->strip == strip_debugger)
+      || ! is_elf_hash_table (info))
     return false;
+
+  ehdr = bfd_get_section_by_name (elf_hash_table (info)->dynobj,
+                                 ".eh_frame_hdr");
+
   for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link_next)
     {
+      if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+       continue;
+
       bed = get_elf_backend_data (abfd);
 
       if ((abfd->flags & DYNAMIC) != 0)
        continue;
 
-      o = bfd_get_section_by_name (abfd, ".stab");
-      if (! o && ! bed->elf_backend_discard_info)
+      eh = NULL;
+      if (ehdr)
+       {
+         eh = bfd_get_section_by_name (abfd, ".eh_frame");
+         if (eh && eh->_raw_size == 0)
+           eh = NULL;
+       }
+
+      stab = strip ? NULL : bfd_get_section_by_name (abfd, ".stab");
+      if ((! stab || elf_section_data(stab)->sec_info_type != ELF_INFO_TYPE_STABS)
+         && ! eh
+         && (strip || ! bed->elf_backend_discard_info))
        continue;
 
       symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
@@ -7912,19 +8019,19 @@ elf_bfd_discard_info (info)
            }
         }
 
-      if (o)
+      if (stab)
        {
          cookie.rels = (NAME(_bfd_elf,link_read_relocs)
-                        (abfd, o, (PTR) NULL,
+                        (abfd, stab, (PTR) NULL,
                          (Elf_Internal_Rela *) NULL,
                          info->keep_memory));
          if (cookie.rels)
            {
              cookie.rel = cookie.rels;
              cookie.relend =
-               cookie.rels + o->reloc_count * bed->s->int_rels_per_ext_rel;
-             if (_bfd_discard_section_stabs (abfd, o,
-                                             elf_section_data (o)->stab_info,
+               cookie.rels + stab->reloc_count * bed->s->int_rels_per_ext_rel;
+             if (_bfd_discard_section_stabs (abfd, stab,
+                                             elf_section_data (stab)->sec_info,
                                              elf_reloc_symbol_deleted_p,
                                              &cookie))
                ret = true;
@@ -7933,6 +8040,30 @@ elf_bfd_discard_info (info)
            }
        }
 
+      if (eh)
+       {
+         cookie.rels = NULL;
+         cookie.rel = NULL;
+         cookie.relend = NULL;
+         if (eh->reloc_count)
+           cookie.rels = (NAME(_bfd_elf,link_read_relocs)
+                          (abfd, eh, (PTR) NULL,
+                           (Elf_Internal_Rela *) NULL,
+                           info->keep_memory));
+         if (cookie.rels)
+           {
+             cookie.rel = cookie.rels;
+             cookie.relend =
+               cookie.rels + eh->reloc_count * bed->s->int_rels_per_ext_rel;
+           }
+         if (_bfd_elf_discard_section_eh_frame (abfd, info, eh, ehdr,
+                                                elf_reloc_symbol_deleted_p,
+                                                &cookie))
+           ret = true;
+         if (! info->keep_memory)
+           free (cookie.rels);
+       }
+
       if (bed->elf_backend_discard_info)
        {
          if (bed->elf_backend_discard_info (abfd, &cookie, info))
@@ -7942,6 +8073,11 @@ elf_bfd_discard_info (info)
       if (freesyms)
        free (freesyms);
     }
+
+  if (ehdr
+      && _bfd_elf_discard_section_eh_frame_hdr (output_bfd,
+                                               info, ehdr))
+    ret = true;
   return ret;
 }
 
@@ -7949,15 +8085,19 @@ static boolean
 elf_section_ignore_discarded_relocs (sec)
      asection *sec;
 {
-  if (strcmp (sec->name, ".stab") == 0)
-    return true;
-  else if ((get_elf_backend_data (sec->owner)
-           ->elf_backend_ignore_discarded_relocs != NULL)
-          && (get_elf_backend_data (sec->owner)
-              ->elf_backend_ignore_discarded_relocs (sec)))
+  switch (elf_section_data (sec)->sec_info_type)
+    {
+    case ELF_INFO_TYPE_STABS:
+    case ELF_INFO_TYPE_EH_FRAME:
+      return true;
+    default:
+      break;
+    }
+  if ((get_elf_backend_data (sec->owner)->elf_backend_ignore_discarded_relocs
+       != NULL)
+      && (*get_elf_backend_data (sec->owner)
+          ->elf_backend_ignore_discarded_relocs) (sec))
     return true;
-  else
-    return false;
-}
-
 
+  return false;
+}
This page took 0.052378 seconds and 4 git commands to generate.