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_vma printing


This patch simplifies code printing bfd_vma values.  I'm reasonably
certain that _bfd_int64_low/high is no longer needed, and in fact
should have disappeared when the printf_vma changes for __MSVCRT__
were added.

bfd/
	PR 6769
	* bfd-in.h (BFD_VMA_FMT): Define.
	(printf_vma, sprintf_vma): Use the above.
	(_bfd_int64_low, _bfd_int64_high): Delete.
	* bfd-in2.h: Regenerate.
binutils/
	PR 6769
	* readelf.c (print_dec_vma, print_hex_vma): Delete.
	(print_vma): Use BFD_VMA_FMT.
	* size.c (size_number, rprint_number): Likewise.

Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.138
diff -u -p -r1.138 bfd-in.h
--- bfd/bfd-in.h	18 Jul 2008 20:49:12 -0000	1.138
+++ bfd/bfd-in.h	28 Jul 2008 03:17:37 -0000
@@ -128,26 +128,17 @@ typedef BFD_HOST_64_BIT bfd_signed_vma;
 typedef BFD_HOST_U_64_BIT bfd_size_type;
 typedef BFD_HOST_U_64_BIT symvalue;
 
-#ifndef fprintf_vma
 #if BFD_HOST_64BIT_LONG
-#define sprintf_vma(s,x) sprintf (s, "%016lx", x)
-#define fprintf_vma(f,x) fprintf (f, "%016lx", x)
-#elif BFD_HOST_64BIT_LONG_LONG
-#ifndef __MSVCRT__
-#define sprintf_vma(s,x) sprintf (s, "%016llx", x)
-#define fprintf_vma(f,x) fprintf (f, "%016llx", x)
-#else
-#define sprintf_vma(s,x) sprintf (s, "%016I64x", x)
-#define fprintf_vma(f,x) fprintf (f, "%016I64x", x)
-#endif
+#define BFD_VMA_FMT "l"
+#elif defined (__MSVCRT__)
+#define BFD_VMA_FMT "I64"
 #else
-#define _bfd_int64_low(x) ((unsigned long) (((x) & 0xffffffff)))
-#define _bfd_int64_high(x) ((unsigned long) (((x) >> 32) & 0xffffffff))
-#define fprintf_vma(s,x) \
-  fprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
-#define sprintf_vma(s,x) \
-  sprintf ((s), "%08lx%08lx", _bfd_int64_high (x), _bfd_int64_low (x))
+#define BFD_VMA_FMT "ll"
 #endif
+
+#ifndef fprintf_vma
+#define sprintf_vma(s,x) sprintf (s, "%016" BFD_VMA_FMT "x", x)
+#define fprintf_vma(f,x) fprintf (f, "%016" BFD_VMA_FMT "x", x)
 #endif
 
 #else /* not BFD64  */
@@ -167,8 +158,9 @@ typedef unsigned long symvalue;
 typedef unsigned long bfd_size_type;
 
 /* Print a bfd_vma x on stream s.  */
-#define fprintf_vma(s,x) fprintf (s, "%08lx", x)
-#define sprintf_vma(s,x) sprintf (s, "%08lx", x)
+#define BFD_VMA_FMT "l"
+#define fprintf_vma(s,x) fprintf (s, "%08" BFD_VMA_FMT "x", x)
+#define sprintf_vma(s,x) sprintf (s, "%08" BFD_VMA_FMT "x", x)
 
 #endif /* not BFD64  */
 
Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.417
diff -u -p -d -w -r1.417 readelf.c
--- binutils/readelf.c	26 Jul 2008 13:10:47 -0000	1.417
+++ binutils/readelf.c	28 Jul 2008 03:51:36 -0000
@@ -372,95 +372,10 @@ byte_put_little_endian (unsigned char *f
     }
 }
 
