This is the mail archive of the binutils@sourceware.org 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]

_bfd_elf_sprintf_vma and _bfd_elf_fprintf_vma


This deletes two half-baked elf.c functions that don't compile when 
BFD_HOST_64BIT_LONG_LONG is true but not BFD_HOST_64BIT_LONG, and
removes their corresponding struct elf_backend_data entries.  The
single place each function was called now does simpler and more robust
target size detection, and both bfd_sprintf_vma and bfd_fprintf_vma
now use the same logic.

bfd/
	* elf-bfd.h (struct elf_backend_data): Delete elf_backend_sprintf_vma
	and elf_backend_fprintf_vma.
	(_bfd_elf_sprintf_vma, _bfd_elf_fprintf_vma): Delete.
	* elf.c (_bfd_elf_sprintf_vma, _bfd_elf_fprintf_vma): Delete.
	* elfxx-target.h (elf_backend_sprintf_vma): Don't define.
	(elf_backend_fprintf_vma): Likewise.
	(elfNN_bed): Don't init removed fields.
	* bfd.c (is32bit): New function.
	(bfd_sprintf_vma, bfd_fprintf_vma): Use the above.

Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.240
diff -u -p -r1.240 elf-bfd.h
--- bfd/elf-bfd.h	24 Aug 2007 15:11:12 -0000	1.240
+++ bfd/elf-bfd.h	12 Sep 2007 08:03:32 -0000
@@ -953,12 +953,6 @@ struct elf_backend_data
   char *(*elf_backend_write_core_note)
     (bfd *abfd, char *buf, int *bufsiz, int note_type, ...);
 
-  /* Functions to print VMAs.  Special code to handle 64 bit ELF files.  */
-  void (* elf_backend_sprintf_vma)
-    (bfd *, char *, bfd_vma);
-  void (* elf_backend_fprintf_vma)
-    (bfd *, void *, bfd_vma);
-
   /* This function returns class of a reloc type.  */
   enum elf_reloc_type_class (*elf_backend_reloc_type_class)
     (const Elf_Internal_Rela *);
@@ -1552,11 +1546,6 @@ extern bfd_boolean _bfd_elf_print_privat
 extern void bfd_elf_print_symbol
   (bfd *, void *, asymbol *, bfd_print_symbol_type);
 
-extern void _bfd_elf_sprintf_vma
-  (bfd *, char *, bfd_vma);
-extern void _bfd_elf_fprintf_vma
-  (bfd *, void *, bfd_vma);
-
 extern unsigned int _bfd_elf_eh_frame_address_size
   (bfd *, asection *);
 extern bfd_byte _bfd_elf_encode_eh_address
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.414
diff -u -p -r1.414 elf.c
--- bfd/elf.c	8 Sep 2007 11:03:31 -0000	1.414
+++ bfd/elf.c	12 Sep 2007 08:03:37 -0000
@@ -8415,63 +8415,6 @@ bfd_get_elf_phdrs (bfd *abfd, void *phdr
   return num_phdrs;
 }
 
