From 7e0cfb2c2458c743e900c023b6de94c77ad12529 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 28 Jul 2008 04:07:32 +0000 Subject: [PATCH] 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. --- bfd/ChangeLog | 8 +++ bfd/bfd-in.h | 30 ++++----- bfd/bfd-in2.h | 30 ++++----- binutils/ChangeLog | 7 +++ binutils/readelf.c | 181 +++++++---------------------------------------------- binutils/size.c | 17 +++-- 6 files changed, 69 insertions(+), 204 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 643d7893e..33b9ccca1 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2008-07-28 Alan Modra + + 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. + 2008-07-27 Alan Modra * elf.c (_bfd_elf_make_section_from_shdr): Ignore return from diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index 21f4f4c78..827cc1a68 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -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 */ diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 087eff890..f8e34acd9 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -135,26 +135,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 */ @@ -174,8 +165,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 */ diff --git a/binutils/ChangeLog b/binutils/ChangeLog index fd95457c7..3ca5ad979 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,10 @@ +2008-07-28 Alan Modra + + PR 6769 + * readelf.c (print_dec_vma, print_hex_vma): Delete. + (print_vma): Use BFD_VMA_FMT. + * size.c (size_number, rprint_number): Likewise. + 2008-07-26 Michael Eager * readelf.c (display_power_gnu_attribute): Display diff --git a/binutils/readelf.c b/binutils/readelf.c index 8b0e13ac8..236816d72 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -372,177 +372,44 @@ byte_put_little_endian (unsigned char *field, bfd_vma value, int size) } } -#if defined BFD64 && !BFD_HOST_64BIT_LONG && !BFD_HOST_64BIT_LONG_LONG +/* Print a VMA value. */ static int -print_dec_vma (bfd_vma vma, int is_signed) +print_vma (bfd_vma vma, print_mode mode) { - 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 + switch (mode) { - char digit = '0' + (vma & 0x0f); - if (digit > '9') - digit += 'a' - '0' - 10; - *bufp++ = digit; - vma >>= 4; - } - while (vma != 0); - nc = bufp - buf; + case FULL_HEX: + nc = printf ("0x"); + /* Drop through. */ - while (bufp > buf) - putchar (*--bufp); - return nc; -} -#endif - -/* Print a VMA value. */ -static int -print_vma (bfd_vma vma, print_mode mode) -{ + case LONG_HEX: #ifdef BFD64 - if (is_32bit_elf) + if (is_32bit_elf) + return nc + printf ("%08.8" BFD_VMA_FMT "x", vma); #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; + printf_vma (vma); + return nc + 16; - switch (mode) - { - case FULL_HEX: - nc = printf ("0x"); - /* Drop through. */ + case DEC_5: + if (vma <= 99999) + return printf ("%5" BFD_VMA_FMT "d", vma); + /* Drop through. */ - case LONG_HEX: - printf_vma (vma); - return nc + 16; + case PREFIX_HEX: + nc = printf ("0x"); + /* 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 + case HEX: + 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: + return printf ("%" BFD_VMA_FMT "d", vma); - 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 - - 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 - } + case UNSIGNED: + return printf ("%" BFD_VMA_FMT "u", vma); } -#endif return 0; } diff --git a/binutils/size.c b/binutils/size.c index f035cab80..415fee101 100644 --- a/binutils/size.c +++ b/binutils/size.c @@ -1,6 +1,7 @@ /* size.c -- report size of various sections of an executable file. Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, - 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 + Free Software Foundation, Inc. This file is part of GNU Binutils. @@ -406,17 +407,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 +426,9 @@ rprint_number (int width, 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); printf ("%*s", width, buffer); } -- 2.11.4.GIT