-#if defined BFD64 && !BFD_HOST_64BIT_LONG && !BFD_HOST_64BIT_LONG_LONG
-static int
-print_dec_vma (bfd_vma vma, int is_signed)
-{
-  char buf[40];
-  char *bufp = buf;
-  int nc = 0;
-
-  if (is_signed && (bfd_signed_vma) vma < 0)
-    {
-      vma = -vma;
-      putchar ('-');
-      nc = 1;
-    }
-
-  do
-    {
-      *bufp++ = '0' + vma % 10;
-      vma /= 10;
-    }
-  while (vma != 0);
-  nc += bufp - buf;
-
-  while (bufp > buf)
-    putchar (*--bufp);
-  return nc;
-}
-
-static int
-print_hex_vma (bfd_vma vma)
-{
-  char buf[32];
-  char *bufp = buf;
-  int nc;
-
-  do
-    {
-      char digit = '0' + (vma & 0x0f);
-      if (digit > '9')
-	digit += 'a' - '0' - 10;
-      *bufp++ = digit;
-      vma >>= 4;
-    }
-  while (vma != 0);
-  nc = bufp - buf;
-
-  while (bufp > buf)
-    putchar (*--bufp);
-  return nc;
-}
-#endif
-
 /* Print a VMA value.  */
 static int
 print_vma (bfd_vma vma, print_mode mode)
 {
-#ifdef BFD64
-  if (is_32bit_elf)
-#endif
-    {
-      switch (mode)
-	{
-	case FULL_HEX:
-	  return printf ("0x%8.8lx", (unsigned long) vma);
-
-	case LONG_HEX:
-	  return printf ("%8.8lx", (unsigned long) vma);
-
-	case DEC_5:
-	  if (vma <= 99999)
-	    return printf ("%5ld", (long) vma);
-	  /* Drop through.  */
-
-	case PREFIX_HEX:
-	  return printf ("0x%lx", (unsigned long) vma);
-
-	case HEX:
-	  return printf ("%lx", (unsigned long) vma);
-
-	case DEC:
-	  return printf ("%ld", (unsigned long) vma);
-
-	case UNSIGNED:
-	  return printf ("%lu", (unsigned long) vma);
-	}
-    }
-#ifdef BFD64
-  else
-    {
       int nc = 0;
 
       switch (mode)
@@ -470,79 +385,31 @@ print_vma (bfd_vma vma, print_mode mode)
 	  /* Drop through.  */
 
 	case LONG_HEX:
+#ifdef BFD64
+      if (is_32bit_elf)
+	return nc + printf ("%08.8" BFD_VMA_FMT "x", vma);
+#endif
 	  printf_vma (vma);
 	  return nc + 16;
 
+    case DEC_5:
+      if (vma <= 99999)
+	return printf ("%5" BFD_VMA_FMT "d", vma);
+      /* Drop through.  */
+
 	case PREFIX_HEX:
 	  nc = printf ("0x");
 	  /* Drop through.  */
 
 	case HEX:
-#if BFD_HOST_64BIT_LONG
-	  return nc + printf ("%lx", vma);
-#elif BFD_HOST_64BIT_LONG_LONG
-#ifndef __MSVCRT__
-	  return nc + printf ("%llx", vma);
-#else
-	  return nc + printf ("%I64x", vma);
-#endif
-#else
-	  return nc + print_hex_vma (vma);
-#endif
+      return nc + printf ("%" BFD_VMA_FMT "x", vma);
 
 	case DEC:
-#if BFD_HOST_64BIT_LONG
-	  return printf ("%ld", vma);
-#elif BFD_HOST_64BIT_LONG_LONG
-#ifndef __MSVCRT__
-	  return printf ("%lld", vma);
-#else
-	  return printf ("%I64d", vma);
-#endif
-#else
-	  return print_dec_vma (vma, 1);
-#endif
-
-	case DEC_5:
-#if BFD_HOST_64BIT_LONG
-	  if (vma <= 99999)
-	    return printf ("%5ld", vma);
-	  else
-	    return printf ("%#lx", vma);
-#elif BFD_HOST_64BIT_LONG_LONG
-#ifndef __MSVCRT__
-	  if (vma <= 99999)
-	    return printf ("%5lld", vma);
-	  else
-	    return printf ("%#llx", vma);
-#else
-	  if (vma <= 99999)
-	    return printf ("%5I64d", vma);
-	  else
-	    return printf ("%#I64x", vma);
-#endif
-#else
-	  if (vma <= 99999)
-	    return printf ("%5ld", _bfd_int64_low (vma));
-	  else
-	    return print_hex_vma (vma);
-#endif
+      return printf ("%" BFD_VMA_FMT "d", vma);
 
 	case UNSIGNED:
-#if BFD_HOST_64BIT_LONG
-	  return printf ("%lu", vma);
-#elif BFD_HOST_64BIT_LONG_LONG
-#ifndef __MSVCRT__
-	  return printf ("%llu", vma);
-#else
-	  return printf ("%I64u", vma);
-#endif
-#else
-	  return print_dec_vma (vma, 0);
-#endif
-	}
+      return printf ("%" BFD_VMA_FMT "u", vma);
     }
-#endif
   return 0;
 }
 
Index: binutils/size.c
===================================================================
RCS file: /cvs/src/src/binutils/size.c,v
retrieving revision 1.30
diff -u -p -r1.30 size.c
--- binutils/size.c	5 Jul 2007 16:54:45 -0000	1.30
+++ binutils/size.c	28 Jul 2008 03:18:08 -0000
@@ -406,17 +406,15 @@ display_file (char *filename)
     }
 }
 
-/* This is what lexical functions are for.  */
-
 static int
 size_number (bfd_size_type num)
 {
   char buffer[40];
 
   sprintf (buffer,
-	   (radix == decimal ? "%lu" :
-	   ((radix == octal) ? "0%lo" : "0x%lx")),
-	   (unsigned long) num);
+	   (radix == decimal ? "%" BFD_VMA_FMT "u" :
+	   ((radix == octal) ? "0%" BFD_VMA_FMT "o" : "0x%" BFD_VMA_FMT "x")),
+	   num);
 
   return strlen (buffer);
 }
@@ -427,9 +425,9 @@ rprint_number (int width, bfd_size_type 
   char buffer[40];
 
   sprintf (buffer,
-	   (radix == decimal ? "%lu" :
-	   ((radix == octal) ? "0%lo" : "0x%lx")),
-	   (unsigned long) num);
+	   (radix == decimal ? "%" BFD_VMA_FMT "u" :
+	   ((radix == octal) ? "0%" BFD_VMA_FMT "o" : "0x%" BFD_VMA_FMT "x")),
+	   num);
 
   printf ("%*s", width, buffer);
 }

-- 
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]