[PATCH] increasing the 64 bits portability of binutils/size.c

francois.petitjean@bureauveritas.com francois.petitjean@bureauveritas.com
Mon Mar 26 18:36:00 GMT 2007


The IBM xlc compiler has a -qwarn64 option which helps to detect 64-bit
portability problems.

fp2@halc10:/u/fp2/dev_c/binutils-070315/binutils $ make size.orig.o
/u/fp2/bin/mxlc -DHAVE_CONFIG_H -I. -I.././binutils -I. -D_GNU_SOURCE -I.
-I.././binutils -I../bfd -I.././binutils/../bfd -I.././binutils/../include
-DLOCALEDIR="\"/opt/freeware/share/locale\"" -DREPORT_BUGS_TO="
\"<URL:http://www.sourceware.org/bugzilla/>\""
-Dbin_dummy_emulation=bin_aix5_emulation     -c size.orig.c
"size.orig.c", line 171.21: 1506-742 (I) 64-bit portability: possible loss
of digits through conversion of long int type into int type.
"size.orig.c", line 251.15: 1506-743 (I) 64-bit portability: possible
change of result through conversion of unsigned long long int type into
unsigned long int type.
"size.orig.c", line 251.38: 1506-743 (I) 64-bit portability: possible
change of result through conversion of unsigned long long int type into
unsigned long int type.
"size.orig.c", line 385.12: 1506-743 (I) 64-bit portability: possible
change of result through conversion of unsigned long long int type into
unsigned long int type.
"size.orig.c", line 387.10: 1506-742 (I) 64-bit portability: possible loss
of digits through conversion of unsigned long int type into int type.
"size.orig.c", line 398.12: 1506-743 (I) 64-bit portability: possible
change of result through conversion of unsigned long long int type into
unsigned long int type.
"size.orig.c", line 458.11: 1506-743 (I) 64-bit portability: possible
change of result through conversion of unsigned long long int type into
unsigned long int type.
"size.orig.c", line 458.34: 1506-743 (I) 64-bit portability: possible
change of result through conversion of unsigned long long int type into
unsigned long int type.
"size.orig.c", line 483.21: 1506-742 (I) 64-bit portability: possible loss
of digits through conversion of unsigned long int type into int type.
"size.orig.c", line 525.7: 1506-743 (I) 64-bit portability: possible change
of result through conversion of int type into unsigned long int type.
"size.orig.c", line 529.7: 1506-743 (I) 64-bit portability: possible change
of result through conversion of int type into unsigned long int type.
fp2@halc10:/u/fp2/dev_c/binutils-070315/binutils $

By applying the following patch, the number of warnings is reduced from 11
to 7. 6 of the remaining warnings are related to printf arguments
conversions..
Basically it is simply s/int/size_t/  in the definition of a few variables.
The unpatched source is the last snapshot 070315.

-bash-2.05b$ diff -u size.orig.c size.c
--- size.orig.c 2007-02-17 14:33:54.000000000 +0100
+++ size.c      2007-03-26 19:53:06.000000000 +0200
@@ -67,8 +67,8 @@
 static void display_file (char *);
 static void display_bfd (bfd *);
 static void display_archive (bfd *);
-static int size_number (bfd_size_type);
-static void rprint_number (int, bfd_size_type);
+static size_t size_number (bfd_size_type);
+static void rprint_number (size_t, bfd_size_type);
 static void print_berkeley_format (bfd *);
 static void sysv_internal_sizer (bfd *, asection *, void *);
 static void sysv_internal_printer (bfd *, asection *, void *);
@@ -166,9 +166,9 @@

       case 201:                /* --radix */
 #ifdef ANSI_LIBRARIES
-       temp = strtol (optarg, NULL, 10);
+       temp = (int) strtol (optarg, NULL, 10);
 #else