-void
-_bfd_elf_sprintf_vma (bfd *abfd ATTRIBUTE_UNUSED, char *buf, bfd_vma value)
-{
-#ifdef BFD64
-  Elf_Internal_Ehdr *i_ehdrp;	/* Elf file header, internal form */
-
-  i_ehdrp = elf_elfheader (abfd);
-  if (i_ehdrp == NULL)
-    sprintf_vma (buf, value);
-  else
-    {
-      if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
-	{
-#if BFD_HOST_64BIT_LONG
-	  sprintf (buf, "%016lx", value);
-#else
-	  sprintf (buf, "%08lx%08lx", _bfd_int64_high (value),
-		   _bfd_int64_low (value));
-#endif
-	}
-      else
-	sprintf (buf, "%08lx", (unsigned long) (value & 0xffffffff));
-    }
-#else
-  sprintf_vma (buf, value);
-#endif
-}
-
-void
-_bfd_elf_fprintf_vma (bfd *abfd ATTRIBUTE_UNUSED, void *stream, bfd_vma value)
-{
-#ifdef BFD64
-  Elf_Internal_Ehdr *i_ehdrp;	/* Elf file header, internal form */
-
-  i_ehdrp = elf_elfheader (abfd);
-  if (i_ehdrp == NULL)
-    fprintf_vma ((FILE *) stream, value);
-  else
-    {
-      if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
-	{
-#if BFD_HOST_64BIT_LONG
-	  fprintf ((FILE *) stream, "%016lx", value);
-#else
-	  fprintf ((FILE *) stream, "%08lx%08lx",
-		   _bfd_int64_high (value), _bfd_int64_low (value));
-#endif
-	}
-      else
-	fprintf ((FILE *) stream, "%08lx",
-		 (unsigned long) (value & 0xffffffff));
-    }
-#else
-  fprintf_vma ((FILE *) stream, value);
-#endif
-}
-
 enum elf_reloc_type_class
 _bfd_elf_reloc_type_class (const Elf_Internal_Rela *rela ATTRIBUTE_UNUSED)
 {
Index: bfd/elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.109
diff -u -p -r1.109 elfxx-target.h
--- bfd/elfxx-target.h	20 Aug 2007 13:05:26 -0000	1.109
+++ bfd/elfxx-target.h	12 Sep 2007 08:03:39 -0000
@@ -494,12 +494,6 @@
 #ifndef elf_backend_write_core_note
 #define elf_backend_write_core_note		NULL
 #endif
-#ifndef elf_backend_sprintf_vma
-#define elf_backend_sprintf_vma			_bfd_elf_sprintf_vma
-#endif
-#ifndef elf_backend_fprintf_vma
-#define elf_backend_fprintf_vma			_bfd_elf_fprintf_vma
-#endif
 #ifndef elf_backend_reloc_type_class
 #define elf_backend_reloc_type_class		_bfd_elf_reloc_type_class
 #endif
@@ -676,8 +670,6 @@ static struct elf_backend_data elfNN_bed
   elf_backend_grok_prstatus,
   elf_backend_grok_psinfo,
   elf_backend_write_core_note,
-  elf_backend_sprintf_vma,
-  elf_backend_fprintf_vma,
   elf_backend_reloc_type_class,
   elf_backend_discard_info,
   elf_backend_ignore_discarded_relocs,
Index: bfd/bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.97
diff -u -p -r1.97 bfd.c
--- bfd/bfd.c	26 Jul 2007 11:05:23 -0000	1.97
+++ bfd/bfd.c	12 Sep 2007 08:03:22 -0000
@@ -1376,31 +1376,51 @@ bfd_record_phdr (bfd *abfd,
   return TRUE;
 }
 
-void
-bfd_sprintf_vma (bfd *abfd, char *buf, bfd_vma value)
+#ifdef BFD64
+/* Return true iff this target is 32-bit.  */
+
+static bfd_boolean
+is32bit (bfd *abfd)
 {
   if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
-    get_elf_backend_data (abfd)->elf_backend_sprintf_vma (abfd, buf, value);
-  else
-    sprintf_vma (buf, value);
+    {
+      const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+      return bed->s->elfclass == ELFCLASS32;
+    }
+
+  /* For non-ELF, make a guess based on the target name.  */
+  return (strstr (bfd_get_target (abfd), "64") == NULL
+	  && strcmp (bfd_get_target (abfd), "mmo") != 0);
 }
+#endif
+
+/* bfd_sprintf_vma and bfd_fprintf_vma display an address in the
+   target's address size.  */
 
 void
-bfd_fprintf_vma (bfd *abfd, void *stream, bfd_vma value)
+bfd_sprintf_vma (bfd *abfd ATTRIBUTE_UNUSED, char *buf, bfd_vma value)
 {
-  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
-    get_elf_backend_data (abfd)->elf_backend_fprintf_vma (abfd, stream, value);
 #ifdef BFD64
-  /* fprintf_vma() on a 64-bit enabled host will always print a 64-bit
-     value, but really we want to display the address in the target's
-     address size.  Since we do not have a field in the bfd structure
-     to tell us this, we take a guess, based on the target's name.  */
-  else if (strstr (bfd_get_target (abfd), "64") == NULL
-	   && strcmp (bfd_get_target (abfd), "mmo") != 0)
-    fprintf ((FILE *) stream, "%08lx", (unsigned long) (value & 0xffffffff));
+  if (is32bit (abfd))
+    {
+      sprintf (buf, "%08lx", (unsigned long) value & 0xffffffff);
+      return;
+    }
+#endif
+  sprintf_vma (buf, value);
+}
+
+void
+bfd_fprintf_vma (bfd *abfd ATTRIBUTE_UNUSED, void *stream, bfd_vma value)
+{
+#ifdef BFD64
+  if (is32bit (abfd))
+    {
+      fprintf ((FILE *) stream, "%08lx", (unsigned long) value & 0xffffffff);
+      return;
+    }
 #endif
-  else
-    fprintf_vma ((FILE *) stream, value);
+  fprintf_vma ((FILE *) stream, value);
 }
 
 /*

-- 
Alan Modra
Australia Development Lab, IBM


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