Unbreak DJGPP build of GDB.
[deliverable/binutils-gdb.git] / bfd / elflink.c
index 4378bb2ace367f743e835776104aa56351b04973..95209061313a800b34a8d7f9bd76d9ddf2bb9393 100644 (file)
@@ -54,6 +54,47 @@ struct elf_find_verdep_info
 static bfd_boolean _bfd_elf_fix_symbol_flags
   (struct elf_link_hash_entry *, struct elf_info_failed *);
 
+asection *
+_bfd_elf_section_for_symbol (struct elf_reloc_cookie *cookie,
+                            unsigned long r_symndx,
+                            bfd_boolean discard)
+{
+  if (r_symndx >= cookie->locsymcount
+      || ELF_ST_BIND (cookie->locsyms[r_symndx].st_info) != STB_LOCAL)
+    {
+      struct elf_link_hash_entry *h;
+
+      h = cookie->sym_hashes[r_symndx - cookie->extsymoff];
+
+      while (h->root.type == bfd_link_hash_indirect
+            || h->root.type == bfd_link_hash_warning)
+       h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+      if ((h->root.type == bfd_link_hash_defined
+          || h->root.type == bfd_link_hash_defweak)
+          && discarded_section (h->root.u.def.section))
+        return h->root.u.def.section;
+      else
+       return NULL;
+    }
+  else
+    {
+      /* It's not a relocation against a global symbol,
+        but it could be a relocation against a local
+        symbol for a discarded section.  */
+      asection *isec;
+      Elf_Internal_Sym *isym;
+
+      /* Need to: get the symbol; get the section.  */
+      isym = &cookie->locsyms[r_symndx];
+      isec = bfd_section_from_elf_index (cookie->abfd, isym->st_shndx);
+      if (isec != NULL
+         && discard ? discarded_section (isec) : 1)
+       return isec;
+     }
+  return NULL;
+}
+
 /* Define a symbol in a dynamic linkage section.  */
 
 struct elf_link_hash_entry *
@@ -77,9 +118,9 @@ _bfd_elf_define_linkage_sym (bfd *abfd,
     }
 
   bh = &h->root;
+  bed = get_elf_backend_data (abfd);
   if (!_bfd_generic_link_add_one_symbol (info, abfd, name, BSF_GLOBAL,
-                                        sec, 0, NULL, FALSE,
-                                        get_elf_backend_data (abfd)->collect,
+                                        sec, 0, NULL, FALSE, bed->collect,
                                         &bh))
     return NULL;
   h = (struct elf_link_hash_entry *) bh;
@@ -90,7 +131,6 @@ _bfd_elf_define_linkage_sym (bfd *abfd,
   if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
     h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
 
-  bed = get_elf_backend_data (abfd);
   (*bed->elf_backend_hide_symbol) (info, h, TRUE);
   return h;
 }
