* elflink.h (elf_link_output_extsym): Don't output symbols from
[deliverable/binutils-gdb.git] / bfd / elf32-mips.c
index de9cf2f8f472479711f32696864c4abd045c9284..f1667321025e18f3c87f0adb45f2f1bdac62fc22 100644 (file)
@@ -80,10 +80,6 @@ static boolean elf32_mips_grok_prstatus
   PARAMS ((bfd *, Elf_Internal_Note *));
 static boolean elf32_mips_grok_psinfo
   PARAMS ((bfd *, Elf_Internal_Note *));
-static boolean elf32_mips_discard_info
-  PARAMS ((bfd *, struct elf_reloc_cookie *, struct bfd_link_info *));
-static boolean elf32_mips_write_section
-  PARAMS ((bfd *, asection *, bfd_byte *));
 static irix_compat_t elf32_mips_irix_compat
   PARAMS ((bfd *));
 
@@ -1391,7 +1387,7 @@ struct elf_reloc_map {
 
 static const struct elf_reloc_map mips_reloc_map[] =
 {
-  { BFD_RELOC_NONE, R_MIPS_NONE, },
+  { BFD_RELOC_NONE, R_MIPS_NONE },
   { BFD_RELOC_16, R_MIPS_16 },
   { BFD_RELOC_32, R_MIPS_32 },
   /* There is no BFD reloc for R_MIPS_REL32.  */
@@ -1574,6 +1570,9 @@ mips_elf32_object_p (abfd)
   if (SGI_COMPAT (abfd))
     elf_bad_symtab (abfd) = true;
 
+  if (ABI_N32_P (abfd))
+    return false;
+
   mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
   bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
 
@@ -1660,103 +1659,6 @@ elf32_mips_grok_psinfo (abfd, note)
   return true;
 }
 \f
-#define PDR_SIZE 32
-
-static boolean
-elf32_mips_discard_info (abfd, cookie, info)
-     bfd *abfd;
-     struct elf_reloc_cookie *cookie;
-     struct bfd_link_info *info;
-{
-  asection *o;
-  boolean ret = false;
-  unsigned char *tdata;
-  size_t i, skip;
-
-  o = bfd_get_section_by_name (abfd, ".pdr");
-  if (! o)
-    return false;
-  if (o->_raw_size == 0)
-    return false;
-  if (o->_raw_size % PDR_SIZE != 0)
-    return false;
-  if (o->output_section != NULL
-      && bfd_is_abs_section (o->output_section))
-    return false;
-
-  tdata = bfd_zmalloc (o->_raw_size / PDR_SIZE);
-  if (! tdata)
-    return false;
-
-  cookie->rels = _bfd_elf32_link_read_relocs (abfd, o, (PTR) NULL,
-                                            (Elf_Internal_Rela *) NULL,
-                                             info->keep_memory);
-  if (!cookie->rels)
-    {
-      free (tdata);
-      return false;
-    }
-
-  cookie->rel = cookie->rels;
-  cookie->relend = cookie->rels + o->reloc_count;
-
-  for (i = 0, skip = 0; i < o->_raw_size; i ++)
-    {
-      if (_bfd_elf32_reloc_symbol_deleted_p (i * PDR_SIZE, cookie))
-       {
-         tdata[i] = 1;
-         skip ++;
-       }
-    }
-
-  if (skip != 0)
-    {
-      elf_section_data (o)->tdata = tdata;
-      o->_cooked_size = o->_raw_size - skip * PDR_SIZE;
-      ret = true;
-    }
-  else
-    free (tdata);
-
-  if (! info->keep_memory)
-    free (cookie->rels);
-
-  return ret;
-}
-
-static boolean
-elf32_mips_write_section (output_bfd, sec, contents)
-     bfd *output_bfd;
-     asection *sec;
-     bfd_byte *contents;
-{
-  bfd_byte *to, *from, *end;
-  int i;
-
-  if (strcmp (sec->name, ".pdr") != 0)
-    return false;
-
-  if (elf_section_data (sec)->tdata == NULL)
-    return false;
-
-  to = contents;
-  end = contents + sec->_raw_size;
-  for (from = contents, i = 0;
-       from < end;
-       from += PDR_SIZE, i++)
-    {
-      if (((unsigned char *)elf_section_data (sec)->tdata)[i] == 1)
-       continue;
-      if (to != from)
-       memcpy (to, from, PDR_SIZE);
-      to += PDR_SIZE;
-    }
-  bfd_set_section_contents (output_bfd, sec->output_section, contents,
-                           (file_ptr) sec->output_offset,
-                           sec->_cooked_size);
-  return true;
-}
-
 /* Depending on the target vector we generate some version of Irix
    executables or "normal" MIPS ELF ABI executables.  */
 static irix_compat_t
@@ -1786,15 +1688,10 @@ bfd_mips_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
      char **errmsg;
 {
   Elf_Internal_Shdr *symtab_hdr;
-  Elf_Internal_Shdr *shndx_hdr;
-  Elf32_External_Sym *extsyms;
-  Elf32_External_Sym *free_extsyms = NULL;
-  Elf_External_Sym_Shndx *shndx_buf = NULL;
-  Elf_Internal_Rela *internal_relocs;
-  Elf_Internal_Rela *free_relocs = NULL;
+  Elf_Internal_Sym *isymbuf = NULL;
+  Elf_Internal_Rela *internal_relocs = NULL;
   Elf_Internal_Rela *irel, *irelend;
   bfd_byte *p;
-  bfd_size_type amt;
 
   BFD_ASSERT (! info->relocateable);
 
@@ -1803,41 +1700,17 @@ bfd_mips_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
   if (datasec->reloc_count == 0)
     return true;
 
-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   /* Read this BFD's symbols if we haven't done so already, or get the cached
      copy if it exists.  */
-  if (symtab_hdr->contents != NULL)
-    extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
-  else
-    {
-      /* Go get them off disk.  */
-      if (info->keep_memory)
-       extsyms = ((Elf32_External_Sym *)
-                  bfd_alloc (abfd, symtab_hdr->sh_size));
-      else
-       extsyms = ((Elf32_External_Sym *)
-                  bfd_malloc (symtab_hdr->sh_size));
-      if (extsyms == NULL)
-       goto error_return;
-      if (! info->keep_memory)
-       free_extsyms = extsyms;
-      if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
-         || (bfd_bread (extsyms, symtab_hdr->sh_size, abfd)
-             != symtab_hdr->sh_size))
-       goto error_return;
-      if (info->keep_memory)
-       symtab_hdr->contents = (unsigned char *) extsyms;
-    }
-
-  shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
-  if (shndx_hdr->sh_size != 0)
+  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  if (symtab_hdr->sh_info != 0)
     {
-      amt = symtab_hdr->sh_info * sizeof (Elf_External_Sym_Shndx);
-      shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
-      if (shndx_buf == NULL)
-       goto error_return;
-      if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0
-         || bfd_bread ((PTR) shndx_buf, amt, abfd) != amt)
+      isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
+      if (isymbuf == NULL)
+       isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
+                                       symtab_hdr->sh_info, 0,
+                                       NULL, NULL, NULL);
+      if (isymbuf == NULL)
        goto error_return;
     }
 