-       temp = atol (optarg);
+       temp = (int) atol (optarg);
 #endif
        switch (temp)
          {
@@ -374,7 +374,7 @@

 /* This is what lexical functions are for.  */

-static int
+static size_t
 size_number (bfd_size_type num)
 {
   char buffer[40];
@@ -388,7 +388,7 @@
 }

 static void
-rprint_number (int width, bfd_size_type num)
+rprint_number (size_t width, bfd_size_type num)
 {
   char buffer[40];

@@ -466,9 +466,9 @@
 /* I REALLY miss lexical functions! */
 bfd_size_type svi_total = 0;
 bfd_vma svi_maxvma = 0;
-int svi_namelen = 0;
-int svi_vmalen = 0;
-int svi_sizelen = 0;
+size_t svi_namelen = 0;
+size_t svi_vmalen = 0;
+size_t svi_sizelen = 0;

 static void
 sysv_internal_sizer (bfd *file ATTRIBUTE_UNUSED, sec_ptr sec,
@@ -480,7 +480,7 @@
       && ! bfd_is_com_section (sec)
       && ! bfd_is_und_section (sec))
     {
-      int namelen = strlen (bfd_section_name (file, sec));
+      size_t namelen = strlen (bfd_section_name (file, sec));

       if (namelen > svi_namelen)
        svi_namelen = namelen;
@@ -522,11 +522,11 @@
   bfd_map_over_sections (file, sysv_internal_sizer, NULL);
   svi_vmalen = size_number ((bfd_size_type)svi_maxvma);

-  if ((size_t) svi_vmalen < sizeof ("addr") - 1)
+  if (svi_vmalen < sizeof ("addr") - 1)
     svi_vmalen = sizeof ("addr")-1;

   svi_sizelen = size_number (svi_total);
-  if ((size_t) svi_sizelen < sizeof ("size") - 1)
+  if (svi_sizelen < sizeof ("size") - 1)
     svi_sizelen = sizeof ("size")-1;

   svi_total = 0;
-bash-2.05b$


/u/fp2/bin/mxlc -DHAVE_CONFIG_H -I. -I.././binutils -I. -D_GNU_SOURCE -I.
-I.././binutils -I../bfd -I.././binutils/../bfd -I.././binutils/../include
-DLOCALEDIR="\"/opt/freeware/share/locale\"" -DREPORT_BUGS_TO="
\"<URL:http://www.sourceware.org/bugzilla/>\""
-Dbin_dummy_emulation=bin_aix5_emulation     -c size.c
"size.c", line 171.16: 1506-742 (I) 64-bit portability: possible loss of
digits through conversion of long int type into int type.
"size.c", line 251.15: 1506-743 (I) 64-bit portability: possible change of
result through conversion of unsigned long long int type into unsigned long
int type.
"size.c", line 251.38: 1506-743 (I) 64-bit portability: possible change of
result through conversion of unsigned long long int type into unsigned long
int type.
"size.c", line 385.12: 1506-743 (I) 64-bit portability: possible change of
result through conversion of unsigned long long int type into unsigned long
int type.
"size.c", line 398.12: 1506-743 (I) 64-bit portability: possible change of
result through conversion of unsigned long long int type into unsigned long
int type.
"size.c", line 458.11: 1506-743 (I) 64-bit portability: possible change of
result through conversion of unsigned long long int type into unsigned long
int type.
"size.c", line 458.34: 1506-743 (I) 64-bit portability: possible change of
result through conversion of unsigned long long int type into unsigned long
int type.
fp2@halc10:/u/fp2/dev_c/binutils-070315/binutils $


Reagrds.


   NOTICE: This message contains information which is confidential and the
   copyright of our company or a third  party. If you are not the intended
   recipient of this message please delete it and destroy all copies. If
   you
   are the intended recipient of this message you should not disclose or
   distribute this message to third parties without the consent of our
   company. Our company does not represent, warrant and/or guarantee that
   the integrity of this message has been maintained nor that the
   communication is free of virus, interception or interference. The
   liability of our company is limited by our General Conditions of
   Services.
   Nota : Ce message contient des informations confidentielles propriété de
   notre société et/ou d'un tiers. Si vous n'êtes pas parmi les
   destinataires désignés de ce message, merci de l'effacer ainsi que
   toutes ses copies. Si vous êtes parmi les destinataires désignés de ce
   message, prière de ne pas le divulguer ni de le transmettre à des tiers
   sans l'accord de notre société. Notre société ne peut garantir que
   l'intégrité de ce message a été préservée ni que la présente
   communication est sans virus, interception ou interférence. La
   responsabilité de notre société est limitée par nos Conditions Générales
   de Services.




More information about the Binutils mailing list