@@ -762,6 +802,7 @@ _bfd_elf_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
                                   asection *p)
 {
   struct elf_link_hash_table *htab;
+  asection *ip;
 
   switch (elf_section_data (p)->this_hdr.sh_type)
     {
@@ -777,18 +818,9 @@ _bfd_elf_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
       if (htab->text_index_section != NULL)
        return p != htab->text_index_section && p != htab->data_index_section;
 
-      if (strcmp (p->name, ".got") == 0
-         || strcmp (p->name, ".got.plt") == 0
-         || strcmp (p->name, ".plt") == 0)
-       {
-         asection *ip;
-
-         if (htab->dynobj != NULL
+      return (htab->dynobj != NULL
              && (ip = bfd_get_linker_section (htab->dynobj, p->name)) != NULL
-             && ip->output_section == p)
-           return TRUE;
-       }
-      return FALSE;
+             && ip->output_section == p);
 
       /* There shouldn't be section relative relocations
         against any other section.  */
@@ -853,7 +885,7 @@ _bfd_elf_link_renumber_dynsyms (bfd *output_bfd,
 
 static void
 elf_merge_st_other (bfd *abfd, struct elf_link_hash_entry *h,
-                   const Elf_Internal_Sym *isym,
+                   const Elf_Internal_Sym *isym, asection *sec,
                    bfd_boolean definition, bfd_boolean dynamic)
 {
   const struct elf_backend_data *bed = get_elf_backend_data (abfd);
@@ -874,7 +906,9 @@ elf_merge_st_other (bfd *abfd, struct elf_link_hash_entry *h,
       if (symvis - 1 < hvis - 1)
        h->other = symvis | (h->other & ~ELF_ST_VISIBILITY (-1));
     }
-  else if (definition && ELF_ST_VISIBILITY (isym->st_other) != STV_DEFAULT)
+  else if (definition
+          && ELF_ST_VISIBILITY (isym->st_other) != STV_DEFAULT
+          && (sec->flags & SEC_READONLY) == 0)
     h->protected_def = 1;
 }
 
@@ -1426,7 +1460,7 @@ _bfd_elf_merge_symbol (bfd *abfd,
       /* Merge st_other.  If the symbol already has a dynamic index,
         but visibility says it should not be visible, turn it into a
         local symbol.  */
-      elf_merge_st_other (abfd, h, sym, newdef, newdyn);
+      elf_merge_st_other (abfd, h, sym, sec, newdef, newdyn);
       if (h->dynindx != -1)
        switch (ELF_ST_VISIBILITY (h->other))
          {
@@ -2289,8 +2323,8 @@ _bfd_elf_link_size_reloc_section (bfd *abfd,
     {
       struct elf_link_hash_entry **p;
 
-      p = (struct elf_link_hash_entry **)
-          bfd_zmalloc (reldata->count * sizeof (struct elf_link_hash_entry *));
+      p = ((struct elf_link_hash_entry **)
+          bfd_zmalloc (reldata->count * sizeof (*p)));
       if (p == NULL)
        return FALSE;
 
@@ -2680,14 +2714,14 @@ _bfd_elf_adjust_dynamic_copy (struct bfd_link_info *info,
   /* Increment the size of DYNBSS to make room for the symbol.  */
   dynbss->size += h->size;
 
-  if (h->protected_def)
-    {
-      info->callbacks->einfo
-       (_("%P: copy reloc against protected `%T' is invalid\n"),
-        h->root.root.string);
-      bfd_set_error (bfd_error_bad_value);
-      return FALSE;
-    }
+  /* No error if extern_protected_data is true.  */
+  if (h->protected_def
+      && (!info->extern_protected_data
+         || (info->extern_protected_data < 0
+             && !get_elf_backend_data (dynbss->owner)->extern_protected_data)))
+    info->callbacks->einfo
+      (_("%P: copy reloc against protected `%T' is dangerous\n"),
+       h->root.root.string);
 
   return TRUE;
 }
@@ -2844,8 +2878,12 @@ _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry *h,
 
   bed = get_elf_backend_data (hash_table->dynobj);
 
-  /* STV_PROTECTED non-function symbols are local.  */
-  if (!bed->is_function_type (h->type))
+  /* If extern_protected_data is false, STV_PROTECTED non-function
+     symbols are local.  */
+  if ((!info->extern_protected_data
+       || (info->extern_protected_data < 0
+          && !bed->extern_protected_data))
+      && !bed->is_function_type (h->type))
     return TRUE;
 
   /* Function pointer equality tests may require that STV_PROTECTED
@@ -2944,6 +2982,10 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef)
   if (abfd == NULL)
     return FALSE;
 
+  /* Return FALSE if the object has been claimed by plugin.  */
+  if (abfd->plugin_format == bfd_plugin_yes)
+    return FALSE;
+
   if (! bfd_check_format (abfd, bfd_object))
     return FALSE;
 
@@ -4093,8 +4135,7 @@ error_free_dyn:
             requested we not re-export it, then mark it as hidden.  */
          if (definition
              && !dynamic
-             && (abfd->no_export
-                 || (abfd->my_archive && abfd->my_archive->no_export))
+             && abfd->no_export
              && ELF_ST_VISIBILITY (isym->st_other) != STV_INTERNAL)
            isym->st_other = (STV_HIDDEN
                              | (isym->st_other & ~ELF_ST_VISIBILITY (-1)));
@@ -4365,7 +4406,7 @@ error_free_dyn:
            }
 
          /* Merge st_other field.  */
-         elf_merge_st_other (abfd, h, isym, definition, dynamic);
+         elf_merge_st_other (abfd, h, isym, sec, definition, dynamic);
 
          /* We don't want to make debug symbol dynamic.  */
          if (definition && (sec->flags & SEC_DEBUGGING) && !info->relocatable)
@@ -4392,8 +4433,8 @@ error_free_dyn:
                    {
                      amt = ((isymend - isym + 1)
                             * sizeof (struct elf_link_hash_entry *));
-                     nondeflt_vers =
-                          (struct elf_link_hash_entry **) bfd_malloc (amt);
+                     nondeflt_vers
+                       = (struct elf_link_hash_entry **) bfd_malloc (amt);
                      if (!nondeflt_vers)
                        goto error_free_vers;
                    }
@@ -4459,7 +4500,7 @@ error_free_dyn:
                }
 
              elf_dyn_lib_class (abfd) = (enum dynamic_lib_link_class)
-                  (elf_dyn_lib_class (abfd) & ~DYN_AS_NEEDED);
+               (elf_dyn_lib_class (abfd) & ~DYN_AS_NEEDED);
 
              add_needed = TRUE;
              ret = elf_add_dt_needed_tag (abfd, info, soname, add_needed);
@@ -4868,8 +4909,7 @@ error_free_dyn:
       /* Add this bfd to the loaded list.  */
       struct elf_link_loaded_list *n;
 
-      n = (struct elf_link_loaded_list *)
-          bfd_alloc (abfd, sizeof (struct elf_link_loaded_list));
+      n = (struct elf_link_loaded_list *) bfd_alloc (abfd, sizeof (*n));
       if (n == NULL)
        goto error_return;
       n->abfd = abfd;
@@ -5430,7 +5470,7 @@ compute_bucket_count (struct bfd_link_info *info ATTRIBUTE_UNUSED,
            {
              best_chlen = max;
              best_size = i;
-              no_improvement_count = 0;
+             no_improvement_count = 0;
            }
          /* PR 11843: Avoid futile long searches for the best bucket size
             when there are a large number of symbols.  */
@@ -6724,7 +6764,7 @@ _bfd_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
   if (entry == NULL)
     {
       entry = (struct bfd_hash_entry *)
-          bfd_hash_allocate (table, sizeof (struct elf_link_hash_entry));
+       bfd_hash_allocate (table, sizeof (struct elf_link_hash_entry));
       if (entry == NULL)
        return entry;
     }
@@ -7275,10 +7315,10 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2,
       if (count1 == 0 || count2 == 0 || count1 != count2)
        goto done;
 
-      symtable1 = (struct elf_symbol *)
-          bfd_malloc (count1 * sizeof (struct elf_symbol));
-      symtable2 = (struct elf_symbol *)
-          bfd_malloc (count2 * sizeof (struct elf_symbol));
+      symtable1
+       = (struct elf_symbol *) bfd_malloc (count1 * sizeof (*symtable1));
+      symtable2
+       = (struct elf_symbol *) bfd_malloc (count2 * sizeof (*symtable2));
       if (symtable1 == NULL || symtable2 == NULL)
        goto done;
 
@@ -7451,8 +7491,6 @@ struct elf_outext_info
 {
   bfd_boolean failed;
   bfd_boolean localsyms;
-  bfd_boolean need_second_pass;
-  bfd_boolean second_pass;
   bfd_boolean file_sym_done;
   struct elf_final_link_info *flinfo;
 };
@@ -7803,28 +7841,34 @@ put_value (bfd_vma size,
 {
   location += (size - chunksz);
 
-  for (; size; size -= chunksz, location -= chunksz, x >>= (chunksz * 8))
+  for (; size; size -= chunksz, location -= chunksz)
     {
       switch (chunksz)
        {
-       default:
-       case 0:
-         abort ();
        case 1:
          bfd_put_8 (input_bfd, x, location);
+         x >>= 8;
          break;
        case 2:
          bfd_put_16 (input_bfd, x, location);
+         x >>= 16;
          break;
        case 4:
          bfd_put_32 (input_bfd, x, location);
+         /* Computed this way because x >>= 32 is undefined if x is a 32-bit value.  */
+         x >>= 16;
+         x >>= 16;
          break;
-       case 8:
 #ifdef BFD64
+       case 8:
          bfd_put_64 (input_bfd, x, location);
-#else
-         abort ();
+         /* Computed this way because x >>= 64 is undefined if x is a 64-bit value.  */
+         x >>= 32;
+         x >>= 32;
+         break;
 #endif
+       default:
+         abort ();
          break;
        }
     }
@@ -8607,7 +8651,7 @@ elf_link_output_sym (struct elf_final_link_info *flinfo,
 
          amt = flinfo->shndxbuf_size * sizeof (Elf_External_Sym_Shndx);
          destshndx = (Elf_External_Sym_Shndx *) bfd_realloc (destshndx,
-                                                              amt * 2);
+                                                             amt * 2);
          if (destshndx == NULL)
            return 0;
          flinfo->symshndxbuf = destshndx;
@@ -8831,27 +8875,6 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
     {
       if (!h->forced_local)
        return TRUE;
-      if (eoinfo->second_pass
-         && !((h->root.type == bfd_link_hash_defined
-               || h->root.type == bfd_link_hash_defweak)
-              && h->root.u.def.section->output_section != NULL))
-       return TRUE;
-
-      if (!eoinfo->file_sym_done
-         && (eoinfo->second_pass ? eoinfo->flinfo->filesym_count == 1
-                                 : eoinfo->flinfo->filesym_count > 1))
-       {
-         /* Output a FILE symbol so that following locals are not associated
-            with the wrong input file.  */
-         memset (&sym, 0, sizeof (sym));
-         sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
-         sym.st_shndx = SHN_ABS;
-         if (!elf_link_output_sym (eoinfo->flinfo, NULL, &sym,
-                                   bfd_und_section_ptr, NULL))
-           return FALSE;
-
-         eoinfo->file_sym_done = TRUE;
-       }
     }
   else
     {
@@ -8935,8 +8958,9 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
      a regular file, or that we have been told to strip.  However, if
      h->indx is set to -2, the symbol is used by a reloc and we must
      output it.  */
+  strip = FALSE;
   if (h->indx == -2)
-    strip = FALSE;
+    ;
   else if ((h->def_dynamic
            || h->ref_dynamic
            || h->root.type == bfd_link_hash_new)
@@ -8953,7 +8977,8 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
            || h->root.type == bfd_link_hash_defweak)
           && ((flinfo->info->strip_discarded
                && discarded_section (h->root.u.def.section))
-              || (h->root.u.def.section->owner != NULL
+              || ((h->root.u.def.section->flags & SEC_LINKER_CREATED) == 0
+                  && h->root.u.def.section->owner != NULL
                   && (h->root.u.def.section->owner->flags & BFD_PLUGIN) != 0)))
     strip = TRUE;
   else if ((h->root.type == bfd_link_hash_undefined
@@ -8961,12 +8986,11 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
           && h->root.u.undef.abfd != NULL
           && (h->root.u.undef.abfd->flags & BFD_PLUGIN) != 0)
     strip = TRUE;
-  else
-    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 or a
-     STT_GNU_IFUNC symbol.  */
+     nothing else to do.   However, if it is a forced local symbol or
+     an ifunc symbol we need to give the backend finish_dynamic_symbol
+     function a chance to make it dynamic.  */
   if (strip
       && h->dynindx == -1
       && h->type != STT_GNU_IFUNC
@@ -9012,19 +9036,6 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
        input_sec = h->root.u.def.section;
        if (input_sec->output_section != NULL)
          {
-           if (eoinfo->localsyms && flinfo->filesym_count == 1)
-             {
-               bfd_boolean second_pass_sym
-                 = (input_sec->owner == flinfo->output_bfd
-                    || input_sec->owner == NULL
-                    || (input_sec->flags & SEC_LINKER_CREATED) != 0
-                    || (input_sec->owner->flags & BFD_LINKER_CREATED) != 0);
-
-               eoinfo->need_second_pass |= second_pass_sym;
-               if (eoinfo->second_pass != second_pass_sym)
-                 return TRUE;
-             }
-
            sym.st_shndx =
              _bfd_elf_section_from_bfd_section (flinfo->output_bfd,
                                                 input_sec->output_section);
@@ -9050,12 +9061,6 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
                    asection *tls_sec = elf_hash_table (flinfo->info)->tls_sec;
                    if (tls_sec != NULL)
                      sym.st_value -= tls_sec->vma;
-                   else
-                     {
-                       /* The TLS section may have been garbage collected.  */
-                       BFD_ASSERT (flinfo->info->gc_sections
-                                   && !input_sec->gc_mark);
-                     }
                  }
              }
          }
@@ -9256,10 +9261,42 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
        }
     }
 
-  /* If we're stripping it, then it was just a dynamic symbol, and
-     there's nothing else to do.  */
-  if (strip || (input_sec->flags & SEC_EXCLUDE) != 0)
+  /* If the symbol is undefined, and we didn't output it to .dynsym,
+     strip it from .symtab too.  Obviously we can't do this for
+     relocatable output or when needed for --emit-relocs.  */
+  else if (input_sec == bfd_und_section_ptr
+          && h->indx != -2
+          && !flinfo->info->relocatable)
+    return TRUE;
+  /* Also strip others that we couldn't earlier due to dynamic symbol
+     processing.  */
+  if (strip)
     return TRUE;
+  if ((input_sec->flags & SEC_EXCLUDE) != 0)
+    return TRUE;
+
+  /* Output a FILE symbol so that following locals are not associated
+     with the wrong input file.  We need one for forced local symbols
+     if we've seen more than one FILE symbol or when we have exactly
+     one FILE symbol but global symbols are present in a file other
+     than the one with the FILE symbol.  We also need one if linker
+     defined symbols are present.  In practice these conditions are
+     always met, so just emit the FILE symbol unconditionally.  */
+  if (eoinfo->localsyms
+      && !eoinfo->file_sym_done
+      && eoinfo->flinfo->filesym_count != 0)
+    {
+      Elf_Internal_Sym fsym;
+
+      memset (&fsym, 0, sizeof (fsym));
+      fsym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
+      fsym.st_shndx = SHN_ABS;
+      if (!elf_link_output_sym (eoinfo->flinfo, NULL, &fsym,
+                               bfd_und_section_ptr, NULL))
+       return FALSE;
+
+      eoinfo->file_sym_done = TRUE;
+    }
 
   indx = bfd_get_symcount (flinfo->output_bfd);
   ret = elf_link_output_sym (flinfo, h->root.root.string, &sym, input_sec, h);
@@ -9288,6 +9325,7 @@ elf_section_ignore_discarded_relocs (asection *sec)
     {
     case SEC_INFO_TYPE_STABS:
     case SEC_INFO_TYPE_EH_FRAME:
+    case SEC_INFO_TYPE_EH_FRAME_ENTRY:
       return TRUE;
     default:
       break;
@@ -9483,8 +9521,9 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
 
       *ppsection = isec;
 
-      /* Don't output the first, undefined, symbol.  */
-      if (ppsection == flinfo->sections)
+      /* Don't output the first, undefined, symbol.  In fact, don't
+        output any undefined local symbol.  */
+      if (isec == bfd_und_section_ptr)
        continue;
 
       if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
@@ -9534,6 +9573,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
 
       if (ELF_ST_TYPE (isym->st_info) == STT_FILE)
        {
+         if (input_bfd->lto_output)
+           /* -flto puts a temp file name here.  This means builds
+              are not reproducible.  Discard the symbol.  */
+           continue;
          have_file_sym = TRUE;
          flinfo->filesym_count += 1;
        }
@@ -9550,8 +9593,10 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
          memset (&osym, 0, sizeof (osym));
          osym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
          osym.st_shndx = SHN_ABS;
-         if (!elf_link_output_sym (flinfo, input_bfd->filename, &osym,
-                                   bfd_abs_section_ptr, NULL))
+         if (!elf_link_output_sym (flinfo,
+                                   (input_bfd->lto_output ? NULL
+                                    : input_bfd->filename),
+                                   &osym, bfd_abs_section_ptr, NULL))
            return FALSE;
        }
 
@@ -9801,6 +9846,24 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
 
                  s_type = h->type;
 
+                 /* If a plugin symbol is referenced from a non-IR file,
+                    mark the symbol as undefined.  Note that the
+                    linker may attach linker created dynamic sections
+                    to the plugin bfd.  Symbols defined in linker
+                    created sections are not plugin symbols.  */
+                 if (h->root.non_ir_ref
+                     && (h->root.type == bfd_link_hash_defined
+                         || h->root.type == bfd_link_hash_defweak)
+                     && (h->root.u.def.section->flags
+                         & SEC_LINKER_CREATED) == 0
+                     && h->root.u.def.section->owner != NULL
+                     && (h->root.u.def.section->owner->flags
+                         & BFD_PLUGIN) != 0)
+                   {
+                     h->root.type = bfd_link_hash_undefined;
+                     h->root.u.undef.abfd = h->root.u.def.section->owner;
+                   }
+
                  ps = NULL;
                  if (h->root.type == bfd_link_hash_defined
                      || h->root.type == bfd_link_hash_defweak)
@@ -10194,6 +10257,14 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
              return FALSE;
          }
          break;
+       case SEC_INFO_TYPE_EH_FRAME_ENTRY:
+         {
+           if (! _bfd_elf_write_section_eh_frame_entry (output_bfd,
+                                                        flinfo->info,
+                                                        o, contents))
+             return FALSE;
+         }
+         break;
        default:
          {
            /* FIXME: octets_per_byte.  */
@@ -10337,7 +10408,7 @@ elf_reloc_link_order (bfd *output_bfd,
 
       size = (bfd_size_type) bfd_get_reloc_size (howto);
       buf = (bfd_byte *) bfd_zmalloc (size);
-      if (buf == NULL)
+      if (buf == NULL && size != 0)
        return FALSE;
       rstat = _bfd_relocate_contents (howto, output_bfd, addend, buf);
       switch (rstat)
@@ -10869,6 +10940,21 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
         to count upwards while actually outputting the relocations.  */
       esdo->rel.count = 0;
       esdo->rela.count = 0;
+
+      if (esdo->this_hdr.sh_offset == (file_ptr) -1)
+       {
+         /* Cache the section contents so that they can be compressed
+            later.  Use bfd_malloc since it will be freed by
+            bfd_compress_section_contents.  */
+         unsigned char *contents = esdo->this_hdr.contents;
+         if ((o->flags & SEC_ELF_COMPRESS) == 0 || contents != NULL)
+           abort ();
+         contents
+           = (unsigned char *) bfd_malloc (esdo->this_hdr.sh_size);
+         if (contents == NULL)
+           goto error_return;
+         esdo->this_hdr.contents = contents;
+       }
     }
 
   /* We have now assigned file positions for all the sections except
@@ -11049,6 +11135,9 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
        return FALSE;
     }
 
+  if (!_bfd_elf_fixup_eh_frame_hdr (info))
+    return FALSE;
+
   /* Since ELF permits relocations to be against local symbols, we
      must have the local symbols available when we do the relocations.
      Since we would rather only read the local symbols once, and we
@@ -11149,21 +11238,11 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
   eoinfo.failed = FALSE;
   eoinfo.flinfo = &flinfo;
   eoinfo.localsyms = TRUE;
-  eoinfo.need_second_pass = FALSE;
-  eoinfo.second_pass = FALSE;
   eoinfo.file_sym_done = FALSE;
   bfd_hash_traverse (&info->hash->table, elf_link_output_extsym, &eoinfo);
   if (eoinfo.failed)
     return FALSE;
 
-  if (eoinfo.need_second_pass)
-    {
-      eoinfo.second_pass = TRUE;
-      bfd_hash_traverse (&info->hash->table, elf_link_output_extsym, &eoinfo);
-      if (eoinfo.failed)
-       return FALSE;
-    }
-
   /* If backend needs to output some local symbols not present in the hash
      table, do it now.  */
   if (bed->elf_backend_output_arch_local_syms
@@ -11968,6 +12047,11 @@ _bfd_elf_gc_mark (struct bfd_link_info *info,
        }
     }
 
+  eh_frame = elf_section_eh_frame_entry (sec);
+  if (ret && eh_frame && !eh_frame->gc_mark)
+    if (!_bfd_elf_gc_mark (info, eh_frame, gc_mark_hook))
+      ret = FALSE;
+
   return ret;
 }
 
@@ -12098,7 +12182,6 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
                                isec->name, ilen) == 0)
                  {
                    dsec->gc_mark = 0;
-                   break;
                  }
              }
          }
@@ -12121,7 +12204,7 @@ elf_gc_sweep_symbol (struct elf_link_hash_entry *h, void *data)
   if (!h->mark
       && (((h->root.type == bfd_link_hash_defined
            || h->root.type == bfd_link_hash_defweak)
-          && !(h->def_regular
+          && !((h->def_regular || ELF_COMMON_DEF_P (h))
                && h->root.u.def.section->gc_mark))
          || h->root.type == bfd_link_hash_undefined
          || h->root.type == bfd_link_hash_undefweak))
@@ -12156,7 +12239,8 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
     {
       asection *o;
 
-      if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
+      if (bfd_get_flavour (sub) != bfd_target_elf_flavour
+         || !(*bed->relocs_compatible) (sub->xvec, abfd->xvec))
        continue;
 
       for (o = sub->sections; o != NULL; o = o->next)
@@ -12344,7 +12428,7 @@ bfd_elf_gc_mark_dynamic_ref_symbol (struct elf_link_hash_entry *h, void *inf)
   if ((h->root.type == bfd_link_hash_defined
        || h->root.type == bfd_link_hash_defweak)
       && (h->ref_dynamic
-         || (h->def_regular
+         || ((h->def_regular || ELF_COMMON_DEF_P (h))
              && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
              && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN
              && (!info->executable
@@ -12383,6 +12467,36 @@ _bfd_elf_gc_keep (struct bfd_link_info *info)
     }
 }
 
+bfd_boolean
+bfd_elf_parse_eh_frame_entries (bfd *abfd ATTRIBUTE_UNUSED,
+                               struct bfd_link_info *info)
+{
+  bfd *ibfd = info->input_bfds;
+
+  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
+    {
+      asection *sec;
+      struct elf_reloc_cookie cookie;
+
+      if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
+       continue;
+
+      if (!init_reloc_cookie (&cookie, info, ibfd))
+       return FALSE;
+
+      for (sec = ibfd->sections; sec; sec = sec->next)
+       {
+         if (CONST_STRNEQ (bfd_section_name (ibfd, sec), ".eh_frame_entry")
+             && init_reloc_cookie_rels (&cookie, info, ibfd, sec))
+           {
+             _bfd_elf_parse_eh_frame_entry (info, sec, &cookie);
+             fini_reloc_cookie_rels (&cookie, sec);
+           }
+       }
+    }
+  return TRUE;
+}
+
 /* Do mark and sweep of unused sections.  */
 
 bfd_boolean
@@ -12406,7 +12520,9 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
 
   /* Try to parse each bfd's .eh_frame section.  Point elf_eh_frame_section
      at the .eh_frame section if we can mark the FDEs individually.  */
-  for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
+  for (sub = info->input_bfds;
+       info->eh_frame_hdr_type != COMPACT_EH_HDR && sub != NULL;
+       sub = sub->link.next)
     {
       asection *sec;
       struct elf_reloc_cookie cookie;
@@ -12443,7 +12559,8 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
     {
       asection *o;
 
-      if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
+      if (bfd_get_flavour (sub) != bfd_target_elf_flavour
+         || !(*bed->relocs_compatible) (sub->xvec, abfd->xvec))
        continue;
 
       /* Start at sections marked with SEC_KEEP (ref _bfd_elf_gc_keep).
@@ -12511,8 +12628,8 @@ bfd_elf_gc_record_vtinherit (bfd *abfd,
  win:
   if (!child->vtable)
     {
-      child->vtable = (struct elf_link_virtual_table_entry *)
-          bfd_zalloc (abfd, sizeof (*child->vtable));
+      child->vtable = ((struct elf_link_virtual_table_entry *)
+                      bfd_zalloc (abfd, sizeof (*child->vtable)));
       if (!child->vtable)
        return FALSE;
     }
@@ -12544,8 +12661,8 @@ bfd_elf_gc_record_vtentry (bfd *abfd ATTRIBUTE_UNUSED,
 
   if (!h->vtable)
     {
-      h->vtable = (struct elf_link_virtual_table_entry *)
-          bfd_zalloc (abfd, sizeof (*h->vtable));
+      h->vtable = ((struct elf_link_virtual_table_entry *)
+                  bfd_zalloc (abfd, sizeof (*h->vtable)));
       if (!h->vtable)
        return FALSE;
     }
@@ -12909,7 +13026,9 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
        }
     }
 
-  o = bfd_get_section_by_name (output_bfd, ".eh_frame");
+  o = NULL;
+  if (info->eh_frame_hdr_type != COMPACT_EH_HDR)
+    o = bfd_get_section_by_name (output_bfd, ".eh_frame");
   if (o != NULL)
     {
       asection *i;
@@ -12957,7 +13076,10 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
        }
     }
 
-  if (info->eh_frame_hdr
+  if (info->eh_frame_hdr_type == COMPACT_EH_HDR)
+    _bfd_elf_end_eh_frame_parsing (info);
+
+  if (info->eh_frame_hdr_type
       && !info->relocatable
       && _bfd_elf_discard_section_eh_frame_hdr (output_bfd, info))
     changed = 1;
@@ -13203,11 +13325,11 @@ _bfd_elf_get_dynamic_reloc_section (bfd *       abfd,
    string table associated with ABFD.  */
 
 asection *
-_bfd_elf_make_dynamic_reloc_section (asection *         sec,
-                                    bfd *              dynobj,
-                                    unsigned int       alignment,
-                                    bfd *              abfd,
-                                    bfd_boolean        is_rela)
+_bfd_elf_make_dynamic_reloc_section (asection *sec,
+                                    bfd *dynobj,
+                                    unsigned int alignment,
+                                    bfd *abfd,
+                                    bfd_boolean is_rela)
 {
   asection * reloc_sec = elf_section_data (sec)->sreloc;
 
@@ -13263,7 +13385,7 @@ _bfd_elf_copy_link_hash_symbol_type (bfd *abfd,
   ehdest->target_internal = ehsrc->target_internal;
 
   isym.st_other = ehsrc->other;
-  elf_merge_st_other (abfd, ehdest, &isym, TRUE, FALSE);
+  elf_merge_st_other (abfd, ehdest, &isym, NULL, TRUE, FALSE);
 }
 
 /* Append a RELA relocation REL to section S in BFD.  */
This page took 0.038854 seconds and 4 git commands to generate.