@@ -1847,8 +1720,6 @@ bfd_mips_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
                      info->keep_memory));
   if (internal_relocs == NULL)
     goto error_return;
-  if (! info->keep_memory)
-    free_relocs = internal_relocs;
 
   relsec->contents = (bfd_byte *) bfd_alloc (abfd, datasec->reloc_count * 12);
   if (relsec->contents == NULL)
@@ -1879,17 +1750,11 @@ bfd_mips_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
       /* Get the target section referred to by the reloc.  */
       if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
        {
-          Elf32_External_Sym *esym;
-          Elf_External_Sym_Shndx *shndx;
-          Elf_Internal_Sym isym;
+          Elf_Internal_Sym *isym;
 
           /* A local symbol.  */
-          esym = extsyms + ELF32_R_SYM (irel->r_info);
-          shndx = shndx_buf + (shndx_buf ? ELF32_R_SYM (irel->r_info) : 0);
-         bfd_elf32_swap_symbol_in (abfd, (const PTR *) esym,
-                                   (const PTR *) shndx, &isym);
-
-         targetsec = bfd_section_from_elf_index (abfd, isym.st_shndx);
+         isym = isymbuf + ELF32_R_SYM (irel->r_info);
+         targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
        }
       else
        {
@@ -1926,21 +1791,21 @@ bfd_mips_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
        strncpy (p + 4, targetsec->output_section->name, 8);
     }
 
-  if (shndx_buf != NULL)
-    free (shndx_buf);
-  if (free_extsyms != NULL)
-    free (free_extsyms);
-  if (free_relocs != NULL)
-    free (free_relocs);
+  if (internal_relocs != NULL
+      && elf_section_data (datasec)->relocs != internal_relocs)
+    free (internal_relocs);
+  if (isymbuf != NULL
+      && symtab_hdr->contents != (unsigned char *) isymbuf)
+    free (isymbuf);
   return true;
 
  error_return:
-  if (shndx_buf != NULL)
-    free (shndx_buf);
-  if (free_extsyms != NULL)
-    free (free_extsyms);
-  if (free_relocs != NULL)
-    free (free_relocs);
+  if (internal_relocs != NULL
+      && elf_section_data (datasec)->relocs != internal_relocs)
+    free (internal_relocs);
+  if (isymbuf != NULL
+      && symtab_hdr->contents != (unsigned char *) isymbuf)
+    free (isymbuf);
   return false;
 }
 \f
@@ -2044,10 +1909,9 @@ static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
 #define elf_backend_default_use_rela_p 0
 #define elf_backend_sign_extend_vma    true
 
-#define elf_backend_discard_info       elf32_mips_discard_info
+#define elf_backend_discard_info       _bfd_mips_elf_discard_info
 #define elf_backend_ignore_discarded_relocs \
                                        _bfd_mips_elf_ignore_discarded_relocs
-#define elf_backend_write_section      elf32_mips_write_section
 #define elf_backend_mips_irix_compat   elf32_mips_irix_compat
 #define elf_backend_mips_rtype_to_howto        mips_elf32_rtype_to_howto
 #define bfd_elf32_bfd_is_local_label_name \
This page took 0.026566 seconds and 4 git commands to generate.