This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] MIPS bfd: move elf32_mips_discard_info, elf32_mips_write_section to elfxx-mips.c


Hi All,

this patch moves elf32_mips_discard_info() and elf32_mips_write_section()
from elf32-mips.c to elfxx-mips.c because it can be used with o32, n32
and n64 backends. It also lets elf64-mips.c use
_bfd_mips_elf_ignore_discarded_relocs() and _bfd_mips_elf_write_section()
which were seemingly omitted there by accident.


Thiemo


2002-07-19  Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>

	/bfd/ChangeLog
	* elfxx-mips.c (_bfd_mips_elf_discard_info): New function, code from
	elf32-mips.c.
	(_bfd_mips_elf_write_section): Likewise.
	* elfxx-mips.h (_bfd_mips_elf_discard_info): New prototype.
	(_bfd_mips_elf_write_section): Likewise.
	* elf32-mips.c (elf32_mips_discard_info): Move to elfxx-mips.c.
	(elf32_mips_write_section): Likewise.
	* elf64-mips.c (_bfd_mips_elf_ignore_discarded_relocs): Use it.
	(_bfd_mips_elf_write_section): Likewise.


diff -BurpNX /bigdisk/src/gcc-exclude source-orig/bfd/elf32-mips.c source/bfd/elf32-mips.c
--- source-orig/bfd/elf32-mips.c	Thu Jul 11 21:23:07 2002
+++ source/bfd/elf32-mips.c	Fri Jul 19 20:36:30 2002
@@ -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 *));
 
@@ -1660,103 +1659,6 @@ elf32_mips_grok_psinfo (abfd, note)
   return true;
 }
 
-#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
@@ -2007,10 +1909,9 @@ static const struct ecoff_debug_swap mip
 #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 \
diff -BurpNX /bigdisk/src/gcc-exclude source-orig/bfd/elf64-mips.c source/bfd/elf64-mips.c
--- source-orig/bfd/elf64-mips.c	Sun Jun  9 00:22:22 2002
+++ source/bfd/elf64-mips.c	Fri Jul 12 13:18:58 2002
@@ -2735,6 +2688,10 @@ const struct elf_size_info mips_elf64_si
 #define elf_backend_may_use_rel_p	1
 #define elf_backend_may_use_rela_p	1
 #define elf_backend_default_use_rela_p	1
+
+#define elf_backend_ignore_discarded_relocs \
+					_bfd_mips_elf_ignore_discarded_relocs
+#define elf_backend_write_section	_bfd_mips_elf_write_section
 
 /* We don't set bfd_elf64_bfd_is_local_label_name because the 32-bit
    MIPS-specific function only applies to IRIX5, which had no 64-bit
diff -BurpNX /bigdisk/src/gcc-exclude source-orig/bfd/elfxx-mips.c source/bfd/elfxx-mips.c
--- source-orig/bfd/elfxx-mips.c	Thu Jul 11 21:23:11 2002
+++ source/bfd/elfxx-mips.c	Fri Jul 12 13:18:58 2002
@@ -6415,6 +6421,70 @@ _bfd_mips_elf_hide_symbol (info, entry, 
   got->_raw_size += MIPS_ELF_GOT_SIZE (dynobj);
 }
 
+#define PDR_SIZE 32
+
+boolean
+_bfd_mips_elf_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;
+}
+
 boolean
 _bfd_mips_elf_ignore_discarded_relocs (sec)
      asection *sec;
@@ -6422,6 +6492,39 @@ _bfd_mips_elf_ignore_discarded_relocs (s
   if (strcmp (sec->name, ".pdr") == 0)
     return true;
   return false;
+}
+
+boolean
+_bfd_mips_elf_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;
 }
 
 /* MIPS ELF uses a special find_nearest_line routine in order the
diff -BurpNX /bigdisk/src/gcc-exclude source-orig/bfd/elfxx-mips.h source/bfd/elfxx-mips.h
--- source-orig/bfd/elfxx-mips.h	Thu Jul 11 21:23:11 2002
+++ source/bfd/elfxx-mips.h	Fri Jul 12 13:18:58 2002
@@ -91,6 +91,10 @@ extern boolean _bfd_mips_elf_set_private
   PARAMS ((bfd *, flagword));
 extern boolean _bfd_mips_elf_print_private_bfd_data
   PARAMS ((bfd *, PTR));
+extern boolean _bfd_mips_elf_discard_info
+  PARAMS ((bfd *, struct elf_reloc_cookie *, struct bfd_link_info *));
+extern boolean _bfd_mips_elf_write_section
+  PARAMS ((bfd *, asection *, bfd_byte *));
 
 extern boolean _bfd_mips_elf_read_ecoff_info
   PARAMS ((bfd *, asection *, struct ecoff_debug_info *));


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]