public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: PATCH: w64 native support
@ 2007-04-11 13:43 Kai Tietz
  2007-04-11 13:58 ` H. J. Lu
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-11 13:43 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 2777 bytes --]

Hello,

I did the windres.h patch changing the long to int types, so that problem 
#2737 seems to be solved.
Additionally I introduced in bfd-in.h the type "bfd_hostptr_t" and its 
hexadeicmal printf representation in macro "BFD_HOSTPTR_T_PRT_X". For now, 
AFAIS, only WIN64 has a long type lesser than a pointer, therefore I made 
the define dependent on the definiton of _WIN64. The modification in 
splay-tree.h header has the same reason.

ChangeLogs:

For bfd:

2007-04-11 Kai Tietz  <kai.tietz@onevision.com>

        * bfd/bfd-in.h: (bfd_hostptr_t): New type for max(long,void *) 
width.
        (BFD_HOSTPTR_T_PRT_X): Printf a bfd_hostptr_t type.
        * bfd/bfd-in2.h: Regenerate.
        * bfd/coffcode.h: Replace use of long by bfd_hostptr_t.
        * bfd/coffgen.c: Likewise.
        * bfd/elf-eh-frame.c: Likewise.
        * bfd/peicode.h: Likewise.

For binutils:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * binutils/resres.c: Cast sizeof explicit to type "long".
        * binutils/resrc.c: Adjust printf formatter for ints.
        * binutils/windres.c: (main): Assert if sizeof(int) not 4 bytes.
        * binutils/windres.h: Changed windows structure to use
        int type instead of long type.

For gas:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * gas/symbols.c: Replace use of long by bfd_hostptr_t and
          print via BFD_HOSTPTR_T_PRT_X.
        * gas/write.c: Likewise.

For gprof:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * gprof/cg_print.c: Explict cast sizeof to long.
        * gprof/hist.c: Likewise.

For include:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * include/splay-tree.h: (libi_uhostptr_t): New type.
        (libi_shostptr_t): New type.
        (splay_tree_key, splay_tree_value): Use libi_uhostptr_t type.
        * include/coff/internal.h: (_n_zeroes, _n_offset): Type as 
bfd_hostptr_t
        instead of long.


For libiberty:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * libiberty/strerror.c: Undefine sys_nerr and sys_errlist for w64 
sake.

Regards,
 i.A. Kai Tietz



------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger

[-- Attachment #2: bfd-w64-native-2.txt --]
[-- Type: text/plain, Size: 28950 bytes --]

Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.126
diff -b -u -r1.126 bfd-in.h
--- bfd/bfd-in.h	20 Mar 2007 20:19:07 -0000	1.126
+++ bfd/bfd-in.h	11 Apr 2007 13:25:21 -0000
@@ -96,6 +96,19 @@
 #endif
 #endif
 
+/* Declaring a type wide enough to hold a host long and a host pointer.  */
+#ifndef BFD_HOSTPTR_T
+#define BFD_HOSTPTR_T
+#undef BFD_HOSTPTR_T_PRINT
+#ifdef _WIN64
+typedef unsigned long long bfd_hostptr_t;
+#define BFD_HOSTPTR_T_PRT_X	"%llx"
+#else
+typedef unsigned long bfd_hostptr_t;
+#define BFD_HOSTPTR_T_PRT_X	"%lx"
+#endif
+#endif
+
 /* Forward declaration.  */
 typedef struct bfd bfd;
 
Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.418
diff -b -u -r1.418 bfd-in2.h
--- bfd/bfd-in2.h	26 Mar 2007 12:23:03 -0000	1.418
+++ bfd/bfd-in2.h	11 Apr 2007 13:25:25 -0000
@@ -103,6 +103,19 @@
 #endif
 #endif
 
+/* Declaring a type wide enough to hold a host long and a host pointer.  */
+#ifndef BFD_HOSTPTR_T
+#define BFD_HOSTPTR_T
+#undef BFD_HOSTPTR_T_PRINT
+#ifdef _WIN64
+typedef unsigned long long bfd_hostptr_t;
+#define BFD_HOSTPTR_T_PRT_X	"%llx"
+#else
+typedef unsigned long bfd_hostptr_t;
+#define BFD_HOSTPTR_T_PRT_X	"%lx"
+#endif
+#endif
+
 /* Forward declaration.  */
 typedef struct bfd bfd;
 
Index: bfd/coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.136
diff -b -u -r1.136 coffcode.h
--- bfd/coffcode.h	26 Mar 2007 12:22:59 -0000	1.136
+++ bfd/coffcode.h	11 Apr 2007 13:25:29 -0000
@@ -4380,7 +4380,7 @@
 
 	  dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
 	  /* We use the native name field to point to the cached field.  */
-	  src->u.syment._n._n_n._n_zeroes = (long) dst;
+	  src->u.syment._n._n_n._n_zeroes = (bfd_hostptr_t) dst;
 	  dst->symbol.section = coff_section_from_bfd_index (abfd,
 						     src->u.syment.n_scnum);
 	  dst->symbol.flags = 0;
Index: bfd/coffgen.c
===================================================================
RCS file: /cvs/src/src/bfd/coffgen.c,v
retrieving revision 1.56
diff -b -u -r1.56 coffgen.c
--- bfd/coffgen.c	2 Apr 2007 16:51:13 -0000	1.56
+++ bfd/coffgen.c	11 Apr 2007 13:25:31 -0000
@@ -725,8 +725,8 @@
 	    {
 	      /* FIXME: We should use a union here.  */
 	      s->u.syment.n_value =
-		(bfd_vma)((combined_entry_type *)
-			  ((unsigned long) s->u.syment.n_value))->offset;
+		(bfd_hostptr_t) ((combined_entry_type *)
+			  ((bfd_hostptr_t) s->u.syment.n_value))->offset;
 	      s->fix_value = 0;
 	    }
 	  if (s->fix_line)
@@ -1640,7 +1640,7 @@
 		}
 
 	      internal_ptr->u.syment._n._n_n._n_offset =
-		((long)
+		((bfd_hostptr_t)
 		 (string_table
 		  + (internal_ptr + 1)->u.auxent.x_file.x_n.x_offset));
 	    }
@@ -1652,13 +1652,13 @@
 	      if (internal_ptr->u.syment.n_numaux > 1
 		  && coff_data (abfd)->pe)
 		internal_ptr->u.syment._n._n_n._n_offset =
-		  ((long)
+		  ((bfd_hostptr_t)
 		   copy_name (abfd,
 			      (internal_ptr + 1)->u.auxent.x_file.x_fname,
 			      internal_ptr->u.syment.n_numaux * symesz));
 	      else
 		internal_ptr->u.syment._n._n_n._n_offset =
-		  ((long)
+		  ((bfd_hostptr_t)
 		   copy_name (abfd,
 			      (internal_ptr + 1)->u.auxent.x_file.x_fname,
 			      (size_t) bfd_coff_filnmlen (abfd)));
@@ -1682,11 +1682,11 @@
 	      if (newstring == NULL)
 		return NULL;
 	      strncpy (newstring, internal_ptr->u.syment._n._n_name, i);
-	      internal_ptr->u.syment._n._n_n._n_offset = (long int) newstring;
+	      internal_ptr->u.syment._n._n_n._n_offset = (bfd_hostptr_t) newstring;
 	      internal_ptr->u.syment._n._n_n._n_zeroes = 0;
 	    }
 	  else if (internal_ptr->u.syment._n._n_n._n_offset == 0)
-	    internal_ptr->u.syment._n._n_n._n_offset = (long int) "";
+	    internal_ptr->u.syment._n._n_n._n_offset = (bfd_vma) "";
 	  else if (!bfd_coff_symname_in_debug (abfd, &internal_ptr->u.syment))
 	    {
 	      /* Long name already.  Point symbol at the string in the
@@ -1698,7 +1698,7 @@
 		    return NULL;
 		}
 	      internal_ptr->u.syment._n._n_n._n_offset =
-		((long int)
+		((bfd_hostptr_t)
 		 (string_table
 		  + internal_ptr->u.syment._n._n_n._n_offset));
 	    }
@@ -1707,7 +1707,7 @@
 	      /* Long name in debug section.  Very similar.  */
 	      if (debug_section == NULL)
 		debug_section = build_debug_section (abfd);
-	      internal_ptr->u.syment._n._n_n._n_offset = (long int)
+	      internal_ptr->u.syment._n._n_n._n_offset = (bfd_hostptr_t)
 		(debug_section + internal_ptr->u.syment._n._n_n._n_offset);
 	    }
 	}
@@ -1784,7 +1784,7 @@
   if (coffsymbol (symbol)->native != NULL
       && coffsymbol (symbol)->native->fix_value)
     ret->value = coffsymbol (symbol)->native->u.syment.n_value -
-      (unsigned long) obj_raw_syments (abfd);
+      (bfd_hostptr_t) obj_raw_syments (abfd);
 }
 
 /* Return the COFF syment for a symbol.  */
@@ -1807,7 +1807,7 @@
 
   if (csym->native->fix_value)
     psyment->n_value = psyment->n_value -
-      (unsigned long) obj_raw_syments (abfd);
+      (bfd_hostptr_t) obj_raw_syments (abfd);
 
   /* FIXME: We should handle fix_line here.  */
 
@@ -1893,7 +1893,7 @@
 	  if (! combined->fix_value)
 	    val = (bfd_vma) combined->u.syment.n_value;
 	  else
-	    val = combined->u.syment.n_value - (unsigned long) root;
+	    val = combined->u.syment.n_value - (bfd_hostptr_t) root;
 
 	  fprintf (file, "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x",
 		   combined->u.syment.n_scnum,
Index: bfd/elf-eh-frame.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-eh-frame.c,v
retrieving revision 1.54
diff -b -u -r1.54 elf-eh-frame.c
--- bfd/elf-eh-frame.c	4 Jan 2007 13:30:39 -0000	1.54
+++ bfd/elf-eh-frame.c	11 Apr 2007 13:25:32 -0000
@@ -917,7 +917,7 @@
       {
 	if (!ent->cie)
 	  {
-	    ecie = ecies + (unsigned long) ent->cie_inf;
+	    ecie = ecies + (bfd_hostptr_t) ent->cie_inf;
 	    ent->cie_inf = ecie->cie.cie_inf;
 	  }
 	ent->new_offset = offset;
Index: bfd/peicode.h
===================================================================
RCS file: /cvs/src/src/bfd/peicode.h,v
retrieving revision 1.50
diff -b -u -r1.50 peicode.h
--- bfd/peicode.h	20 Sep 2006 11:35:07 -0000	1.50
+++ bfd/peicode.h	11 Apr 2007 13:25:34 -0000
@@ -565,7 +565,7 @@
   /* Initialise the internal symbol structure.  */
   ent->u.syment.n_sclass          = sclass;
   ent->u.syment.n_scnum           = section->target_index;
-  ent->u.syment._n._n_n._n_offset = (long) sym;
+  ent->u.syment._n._n_n._n_offset = (bfd_hostptr_t) sym;
 
   sym->symbol.the_bfd = vars->abfd;
   sym->symbol.name    = vars->string_ptr;
Index: binutils/resrc.c
===================================================================
RCS file: /cvs/src/src/binutils/resrc.c,v
retrieving revision 1.27
diff -b -u -r1.27 resrc.c
--- binutils/resrc.c	8 May 2005 14:17:39 -0000	1.27
+++ binutils/resrc.c	11 Apr 2007 13:25:35 -0000
@@ -1515,9 +1515,9 @@
   /* Print out some COFF information that rc files can't represent.  */
 
   if (rd->time != 0)
-    fprintf (e, "// Time stamp: %lu\n", rd->time);
+    fprintf (e, "// Time stamp: %u\n", rd->time);
   if (rd->characteristics != 0)
-    fprintf (e, "// Characteristics: %lu\n", rd->characteristics);
+    fprintf (e, "// Characteristics: %u\n", rd->characteristics);
   if (rd->major != 0 || rd->minor != 0)
     fprintf (e, "// Version: %d %d\n", rd->major, rd->minor);
 
@@ -1546,7 +1546,7 @@
 	      && re->id.u.id != (unsigned long) (unsigned int) *language
 	      && (re->id.u.id & 0xffff) == re->id.u.id)
 	    {
-	      fprintf (e, "LANGUAGE %lu, %lu\n",
+	      fprintf (e, "LANGUAGE %u, %u\n",
 		       re->id.u.id & ((1 << SUBLANG_SHIFT) - 1),
 		       (re->id.u.id >> SUBLANG_SHIFT) & 0xff);
 	      *language = re->id.u.id;
@@ -1774,9 +1774,9 @@
     }
 
   if (res->coff_info.codepage != 0)
-    fprintf (e, "// Code page: %lu\n", res->coff_info.codepage);
+    fprintf (e, "// Code page: %u\n", res->coff_info.codepage);
   if (res->coff_info.reserved != 0)
-    fprintf (e, "// COFF reserved value: %lu\n", res->coff_info.reserved);
+    fprintf (e, "// COFF reserved value: %u\n", res->coff_info.reserved);
 
   if (name != NULL)
     res_id_print (e, *name, 0);
@@ -1809,7 +1809,7 @@
 	       res->u.dialog->width, res->u.dialog->height);
       if (res->u.dialog->ex != NULL
 	  && res->u.dialog->ex->help != 0)
-	fprintf (e, ", %lu", res->u.dialog->ex->help);
+	fprintf (e, ", %u", res->u.dialog->ex->help);
     }
 
   fprintf (e, "\n");
@@ -1841,11 +1841,11 @@
 		 res->res_info.language & ((1<<SUBLANG_SHIFT)-1),
 		 (res->res_info.language >> SUBLANG_SHIFT) & 0xff);
       if (res->res_info.characteristics != 0)
-	fprintf (e, "%sCHARACTERISTICS %lu\n",
+	fprintf (e, "%sCHARACTERISTICS %u\n",
 		 modifiers ? "// " : "",
 		 res->res_info.characteristics);
       if (res->res_info.version != 0)
-	fprintf (e, "%sVERSION %lu\n",
+	fprintf (e, "%sVERSION %u\n",
 		 modifiers ? "// " : "",
 		 res->res_info.version);
     }
@@ -1981,7 +1981,7 @@
     {
       fprintf (e, "// width: %d; height %d; planes %d; bits %d\n",
 	     gc->width, gc->height, gc->planes, gc->bits);
-      fprintf (e, "// data bytes: %lu; index: %d\n",
+      fprintf (e, "// data bytes: %u; index: %d\n",
 	       gc->bytes, gc->index);
     }
 }
@@ -1993,10 +1993,10 @@
 {
   const struct dialog_control *control;
 
-  fprintf (e, "STYLE 0x%lx\n", dialog->style);
+  fprintf (e, "STYLE 0x%x\n", dialog->style);
 
   if (dialog->exstyle != 0)
-    fprintf (e, "EXSTYLE 0x%lx\n", dialog->exstyle);
+    fprintf (e, "EXSTYLE 0x%x\n", dialog->exstyle);
 
   if ((dialog->class.named && dialog->class.u.n.length > 0)
       || dialog->class.u.id != 0)
@@ -2121,7 +2121,7 @@
       res_id_print (e, control->class, 0);
       if (control->class.named)
 	fprintf (e, "\"");
-      fprintf (e, ", 0x%lx, ", control->style);
+      fprintf (e, ", 0x%x, ", control->style);
     }
 
   fprintf (e, "%d, %d", control->x, control->y);
@@ -2137,10 +2137,10 @@
       /* FIXME: We don't need to print the style if it is the default.
 	 More importantly, in certain cases we actually need to turn
 	 off parts of the forced style, by using NOT.  */
-      fprintf (e, ", 0x%lx", control->style);
+      fprintf (e, ", 0x%x", control->style);
 
       if (control->exstyle != 0 || control->help != 0)
-	fprintf (e, ", 0x%lx, %lu", control->exstyle, control->help);
+	fprintf (e, ", 0x%x, %u", control->exstyle, control->help);
     }
 
   fprintf (e, "\n");
@@ -2176,7 +2176,7 @@
     {
       fprintf (e, "// width: %d; height %d; colors: %d; planes %d; bits %d\n",
 	       gi->width, gi->height, gi->colors, gi->planes, gi->bits);
-      fprintf (e, "// data bytes: %lu; index: %d\n",
+      fprintf (e, "// data bytes: %u; index: %d\n",
 	       gi->bytes, gi->index);
     }
 }
@@ -2187,7 +2187,7 @@
 write_rc_menu (FILE *e, const struct menu *menu, int menuex)
 {
   if (menu->help != 0)
-    fprintf (e, "// Help ID: %lu\n", menu->help);
+    fprintf (e, "// Help ID: %u\n", menu->help);
   write_rc_menuitems (e, menu->items, menuex, 0);
 }
 
@@ -2255,12 +2255,12 @@
 	      fprintf (e, ", %d", mi->id);
 	      if (mi->type != 0 || mi->state != 0 || mi->help != 0)
 		{
-		  fprintf (e, ", %lu", mi->type);
+		  fprintf (e, ", %u", mi->type);
 		  if (mi->state != 0 || mi->help != 0)
 		    {
-		      fprintf (e, ", %lu", mi->state);
+		      fprintf (e, ", %u", mi->state);
 		      if (mi->help != 0)
-			fprintf (e, ", %lu", mi->help);
+			fprintf (e, ", %u", mi->help);
 		    }
 		}
 	    }
@@ -2304,7 +2304,7 @@
 	  break;
 
 	case RCDATA_DWORD:
-	  fprintf (e, "%luL", ri->u.dword);
+	  fprintf (e, "%uL", ri->u.dword);
 	  break;
 
 	case RCDATA_STRING:
@@ -2486,29 +2486,29 @@
 
   f = versioninfo->fixed;
   if (f->file_version_ms != 0 || f->file_version_ls != 0)
-    fprintf (e, " FILEVERSION %lu, %lu, %lu, %lu\n",
+    fprintf (e, " FILEVERSION %u, %u, %u, %u\n",
 	     (f->file_version_ms >> 16) & 0xffff,
 	     f->file_version_ms & 0xffff,
 	     (f->file_version_ls >> 16) & 0xffff,
 	     f->file_version_ls & 0xffff);
   if (f->product_version_ms != 0 || f->product_version_ls != 0)
-    fprintf (e, " PRODUCTVERSION %lu, %lu, %lu, %lu\n",
+    fprintf (e, " PRODUCTVERSION %u, %u, %u, %u\n",
 	     (f->product_version_ms >> 16) & 0xffff,
 	     f->product_version_ms & 0xffff,
 	     (f->product_version_ls >> 16) & 0xffff,
 	     f->product_version_ls & 0xffff);
   if (f->file_flags_mask != 0)
-    fprintf (e, " FILEFLAGSMASK 0x%lx\n", f->file_flags_mask);
+    fprintf (e, " FILEFLAGSMASK 0x%x\n", f->file_flags_mask);
   if (f->file_flags != 0)
-    fprintf (e, " FILEFLAGS 0x%lx\n", f->file_flags);
+    fprintf (e, " FILEFLAGS 0x%x\n", f->file_flags);
   if (f->file_os != 0)
-    fprintf (e, " FILEOS 0x%lx\n", f->file_os);
+    fprintf (e, " FILEOS 0x%x\n", f->file_os);
   if (f->file_type != 0)
-    fprintf (e, " FILETYPE 0x%lx\n", f->file_type);
+    fprintf (e, " FILETYPE 0x%x\n", f->file_type);
   if (f->file_subtype != 0)
-    fprintf (e, " FILESUBTYPE 0x%lx\n", f->file_subtype);
+    fprintf (e, " FILESUBTYPE 0x%x\n", f->file_subtype);
   if (f->file_date_ms != 0 || f->file_date_ls != 0)
-    fprintf (e, "// Date: %lu, %lu\n", f->file_date_ms, f->file_date_ls);
+    fprintf (e, "// Date: %u, %u\n", f->file_date_ms, f->file_date_ls);
 
   fprintf (e, "BEGIN\n");
 
Index: binutils/resres.c
===================================================================
RCS file: /cvs/src/src/binutils/resres.c,v
retrieving revision 1.7
diff -b -u -r1.7 resres.c
--- binutils/resres.c	16 Jun 2005 09:18:19 -0000	1.7
+++ binutils/resres.c	11 Apr 2007 13:25:36 -0000
@@ -475,7 +475,7 @@
   else
     /* named id */
     {
-      if (fseek (fres, -sizeof (ord), SEEK_CUR) != 0)
+      if (fseek (fres, - ((long) sizeof (ord)), SEEK_CUR) != 0)
 	fatal ("%s: %s: could not seek in file", program_name, filename);
       id_s = read_unistring (&len);
       id->named = 1;
Index: binutils/windres.c
===================================================================
RCS file: /cvs/src/src/binutils/windres.c,v
retrieving revision 1.28
diff -b -u -r1.28 windres.c
--- binutils/windres.c	17 Feb 2007 13:33:54 -0000	1.28
+++ binutils/windres.c	11 Apr 2007 13:25:36 -0000
@@ -263,7 +263,7 @@
 res_id_print (FILE *stream, struct res_id id, int quote)
 {
   if (! id.named)
-    fprintf (stream, "%lu", id.u.id);
+    fprintf (stream, "%u", id.u.id);
   else
     {
       if (quote)
@@ -320,12 +320,12 @@
 
       if (*resources == NULL)
 	{
-	  static unsigned long timeval;
+	  static unsigned int timeval;
 
 	  /* Use the same timestamp for every resource created in a
              single run.  */
 	  if (timeval == 0)
-	    timeval = time (NULL);
+	    timeval = (unsigned int) time (NULL);
 
 	  *resources = ((struct res_directory *)
 			res_alloc (sizeof **resources));
@@ -756,6 +756,9 @@
   struct res_directory *resources;
   int use_temp_file;
 
+  /* Check, that the type int has a size of 4 bytes, otherwise fail.  */
+  assert (sizeof (int) == 4);
+
 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
   setlocale (LC_MESSAGES, "");
 #endif
Index: binutils/windres.h
===================================================================
RCS file: /cvs/src/src/binutils/windres.h,v
retrieving revision 1.14
diff -b -u -r1.14 windres.h
--- binutils/windres.h	8 May 2005 14:17:39 -0000	1.14
+++ binutils/windres.h	11 Apr 2007 13:25:38 -0000
@@ -35,9 +35,9 @@
 {
   /* Resource flags.  According to the MS docs, this is currently
      always zero.  */
-  unsigned long characteristics;
+  unsigned int characteristics;
   /* Time/date stamp.  */
-  unsigned long time;
+  unsigned int time;
   /* Major version number.  */
   unsigned short major;
   /* Minor version number.  */
@@ -63,7 +63,7 @@
       unichar *name;
     } n;
     /* If the named field is zero, this is the ID.  */
-    unsigned long id;
+    unsigned int id;
   } u;
 };
 
@@ -127,11 +127,11 @@
      COFF file, the res_directory structure has a characteristics
      field, but I don't know if it's related to the one in the res
      file.  */
-  unsigned long characteristics;
+  unsigned int characteristics;
   /* Version of the resource.  Entirely user defined.  In a COFF file,
      the res_directory structure has a characteristics field, but I
      don't know if it's related to the one in the res file.  */
-  unsigned long version;
+  unsigned int version;
   /* Memory flags.  This is a combination of the MEMFLAG values
      defined below.  Most of these values are historical, and are not
      meaningful for win32.  I don't think there is any way to store
@@ -146,11 +146,11 @@
 {
   /* The code page used for the data.  I don't really know what this
      should be.  */
-  unsigned long codepage;
+  unsigned int codepage;
   /* A resource entry in a COFF file has a reserved field, which we
      record here when reading a COFF file.  When writing a COFF file,
      we set this field to zero.  */
-  unsigned long reserved;
+  unsigned int reserved;
 };
 
 /* Resource data is stored in a res_resource structure.  */
@@ -164,7 +164,7 @@
   {
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const unsigned char *data;
     } data;
     struct accelerator *acc;
@@ -250,7 +250,7 @@
   /* Y coordinate of hotspot.  */
   short yhotspot;
   /* Length of bitmap data.  */
-  unsigned long length;
+  unsigned int length;
   /* Data.  */
   const unsigned char *data;
 };
@@ -270,7 +270,7 @@
   /* Bits per pixel.  */
   unsigned short bits;
   /* Number of bytes in cursor resource.  */
-  unsigned long bytes;
+  unsigned int bytes;
   /* Index of cursor resource.  */
   unsigned short index;
 };
@@ -280,9 +280,9 @@
 struct dialog
 {
   /* Basic window style.  */
-  unsigned long style;
+  unsigned int style;
   /* Extended window style.  */
-  unsigned long exstyle;
+  unsigned int exstyle;
   /* X coordinate.  */
   unsigned short x;
   /* Y coordinate.  */
@@ -312,7 +312,7 @@
 struct dialog_ex
 {
   /* Help ID.  */
-  unsigned long help;
+  unsigned int help;
   /* Font weight.  */
   unsigned short weight;
   /* Whether the font is italic.  */
@@ -482,9 +482,9 @@
   /* ID.  */
   unsigned short id;
   /* Style.  */
-  unsigned long style;
+  unsigned int style;
   /* Extended style.  */
-  unsigned long exstyle;
+  unsigned int exstyle;
   /* X coordinate.  */
   unsigned short x;
   /* Y coordinate.  */
@@ -500,7 +500,7 @@
   /* Extra data for the window procedure.  */
   struct rcdata_item *data;
   /* Help ID.  Only used in an extended dialog.  */
-  unsigned long help;
+  unsigned int help;
 };
 
 /* Control classes.  These can be used as the ID field in a struct
@@ -521,7 +521,7 @@
   /* Index of font entry.  */
   short index;
   /* Length of font information.  */
-  unsigned long length;
+  unsigned int length;
   /* Font information.  */
   const unsigned char *data;
 };
@@ -543,7 +543,7 @@
   /* Bits per pixel.  */
   unsigned short bits;
   /* Number of bytes in cursor resource.  */
-  unsigned long bytes;
+  unsigned int bytes;
   /* Index of cursor resource.  */
   unsigned short index;
 };
@@ -556,7 +556,7 @@
   struct menuitem *items;
   /* Help ID.  I don't think there is any way to set this in an rc
      file, but it can appear in the binary format.  */
-  unsigned long help;
+  unsigned int help;
 };
 
 /* A menu resource is a list of menuitem structures.  */
@@ -567,9 +567,9 @@
   struct menuitem *next;
   /* Type.  In a normal menu, rather than a menuex, this is the flags
      field.  */
-  unsigned long type;
+  unsigned int type;
   /* State.  This is only used in a menuex.  */
-  unsigned long state;
+  unsigned int state;
   /* Id.  */
   unsigned short id;
   /* Unicode text.  */
@@ -577,7 +577,7 @@
   /* Popup menu items for a popup.  */
   struct menuitem *popup;
   /* Help ID.  This is only used in a menuex.  */
-  unsigned long help;
+  unsigned int help;
 };
 
 /* Menu item flags.  These can appear in the flags field of a struct
@@ -613,20 +613,20 @@
   union
   {
     unsigned int word;
-    unsigned long dword;
+    unsigned int dword;
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const char *s;
     } string;
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const unichar *w;
     } wstring;
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const unsigned char *data;
     } buffer;
   } u;
@@ -661,24 +661,24 @@
 struct fixed_versioninfo
 {
   /* The file version, which is two 32 bit integers.  */
-  unsigned long file_version_ms;
-  unsigned long file_version_ls;
+  unsigned int file_version_ms;
+  unsigned int file_version_ls;
   /* The product version, which is two 32 bit integers.  */
-  unsigned long product_version_ms;
-  unsigned long product_version_ls;
+  unsigned int product_version_ms;
+  unsigned int product_version_ls;
   /* The file flags mask.  */
-  unsigned long file_flags_mask;
+  unsigned int file_flags_mask;
   /* The file flags.  */
-  unsigned long file_flags;
+  unsigned int file_flags;
   /* The OS type.  */
-  unsigned long file_os;
+  unsigned int file_os;
   /* The file type.  */
-  unsigned long file_type;
+  unsigned int file_type;
   /* The file subtype.  */
-  unsigned long file_subtype;
+  unsigned int file_subtype;
   /* The date, which in Windows is two 32 bit integers.  */
-  unsigned long file_date_ms;
-  unsigned long file_date_ls;
+  unsigned int file_date_ms;
+  unsigned int file_date_ls;
 };
 
 /* A list of variable version information.  */
@@ -742,7 +742,7 @@
   /* Next data.  */
   struct bindata *next;
   /* Length of data.  */
-  unsigned long length;
+  unsigned int length;
   /* Data.  */
   unsigned char *data;
 };
Index: gas/symbols.c
===================================================================
RCS file: /cvs/src/src/gas/symbols.c,v
retrieving revision 1.83
diff -b -u -r1.83 symbols.c
--- gas/symbols.c	15 Mar 2007 12:11:49 -0000	1.83
+++ gas/symbols.c	11 Apr 2007 13:25:42 -0000
@@ -2728,14 +2728,15 @@
   const char *name = S_GET_NAME (sym);
   if (!name || !name[0])
     name = "(unnamed)";
-  fprintf (file, "sym %lx %s", (unsigned long) sym, name);
+  fprintf (file, "sym " BFD_HOSTPTR_T_PRT_X " %s", (bfd_hostptr_t) sym, name);
 
   if (LOCAL_SYMBOL_CHECK (sym))
     {
       struct local_symbol *locsym = (struct local_symbol *) sym;
       if (local_symbol_get_frag (locsym) != &zero_address_frag
 	  && local_symbol_get_frag (locsym) != NULL)
-	fprintf (file, " frag %lx", (long) local_symbol_get_frag (locsym));
+        fprintf (file, " frag " BFD_HOSTPTR_T_PRT_X,
+        	 (bfd_hostptr_t) local_symbol_get_frag (locsym));
       if (local_symbol_resolved_p (locsym))
 	fprintf (file, " resolved");
       fprintf (file, " local");
@@ -2743,7 +2744,7 @@
   else
     {
       if (sym->sy_frag != &zero_address_frag)
-	fprintf (file, " frag %lx", (long) sym->sy_frag);
+        fprintf (file, " frag "BFD_HOSTPTR_T_PRT_X, (bfd_hostptr_t) sym->sy_frag);
       if (sym->written)
 	fprintf (file, " written");
       if (sym->sy_resolved)
@@ -2817,7 +2818,7 @@
 void
 print_expr_1 (FILE *file, expressionS *exp)
 {
-  fprintf (file, "expr %lx ", (long) exp);
+  fprintf (file, "expr " BFD_HOSTPTR_T_PRT_X " ", (bfd_hostptr_t) exp);
   switch (exp->X_op)
     {
     case O_illegal:
Index: gas/write.c
===================================================================
RCS file: /cvs/src/src/gas/write.c,v
retrieving revision 1.112
diff -b -u -r1.112 write.c
--- gas/write.c	26 Mar 2007 12:23:48 -0000	1.112
+++ gas/write.c	11 Apr 2007 13:25:44 -0000
@@ -2486,7 +2486,8 @@
 print_fixup (fixS *fixp)
 {
   indent_level = 1;
-  fprintf (stderr, "fix %lx %s:%d", (long) fixp, fixp->fx_file, fixp->fx_line);
+  fprintf (stderr, "fix " BFD_HOSTPTR_T_PRT_X " %s:%d",
+  	   (bfd_hostptr_t) fixp, fixp->fx_file, fixp->fx_line);
   if (fixp->fx_pcrel)
     fprintf (stderr, " pcrel");
   if (fixp->fx_pcrel_adjust)
@@ -2503,8 +2504,8 @@
     fprintf (stderr, " tcbit");
   if (fixp->fx_done)
     fprintf (stderr, " done");
-  fprintf (stderr, "\n    size=%d frag=%lx where=%ld offset=%lx addnumber=%lx",
-	   fixp->fx_size, (long) fixp->fx_frag, (long) fixp->fx_where,
+  fprintf (stderr, "\n    size=%d frag=" BFD_HOSTPTR_T_PRT_X " where=%ld offset=%lx addnumber=%lx",
+	   fixp->fx_size, (bfd_hostptr_t) fixp->fx_frag, (long) fixp->fx_where,
 	   (long) fixp->fx_offset, (long) fixp->fx_addnumber);
   fprintf (stderr, "\n    %s (%d)", bfd_get_reloc_code_name (fixp->fx_r_type),
 	   fixp->fx_r_type);
Index: gprof/cg_print.c
===================================================================
RCS file: /cvs/src/src/gprof/cg_print.c,v
retrieving revision 1.12
diff -b -u -r1.12 cg_print.c
--- gprof/cg_print.c	9 May 2005 06:55:24 -0000	1.12
+++ gprof/cg_print.c	11 Apr 2007 13:26:04 -0000
@@ -76,7 +76,7 @@
     }
 
   printf (_("\ngranularity: each sample hit covers %ld byte(s)"),
-	  (long) hist_scale * sizeof (UNIT));
+	  (long) hist_scale * (long) sizeof (UNIT));
 
   if (print_time > 0.0)
     printf (_(" for %.2f%% of %.2f seconds\n\n"),
Index: gprof/hist.c
===================================================================
RCS file: /cvs/src/src/gprof/hist.c,v
retrieving revision 1.17
diff -b -u -r1.17 hist.c
--- gprof/hist.c	10 Apr 2007 08:47:50 -0000	1.17
+++ gprof/hist.c	11 Apr 2007 13:26:04 -0000
@@ -464,7 +464,7 @@
   if (bsd_style_output)
     {
       printf (_("\ngranularity: each sample hit covers %ld byte(s)"),
-	      (long) hist_scale * sizeof (UNIT));
+	      (long) hist_scale * (long) sizeof (UNIT));
       if (total_time > 0.0)
 	{
 	  printf (_(" for %.2f%% of %.2f %s\n\n"),
Index: include/splay-tree.h
===================================================================
RCS file: /cvs/src/src/include/splay-tree.h,v
retrieving revision 1.13
diff -b -u -r1.13 splay-tree.h
--- include/splay-tree.h	10 May 2005 10:21:08 -0000	1.13
+++ include/splay-tree.h	11 Apr 2007 13:26:05 -0000
@@ -36,6 +36,14 @@
 
 #include "ansidecl.h"
 
+#ifndef _WIN64
+  typedef unsigned long int libi_uhostptr_t;
+  typedef long int libi_shostptr_t;
+#else
+  typedef unsigned long long libi_uhostptr_t;
+  typedef long long libi_shostptr_t;
+#endif
+
 #ifndef GTY
 #define GTY(X)
 #endif
@@ -44,8 +52,8 @@
    these types, if necessary.  These types should be sufficiently wide
    that any pointer or scalar can be cast to these types, and then
    cast back, without loss of precision.  */
-typedef unsigned long int splay_tree_key;
-typedef unsigned long int splay_tree_value;
+typedef libi_uhostptr_t splay_tree_key;
+typedef libi_uhostptr_t splay_tree_value;
 
 /* Forward declaration for a node in the tree.  */
 typedef struct splay_tree_node_s *splay_tree_node;
Index: include/coff/internal.h
===================================================================
RCS file: /cvs/src/src/include/coff/internal.h,v
retrieving revision 1.21
diff -b -u -r1.21 internal.h
--- include/coff/internal.h	19 Mar 2007 23:06:06 -0000	1.21
+++ include/coff/internal.h	11 Apr 2007 13:26:06 -0000
@@ -419,8 +419,8 @@
     char _n_name[SYMNMLEN];	/* old COFF version	*/
     struct
     {
-      long _n_zeroes;		/* new == 0		*/
-      long _n_offset;		/* offset into string table */
+      bfd_hostptr_t _n_zeroes;		/* new == 0		*/
+      bfd_hostptr_t _n_offset;		/* offset into string table */
     }      _n_n;
     char *_n_nptr[2];		/* allows for overlaying	*/
   }     _n;
Index: libiberty/strerror.c
===================================================================
RCS file: /cvs/src/src/libiberty/strerror.c,v
retrieving revision 1.12
diff -b -u -r1.12 strerror.c
--- libiberty/strerror.c	28 Mar 2005 02:09:01 -0000	1.12
+++ libiberty/strerror.c	11 Apr 2007 13:26:17 -0000
@@ -469,6 +469,9 @@
 
 #else
 
+#undef sys_nerr
+#undef sys_errlist
+
 extern int sys_nerr;
 extern char *sys_errlist[];
 
=

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-11 13:43 PATCH: w64 native support Kai Tietz
@ 2007-04-11 13:58 ` H. J. Lu
  2007-04-11 14:07   ` H. J. Lu
  2007-04-11 14:57   ` Kai Tietz
  0 siblings, 2 replies; 48+ messages in thread
From: H. J. Lu @ 2007-04-11 13:58 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Wed, Apr 11, 2007 at 03:42:31PM +0200, Kai Tietz wrote:
> Hello,
> 
> I did the windres.h patch changing the long to int types, so that problem 
> #2737 seems to be solved.

No, it doesn't work on big endian host. You should array of char
in external data structures.

> Additionally I introduced in bfd-in.h the type "bfd_hostptr_t" and its 
> hexadeicmal printf representation in macro "BFD_HOSTPTR_T_PRT_X". For now, 
> AFAIS, only WIN64 has a long type lesser than a pointer, therefore I made 
> the define dependent on the definiton of _WIN64. The modification in 

I don't believe we need BFD_HOSTPTR_T_PRT_X. As I said before, the
PE problem is there is no clear line between external and internal
data structues.  You should be able to use long long, even in big
endian, internally to hold any PE data type. You just need to convert
it to the proper size in proper endian when you write it out. You
shouldn't have any problem when it is done peoperly.


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-11 13:58 ` H. J. Lu
@ 2007-04-11 14:07   ` H. J. Lu
  2007-04-11 18:22     ` PATCH: windres Kai Tietz
  2007-04-18 11:59     ` PATCH: w64 native support Kai Tietz
  2007-04-11 14:57   ` Kai Tietz
  1 sibling, 2 replies; 48+ messages in thread
From: H. J. Lu @ 2007-04-11 14:07 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Wed, Apr 11, 2007 at 06:58:37AM -0700, H. J. Lu wrote:
> On Wed, Apr 11, 2007 at 03:42:31PM +0200, Kai Tietz wrote:
> > Hello,
> > 
> > I did the windres.h patch changing the long to int types, so that problem 
> > #2737 seems to be solved.
> 
> No, it doesn't work on big endian host. You should array of char
> in external data structures.
> 
> > Additionally I introduced in bfd-in.h the type "bfd_hostptr_t" and its 
> > hexadeicmal printf representation in macro "BFD_HOSTPTR_T_PRT_X". For now, 
> > AFAIS, only WIN64 has a long type lesser than a pointer, therefore I made 
> > the define dependent on the definiton of _WIN64. The modification in 
> 
> I don't believe we need BFD_HOSTPTR_T_PRT_X. As I said before, the
> PE problem is there is no clear line between external and internal
> data structues.  You should be able to use long long, even in big
> endian, internally to hold any PE data type. You just need to convert
> it to the proper size in proper endian when you write it out. You
> shouldn't have any problem when it is done peoperly.

We do need a new type when casting from pointer to integer. But
it should be determined in autoconf. You can use AC_CHECK_SIZEOF.


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-11 13:58 ` H. J. Lu
  2007-04-11 14:07   ` H. J. Lu
@ 2007-04-11 14:57   ` Kai Tietz
  2007-04-11 15:17     ` Daniel Jacobowitz
  1 sibling, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-11 14:57 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

"H. J. Lu" <hjl@lucon.org> wrote on 11.04.2007 15:58:37:

> On Wed, Apr 11, 2007 at 03:42:31PM +0200, Kai Tietz wrote:
> > Hello,
> > 
> > I did the windres.h patch changing the long to int types, so that 
problem 
> > #2737 seems to be solved.
> 
> No, it doesn't work on big endian host. You should array of char
> in external data structures.

Ok, I take a look for big-endian hosts and the external data structures.

> > Additionally I introduced in bfd-in.h the type "bfd_hostptr_t" and its 

> > hexadeicmal printf representation in macro "BFD_HOSTPTR_T_PRT_X". For 
now, 
> > AFAIS, only WIN64 has a long type lesser than a pointer, therefore I 
made 
> > the define dependent on the definiton of _WIN64. The modification in 
> 
> I don't believe we need BFD_HOSTPTR_T_PRT_X. As I said before, the
> PE problem is there is no clear line between external and internal
> data structues.  You should be able to use long long, even in big
> endian, internally to hold any PE data type. You just need to convert
> it to the proper size in proper endian when you write it out. You
> shouldn't have any problem when it is done peoperly.

The "long long" would work, if there would not be the -Werror parameter 
for gcc. The gcc bubbles a warning also for the case, that the integer 
casted to/from a pointer is bigger :(. This would break an cross from 
32-bit to 64-bit.
The helper macro BFD_HOSTPTR_T_PTR_X is for sure not coercively, but 
simplivies the readability AFAICS. 

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger



^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-11 14:57   ` Kai Tietz
@ 2007-04-11 15:17     ` Daniel Jacobowitz
  2007-04-11 15:24       ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: Daniel Jacobowitz @ 2007-04-11 15:17 UTC (permalink / raw)
  To: Kai Tietz; +Cc: H. J. Lu, binutils

On Wed, Apr 11, 2007 at 04:17:40PM +0200, Kai Tietz wrote:
> The "long long" would work, if there would not be the -Werror parameter 
> for gcc. The gcc bubbles a warning also for the case, that the integer 
> casted to/from a pointer is bigger :(. This would break an cross from 
> 32-bit to 64-bit.

We already have an autoconf macro in the tree to generate a stdint.h.
Gnulib also has one that we can import.

It's long past time to start assuming intptr_t.

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-11 15:17     ` Daniel Jacobowitz
@ 2007-04-11 15:24       ` Kai Tietz
  2007-04-11 15:43         ` Daniel Jacobowitz
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-11 15:24 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: binutils, H. J. Lu

[-- Attachment #1: Type: text/plain, Size: 1506 bytes --]

Daniel Jacobowitz <drow@false.org> wrote on 11.04.2007 17:00:31:

> On Wed, Apr 11, 2007 at 04:17:40PM +0200, Kai Tietz wrote:
> > The "long long" would work, if there would not be the -Werror 
parameter 
> > for gcc. The gcc bubbles a warning also for the case, that the integer 

> > casted to/from a pointer is bigger :(. This would break an cross from 
> > 32-bit to 64-bit.
> 
> We already have an autoconf macro in the tree to generate a stdint.h.
> Gnulib also has one that we can import.
> 
> It's long past time to start assuming intptr_t.

Yes, ice ages ... It seems that on every project and library the same old 
story reappears ;)
But as I learned, not on every c-runtime necessarily an stdint header is 
present and/or want to be included ;()

Re-inventing the wheel, may this patch could work (beside the 
BFD_HOSTPTR_T_PRT_X).

Regards,
i.A. Kai Tietz

 


------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger



[-- Attachment #2: bfd_config.txt --]
[-- Type: text/plain, Size: 2997 bytes --]

Index: configure.in
===================================================================
RCS file: /cvs/src/src/bfd/configure.in,v
retrieving revision 1.226
diff -b -u -r1.226 configure.in
--- configure.in	23 Mar 2007 02:51:30 -0000	1.226
+++ configure.in	11 Apr 2007 15:15:56 -0000
@@ -99,6 +99,7 @@
 AC_PROG_INSTALL
 
 BFD_HOST_64BIT_LONG=0
+BFD_HOST_64BIT_LONG_LONG=0
 BFD_HOST_LONG_LONG=0
 BFD_HOST_64_BIT_DEFINED=0
 BFD_HOST_64_BIT=
@@ -114,11 +115,20 @@
 fi
 
 AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(void *)
 if test "x${ac_cv_sizeof_long}" = "x8"; then
   host64=true
   BFD_HOST_64BIT_LONG=1
+  if test "x${ac_cv_sizeof_void_p}" = "x${ac_cv_sizeof_long_long}"; then
+    BFD_HOST_64BIT_LONG_LONG=1
+  fi
   test -n "${HOST_64BIT_TYPE}" || HOST_64BIT_TYPE="long"
   test -n "${HOST_U_64BIT_TYPE}" || HOST_U_64BIT_TYPE="unsigned long"
+elif test "x${ac_cv_sizeof_void_p}" = "x${ac_cv_sizeof_long_long}"; then
+  host64=true
+  BFD_HOST_64BIT_LONG_LONG=1
+  test -n "${HOST_64BIT_TYPE}" || HOST_64BIT_TYPE="long long"
+  test -n "${HOST_U_64BIT_TYPE}" || HOST_U_64BIT_TYPE="unsigned long long"
 elif test "x${ac_cv_sizeof_long_long}" = "x8"; then
   test -n "${HOST_64BIT_TYPE}" || HOST_64BIT_TYPE="long long"
   test -n "${HOST_U_64BIT_TYPE}" || HOST_U_64BIT_TYPE="unsigned long long"
@@ -131,6 +141,7 @@
 fi
 
 AC_SUBST(BFD_HOST_64BIT_LONG)
+AC_SUBST(BFD_HOST_64BIT_LONG_LONG)
 AC_SUBST(BFD_HOST_LONG_LONG)
 AC_SUBST(BFD_HOST_64_BIT_DEFINED)
 AC_SUBST(BFD_HOST_64_BIT)
Index: bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.126
diff -b -u -r1.126 bfd-in.h
--- bfd-in.h	20 Mar 2007 20:19:07 -0000	1.126
+++ bfd-in.h	11 Apr 2007 15:16:10 -0000
@@ -76,6 +76,7 @@
 #define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
 
 #define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@
+#define BFD_HOST_64BIT_LONG_LONG @BFD_HOST_64BIT_LONG_LONG@
 #define BFD_HOST_LONG_LONG @BFD_HOST_LONG_LONG@
 #if @BFD_HOST_64_BIT_DEFINED@
 #define BFD_HOST_64_BIT @BFD_HOST_64_BIT@
@@ -96,6 +97,16 @@
 #endif
 #endif
 
+/* Declaring a type wide enough to hold a host long and a host pointer.  */
+#if BFD_HOST_64BIT_LONG_LONG == 1 && BFD_HOST_64BIT_LONG == 0
+#undef BFD_HOSTPTR_T_PRINT
+typedef unsigned long long bfd_hostptr_t;
+#define BFD_HOSTPTR_T_PRT_X	"%llx"
+#else
+typedef unsigned long bfd_hostptr_t;
+#define BFD_HOSTPTR_T_PRT_X	"%lx"
+#endif
+
 /* Forward declaration.  */
 typedef struct bfd bfd;
 
@@ -129,6 +140,9 @@
 #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
+#define sprintf_vma(s,x) sprintf (s, "%016llx", x)
+#define fprintf_vma(f,x) fprintf (f, "%016llx", x)
 #else
 #define _bfd_int64_low(x) ((unsigned long) (((x) & 0xffffffff)))
 #define _bfd_int64_high(x) ((unsigned long) (((x) >> 32) & 0xffffffff))
=

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-11 15:24       ` Kai Tietz
@ 2007-04-11 15:43         ` Daniel Jacobowitz
  2007-04-11 15:49           ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: Daniel Jacobowitz @ 2007-04-11 15:43 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils, H. J. Lu

On Wed, Apr 11, 2007 at 05:21:14PM +0200, Kai Tietz wrote:
> Yes, ice ages ... It seems that on every project and library the same old 
> story reappears ;)
> But as I learned, not on every c-runtime necessarily an stdint header is 
> present and/or want to be included ;()
> 
> Re-inventing the wheel, may this patch could work (beside the 
> BFD_HOSTPTR_T_PRT_X).

Please read my message a second time, since you missed my point :-)
If the OS is missing a usable intptr_t we already have autoconf macros
to create it.

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-11 15:43         ` Daniel Jacobowitz
@ 2007-04-11 15:49           ` Kai Tietz
  2007-04-11 17:34             ` Daniel Jacobowitz
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-11 15:49 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: binutils, H. J. Lu

Daniel Jacobowitz <drow@false.org> wrote on 11.04.2007 17:24:04:

> On Wed, Apr 11, 2007 at 05:21:14PM +0200, Kai Tietz wrote:
> > Yes, ice ages ... It seems that on every project and library the same 
old 
> > story reappears ;)
> > But as I learned, not on every c-runtime necessarily an stdint header 
is 
> > present and/or want to be included ;()
> > 
> > Re-inventing the wheel, may this patch could work (beside the 
> > BFD_HOSTPTR_T_PRT_X).
> 
> Please read my message a second time, since you missed my point :-)
> If the OS is missing a usable intptr_t we already have autoconf macros
> to create it.

I didn't missed your point, but what is needed would be something like a 
longptr_t (which is not part of C99 AFAIK). The same discussion I had in 
the past about the subject "splay-tree.h" header. Not on all platforms is 
a long less or equal to a pointer.

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger



^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-11 15:49           ` Kai Tietz
@ 2007-04-11 17:34             ` Daniel Jacobowitz
  0 siblings, 0 replies; 48+ messages in thread
From: Daniel Jacobowitz @ 2007-04-11 17:34 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils, H. J. Lu

On Wed, Apr 11, 2007 at 05:42:19PM +0200, Kai Tietz wrote:
> I didn't missed your point, but what is needed would be something like a 
> longptr_t

Why?  Do you need something that can hold either a long or a pointer?
You were complaining, in the message I replied to, about warnings on
casts.  You can solve that by casting through intptr_t.

-- 
Daniel Jacobowitz
CodeSourcery

^ permalink raw reply	[flat|nested] 48+ messages in thread

* PATCH: windres
  2007-04-11 14:07   ` H. J. Lu
@ 2007-04-11 18:22     ` Kai Tietz
  2007-04-12 15:55       ` H. J. Lu
  2007-04-18 11:59     ` PATCH: w64 native support Kai Tietz
  1 sibling, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-11 18:22 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1363 bytes --]

Hello,

I have isolated the windres patch from the w64 one.

ChangeLog:

2007-04-11 Kai Tietz  <kai.tietz@onevision.com>

        * binutils/resres.c: Cast sizeof explicit to type "long".
        (res_hdr): Changed to use int instead of long.
        (resres_host_bigendian, HOST_ISBIGENDIAN): Check for
        big endian hosts.
        (write_res_data_16, write_res_data_32, write_res_data_res_hdr,
         read_res_data_16, read_res_data_32, read_res_data_res_hdr): New.
        * binutils/resrc.c: Adjust printf formatter for ints.
        * binutils/windres.c: (main): Assert if sizeof(int) not 4 bytes.
        * binutils/windres.h: Changed windows structure to use
        int type instead of long type.

Regards,
 i.A. Kai Tietz


------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger

[-- Attachment #2: windres.txt --]
[-- Type: text/plain, Size: 23047 bytes --]

Index: resrc.c
===================================================================
RCS file: /cvs/src/src/binutils/resrc.c,v
retrieving revision 1.27
diff -b -u -r1.27 resrc.c
--- resrc.c	8 May 2005 14:17:39 -0000	1.27
+++ resrc.c	11 Apr 2007 17:23:21 -0000
@@ -1515,9 +1515,9 @@
   /* Print out some COFF information that rc files can't represent.  */
 
   if (rd->time != 0)
-    fprintf (e, "// Time stamp: %lu\n", rd->time);
+    fprintf (e, "// Time stamp: %u\n", rd->time);
   if (rd->characteristics != 0)
-    fprintf (e, "// Characteristics: %lu\n", rd->characteristics);
+    fprintf (e, "// Characteristics: %u\n", rd->characteristics);
   if (rd->major != 0 || rd->minor != 0)
     fprintf (e, "// Version: %d %d\n", rd->major, rd->minor);
 
@@ -1546,7 +1546,7 @@
 	      && re->id.u.id != (unsigned long) (unsigned int) *language
 	      && (re->id.u.id & 0xffff) == re->id.u.id)
 	    {
-	      fprintf (e, "LANGUAGE %lu, %lu\n",
+	      fprintf (e, "LANGUAGE %u, %u\n",
 		       re->id.u.id & ((1 << SUBLANG_SHIFT) - 1),
 		       (re->id.u.id >> SUBLANG_SHIFT) & 0xff);
 	      *language = re->id.u.id;
@@ -1774,9 +1774,9 @@
     }
 
   if (res->coff_info.codepage != 0)
-    fprintf (e, "// Code page: %lu\n", res->coff_info.codepage);
+    fprintf (e, "// Code page: %u\n", res->coff_info.codepage);
   if (res->coff_info.reserved != 0)
-    fprintf (e, "// COFF reserved value: %lu\n", res->coff_info.reserved);
+    fprintf (e, "// COFF reserved value: %u\n", res->coff_info.reserved);
 
   if (name != NULL)
     res_id_print (e, *name, 0);
@@ -1809,7 +1809,7 @@
 	       res->u.dialog->width, res->u.dialog->height);
       if (res->u.dialog->ex != NULL
 	  && res->u.dialog->ex->help != 0)
-	fprintf (e, ", %lu", res->u.dialog->ex->help);
+	fprintf (e, ", %u", res->u.dialog->ex->help);
     }
 
   fprintf (e, "\n");
@@ -1841,11 +1841,11 @@
 		 res->res_info.language & ((1<<SUBLANG_SHIFT)-1),
 		 (res->res_info.language >> SUBLANG_SHIFT) & 0xff);
       if (res->res_info.characteristics != 0)
-	fprintf (e, "%sCHARACTERISTICS %lu\n",
+	fprintf (e, "%sCHARACTERISTICS %u\n",
 		 modifiers ? "// " : "",
 		 res->res_info.characteristics);
       if (res->res_info.version != 0)
-	fprintf (e, "%sVERSION %lu\n",
+	fprintf (e, "%sVERSION %u\n",
 		 modifiers ? "// " : "",
 		 res->res_info.version);
     }
@@ -1981,7 +1981,7 @@
     {
       fprintf (e, "// width: %d; height %d; planes %d; bits %d\n",
 	     gc->width, gc->height, gc->planes, gc->bits);
-      fprintf (e, "// data bytes: %lu; index: %d\n",
+      fprintf (e, "// data bytes: %u; index: %d\n",
 	       gc->bytes, gc->index);
     }
 }
@@ -1993,10 +1993,10 @@
 {
   const struct dialog_control *control;
 
-  fprintf (e, "STYLE 0x%lx\n", dialog->style);
+  fprintf (e, "STYLE 0x%x\n", dialog->style);
 
   if (dialog->exstyle != 0)
-    fprintf (e, "EXSTYLE 0x%lx\n", dialog->exstyle);
+    fprintf (e, "EXSTYLE 0x%x\n", dialog->exstyle);
 
   if ((dialog->class.named && dialog->class.u.n.length > 0)
       || dialog->class.u.id != 0)
@@ -2121,7 +2121,7 @@
       res_id_print (e, control->class, 0);
       if (control->class.named)
 	fprintf (e, "\"");
-      fprintf (e, ", 0x%lx, ", control->style);
+      fprintf (e, ", 0x%x, ", control->style);
     }
 
   fprintf (e, "%d, %d", control->x, control->y);
@@ -2137,10 +2137,10 @@
       /* FIXME: We don't need to print the style if it is the default.
 	 More importantly, in certain cases we actually need to turn
 	 off parts of the forced style, by using NOT.  */
-      fprintf (e, ", 0x%lx", control->style);
+      fprintf (e, ", 0x%x", control->style);
 
       if (control->exstyle != 0 || control->help != 0)
-	fprintf (e, ", 0x%lx, %lu", control->exstyle, control->help);
+	fprintf (e, ", 0x%x, %u", control->exstyle, control->help);
     }
 
   fprintf (e, "\n");
@@ -2176,7 +2176,7 @@
     {
       fprintf (e, "// width: %d; height %d; colors: %d; planes %d; bits %d\n",
 	       gi->width, gi->height, gi->colors, gi->planes, gi->bits);
-      fprintf (e, "// data bytes: %lu; index: %d\n",
+      fprintf (e, "// data bytes: %u; index: %d\n",
 	       gi->bytes, gi->index);
     }
 }
@@ -2187,7 +2187,7 @@
 write_rc_menu (FILE *e, const struct menu *menu, int menuex)
 {
   if (menu->help != 0)
-    fprintf (e, "// Help ID: %lu\n", menu->help);
+    fprintf (e, "// Help ID: %u\n", menu->help);
   write_rc_menuitems (e, menu->items, menuex, 0);
 }
 
@@ -2255,12 +2255,12 @@
 	      fprintf (e, ", %d", mi->id);
 	      if (mi->type != 0 || mi->state != 0 || mi->help != 0)
 		{
-		  fprintf (e, ", %lu", mi->type);
+		  fprintf (e, ", %u", mi->type);
 		  if (mi->state != 0 || mi->help != 0)
 		    {
-		      fprintf (e, ", %lu", mi->state);
+		      fprintf (e, ", %u", mi->state);
 		      if (mi->help != 0)
-			fprintf (e, ", %lu", mi->help);
+			fprintf (e, ", %u", mi->help);
 		    }
 		}
 	    }
@@ -2304,7 +2304,7 @@
 	  break;
 
 	case RCDATA_DWORD:
-	  fprintf (e, "%luL", ri->u.dword);
+	  fprintf (e, "%uL", ri->u.dword);
 	  break;
 
 	case RCDATA_STRING:
@@ -2486,29 +2486,29 @@
 
   f = versioninfo->fixed;
   if (f->file_version_ms != 0 || f->file_version_ls != 0)
-    fprintf (e, " FILEVERSION %lu, %lu, %lu, %lu\n",
+    fprintf (e, " FILEVERSION %u, %u, %u, %u\n",
 	     (f->file_version_ms >> 16) & 0xffff,
 	     f->file_version_ms & 0xffff,
 	     (f->file_version_ls >> 16) & 0xffff,
 	     f->file_version_ls & 0xffff);
   if (f->product_version_ms != 0 || f->product_version_ls != 0)
-    fprintf (e, " PRODUCTVERSION %lu, %lu, %lu, %lu\n",
+    fprintf (e, " PRODUCTVERSION %u, %u, %u, %u\n",
 	     (f->product_version_ms >> 16) & 0xffff,
 	     f->product_version_ms & 0xffff,
 	     (f->product_version_ls >> 16) & 0xffff,
 	     f->product_version_ls & 0xffff);
   if (f->file_flags_mask != 0)
-    fprintf (e, " FILEFLAGSMASK 0x%lx\n", f->file_flags_mask);
+    fprintf (e, " FILEFLAGSMASK 0x%x\n", f->file_flags_mask);
   if (f->file_flags != 0)
-    fprintf (e, " FILEFLAGS 0x%lx\n", f->file_flags);
+    fprintf (e, " FILEFLAGS 0x%x\n", f->file_flags);
   if (f->file_os != 0)
-    fprintf (e, " FILEOS 0x%lx\n", f->file_os);
+    fprintf (e, " FILEOS 0x%x\n", f->file_os);
   if (f->file_type != 0)
-    fprintf (e, " FILETYPE 0x%lx\n", f->file_type);
+    fprintf (e, " FILETYPE 0x%x\n", f->file_type);
   if (f->file_subtype != 0)
-    fprintf (e, " FILESUBTYPE 0x%lx\n", f->file_subtype);
+    fprintf (e, " FILESUBTYPE 0x%x\n", f->file_subtype);
   if (f->file_date_ms != 0 || f->file_date_ls != 0)
-    fprintf (e, "// Date: %lu, %lu\n", f->file_date_ms, f->file_date_ls);
+    fprintf (e, "// Date: %u, %u\n", f->file_date_ms, f->file_date_ls);
 
   fprintf (e, "BEGIN\n");
 
Index: resres.c
===================================================================
RCS file: /cvs/src/src/binutils/resres.c,v
retrieving revision 1.7
diff -b -u -r1.7 resres.c
--- resres.c	16 Jun 2005 09:18:19 -0000	1.7
+++ resres.c	11 Apr 2007 17:23:21 -0000
@@ -33,10 +33,13 @@
 
 struct res_hdr
   {
-    unsigned long data_size;
-    unsigned long header_size;
+    unsigned int data_size;
+    unsigned int header_size;
   };
 
+static unsigned int resres_host_bigendian = 0x12345678;
+#define HOST_ISBIGENDIAN	(((unsigned char *)&resres_host_bigendian)[0] != 0x78 ? 1 : 0)
+
 static void write_res_directory
   PARAMS ((const struct res_directory *,
 	   const struct res_id *, const struct res_id *,
@@ -51,12 +54,18 @@
 static void write_res_id PARAMS ((const struct res_id *));
 static void write_res_info PARAMS ((const struct res_res_info *));
 static void write_res_data PARAMS ((const void *, size_t, int));
+static void write_res_data_16 PARAMS ((unsigned short));
+static void write_res_data_32 PARAMS ((unsigned int));
 static void write_res_header
   PARAMS ((unsigned long, const struct res_id *, const struct res_id *,
 	   const struct res_res_info *));
+static void write_res_data_res_hdr PARAMS ((struct res_hdr *));
 
 static int read_resource_entry PARAMS ((void));
 static void read_res_data PARAMS ((void *, size_t, int));
+static void read_res_data_16 PARAMS ((void *));
+static void read_res_data_32 PARAMS ((void *));
+static int read_res_data_res_hdr PARAMS ((struct res_hdr *));
 static void read_res_id PARAMS ((struct res_id *));
 static unichar *read_unistring PARAMS ((int *));
 static void skip_null_resource PARAMS ((void));
@@ -138,6 +147,34 @@
   fclose (fres);
 }
 
+static void
+write_res_data_res_hdr (reshdr)
+     struct res_hdr *reshdr;
+{
+  write_res_data_32 (reshdr->data_size);
+  write_res_data_32 (reshdr->header_size);
+}
+
+static int
+read_res_data_res_hdr (reshdr)
+     struct res_hdr *reshdr;
+{
+  char c[4];
+  if (fread (c, 4, 1, fres) != (size_t) 4)
+    return 0;
+  reshdr->data_size=(unsigned int) c[3]; reshdr->data_size<<=8;
+  reshdr->data_size|=(unsigned int) c[2]; reshdr->data_size<<=8;
+  reshdr->data_size|=(unsigned int) c[1]; reshdr->data_size<<=8;
+  reshdr->data_size|=(unsigned int) c[0];
+  if (fread (c, 4, 1, fres) != (size_t) 4)
+    return 0;
+  reshdr->header_size=(unsigned int) c[3]; reshdr->header_size<<=8;
+  reshdr->header_size|=(unsigned int) c[2]; reshdr->header_size<<=8;
+  reshdr->header_size|=(unsigned int) c[1]; reshdr->header_size<<=8;
+  reshdr->header_size|=(unsigned int) c[0];
+  return 1;
+}
+
 /* Read a resource entry, returns 0 when all resources are read */
 static int
 read_resource_entry (void)
@@ -154,7 +191,7 @@
   res_align_file ();
 
   /* Read header */
-  if (fread (&reshdr, sizeof (reshdr), 1, fres) != 1)
+  if (read_res_data_res_hdr (&reshdr) != 1)
     return 0;
 
   /* read resource type */
@@ -165,11 +202,11 @@
   res_align_file ();
 
   /* Read additional resource header */
-  read_res_data (&resinfo.version, sizeof (resinfo.version), 1);
-  read_res_data (&resinfo.memflags, sizeof (resinfo.memflags), 1);
-  read_res_data (&resinfo.language, sizeof (resinfo.language), 1);
-  read_res_data (&version, sizeof (version), 1);
-  read_res_data (&resinfo.characteristics, sizeof (resinfo.characteristics), 1);
+  read_res_data_32 (&resinfo.version);
+  read_res_data_16 (&resinfo.memflags);
+  read_res_data_16 (&resinfo.language);
+  read_res_data_32 (&version);
+  read_res_data_32 (&resinfo.characteristics);
 
   res_align_file ();
 
@@ -178,7 +215,7 @@
   /* Read data */
   read_res_data (buff, reshdr.data_size, 1);
   /* Convert binary data to resource */
-  r = bin_to_res (type, buff, reshdr.data_size, 0);
+  r = bin_to_res (type, buff, reshdr.data_size, HOST_ISBIGENDIAN);
   r->res_info = resinfo;
   /* Add resource to resource directory */
   res_add_resource (r, &type, &name, resinfo.language, 0);
@@ -354,7 +391,7 @@
   unsigned long datasize = 0;
   const struct bindata *bin_rep, *data;
 
-  bin_rep = res_to_bin (res, 0);
+  bin_rep = res_to_bin (res, HOST_ISBIGENDIAN);
   for (data = bin_rep; data != NULL; data = data->next)
     datasize += data->length;
 
@@ -390,7 +427,7 @@
   reshdr.header_size = (reshdr.header_size + 3) & ~3;
 
   res_align_file ();
-  write_res_data (&reshdr, sizeof (reshdr), 1);
+  write_res_data_res_hdr (&reshdr);
   write_res_id (type);
   write_res_id (name);
 
@@ -412,6 +449,32 @@
     fatal ("%s: could not write to file", filename);
 }
 
+static void
+write_res_data_16 (value)
+     unsigned short value;
+{
+  unsigned char c[2];
+  c[1]=(unsigned char) ((value>>8)&0xff);
+  c[0]=(unsigned char) (value&0xff);
+  
+  if ((size_t) fwrite (c, 2, 1, fres) != (size_t) 2)
+    fatal ("%s: could not write to file", filename);
+}
+
+static void
+write_res_data_32 (value)
+     unsigned int value;
+{
+  unsigned char c[4];
+  c[3]=(unsigned char) ((value>>24)&0xff);
+  c[2]=(unsigned char) ((value>>16)&0xff);
+  c[1]=(unsigned char) ((value>>8)&0xff);
+  c[0]=(unsigned char) (value&0xff);
+  
+  if ((size_t) fwrite (c, 4, 1, fres) != (size_t) 4)
+    fatal ("%s: could not write to file", filename);
+}
+
 /* Read data from file, abort on failure */
 static void
 read_res_data (data, size, count)
@@ -423,6 +486,34 @@
     fatal ("%s: unexpected end of file", filename);
 }
 
+static void
+read_res_data_16 (data)
+     void *data;
+{
+  unsigned char c[2];
+  unsigned short v;
+  if (fread (data, 2, 1, fres) != (size_t) 2)
+    fatal ("%s: unexpected end of file", filename);
+  v=(unsigned short) c[1]; v<<=8;
+  v|=(unsigned short) c[0];
+  *((unsigned short *) data)=v;
+}
+
+static void
+read_res_data_32 (data)
+     void *data;
+{
+  unsigned char c[4];
+  unsigned int v;
+  if (fread (data, 4, 1, fres) != (size_t) 4)
+    fatal ("%s: unexpected end of file", filename);
+  v=(unsigned int) c[3]; v<<=8;
+  v|=(unsigned int) c[2]; v<<=8;
+  v|=(unsigned int) c[1]; v<<=8;
+  v|=(unsigned int) c[0];
+  *((unsigned int *) data)=v;
+}
+
 /* Write a resource id */
 static void
 write_res_id (id)
@@ -437,10 +528,8 @@
     }
   else
     {
-      unsigned short i = 0xFFFF;
-      write_res_data (&i, sizeof (i), 1);
-      i = id->u.id;
-      write_res_data (&i, sizeof (i), 1);
+      write_res_data_16 (0xFFFF);
+      write_res_data_16(id->u.id);
     }
 }
 
@@ -449,11 +538,11 @@
 write_res_info (info)
      const struct res_res_info *info;
 {
-  write_res_data (&info->version, sizeof (info->version), 1);
-  write_res_data (&info->memflags, sizeof (info->memflags), 1);
-  write_res_data (&info->language, sizeof (info->language), 1);
-  write_res_data (&info->version, sizeof (info->version), 1);
-  write_res_data (&info->characteristics, sizeof (info->characteristics), 1);
+  write_res_data_32 (info->version);
+  write_res_data_16 (info->memflags);
+  write_res_data_16 (info->language);
+  write_res_data_32 (info->version);
+  write_res_data_32 (info->characteristics);
 }
 
 /* read a resource identifier */
@@ -465,17 +554,17 @@
   unichar *id_s = NULL;
   int len;
 
-  read_res_data (&ord, sizeof (ord), 1);
+  read_res_data_16 (&ord);
   if (ord == 0xFFFF)		/* an ordinal id */
     {
-      read_res_data (&ord, sizeof (ord), 1);
+      read_res_data_16 (&ord);
       id->named = 0;
       id->u.id = ord;
     }
   else
     /* named id */
     {
-      if (fseek (fres, -sizeof (ord), SEEK_CUR) != 0)
+      if (fseek (fres, -2, SEEK_CUR) != 0)
 	fatal ("%s: %s: could not seek in file", program_name, filename);
       id_s = read_unistring (&len);
       id->named = 1;
@@ -530,7 +619,7 @@
 {
   struct res_hdr reshdr =
   {0, 0};
-  read_res_data (&reshdr, sizeof (reshdr), 1);
+  read_res_data_res_hdr (&reshdr);
   if ((reshdr.data_size != 0) || (reshdr.header_size != 0x20))
     goto skip_err;
 
Index: windres.c
===================================================================
RCS file: /cvs/src/src/binutils/windres.c,v
retrieving revision 1.28
diff -b -u -r1.28 windres.c
--- windres.c	17 Feb 2007 13:33:54 -0000	1.28
+++ windres.c	11 Apr 2007 17:23:22 -0000
@@ -263,7 +263,7 @@
 res_id_print (FILE *stream, struct res_id id, int quote)
 {
   if (! id.named)
-    fprintf (stream, "%lu", id.u.id);
+    fprintf (stream, "%u", id.u.id);
   else
     {
       if (quote)
@@ -320,12 +320,12 @@
 
       if (*resources == NULL)
 	{
-	  static unsigned long timeval;
+	  static unsigned int timeval;
 
 	  /* Use the same timestamp for every resource created in a
              single run.  */
 	  if (timeval == 0)
-	    timeval = time (NULL);
+	    timeval = (unsigned int) time (NULL);
 
 	  *resources = ((struct res_directory *)
 			res_alloc (sizeof **resources));
@@ -756,6 +756,9 @@
   struct res_directory *resources;
   int use_temp_file;
 
+  /* Check, that the type int has a size of 4 bytes, otherwise fail.  */
+  assert (sizeof (int) == 4);
+
 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
   setlocale (LC_MESSAGES, "");
 #endif
Index: windres.h
===================================================================
RCS file: /cvs/src/src/binutils/windres.h,v
retrieving revision 1.14
diff -b -u -r1.14 windres.h
--- windres.h	8 May 2005 14:17:39 -0000	1.14
+++ windres.h	11 Apr 2007 17:23:22 -0000
@@ -35,9 +35,9 @@
 {
   /* Resource flags.  According to the MS docs, this is currently
      always zero.  */
-  unsigned long characteristics;
+  unsigned int characteristics;
   /* Time/date stamp.  */
-  unsigned long time;
+  unsigned int time;
   /* Major version number.  */
   unsigned short major;
   /* Minor version number.  */
@@ -63,7 +63,7 @@
       unichar *name;
     } n;
     /* If the named field is zero, this is the ID.  */
-    unsigned long id;
+    unsigned int id;
   } u;
 };
 
@@ -127,11 +127,11 @@
      COFF file, the res_directory structure has a characteristics
      field, but I don't know if it's related to the one in the res
      file.  */
-  unsigned long characteristics;
+  unsigned int characteristics;
   /* Version of the resource.  Entirely user defined.  In a COFF file,
      the res_directory structure has a characteristics field, but I
      don't know if it's related to the one in the res file.  */
-  unsigned long version;
+  unsigned int version;
   /* Memory flags.  This is a combination of the MEMFLAG values
      defined below.  Most of these values are historical, and are not
      meaningful for win32.  I don't think there is any way to store
@@ -146,11 +146,11 @@
 {
   /* The code page used for the data.  I don't really know what this
      should be.  */
-  unsigned long codepage;
+  unsigned int codepage;
   /* A resource entry in a COFF file has a reserved field, which we
      record here when reading a COFF file.  When writing a COFF file,
      we set this field to zero.  */
-  unsigned long reserved;
+  unsigned int reserved;
 };
 
 /* Resource data is stored in a res_resource structure.  */
@@ -164,7 +164,7 @@
   {
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const unsigned char *data;
     } data;
     struct accelerator *acc;
@@ -250,7 +250,7 @@
   /* Y coordinate of hotspot.  */
   short yhotspot;
   /* Length of bitmap data.  */
-  unsigned long length;
+  unsigned int length;
   /* Data.  */
   const unsigned char *data;
 };
@@ -270,7 +270,7 @@
   /* Bits per pixel.  */
   unsigned short bits;
   /* Number of bytes in cursor resource.  */
-  unsigned long bytes;
+  unsigned int bytes;
   /* Index of cursor resource.  */
   unsigned short index;
 };
@@ -280,9 +280,9 @@
 struct dialog
 {
   /* Basic window style.  */
-  unsigned long style;
+  unsigned int style;
   /* Extended window style.  */
-  unsigned long exstyle;
+  unsigned int exstyle;
   /* X coordinate.  */
   unsigned short x;
   /* Y coordinate.  */
@@ -312,7 +312,7 @@
 struct dialog_ex
 {
   /* Help ID.  */
-  unsigned long help;
+  unsigned int help;
   /* Font weight.  */
   unsigned short weight;
   /* Whether the font is italic.  */
@@ -482,9 +482,9 @@
   /* ID.  */
   unsigned short id;
   /* Style.  */
-  unsigned long style;
+  unsigned int style;
   /* Extended style.  */
-  unsigned long exstyle;
+  unsigned int exstyle;
   /* X coordinate.  */
   unsigned short x;
   /* Y coordinate.  */
@@ -500,7 +500,7 @@
   /* Extra data for the window procedure.  */
   struct rcdata_item *data;
   /* Help ID.  Only used in an extended dialog.  */
-  unsigned long help;
+  unsigned int help;
 };
 
 /* Control classes.  These can be used as the ID field in a struct
@@ -521,7 +521,7 @@
   /* Index of font entry.  */
   short index;
   /* Length of font information.  */
-  unsigned long length;
+  unsigned int length;
   /* Font information.  */
   const unsigned char *data;
 };
@@ -543,7 +543,7 @@
   /* Bits per pixel.  */
   unsigned short bits;
   /* Number of bytes in cursor resource.  */
-  unsigned long bytes;
+  unsigned int bytes;
   /* Index of cursor resource.  */
   unsigned short index;
 };
@@ -556,7 +556,7 @@
   struct menuitem *items;
   /* Help ID.  I don't think there is any way to set this in an rc
      file, but it can appear in the binary format.  */
-  unsigned long help;
+  unsigned int help;
 };
 
 /* A menu resource is a list of menuitem structures.  */
@@ -567,9 +567,9 @@
   struct menuitem *next;
   /* Type.  In a normal menu, rather than a menuex, this is the flags
      field.  */
-  unsigned long type;
+  unsigned int type;
   /* State.  This is only used in a menuex.  */
-  unsigned long state;
+  unsigned int state;
   /* Id.  */
   unsigned short id;
   /* Unicode text.  */
@@ -577,7 +577,7 @@
   /* Popup menu items for a popup.  */
   struct menuitem *popup;
   /* Help ID.  This is only used in a menuex.  */
-  unsigned long help;
+  unsigned int help;
 };
 
 /* Menu item flags.  These can appear in the flags field of a struct
@@ -613,20 +613,20 @@
   union
   {
     unsigned int word;
-    unsigned long dword;
+    unsigned int dword;
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const char *s;
     } string;
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const unichar *w;
     } wstring;
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const unsigned char *data;
     } buffer;
   } u;
@@ -661,24 +661,24 @@
 struct fixed_versioninfo
 {
   /* The file version, which is two 32 bit integers.  */
-  unsigned long file_version_ms;
-  unsigned long file_version_ls;
+  unsigned int file_version_ms;
+  unsigned int file_version_ls;
   /* The product version, which is two 32 bit integers.  */
-  unsigned long product_version_ms;
-  unsigned long product_version_ls;
+  unsigned int product_version_ms;
+  unsigned int product_version_ls;
   /* The file flags mask.  */
-  unsigned long file_flags_mask;
+  unsigned int file_flags_mask;
   /* The file flags.  */
-  unsigned long file_flags;
+  unsigned int file_flags;
   /* The OS type.  */
-  unsigned long file_os;
+  unsigned int file_os;
   /* The file type.  */
-  unsigned long file_type;
+  unsigned int file_type;
   /* The file subtype.  */
-  unsigned long file_subtype;
+  unsigned int file_subtype;
   /* The date, which in Windows is two 32 bit integers.  */
-  unsigned long file_date_ms;
-  unsigned long file_date_ls;
+  unsigned int file_date_ms;
+  unsigned int file_date_ls;
 };
 
 /* A list of variable version information.  */
@@ -742,7 +742,7 @@
   /* Next data.  */
   struct bindata *next;
   /* Length of data.  */
-  unsigned long length;
+  unsigned int length;
   /* Data.  */
   unsigned char *data;
 };
=

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-11 18:22     ` PATCH: windres Kai Tietz
@ 2007-04-12 15:55       ` H. J. Lu
  2007-04-12 16:51         ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: H. J. Lu @ 2007-04-12 15:55 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Wed, Apr 11, 2007 at 07:33:31PM +0200, Kai Tietz wrote:
> Hello,
> 
> I have isolated the windres patch from the w64 one.
> 
> ChangeLog:
> 
> 2007-04-11 Kai Tietz  <kai.tietz@onevision.com>
> 
>         * binutils/resres.c: Cast sizeof explicit to type "long".
>         (res_hdr): Changed to use int instead of long.
>         (resres_host_bigendian, HOST_ISBIGENDIAN): Check for
>         big endian hosts.
>         (write_res_data_16, write_res_data_32, write_res_data_res_hdr,
>          read_res_data_16, read_res_data_32, read_res_data_res_hdr): New.
>         * binutils/resrc.c: Adjust printf formatter for ints.
>         * binutils/windres.c: (main): Assert if sizeof(int) not 4 bytes.
>         * binutils/windres.h: Changed windows structure to use
>         int type instead of long type.
> 

Can you try to use existing data type I/O routines in bfd?


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-12 15:55       ` H. J. Lu
@ 2007-04-12 16:51         ` Kai Tietz
  2007-04-12 18:03           ` H. J. Lu
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-12 16:51 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

"H. J. Lu" <hjl@lucon.org> wrote on 12.04.2007 17:55:25:

> Can you try to use existing data type I/O routines in bfd?

You mean the endian swapping ?

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger



^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-12 16:51         ` Kai Tietz
@ 2007-04-12 18:03           ` H. J. Lu
  2007-04-13 14:41             ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: H. J. Lu @ 2007-04-12 18:03 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Thu, Apr 12, 2007 at 06:23:21PM +0200, Kai Tietz wrote:
> "H. J. Lu" <hjl@lucon.org> wrote on 12.04.2007 17:55:25:
> 
> > Can you try to use existing data type I/O routines in bfd?
> 
> You mean the endian swapping ?
> 

Yes. Also you should use

unsigned char characteristics [4];

instead of

unsigned long characteristics;

or

unsigned int characteristics;


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-12 18:03           ` H. J. Lu
@ 2007-04-13 14:41             ` Kai Tietz
  2007-04-13 14:49               ` H. J. Lu
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-13 14:41 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

"H. J. Lu" <hjl@lucon.org> wrote on 12.04.2007 18:56:45:

> On Thu, Apr 12, 2007 at 06:23:21PM +0200, Kai Tietz wrote:
> > "H. J. Lu" <hjl@lucon.org> wrote on 12.04.2007 17:55:25:
> > 
> > > Can you try to use existing data type I/O routines in bfd?
> > 
> > You mean the endian swapping ?
> > 
> 
> Yes. Also you should use
> 
> unsigned char characteristics [4];
> 
> instead of
> 
> unsigned long characteristics;
> 
> or
> 
> unsigned int characteristics;

Nightmares, ... 8| I begun to modify structure using character arrays ... 
I come to the point, that this means for big parts of windres better a 
complete rewrite. Structures with internal/external scope and data 
modifications are really wired.
May we should first use my last patch, so that the problem is solved, and 
then I will begin to reorganize the windres tool to be host idependent. By 
this I can add some missing resource types to it.

What do you think about my suggestion to continue ?

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-13 14:41             ` Kai Tietz
@ 2007-04-13 14:49               ` H. J. Lu
  2007-04-16 10:05                 ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: H. J. Lu @ 2007-04-13 14:49 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Fri, Apr 13, 2007 at 04:19:25PM +0200, Kai Tietz wrote:
> "H. J. Lu" <hjl@lucon.org> wrote on 12.04.2007 18:56:45:
> 
> > On Thu, Apr 12, 2007 at 06:23:21PM +0200, Kai Tietz wrote:
> > > "H. J. Lu" <hjl@lucon.org> wrote on 12.04.2007 17:55:25:
> > > 
> > > > Can you try to use existing data type I/O routines in bfd?
> > > 
> > > You mean the endian swapping ?
> > > 
> > 
> > Yes. Also you should use
> > 
> > unsigned char characteristics [4];
> > 
> > instead of
> > 
> > unsigned long characteristics;
> > 
> > or
> > 
> > unsigned int characteristics;
> 
> Nightmares, ... 8| I begun to modify structure using character arrays ... 
> I come to the point, that this means for big parts of windres better a 
> complete rewrite. Structures with internal/external scope and data 
> modifications are really wired.
> May we should first use my last patch, so that the problem is solved, and 
> then I will begin to reorganize the windres tool to be host idependent. By 
> this I can add some missing resource types to it.
> 
> What do you think about my suggestion to continue ?
> 

That is fine with me. If you do this, you don't need to handle
endian and just replace long with int since you will rewrite it
later anyway.


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-13 14:49               ` H. J. Lu
@ 2007-04-16 10:05                 ` Kai Tietz
  2007-04-16 21:59                   ` Christopher Faylor
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-16 10:05 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 2046 bytes --]

"H. J. Lu" <hjl@lucon.org> wrote on 13.04.2007 16:41:06:

> > Nightmares, ... 8| I begun to modify structure using character arrays 
... 
> > I come to the point, that this means for big parts of windres better a 

> > complete rewrite. Structures with internal/external scope and data 
> > modifications are really wired.
> > May we should first use my last patch, so that the problem is solved, 
and 
> > then I will begin to reorganize the windres tool to be host 
idependent. By 
> > this I can add some missing resource types to it.
> > 
> > What do you think about my suggestion to continue ?
> > 
> 
> That is fine with me. If you do this, you don't need to handle
> endian and just replace long with int since you will rewrite it
> later anyway.

This is the patch changing the windres source using int instead of long. I 
bootstrap it on cygwin 32 and for x86_64-mingw.
This patch does not solve the endian problem, reasoned by the use of 
fwrite/fread.
ChangeLog for binutils/:

2007-04-16  Kai Tietz  <Kai.Tietz@onevision.com>

        * rclex.l: Replace long by int usage.
        * rcparse.y: Likewise.
        * resbin.c: Likewise.
        * rescoff.c: Likewise.
        * resrc.c: Likewise.
        * resres.c: Likewise.
        * windres.h: Likewise.
        * windres.c: Likewise.
        (main): Add assert if sizeof int has not 4 byte
        size.


Regards,
 i.A. Kai Tietz



------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


[-- Attachment #2: windres_int.txt --]
[-- Type: text/plain, Size: 47571 bytes --]

Index: rclex.l
===================================================================
RCS file: /cvs/src/src/binutils/rclex.l,v
retrieving revision 1.14
diff -B -b -u -r1.14 rclex.l
--- rclex.l	12 Oct 2005 00:16:12 -0000	1.14
+++ rclex.l	16 Apr 2007 09:13:35 -0000
@@ -70,7 +70,7 @@
 /* Local functions.  */
 
 static void cpp_line (const char *);
-static char *handle_quotes (const char *, unsigned long *);
+static char *handle_quotes (const char *, unsigned int *);
 static char *get_string (int);
 
 %}
@@ -201,7 +201,7 @@
 
 ("\""[^\"\n]*"\""[ \t\n]*)+ {
 			  char *s;
-			  unsigned long length;
+			  unsigned int length;
 
 			  s = handle_quotes (yytext, &length);
 			  if (! rcdata_mode)
@@ -303,7 +303,7 @@
    merged separated by whitespace are merged, as in C.  */
 
 static char *
-handle_quotes (const char *input, unsigned long *len)
+handle_quotes (const char *input, unsigned int *len)
 {
   char *ret, *s;
   const char *t;
Index: rcparse.y
===================================================================
RCS file: /cvs/src/src/binutils/rcparse.y,v
retrieving revision 1.22
diff -B -b -u -r1.22 rcparse.y
--- rcparse.y	8 May 2005 14:17:39 -0000	1.22
+++ rcparse.y	16 Apr 2007 09:13:36 -0000
@@ -45,14 +45,14 @@
 /* This is used when building a style.  It is modified by the
    nonterminal styleexpr.  */
 
-static unsigned long style;
+static unsigned int style;
 
 /* These are used when building a control.  They are set before using
    control_params.  */
 
-static unsigned long base_style;
-static unsigned long default_style;
-static unsigned long class;
+static unsigned int base_style;
+static unsigned int default_style;
+static unsigned int class;
 static struct res_id res_text_field;
 static unichar null_unichar;
 
@@ -88,16 +88,16 @@
   } memflags;
   struct
   {
-    unsigned long val;
+    unsigned int val;
     /* Nonzero if this number was explicitly specified as long.  */
     int dword;
   } i;
-  unsigned long il;
+  unsigned int il;
   unsigned short is;
   const char *s;
   struct
   {
-    unsigned long length;
+    unsigned int length;
     const char *s;
   } ss;
 };
Index: resbin.c
===================================================================
RCS file: /cvs/src/src/binutils/resbin.c,v
retrieving revision 1.10
diff -B -b -u -r1.10 resbin.c
--- resbin.c	29 Mar 2006 00:24:28 -0000	1.10
+++ resbin.c	16 Apr 2007 09:13:37 -0000
@@ -40,39 +40,39 @@
 static void toosmall (const char *);
 
 static unichar *get_unicode
-  (const unsigned char *, unsigned long, int, int *);
+  (const unsigned char *, unsigned int, int, int *);
 static int get_resid
-  (struct res_id *, const unsigned char *, unsigned long, int);
+  (struct res_id *, const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_generic
-  (enum res_type, const unsigned char *, unsigned long);
+  (enum res_type, const unsigned char *, unsigned int);
 static struct res_resource *bin_to_res_cursor
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_menu
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct menuitem *bin_to_res_menuitems
-  (const unsigned char *, unsigned long, int, int *);
+  (const unsigned char *, unsigned int, int, int *);
 static struct menuitem *bin_to_res_menuexitems
-  (const unsigned char *, unsigned long, int, int *);
+  (const unsigned char *, unsigned int, int, int *);
 static struct res_resource *bin_to_res_dialog
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_string
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_fontdir
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_accelerators
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_rcdata
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_group_cursor
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_group_icon
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_version
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static struct res_resource *bin_to_res_userdata
-  (const unsigned char *, unsigned long, int);
+  (const unsigned char *, unsigned int, int);
 static void get_version_header
-  (const unsigned char *, unsigned long, int, const char *,
+  (const unsigned char *, unsigned int, int, const char *,
    unichar **, int *, int *, int *, int *);
 
 /* Given a resource type ID, a pointer to data, a length, return a
@@ -82,7 +82,7 @@
 
 struct res_resource *
 bin_to_res (struct res_id type, const unsigned char *data,
-	    unsigned long length, int big_endian)
+	    unsigned int length, int big_endian)
 {
   if (type.named)
     return bin_to_res_userdata (data, length, big_endian);
@@ -135,7 +135,7 @@
 /* Swap in a NULL terminated unicode string.  */
 
 static unichar *
-get_unicode (const unsigned char *data, unsigned long length,
+get_unicode (const unsigned char *data, unsigned int length,
 	     int big_endian, int *retlen)
 {
   int c, i;
@@ -144,7 +144,7 @@
   c = 0;
   while (1)
     {
-      if (length < (unsigned long) c * 2 + 2)
+      if (length < (unsigned int) c * 2 + 2)
 	toosmall (_("null terminated unicode string"));
       if (get_16 (big_endian, data + c * 2) == 0)
 	break;
@@ -167,7 +167,7 @@
 
 static int
 get_resid (struct res_id *id, const unsigned char *data,
-	   unsigned long length, int big_endian)
+	   unsigned int length, int big_endian)
 {
   int first;
 
@@ -196,7 +196,7 @@
 
 struct res_resource *
 bin_to_res_generic (enum res_type type, const unsigned char *data,
-		    unsigned long length)
+		    unsigned int length)
 {
   struct res_resource *r;
 
@@ -211,7 +211,7 @@
 /* Convert a cursor resource from binary.  */
 
 struct res_resource *
-bin_to_res_cursor (const unsigned char *data, unsigned long length,
+bin_to_res_cursor (const unsigned char *data, unsigned int length,
 		   int big_endian)
 {
   struct cursor *c;
@@ -236,7 +236,7 @@
 /* Convert a menu resource from binary.  */
 
 struct res_resource *
-bin_to_res_menu (const unsigned char *data, unsigned long length,
+bin_to_res_menu (const unsigned char *data, unsigned int length,
 		 int big_endian)
 {
   struct res_resource *r;
@@ -286,7 +286,7 @@
 /* Convert menu items from binary.  */
 
 static struct menuitem *
-bin_to_res_menuitems (const unsigned char *data, unsigned long length,
+bin_to_res_menuitems (const unsigned char *data, unsigned int length,
 		      int big_endian, int *read)
 {
   struct menuitem *first, **pp;
@@ -364,7 +364,7 @@
 /* Convert menuex items from binary.  */
 
 static struct menuitem *
-bin_to_res_menuexitems (const unsigned char *data, unsigned long length,
+bin_to_res_menuexitems (const unsigned char *data, unsigned int length,
 			int big_endian, int *read)
 {
   struct menuitem *first, **pp;
@@ -439,7 +439,7 @@
 /* Convert a dialog resource from binary.  */
 
 static struct res_resource *
-bin_to_res_dialog (const unsigned char *data, unsigned long length,
+bin_to_res_dialog (const unsigned char *data, unsigned int length,
 		   int big_endian)
 {
   int signature;
@@ -625,7 +625,7 @@
 /* Convert a stringtable resource from binary.  */
 
 static struct res_resource *
-bin_to_res_string (const unsigned char *data, unsigned long length,
+bin_to_res_string (const unsigned char *data, unsigned int length,
 		   int big_endian)
 {
   struct stringtable *st;
@@ -672,7 +672,7 @@
 /* Convert a fontdir resource from binary.  */
 
 static struct res_resource *
-bin_to_res_fontdir (const unsigned char *data, unsigned long length,
+bin_to_res_fontdir (const unsigned char *data, unsigned int length,
 		    int big_endian)
 {
   int c, i;
@@ -742,7 +742,7 @@
 /* Convert an accelerators resource from binary.  */
 
 static struct res_resource *
-bin_to_res_accelerators (const unsigned char *data, unsigned long length,
+bin_to_res_accelerators (const unsigned char *data, unsigned int length,
 			 int big_endian)
 {
   struct accelerator *first, **pp;
@@ -785,7 +785,7 @@
 /* Convert an rcdata resource from binary.  */
 
 static struct res_resource *
-bin_to_res_rcdata (const unsigned char *data, unsigned long length,
+bin_to_res_rcdata (const unsigned char *data, unsigned int length,
 		   int big_endian ATTRIBUTE_UNUSED)
 {
   struct rcdata_item *ri;
@@ -808,7 +808,7 @@
 /* Convert a group cursor resource from binary.  */
 
 static struct res_resource *
-bin_to_res_group_cursor (const unsigned char *data, unsigned long length,
+bin_to_res_group_cursor (const unsigned char *data, unsigned int length,
 			 int big_endian)
 {
   int type, c, i;
@@ -864,7 +864,7 @@
 /* Convert a group icon resource from binary.  */
 
 static struct res_resource *
-bin_to_res_group_icon (const unsigned char *data, unsigned long length,
+bin_to_res_group_icon (const unsigned char *data, unsigned int length,
 		       int big_endian)
 {
   int type, c, i;
@@ -924,7 +924,7 @@
    to the type, and *OFF to the offset to the children.  */
 
 static void
-get_version_header (const unsigned char *data, unsigned long length,
+get_version_header (const unsigned char *data, unsigned int length,
 		    int big_endian, const char *key, unichar **pkey,
 		    int *len, int *vallen, int *type, int *off)
 {
@@ -973,7 +973,7 @@
 /* Convert a version resource from binary.  */
 
 static struct res_resource *
-bin_to_res_version (const unsigned char *data, unsigned long length,
+bin_to_res_version (const unsigned char *data, unsigned int length,
 		    int big_endian)
 {
   int verlen, vallen, type, off;
@@ -986,7 +986,7 @@
 		      (unichar **) NULL, &verlen, &vallen, &type, &off);
 
   if ((unsigned int) verlen != length)
-    fatal (_("version length %d does not match resource length %lu"),
+    fatal (_("version length %d does not match resource length %u"),
 	   verlen, length);
 
   if (type != 0)
@@ -999,7 +999,7 @@
     fi = NULL;
   else
     {
-      unsigned long signature, fiv;
+      unsigned int signature, fiv;
 
       if (vallen != 52)
 	fatal (_("unexpected fixed version information length %d"), vallen);
@@ -1009,11 +1009,11 @@
 
       signature = get_32 (big_endian, data);
       if (signature != 0xfeef04bd)
-	fatal (_("unexpected fixed version signature %lu"), signature);
+	fatal (_("unexpected fixed version signature %u"), signature);
 
       fiv = get_32 (big_endian, data + 4);
       if (fiv != 0 && fiv != 0x10000)
-	fatal (_("unexpected fixed version info version %lu"), fiv);
+	fatal (_("unexpected fixed version info version %u"), fiv);
 
       fi = (struct fixed_versioninfo *) res_alloc (sizeof *fi);
 
@@ -1192,7 +1192,7 @@
 /* Convert an arbitrary user defined resource from binary.  */
 
 static struct res_resource *
-bin_to_res_userdata (const unsigned char *data, unsigned long length,
+bin_to_res_userdata (const unsigned char *data, unsigned int length,
 		     int big_endian ATTRIBUTE_UNUSED)
 {
   struct rcdata_item *ri;
@@ -1220,7 +1220,7 @@
 
 /* Local functions used to convert resources to binary format.  */
 
-static void dword_align_bin (struct bindata ***, unsigned long *);
+static void dword_align_bin (struct bindata ***, unsigned int *);
 static struct bindata *resid_to_bin (struct res_id, int);
 static struct bindata *unicode_to_bin (const unichar *, int);
 static struct bindata *res_to_bin_accelerator
@@ -1249,7 +1249,7 @@
 static struct bindata *res_to_bin_versioninfo
   (const struct versioninfo *, int);
 static struct bindata *res_to_bin_generic
-  (unsigned long, const unsigned char *);
+  (unsigned int, const unsigned char *);
 
 /* Convert a resource to binary.  */
 
@@ -1296,7 +1296,7 @@
    boundary.  It updates *PPP and *LENGTH.  */
 
 static void
-dword_align_bin (struct bindata ***ppp, unsigned long *length)
+dword_align_bin (struct bindata ***ppp, unsigned int *length)
 {
   int add;
   struct bindata *d;
@@ -1502,7 +1502,7 @@
 {
   int dialogex;
   struct bindata *first, **pp;
-  unsigned long length;
+  unsigned int length;
   int off, c;
   struct dialog_control *dc;
 
@@ -1654,7 +1654,7 @@
 	put_16 (big_endian, 0, d->data);
       else
 	{
-	  unsigned long sublen;
+	  unsigned int sublen;
 
 	  dword_align_bin (&pp, &length);
 
@@ -1858,7 +1858,7 @@
 res_to_bin_menuexitems (const struct menuitem *items, int big_endian)
 {
   struct bindata *first, **pp;
-  unsigned long length;
+  unsigned int length;
   const struct menuitem *mi;
 
   first = NULL;
@@ -1965,7 +1965,7 @@
 
 	case RCDATA_WSTRING:
 	  {
-	    unsigned long i;
+	    unsigned int i;
 
 	    d->length = ri->u.wstring.length * 2;
 	    d->data = (unsigned char *) reswr_alloc (d->length);
@@ -2055,7 +2055,7 @@
 res_to_bin_versioninfo (const struct versioninfo *versioninfo, int big_endian)
 {
   struct bindata *first, **pp;
-  unsigned long length;
+  unsigned int length;
   struct ver_info *vi;
 
   first = (struct bindata *) reswr_alloc (sizeof *first);
@@ -2114,7 +2114,7 @@
   for (vi = versioninfo->var; vi != NULL; vi = vi->next)
     {
       struct bindata *vid;
-      unsigned long vilen;
+      unsigned int vilen;
 
       dword_align_bin (&pp, &length);
 
@@ -2138,7 +2138,7 @@
 
 	case VERINFO_STRING:
 	  {
-	    unsigned long hold, vslen;
+	    unsigned int hold, vslen;
 	    struct bindata *vsd;
 	    const struct ver_stringinfo *vs;
 
@@ -2174,7 +2174,7 @@
 	    for (vs = vi->u.string.strings; vs != NULL; vs = vs->next)
 	      {
 		struct bindata *vssd;
-		unsigned long vsslen;
+		unsigned int vsslen;
 
 		hold = length;
 		dword_align_bin (&pp, &length);
@@ -2226,7 +2226,7 @@
 
 	case VERINFO_VAR:
 	  {
-	    unsigned long hold, vvlen, vvvlen;
+	    unsigned int hold, vvlen, vvvlen;
 	    struct bindata *vvd;
 	    const struct ver_varinfo *vv;
 
@@ -2304,7 +2304,7 @@
 /* Convert a generic resource to binary.  */
 
 static struct bindata *
-res_to_bin_generic (unsigned long length, const unsigned char *data)
+res_to_bin_generic (unsigned int length, const unsigned char *data)
 {
   struct bindata *d;
 
Index: rescoff.c
===================================================================
RCS file: /cvs/src/src/binutils/rescoff.c,v
retrieving revision 1.7
diff -B -b -u -r1.7 rescoff.c
--- rescoff.c	8 May 2005 14:17:39 -0000	1.7
+++ rescoff.c	16 Apr 2007 09:13:37 -0000
@@ -209,7 +209,7 @@
 
   for (i = 0; i < name_count; i++, ere++)
     {
-      unsigned long name, rva;
+      unsigned int name, rva;
       struct res_entry *re;
       const bfd_byte *ers;
       int length, j;
@@ -263,7 +263,7 @@
 
   for (i = 0; i < id_count; i++, ere++)
     {
-      unsigned long name, rva;
+      unsigned int name, rva;
       struct res_entry *re;
 
       if ((const bfd_byte *) ere >= finfo->data_end)
@@ -311,7 +311,7 @@
 {
   const struct extern_res_data *erd;
   struct res_resource *r;
-  unsigned long size, rva;
+  unsigned int size, rva;
   const bfd_byte *resdata;
 
   if (type == NULL)
@@ -351,7 +351,7 @@
   /* The last structure we have added to the list.  */
   struct bindata *last;
   /* The size of the list as a whole.  */
-  unsigned long length;
+  unsigned int length;
 };
 
 /* This structure keeps track of information as we build the directory
@@ -369,11 +369,11 @@
 
   /* These fields are computed initially, and then not changed.  */
   /* Length of directory tables and entries.  */
-  unsigned long dirsize;
+  unsigned int dirsize;
   /* Length of directory entry strings.  */
-  unsigned long dirstrsize;
+  unsigned int dirstrsize;
   /* Length of resource data entries.  */
-  unsigned long dataentsize;
+  unsigned int dataentsize;
 
   /* These fields are updated as we add data.  */
   /* Directory tables and entries.  */
@@ -421,7 +421,7 @@
   asection *sec;
   struct coff_write_info cwi;
   struct bindata *d;
-  unsigned long length, offset;
+  unsigned int length, offset;
 
   if (filename == NULL)
     fatal (_("filename required for COFF output"));
@@ -701,7 +701,7 @@
   arelent *r;
   struct extern_res_data *erd;
   struct bindata *d;
-  unsigned long length;
+  unsigned int length;
 
   /* For some reason, although every other address is a section
      offset, the address of the resource data itself is an RVA.  That
Index: resrc.c
===================================================================
RCS file: /cvs/src/src/binutils/resrc.c,v
retrieving revision 1.27
diff -B -b -u -r1.27 resrc.c
--- resrc.c	8 May 2005 14:17:39 -0000	1.27
+++ resrc.c	16 Apr 2007 09:13:39 -0000
@@ -110,9 +110,9 @@
     } cursor;
   } u;
   /* Bytes in image.  */
-  unsigned long bytes;
+  unsigned int bytes;
   /* File offset of image.  */
-  unsigned long offset;
+  unsigned int offset;
 };
 
 /* The name of the rc file we are reading.  */
@@ -169,8 +169,8 @@
 static void close_input_stream (void);
 static void unexpected_eof (const char *);
 static int get_word (FILE *, const char *);
-static unsigned long get_long (FILE *, const char *);
-static void get_data (FILE *, unsigned char *, unsigned long, const char *);
+static unsigned int get_long (FILE *, const char *);
+static void get_data (FILE *, unsigned char *, unsigned int, const char *);
 static void define_fontdirs (void);
 \f
 /* Run `cmd' and redirect the output to `redir'.  */
@@ -555,7 +555,7 @@
 /* Read a 32 bit word from a file.  The data is assumed to be little
    endian.  */
 
-static unsigned long
+static unsigned int
 get_long (FILE *e, const char *msg)
 {
   int b1, b2, b3, b4;
@@ -575,15 +575,15 @@
 /* Read data from a file.  This is a wrapper to do error checking.  */
 
 static void
-get_data (FILE *e, unsigned char *p, unsigned long c, const char *msg)
+get_data (FILE *e, unsigned char *p, unsigned int c, const char *msg)
 {
-  unsigned long got;
+  unsigned int got;
 
   got = fread (p, 1, c, e);
   if (got == c)
     return;
 
-  fatal (_("%s: read of %lu returned %lu"), msg, c, got);
+  fatal (_("%s: read of %u returned %u"), msg, c, got);
 }
 \f
 /* Define an accelerator resource.  */
@@ -704,7 +704,7 @@
       struct cursor *c;
 
       if (fseek (e, icondirs[i].offset, SEEK_SET) != 0)
-	fatal (_("%s: fseek to %lu failed: %s"), real_filename,
+	fatal (_("%s: fseek to %u failed: %s"), real_filename,
 	       icondirs[i].offset, strerror (errno));
 
       data = (unsigned char *) res_alloc (icondirs[i].bytes);
@@ -788,10 +788,10 @@
    merely allocates and fills in a structure.  */
 
 struct dialog_control *
-define_control (const struct res_id iid, unsigned long id, unsigned long x,
-		unsigned long y, unsigned long width, unsigned long height,
-		unsigned long class, unsigned long style,
-		unsigned long exstyle)
+define_control (const struct res_id iid, unsigned int id, unsigned int x,
+		unsigned int y, unsigned int width, unsigned int height,
+		unsigned int class, unsigned int style,
+		unsigned int exstyle)
 {
   struct dialog_control *n;
 
@@ -814,9 +814,9 @@
 }
 
 struct dialog_control *
-define_icon_control (struct res_id iid, unsigned long id, unsigned long x,
-		     unsigned long y, unsigned long style,
-		     unsigned long exstyle, unsigned long help,
+define_icon_control (struct res_id iid, unsigned int id, unsigned int x,
+		     unsigned int y, unsigned int style,
+		     unsigned int exstyle, unsigned int help,
 		     struct rcdata_item *data, struct dialog_ex *ex)
 {
   struct dialog_control *n;
@@ -1000,7 +1000,7 @@
       struct res_id name;
 
       if (fseek (e, icondirs[i].offset, SEEK_SET) != 0)
-	fatal (_("%s: fseek to %lu failed: %s"), real_filename,
+	fatal (_("%s: fseek to %u failed: %s"), real_filename,
 	       icondirs[i].offset, strerror (errno));
 
       data = (unsigned char *) res_alloc (icondirs[i].bytes);
@@ -1095,8 +1095,8 @@
    allocates and fills in a structure.  */
 
 struct menuitem *
-define_menuitem (const char *text, int menuid, unsigned long type,
-		 unsigned long state, unsigned long help,
+define_menuitem (const char *text, int menuid, unsigned int type,
+		 unsigned int state, unsigned int help,
 		 struct menuitem *menuitems)
 {
   struct menuitem *mi;
@@ -1168,7 +1168,7 @@
 /* Create an rcdata item holding a string.  */
 
 struct rcdata_item *
-define_rcdata_string (const char *string, unsigned long len)
+define_rcdata_string (const char *string, unsigned int len)
 {
   struct rcdata_item *ri;
   char *s;
@@ -1187,7 +1187,7 @@
 /* Create an rcdata item holding a number.  */
 
 struct rcdata_item *
-define_rcdata_number (unsigned long val, int dword)
+define_rcdata_number (unsigned int val, int dword)
 {
   struct rcdata_item *ri;
 
@@ -1204,7 +1204,7 @@
 
 void
 define_stringtable (const struct res_res_info *resinfo,
-		    unsigned long stringid, const char *string)
+		    unsigned int stringid, const char *string)
 {
   struct res_id id;
   struct res_resource *r;
@@ -1414,8 +1414,8 @@
 /* Append version variable information to a list.  */
 
 struct ver_varinfo *
-append_vertrans (struct ver_varinfo *var, unsigned long language,
-		 unsigned long charset)
+append_vertrans (struct ver_varinfo *var, unsigned int language,
+		 unsigned int charset)
 {
   struct ver_varinfo *vv, **pp;
 
@@ -1456,7 +1456,7 @@
 static void write_rc_stringtable
   (FILE *, const struct res_id *, const struct stringtable *);
 static void write_rc_versioninfo (FILE *, const struct versioninfo *);
-static void write_rc_filedata (FILE *, unsigned long, const unsigned char *);
+static void write_rc_filedata (FILE *, unsigned int, const unsigned char *);
 
 /* Indent a given number of spaces.  */
 
@@ -1515,9 +1515,9 @@
   /* Print out some COFF information that rc files can't represent.  */
 
   if (rd->time != 0)
-    fprintf (e, "// Time stamp: %lu\n", rd->time);
+    fprintf (e, "// Time stamp: %u\n", rd->time);
   if (rd->characteristics != 0)
-    fprintf (e, "// Characteristics: %lu\n", rd->characteristics);
+    fprintf (e, "// Characteristics: %u\n", rd->characteristics);
   if (rd->major != 0 || rd->minor != 0)
     fprintf (e, "// Version: %d %d\n", rd->major, rd->minor);
 
@@ -1543,10 +1543,10 @@
 	  /* If we're at level 3, then this key represents a language.
 	     Use it to update the current language.  */
 	  if (! re->id.named
-	      && re->id.u.id != (unsigned long) (unsigned int) *language
+	      && re->id.u.id != (unsigned int) (unsigned int) *language
 	      && (re->id.u.id & 0xffff) == re->id.u.id)
 	    {
-	      fprintf (e, "LANGUAGE %lu, %lu\n",
+	      fprintf (e, "LANGUAGE %u, %u\n",
 		       re->id.u.id & ((1 << SUBLANG_SHIFT) - 1),
 		       (re->id.u.id >> SUBLANG_SHIFT) & 0xff);
 	      *language = re->id.u.id;
@@ -1766,7 +1766,7 @@
 
   if (rt != 0
       && type != NULL
-      && (type->named || type->u.id != (unsigned long) rt))
+      && (type->named || type->u.id != (unsigned int) rt))
     {
       fprintf (e, "// Unexpected resource type mismatch: ");
       res_id_print (e, *type, 1);
@@ -1774,9 +1774,9 @@
     }
 
   if (res->coff_info.codepage != 0)
-    fprintf (e, "// Code page: %lu\n", res->coff_info.codepage);
+    fprintf (e, "// Code page: %u\n", res->coff_info.codepage);
   if (res->coff_info.reserved != 0)
-    fprintf (e, "// COFF reserved value: %lu\n", res->coff_info.reserved);
+    fprintf (e, "// COFF reserved value: %u\n", res->coff_info.reserved);
 
   if (name != NULL)
     res_id_print (e, *name, 0);
@@ -1809,7 +1809,7 @@
 	       res->u.dialog->width, res->u.dialog->height);
       if (res->u.dialog->ex != NULL
 	  && res->u.dialog->ex->help != 0)
-	fprintf (e, ", %lu", res->u.dialog->ex->help);
+	fprintf (e, ", %u", res->u.dialog->ex->help);
     }
 
   fprintf (e, "\n");
@@ -1841,11 +1841,11 @@
 		 res->res_info.language & ((1<<SUBLANG_SHIFT)-1),
 		 (res->res_info.language >> SUBLANG_SHIFT) & 0xff);
       if (res->res_info.characteristics != 0)
-	fprintf (e, "%sCHARACTERISTICS %lu\n",
+	fprintf (e, "%sCHARACTERISTICS %u\n",
 		 modifiers ? "// " : "",
 		 res->res_info.characteristics);
       if (res->res_info.version != 0)
-	fprintf (e, "%sVERSION %lu\n",
+	fprintf (e, "%sVERSION %u\n",
 		 modifiers ? "// " : "",
 		 res->res_info.version);
     }
@@ -1981,7 +1981,7 @@
     {
       fprintf (e, "// width: %d; height %d; planes %d; bits %d\n",
 	     gc->width, gc->height, gc->planes, gc->bits);
-      fprintf (e, "// data bytes: %lu; index: %d\n",
+      fprintf (e, "// data bytes: %u; index: %d\n",
 	       gc->bytes, gc->index);
     }
 }
@@ -1993,10 +1993,10 @@
 {
   const struct dialog_control *control;
 
-  fprintf (e, "STYLE 0x%lx\n", dialog->style);
+  fprintf (e, "STYLE 0x%x\n", dialog->style);
 
   if (dialog->exstyle != 0)
-    fprintf (e, "EXSTYLE 0x%lx\n", dialog->exstyle);
+    fprintf (e, "EXSTYLE 0x%x\n", dialog->exstyle);
 
   if ((dialog->class.named && dialog->class.u.n.length > 0)
       || dialog->class.u.id != 0)
@@ -2050,7 +2050,7 @@
 {
   const char *name;
   unsigned short class;
-  unsigned long style;
+  unsigned int style;
 };
 
 static const struct control_info control_info[] =
@@ -2059,23 +2059,23 @@
   { "AUTOCHECKBOX", CTL_BUTTON, BS_AUTOCHECKBOX },
   { "AUTORADIOBUTTON", CTL_BUTTON, BS_AUTORADIOBUTTON },
   { "CHECKBOX", CTL_BUTTON, BS_CHECKBOX },
-  { "COMBOBOX", CTL_COMBOBOX, (unsigned long) -1 },
+  { "COMBOBOX", CTL_COMBOBOX, (unsigned int) -1 },
   { "CTEXT", CTL_STATIC, SS_CENTER },
   { "DEFPUSHBUTTON", CTL_BUTTON, BS_DEFPUSHBUTTON },
-  { "EDITTEXT", CTL_EDIT, (unsigned long) -1 },
+  { "EDITTEXT", CTL_EDIT, (unsigned int) -1 },
   { "GROUPBOX", CTL_BUTTON, BS_GROUPBOX },
   { "ICON", CTL_STATIC, SS_ICON },
-  { "LISTBOX", CTL_LISTBOX, (unsigned long) -1 },
+  { "LISTBOX", CTL_LISTBOX, (unsigned int) -1 },
   { "LTEXT", CTL_STATIC, SS_LEFT },
   { "PUSHBOX", CTL_BUTTON, BS_PUSHBOX },
   { "PUSHBUTTON", CTL_BUTTON, BS_PUSHBUTTON },
   { "RADIOBUTTON", CTL_BUTTON, BS_RADIOBUTTON },
   { "RTEXT", CTL_STATIC, SS_RIGHT },
-  { "SCROLLBAR", CTL_SCROLLBAR, (unsigned long) -1 },
+  { "SCROLLBAR", CTL_SCROLLBAR, (unsigned int) -1 },
   { "STATE3", CTL_BUTTON, BS_3STATE },
   /* It's important that USERBUTTON come after all the other button
      types, so that it won't be matched too early.  */
-  { "USERBUTTON", CTL_BUTTON, (unsigned long) -1 },
+  { "USERBUTTON", CTL_BUTTON, (unsigned int) -1 },
   { NULL, 0, 0 }
 };
 
@@ -2094,7 +2094,7 @@
     {
       for (ci = control_info; ci->name != NULL; ++ci)
 	if (ci->class == control->class.u.id
-	    && (ci->style == (unsigned long) -1
+	    && (ci->style == (unsigned int) -1
 		|| ci->style == (control->style & 0xff)))
 	  break;
     }
@@ -2121,7 +2121,7 @@
       res_id_print (e, control->class, 0);
       if (control->class.named)
 	fprintf (e, "\"");
-      fprintf (e, ", 0x%lx, ", control->style);
+      fprintf (e, ", 0x%x, ", control->style);
     }
 
   fprintf (e, "%d, %d", control->x, control->y);
@@ -2137,10 +2137,10 @@
       /* FIXME: We don't need to print the style if it is the default.
 	 More importantly, in certain cases we actually need to turn
 	 off parts of the forced style, by using NOT.  */
-      fprintf (e, ", 0x%lx", control->style);
+      fprintf (e, ", 0x%x", control->style);
 
       if (control->exstyle != 0 || control->help != 0)
-	fprintf (e, ", 0x%lx, %lu", control->exstyle, control->help);
+	fprintf (e, ", 0x%x, %u", control->exstyle, control->help);
     }
 
   fprintf (e, "\n");
@@ -2176,7 +2176,7 @@
     {
       fprintf (e, "// width: %d; height %d; colors: %d; planes %d; bits %d\n",
 	       gi->width, gi->height, gi->colors, gi->planes, gi->bits);
-      fprintf (e, "// data bytes: %lu; index: %d\n",
+      fprintf (e, "// data bytes: %u; index: %d\n",
 	       gi->bytes, gi->index);
     }
 }
@@ -2187,7 +2187,7 @@
 write_rc_menu (FILE *e, const struct menu *menu, int menuex)
 {
   if (menu->help != 0)
-    fprintf (e, "// Help ID: %lu\n", menu->help);
+    fprintf (e, "// Help ID: %u\n", menu->help);
   write_rc_menuitems (e, menu->items, menuex, 0);
 }
 
@@ -2255,12 +2255,12 @@
 	      fprintf (e, ", %d", mi->id);
 	      if (mi->type != 0 || mi->state != 0 || mi->help != 0)
 		{
-		  fprintf (e, ", %lu", mi->type);
+		  fprintf (e, ", %u", mi->type);
 		  if (mi->state != 0 || mi->help != 0)
 		    {
-		      fprintf (e, ", %lu", mi->state);
+		      fprintf (e, ", %u", mi->state);
 		      if (mi->help != 0)
-			fprintf (e, ", %lu", mi->help);
+			fprintf (e, ", %u", mi->help);
 		    }
 		}
 	    }
@@ -2304,13 +2304,13 @@
 	  break;
 
 	case RCDATA_DWORD:
-	  fprintf (e, "%luL", ri->u.dword);
+	  fprintf (e, "%uL", ri->u.dword);
 	  break;
 
 	case RCDATA_STRING:
 	  {
 	    const char *s;
-	    unsigned long i;
+	    unsigned int i;
 
 	    fprintf (e, "\"");
 	    s = ri->u.string.s;
@@ -2333,7 +2333,7 @@
 
 	case RCDATA_BUFFER:
 	  {
-	    unsigned long i;
+	    unsigned int i;
 	    int first;
 
 	    /* Assume little endian data.  */
@@ -2341,7 +2341,7 @@
 	    first = 1;
 	    for (i = 0; i + 3 < ri->u.buffer.length; i += 4)
 	      {
-		unsigned long l;
+		unsigned int l;
 		int j;
 
 		if (! first)
@@ -2350,7 +2350,7 @@
 			 | ri->u.buffer.data[i + 2]) << 8)
 		       | ri->u.buffer.data[i + 1]) << 8)
 		     | ri->u.buffer.data[i]);
-		fprintf (e, "%luL", l);
+		fprintf (e, "%uL", l);
 		if (i + 4 < ri->u.buffer.length || ri->next != NULL)
 		  fprintf (e, ",");
 		for (j = 0; j < 4; ++j)
@@ -2448,7 +2448,7 @@
 write_rc_stringtable (FILE *e, const struct res_id *name,
 		      const struct stringtable *stringtable)
 {
-  unsigned long offset;
+  unsigned int offset;
   int i;
 
   if (name != NULL && ! name->named)
@@ -2466,7 +2466,7 @@
     {
       if (stringtable->strings[i].length != 0)
 	{
-	  fprintf (e, "  %lu, \"", offset + i);
+	  fprintf (e, "  %u, \"", offset + i);
 	  unicode_print (e, stringtable->strings[i].string,
 			 stringtable->strings[i].length);
 	  fprintf (e, "\"\n");
@@ -2486,29 +2486,29 @@
 
   f = versioninfo->fixed;
   if (f->file_version_ms != 0 || f->file_version_ls != 0)
-    fprintf (e, " FILEVERSION %lu, %lu, %lu, %lu\n",
+    fprintf (e, " FILEVERSION %u, %u, %u, %u\n",
 	     (f->file_version_ms >> 16) & 0xffff,
 	     f->file_version_ms & 0xffff,
 	     (f->file_version_ls >> 16) & 0xffff,
 	     f->file_version_ls & 0xffff);
   if (f->product_version_ms != 0 || f->product_version_ls != 0)
-    fprintf (e, " PRODUCTVERSION %lu, %lu, %lu, %lu\n",
+    fprintf (e, " PRODUCTVERSION %u, %u, %u, %u\n",
 	     (f->product_version_ms >> 16) & 0xffff,
 	     f->product_version_ms & 0xffff,
 	     (f->product_version_ls >> 16) & 0xffff,
 	     f->product_version_ls & 0xffff);
   if (f->file_flags_mask != 0)
-    fprintf (e, " FILEFLAGSMASK 0x%lx\n", f->file_flags_mask);
+    fprintf (e, " FILEFLAGSMASK 0x%x\n", f->file_flags_mask);
   if (f->file_flags != 0)
-    fprintf (e, " FILEFLAGS 0x%lx\n", f->file_flags);
+    fprintf (e, " FILEFLAGS 0x%x\n", f->file_flags);
   if (f->file_os != 0)
-    fprintf (e, " FILEOS 0x%lx\n", f->file_os);
+    fprintf (e, " FILEOS 0x%x\n", f->file_os);
   if (f->file_type != 0)
-    fprintf (e, " FILETYPE 0x%lx\n", f->file_type);
+    fprintf (e, " FILETYPE 0x%x\n", f->file_type);
   if (f->file_subtype != 0)
-    fprintf (e, " FILESUBTYPE 0x%lx\n", f->file_subtype);
+    fprintf (e, " FILESUBTYPE 0x%x\n", f->file_subtype);
   if (f->file_date_ms != 0 || f->file_date_ls != 0)
-    fprintf (e, "// Date: %lu, %lu\n", f->file_date_ms, f->file_date_ls);
+    fprintf (e, "// Date: %u, %u\n", f->file_date_ms, f->file_date_ls);
 
   fprintf (e, "BEGIN\n");
 
@@ -2568,13 +2568,13 @@
 /* Write out data which would normally be read from a file.  */
 
 static void
-write_rc_filedata (FILE *e, unsigned long length, const unsigned char *data)
+write_rc_filedata (FILE *e, unsigned int length, const unsigned char *data)
 {
-  unsigned long i;
+  unsigned int i;
 
   for (i = 0; i + 15 < length; i += 16)
     {
-      fprintf (e, "// %4lx: ", i);
+      fprintf (e, "// %4x: ", i);
       fprintf (e, "%02x %02x %02x %02x %02x %02x %02x %02x ",
 	       data[i + 0], data[i + 1], data[i + 2], data[i + 3],
 	       data[i + 4], data[i + 5], data[i + 6], data[i + 7]);
@@ -2585,7 +2585,7 @@
 
   if (i < length)
     {
-      fprintf (e, "// %4lx:", i);
+      fprintf (e, "// %4x:", i);
       while (i < length)
 	{
 	  fprintf (e, " %02x", data[i]);
Index: resres.c
===================================================================
RCS file: /cvs/src/src/binutils/resres.c,v
retrieving revision 1.7
diff -B -b -u -r1.7 resres.c
--- resres.c	16 Jun 2005 09:18:19 -0000	1.7
+++ resres.c	16 Apr 2007 09:13:39 -0000
@@ -33,8 +33,8 @@
 
 struct res_hdr
   {
-    unsigned long data_size;
-    unsigned long header_size;
+    unsigned int data_size;
+    unsigned int header_size;
   };
 
 static void write_res_directory
@@ -52,7 +52,7 @@
 static void write_res_info PARAMS ((const struct res_res_info *));
 static void write_res_data PARAMS ((const void *, size_t, int));
 static void write_res_header
-  PARAMS ((unsigned long, const struct res_id *, const struct res_id *,
+  PARAMS ((unsigned int, const struct res_id *, const struct res_id *,
 	   const struct res_res_info *));
 
 static int read_resource_entry PARAMS ((void));
@@ -61,7 +61,7 @@
 static unichar *read_unistring PARAMS ((int *));
 static void skip_null_resource PARAMS ((void));
 
-static unsigned long get_id_size PARAMS ((const struct res_id *));
+static unsigned int get_id_size PARAMS ((const struct res_id *));
 static void res_align_file PARAMS ((void));
 
 static void
@@ -219,7 +219,7 @@
 	  /* If we're at level 3, then this key represents a language.
 	     Use it to update the current language.  */
 	  if (!re->id.named
-	      && re->id.u.id != (unsigned long) *language
+	      && re->id.u.id != (unsigned int) *language
 	      && (re->id.u.id & 0xffff) == re->id.u.id)
 	    {
 	      *language = re->id.u.id;
@@ -331,7 +331,7 @@
 
   if (rt != 0
       && type != NULL
-      && (type->named || type->u.id != (unsigned long) rt))
+      && (type->named || type->u.id != (unsigned int) rt))
     {
       fprintf (stderr, "// Unexpected resource type mismatch: ");
       res_id_print (stderr, *type, 1);
@@ -351,7 +351,7 @@
      const struct res_id *name;
      const struct res_res_info *resinfo;
 {
-  unsigned long datasize = 0;
+  unsigned int datasize = 0;
   const struct bindata *bin_rep, *data;
 
   bin_rep = res_to_bin (res, 0);
@@ -365,7 +365,7 @@
 }
 
 /* Get number of bytes needed to store an id in binary format */
-static unsigned long
+static unsigned int
 get_id_size (id)
      const struct res_id *id;
 {
@@ -378,7 +378,7 @@
 /* Write a resource header */
 static void
 write_res_header (datasize, type, name, resinfo)
-     unsigned long datasize;
+     unsigned int datasize;
      const struct res_id *type;
      const struct res_id *name;
      const struct res_res_info *resinfo;
@@ -430,7 +430,7 @@
 {
   if (id->named)
     {
-      unsigned long len = id->u.n.length;
+      unsigned int len = id->u.n.length;
       unichar null_term = 0;
       write_res_data (id->u.n.name, len * sizeof (unichar), 1);
       write_res_data (&null_term, sizeof (null_term), 1);
@@ -586,7 +586,7 @@
 
       if (*resources == NULL)
 	{
-	  static unsigned long timeval;
+	  static unsigned int timeval;
 
 	  /* Use the same timestamp for every resource created in a
 	     single run.  */
Index: windres.c
===================================================================
RCS file: /cvs/src/src/binutils/windres.c,v
retrieving revision 1.28
diff -B -b -u -r1.28 windres.c
--- windres.c	17 Feb 2007 13:33:54 -0000	1.28
+++ windres.c	16 Apr 2007 09:13:39 -0000
@@ -263,7 +263,7 @@
 res_id_print (FILE *stream, struct res_id id, int quote)
 {
   if (! id.named)
-    fprintf (stream, "%lu", id.u.id);
+    fprintf (stream, "%u", id.u.id);
   else
     {
       if (quote)
@@ -320,12 +320,12 @@
 
       if (*resources == NULL)
 	{
-	  static unsigned long timeval;
+	  static unsigned int timeval;
 
 	  /* Use the same timestamp for every resource created in a
              single run.  */
 	  if (timeval == 0)
-	    timeval = time (NULL);
+	    timeval = (unsigned int) time (NULL);
 
 	  *resources = ((struct res_directory *)
 			res_alloc (sizeof **resources));
@@ -756,6 +756,9 @@
   struct res_directory *resources;
   int use_temp_file;
 
+  /* TODO: Test that sizeof int has 4 byte size.  */
+  assert (sizeof (int) == 4);
+
 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
   setlocale (LC_MESSAGES, "");
 #endif
Index: windres.h
===================================================================
RCS file: /cvs/src/src/binutils/windres.h,v
retrieving revision 1.14
diff -B -b -u -r1.14 windres.h
--- windres.h	8 May 2005 14:17:39 -0000	1.14
+++ windres.h	16 Apr 2007 09:13:40 -0000
@@ -35,9 +35,9 @@
 {
   /* Resource flags.  According to the MS docs, this is currently
      always zero.  */
-  unsigned long characteristics;
+  unsigned int characteristics;
   /* Time/date stamp.  */
-  unsigned long time;
+  unsigned int time;
   /* Major version number.  */
   unsigned short major;
   /* Minor version number.  */
@@ -63,7 +63,7 @@
       unichar *name;
     } n;
     /* If the named field is zero, this is the ID.  */
-    unsigned long id;
+    unsigned int id;
   } u;
 };
 
@@ -127,11 +127,11 @@
      COFF file, the res_directory structure has a characteristics
      field, but I don't know if it's related to the one in the res
      file.  */
-  unsigned long characteristics;
+  unsigned int characteristics;
   /* Version of the resource.  Entirely user defined.  In a COFF file,
      the res_directory structure has a characteristics field, but I
      don't know if it's related to the one in the res file.  */
-  unsigned long version;
+  unsigned int version;
   /* Memory flags.  This is a combination of the MEMFLAG values
      defined below.  Most of these values are historical, and are not
      meaningful for win32.  I don't think there is any way to store
@@ -146,11 +146,11 @@
 {
   /* The code page used for the data.  I don't really know what this
      should be.  */
-  unsigned long codepage;
+  unsigned int codepage;
   /* A resource entry in a COFF file has a reserved field, which we
      record here when reading a COFF file.  When writing a COFF file,
      we set this field to zero.  */
-  unsigned long reserved;
+  unsigned int reserved;
 };
 
 /* Resource data is stored in a res_resource structure.  */
@@ -164,7 +164,7 @@
   {
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const unsigned char *data;
     } data;
     struct accelerator *acc;
@@ -250,7 +250,7 @@
   /* Y coordinate of hotspot.  */
   short yhotspot;
   /* Length of bitmap data.  */
-  unsigned long length;
+  unsigned int length;
   /* Data.  */
   const unsigned char *data;
 };
@@ -270,7 +270,7 @@
   /* Bits per pixel.  */
   unsigned short bits;
   /* Number of bytes in cursor resource.  */
-  unsigned long bytes;
+  unsigned int bytes;
   /* Index of cursor resource.  */
   unsigned short index;
 };
@@ -280,9 +280,9 @@
 struct dialog
 {
   /* Basic window style.  */
-  unsigned long style;
+  unsigned int style;
   /* Extended window style.  */
-  unsigned long exstyle;
+  unsigned int exstyle;
   /* X coordinate.  */
   unsigned short x;
   /* Y coordinate.  */
@@ -312,7 +312,7 @@
 struct dialog_ex
 {
   /* Help ID.  */
-  unsigned long help;
+  unsigned int help;
   /* Font weight.  */
   unsigned short weight;
   /* Whether the font is italic.  */
@@ -482,9 +482,9 @@
   /* ID.  */
   unsigned short id;
   /* Style.  */
-  unsigned long style;
+  unsigned int style;
   /* Extended style.  */
-  unsigned long exstyle;
+  unsigned int exstyle;
   /* X coordinate.  */
   unsigned short x;
   /* Y coordinate.  */
@@ -500,7 +500,7 @@
   /* Extra data for the window procedure.  */
   struct rcdata_item *data;
   /* Help ID.  Only used in an extended dialog.  */
-  unsigned long help;
+  unsigned int help;
 };
 
 /* Control classes.  These can be used as the ID field in a struct
@@ -521,7 +521,7 @@
   /* Index of font entry.  */
   short index;
   /* Length of font information.  */
-  unsigned long length;
+  unsigned int length;
   /* Font information.  */
   const unsigned char *data;
 };
@@ -543,7 +543,7 @@
   /* Bits per pixel.  */
   unsigned short bits;
   /* Number of bytes in cursor resource.  */
-  unsigned long bytes;
+  unsigned int bytes;
   /* Index of cursor resource.  */
   unsigned short index;
 };
@@ -556,7 +556,7 @@
   struct menuitem *items;
   /* Help ID.  I don't think there is any way to set this in an rc
      file, but it can appear in the binary format.  */
-  unsigned long help;
+  unsigned int help;
 };
 
 /* A menu resource is a list of menuitem structures.  */
@@ -567,9 +567,9 @@
   struct menuitem *next;
   /* Type.  In a normal menu, rather than a menuex, this is the flags
      field.  */
-  unsigned long type;
+  unsigned int type;
   /* State.  This is only used in a menuex.  */
-  unsigned long state;
+  unsigned int state;
   /* Id.  */
   unsigned short id;
   /* Unicode text.  */
@@ -577,7 +577,7 @@
   /* Popup menu items for a popup.  */
   struct menuitem *popup;
   /* Help ID.  This is only used in a menuex.  */
-  unsigned long help;
+  unsigned int help;
 };
 
 /* Menu item flags.  These can appear in the flags field of a struct
@@ -613,20 +613,20 @@
   union
   {
     unsigned int word;
-    unsigned long dword;
+    unsigned int dword;
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const char *s;
     } string;
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const unichar *w;
     } wstring;
     struct
     {
-      unsigned long length;
+      unsigned int length;
       const unsigned char *data;
     } buffer;
   } u;
@@ -661,24 +661,24 @@
 struct fixed_versioninfo
 {
   /* The file version, which is two 32 bit integers.  */
-  unsigned long file_version_ms;
-  unsigned long file_version_ls;
+  unsigned int file_version_ms;
+  unsigned int file_version_ls;
   /* The product version, which is two 32 bit integers.  */
-  unsigned long product_version_ms;
-  unsigned long product_version_ls;
+  unsigned int product_version_ms;
+  unsigned int product_version_ls;
   /* The file flags mask.  */
-  unsigned long file_flags_mask;
+  unsigned int file_flags_mask;
   /* The file flags.  */
-  unsigned long file_flags;
+  unsigned int file_flags;
   /* The OS type.  */
-  unsigned long file_os;
+  unsigned int file_os;
   /* The file type.  */
-  unsigned long file_type;
+  unsigned int file_type;
   /* The file subtype.  */
-  unsigned long file_subtype;
+  unsigned int file_subtype;
   /* The date, which in Windows is two 32 bit integers.  */
-  unsigned long file_date_ms;
-  unsigned long file_date_ls;
+  unsigned int file_date_ms;
+  unsigned int file_date_ls;
 };
 
 /* A list of variable version information.  */
@@ -742,7 +742,7 @@
   /* Next data.  */
   struct bindata *next;
   /* Length of data.  */
-  unsigned long length;
+  unsigned int length;
   /* Data.  */
   unsigned char *data;
 };
@@ -761,7 +761,7 @@
   (const char *, const char *, const struct res_directory *);
 
 extern struct res_resource *bin_to_res
-  (struct res_id, const unsigned char *, unsigned long, int);
+  (struct res_id, const unsigned char *, unsigned int, int);
 extern struct bindata *res_to_bin (const struct res_resource *, int);
 
 extern FILE *open_file_search
@@ -812,11 +812,11 @@
 extern void define_dialog
   (struct res_id, const struct res_res_info *, const struct dialog *);
 extern struct dialog_control *define_control
-  (const struct res_id, unsigned long, unsigned long, unsigned long,
-   unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
+  (const struct res_id, unsigned int, unsigned int, unsigned int,
+   unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
 extern struct dialog_control *define_icon_control
-  (struct res_id, unsigned long, unsigned long, unsigned long, unsigned long,
-   unsigned long, unsigned long, struct rcdata_item *, struct dialog_ex *);
+  (struct res_id, unsigned int, unsigned int, unsigned int, unsigned int,
+   unsigned int, unsigned int, struct rcdata_item *, struct dialog_ex *);
 extern void define_font
   (struct res_id, const struct res_res_info *, const char *);
 extern void define_icon
@@ -824,7 +824,7 @@
 extern void define_menu
   (struct res_id, const struct res_res_info *, struct menuitem *);
 extern struct menuitem *define_menuitem
-  (const char *, int, unsigned long, unsigned long, unsigned long,
+  (const char *, int, unsigned int, unsigned int, unsigned int,
    struct menuitem *);
 extern void define_messagetable
   (struct res_id, const struct res_res_info *, const char *);
@@ -833,10 +833,10 @@
 extern void define_rcdata_file 
   (struct res_id, const struct res_res_info *, const char *);
 extern struct rcdata_item *define_rcdata_string
-  (const char *, unsigned long);
-extern struct rcdata_item *define_rcdata_number (unsigned long, int);
+  (const char *, unsigned int);
+extern struct rcdata_item *define_rcdata_number (unsigned int, int);
 extern void define_stringtable
-  (const struct res_res_info *, unsigned long, const char *);
+  (const struct res_res_info *, unsigned int, const char *);
 extern void define_user_data
   (struct res_id, struct res_id, const struct res_res_info *,
    struct rcdata_item *);
@@ -851,4 +851,4 @@
 extern struct ver_stringinfo *append_verval
   (struct ver_stringinfo *, const char *, const char *);
 extern struct ver_varinfo *append_vertrans
-  (struct ver_varinfo *, unsigned long, unsigned long);
+  (struct ver_varinfo *, unsigned int, unsigned int);
=

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-16 10:05                 ` Kai Tietz
@ 2007-04-16 21:59                   ` Christopher Faylor
  2007-04-16 22:20                     ` H. J. Lu
  0 siblings, 1 reply; 48+ messages in thread
From: Christopher Faylor @ 2007-04-16 21:59 UTC (permalink / raw)
  To: Kai Tietz, binutils

On Mon, Apr 16, 2007 at 11:20:49AM +0200, Kai Tietz wrote:
>"H. J. Lu" <hjl@lucon.org> wrote on 13.04.2007 16:41:06:
>
>> > Nightmares, ... 8| I begun to modify structure using character arrays 
>... 
>> > I come to the point, that this means for big parts of windres better a 
>
>> > complete rewrite. Structures with internal/external scope and data 
>> > modifications are really wired.
>> > May we should first use my last patch, so that the problem is solved, 
>and 
>> > then I will begin to reorganize the windres tool to be host 
>idependent. By 
>> > this I can add some missing resource types to it.
>> > 
>> > What do you think about my suggestion to continue ?
>> > 
>> 
>> That is fine with me. If you do this, you don't need to handle
>> endian and just replace long with int since you will rewrite it
>> later anyway.
>
>This is the patch changing the windres source using int instead of long. I 
>bootstrap it on cygwin 32 and for x86_64-mingw.
>This patch does not solve the endian problem, reasoned by the use of 
>fwrite/fread.
>ChangeLog for binutils/:

If you are assuming that int means 32 bits, wouldn't it make sense to
use a type like u_int32_t which explicitly spells that out?

cgf

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-16 21:59                   ` Christopher Faylor
@ 2007-04-16 22:20                     ` H. J. Lu
  2007-04-17 10:59                       ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: H. J. Lu @ 2007-04-16 22:20 UTC (permalink / raw)
  To: Kai Tietz, binutils

On Mon, Apr 16, 2007 at 05:07:10PM -0400, Christopher Faylor wrote:
> On Mon, Apr 16, 2007 at 11:20:49AM +0200, Kai Tietz wrote:
> >"H. J. Lu" <hjl@lucon.org> wrote on 13.04.2007 16:41:06:
> >
> >> > Nightmares, ... 8| I begun to modify structure using character arrays 
> >... 
> >> > I come to the point, that this means for big parts of windres better a 
> >
> >> > complete rewrite. Structures with internal/external scope and data 
> >> > modifications are really wired.
> >> > May we should first use my last patch, so that the problem is solved, 
> >and 
> >> > then I will begin to reorganize the windres tool to be host 
> >idependent. By 
> >> > this I can add some missing resource types to it.
> >> > 
> >> > What do you think about my suggestion to continue ?
> >> > 
> >> 
> >> That is fine with me. If you do this, you don't need to handle
> >> endian and just replace long with int since you will rewrite it
> >> later anyway.
> >
> >This is the patch changing the windres source using int instead of long. I 
> >bootstrap it on cygwin 32 and for x86_64-mingw.
> >This patch does not solve the endian problem, reasoned by the use of 
> >fwrite/fread.
> >ChangeLog for binutils/:
> 
> If you are assuming that int means 32 bits, wouldn't it make sense to
> use a type like u_int32_t which explicitly spells that out?

u_int32_t is a good idea if it doesn't require extra change since
this is a temporary patch until windres can be rewritten properly.


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-16 22:20                     ` H. J. Lu
@ 2007-04-17 10:59                       ` Kai Tietz
  2007-04-18  4:34                         ` Christopher Faylor
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-17 10:59 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

"H. J. Lu" <hjl@lucon.org> wrote on 16.04.2007 23:58:49:

> On Mon, Apr 16, 2007 at 05:07:10PM -0400, Christopher Faylor wrote:
> > On Mon, Apr 16, 2007 at 11:20:49AM +0200, Kai Tietz wrote:
> > >"H. J. Lu" <hjl@lucon.org> wrote on 13.04.2007 16:41:06:
> > >
> > >> > Nightmares, ... 8| I begun to modify structure using character 
arrays 
> > >... 
> > >> > I come to the point, that this means for big parts of 
windresbetter a 
> > >
> > >> > complete rewrite. Structures with internal/external scope and 
data 
> > >> > modifications are really wired.
> > >> > May we should first use my last patch, so that the problem is 
solved, 
> > >and 
> > >> > then I will begin to reorganize the windres tool to be host 
> > >idependent. By 
> > >> > this I can add some missing resource types to it.
> > >> > 
> > >> > What do you think about my suggestion to continue ?
> > >> > 
> > >> 
> > >> That is fine with me. If you do this, you don't need to handle
> > >> endian and just replace long with int since you will rewrite it
> > >> later anyway.
> > >
> > >This is the patch changing the windres source using int instead of 
long. I 
> > >bootstrap it on cygwin 32 and for x86_64-mingw.
> > >This patch does not solve the endian problem, reasoned by the use of 
> > >fwrite/fread.
> > >ChangeLog for binutils/:
> > 
> > If you are assuming that int means 32 bits, wouldn't it make sense to
> > use a type like u_int32_t which explicitly spells that out?
> 
> u_int32_t is a good idea if it doesn't require extra change since
> this is a temporary patch until windres can be rewritten properly.

Such a types as u_int32_t, u_int16_t, ... are really a good idea, but that
these types are not available on all platforms in sys/types.h. :( So this 
would
need some further work on a temporary thing.
But I think, it would be a good idea to introduce those kind of types to 
bfd.
E.g. bfd_uint32_t, bfd_int32, bfd_int16, ...

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger



^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-17 10:59                       ` Kai Tietz
@ 2007-04-18  4:34                         ` Christopher Faylor
  2007-04-18  9:49                           ` H. J. Lu
  0 siblings, 1 reply; 48+ messages in thread
From: Christopher Faylor @ 2007-04-18  4:34 UTC (permalink / raw)
  To: H. J. Lu, binutils, Kai Tietz

On Tue, Apr 17, 2007 at 09:32:30AM +0200, Kai Tietz wrote:
>"H. J. Lu" <hjl@lucon.org> wrote on 16.04.2007 23:58:49:
>>On Mon, Apr 16, 2007 at 05:07:10PM -0400, Christopher Faylor wrote:
>>>If you are assuming that int means 32 bits, wouldn't it make sense to
>>>use a type like u_int32_t which explicitly spells that out?
>>
>>u_int32_t is a good idea if it doesn't require extra change since this
>>is a temporary patch until windres can be rewritten properly.
>
>Such a types as u_int32_t, u_int16_t, ...  are really a good idea, but
>that these types are not available on all platforms in sys/types.h.  :(
>So this would need some further work on a temporary thing.  But I
>think, it would be a good idea to introduce those kind of types to bfd.
>E.g. bfd_uint32_t, bfd_int32, bfd_int16, ...

We've all had experience with "temporary" changes, though, so I think it
makes sense to do this the right way.  Doesn't configure provide a way to
determine the size of ints/longs?

cgf

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-18  4:34                         ` Christopher Faylor
@ 2007-04-18  9:49                           ` H. J. Lu
  2007-04-20 13:34                             ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: H. J. Lu @ 2007-04-18  9:49 UTC (permalink / raw)
  To: binutils, Kai Tietz

On Wed, Apr 18, 2007 at 12:09:59AM -0400, Christopher Faylor wrote:
> On Tue, Apr 17, 2007 at 09:32:30AM +0200, Kai Tietz wrote:
> >"H. J. Lu" <hjl@lucon.org> wrote on 16.04.2007 23:58:49:
> >>On Mon, Apr 16, 2007 at 05:07:10PM -0400, Christopher Faylor wrote:
> >>>If you are assuming that int means 32 bits, wouldn't it make sense to
> >>>use a type like u_int32_t which explicitly spells that out?
> >>
> >>u_int32_t is a good idea if it doesn't require extra change since this
> >>is a temporary patch until windres can be rewritten properly.
> >
> >Such a types as u_int32_t, u_int16_t, ...  are really a good idea, but
> >that these types are not available on all platforms in sys/types.h.  :(
> >So this would need some further work on a temporary thing.  But I
> >think, it would be a good idea to introduce those kind of types to bfd.
> >E.g. bfd_uint32_t, bfd_int32, bfd_int16, ...
> 
> We've all had experience with "temporary" changes, though, so I think it
> makes sense to do this the right way.  Doesn't configure provide a way to
> determine the size of ints/longs?

I don't think binutils will work at all if sizeof int < 32.  I am not
sure if we should worry about int > 32 here. In anycase, as I said
before, the proper thing to do is to use unsigned char [4]:

http://sourceware.org/ml/binutils/2007-04/msg00154.html

Anything less is temporary.


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-11 14:07   ` H. J. Lu
  2007-04-11 18:22     ` PATCH: windres Kai Tietz
@ 2007-04-18 11:59     ` Kai Tietz
  2007-06-29  5:37       ` NightStrike
  2007-07-12  7:30       ` Nick Clifton
  1 sibling, 2 replies; 48+ messages in thread
From: Kai Tietz @ 2007-04-18 11:59 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 2806 bytes --]

"H. J. Lu" <hjl@lucon.org> wrote on 11.04.2007 16:07:40:

> We do need a new type when casting from pointer to integer. But
> it should be determined in autoconf. You can use AC_CHECK_SIZEOF.

I adjust my patch not using the printf macro and using configure.in in bfd 
to find the proper type for bfd_hostptr_t. Also I adjust the autodetection 
of 64 bit in configure by using the size of a "void *" == 8 for detection.

ChangeLog:

2007-04-18  Kai Tietz   <kai.tietz@onevision.com>

        * bfd/bfd-in.h: (BFD_HOST_64BIT_LONG_LONG): New
        as equivalent for BFD_HOST_64BIT_LONG.
        (BFD_HOSTPTR_T): Host pointer type for casting a
        pointer to an integer type.
        (bfd_hostptr_t): The typedef of BFD_HOSTPTR_T.
        (sprintf_vma, fprintf_vma): Add support for long long prints.
        * bfd/bfd-in2.h: Regenerate.
        * bfd/configure.in: (BFD_HOST_64BIT_LONG_LONG): New
        as equivalent for BFD_HOST_64BIT_LONG.
        (BFD_HOSTPTR_T): Host pointer type for casting a
        pointer to an integer type. Defauls is "unsigned long".
        (AC_CHECK_SIZEOF(void *)): New.
        (host64): Set it if the pointer size is 8.
        * bfd/configure: Regenerate.
        * bfd/config.in: Add macro SIZEOF_VOID_P.
        * bfd/coffcode.h: Replace host ptr type assuming "long" to
        bfd_hostptr_t type.
        * bfd/coffgen.c: Likewise.
        * bfd/elf-eh-frame.c: Likewise.
        * bfd/peicode.h: Likewise.
        * gas/symbols.c: Print bfd_hostptr_t to file via fprintf_vma.
        * gas/write.c: Likewise.
        * gprof/cg_print.c: Force cast of sizeof to be a long.
        * gprof/hist.c: Likewise.
        * include/splay-tree.h: New type libi_uhostptr_t needed for
        w64 when a long is not wide enought for a pointer for
        splay_tree_key and splay_tree_value..
        (splay_tree_key, splay_tree_value): As above, see comment.
        * include/coff/internal.h:  Replace host ptr type assuming "long"
        to bfd_hostptr_t type.
        * libiberty/strerror.c: Undefine sys_nerr and sys_errlist if
        allready defined in front by runtime headers.

Regards,
 i.A. Kai Tietz


------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger



[-- Attachment #2: nativew64.txt --]
[-- Type: text/plain, Size: 15639 bytes --]

Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.126
diff -b -u -r1.126 bfd-in.h
--- bfd/bfd-in.h	20 Mar 2007 20:19:07 -0000	1.126
+++ bfd/bfd-in.h	18 Apr 2007 09:14:53 -0000
@@ -76,6 +76,7 @@
 #define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
 
 #define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@
+#define BFD_HOST_64BIT_LONG_LONG @BFD_HOST_64BIT_LONG_LONG@
 #define BFD_HOST_LONG_LONG @BFD_HOST_LONG_LONG@
 #if @BFD_HOST_64_BIT_DEFINED@
 #define BFD_HOST_64_BIT @BFD_HOST_64_BIT@
@@ -96,6 +97,10 @@
 #endif
 #endif
 
+/* Declaring a type wide enough to hold a host long and a host pointer.  */
+#define BFD_HOSTPTR_T	@BFD_HOSTPTR_T@
+typedef BFD_HOSTPTR_T bfd_hostptr_t;
+
 /* Forward declaration.  */
 typedef struct bfd bfd;
 
@@ -129,6 +134,9 @@
 #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
+#define sprintf_vma(s,x) sprintf (s, "%016llx", x)
+#define fprintf_vma(f,x) fprintf (f, "%016llx", x)
 #else
 #define _bfd_int64_low(x) ((unsigned long) (((x) & 0xffffffff)))
 #define _bfd_int64_high(x) ((unsigned long) (((x) >> 32) & 0xffffffff))
Index: bfd/coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.136
diff -b -u -r1.136 coffcode.h
--- bfd/coffcode.h	26 Mar 2007 12:22:59 -0000	1.136
+++ bfd/coffcode.h	18 Apr 2007 09:15:01 -0000
@@ -4380,7 +4380,7 @@
 
 	  dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
 	  /* We use the native name field to point to the cached field.  */
-	  src->u.syment._n._n_n._n_zeroes = (long) dst;
+	  src->u.syment._n._n_n._n_zeroes = (bfd_hostptr_t) dst;
 	  dst->symbol.section = coff_section_from_bfd_index (abfd,
 						     src->u.syment.n_scnum);
 	  dst->symbol.flags = 0;
Index: bfd/coffgen.c
===================================================================
RCS file: /cvs/src/src/bfd/coffgen.c,v
retrieving revision 1.56
diff -b -u -r1.56 coffgen.c
--- bfd/coffgen.c	2 Apr 2007 16:51:13 -0000	1.56
+++ bfd/coffgen.c	18 Apr 2007 09:15:04 -0000
@@ -725,8 +725,8 @@
 	    {
 	      /* FIXME: We should use a union here.  */
 	      s->u.syment.n_value =
-		(bfd_vma)((combined_entry_type *)
-			  ((unsigned long) s->u.syment.n_value))->offset;
+		(bfd_hostptr_t) ((combined_entry_type *)
+			  ((bfd_hostptr_t) s->u.syment.n_value))->offset;
 	      s->fix_value = 0;
 	    }
 	  if (s->fix_line)
@@ -1640,7 +1640,7 @@
 		}
 
 	      internal_ptr->u.syment._n._n_n._n_offset =
-		((long)
+		((bfd_hostptr_t)
 		 (string_table
 		  + (internal_ptr + 1)->u.auxent.x_file.x_n.x_offset));
 	    }
@@ -1652,13 +1652,13 @@
 	      if (internal_ptr->u.syment.n_numaux > 1
 		  && coff_data (abfd)->pe)
 		internal_ptr->u.syment._n._n_n._n_offset =
-		  ((long)
+		  ((bfd_hostptr_t)
 		   copy_name (abfd,
 			      (internal_ptr + 1)->u.auxent.x_file.x_fname,
 			      internal_ptr->u.syment.n_numaux * symesz));
 	      else
 		internal_ptr->u.syment._n._n_n._n_offset =
-		  ((long)
+		  ((bfd_hostptr_t)
 		   copy_name (abfd,
 			      (internal_ptr + 1)->u.auxent.x_file.x_fname,
 			      (size_t) bfd_coff_filnmlen (abfd)));
@@ -1682,11 +1682,11 @@
 	      if (newstring == NULL)
 		return NULL;
 	      strncpy (newstring, internal_ptr->u.syment._n._n_name, i);
-	      internal_ptr->u.syment._n._n_n._n_offset = (long int) newstring;
+	      internal_ptr->u.syment._n._n_n._n_offset = (bfd_hostptr_t) newstring;
 	      internal_ptr->u.syment._n._n_n._n_zeroes = 0;
 	    }
 	  else if (internal_ptr->u.syment._n._n_n._n_offset == 0)
-	    internal_ptr->u.syment._n._n_n._n_offset = (long int) "";
+	    internal_ptr->u.syment._n._n_n._n_offset = (bfd_vma) "";
 	  else if (!bfd_coff_symname_in_debug (abfd, &internal_ptr->u.syment))
 	    {
 	      /* Long name already.  Point symbol at the string in the
@@ -1698,7 +1698,7 @@
 		    return NULL;
 		}
 	      internal_ptr->u.syment._n._n_n._n_offset =
-		((long int)
+		((bfd_hostptr_t)
 		 (string_table
 		  + internal_ptr->u.syment._n._n_n._n_offset));
 	    }
@@ -1707,7 +1707,7 @@
 	      /* Long name in debug section.  Very similar.  */
 	      if (debug_section == NULL)
 		debug_section = build_debug_section (abfd);
-	      internal_ptr->u.syment._n._n_n._n_offset = (long int)
+	      internal_ptr->u.syment._n._n_n._n_offset = (bfd_hostptr_t)
 		(debug_section + internal_ptr->u.syment._n._n_n._n_offset);
 	    }
 	}
@@ -1784,7 +1784,7 @@
   if (coffsymbol (symbol)->native != NULL
       && coffsymbol (symbol)->native->fix_value)
     ret->value = coffsymbol (symbol)->native->u.syment.n_value -
-      (unsigned long) obj_raw_syments (abfd);
+      (bfd_hostptr_t) obj_raw_syments (abfd);
 }
 
 /* Return the COFF syment for a symbol.  */
@@ -1807,7 +1807,7 @@
 
   if (csym->native->fix_value)
     psyment->n_value = psyment->n_value -
-      (unsigned long) obj_raw_syments (abfd);
+      (bfd_hostptr_t) obj_raw_syments (abfd);
 
   /* FIXME: We should handle fix_line here.  */
 
@@ -1893,7 +1893,7 @@
 	  if (! combined->fix_value)
 	    val = (bfd_vma) combined->u.syment.n_value;
 	  else
-	    val = combined->u.syment.n_value - (unsigned long) root;
+	    val = combined->u.syment.n_value - (bfd_hostptr_t) root;
 
 	  fprintf (file, "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x",
 		   combined->u.syment.n_scnum,
Index: bfd/config.in
===================================================================
RCS file: /cvs/src/src/bfd/config.in,v
retrieving revision 1.32
diff -b -u -r1.32 config.in
--- bfd/config.in	5 Jun 2006 12:25:49 -0000	1.32
+++ bfd/config.in	18 Apr 2007 09:15:04 -0000
@@ -245,6 +245,9 @@
 /* The size of a `off_t', as computed by sizeof. */
 #undef SIZEOF_OFF_T
 
+/* The sizeof of a 'void *', as computed by sizeof. */
+#undef SIZEOF_VOID_P
+
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
Index: bfd/configure.in
===================================================================
RCS file: /cvs/src/src/bfd/configure.in,v
retrieving revision 1.227
diff -b -u -r1.227 configure.in
--- bfd/configure.in	14 Apr 2007 20:36:56 -0000	1.227
+++ bfd/configure.in	18 Apr 2007 09:15:14 -0000
@@ -99,10 +99,12 @@
 AC_PROG_INSTALL
 
 BFD_HOST_64BIT_LONG=0
+BFD_HOST_64BIT_LONG_LONG=0
 BFD_HOST_LONG_LONG=0
 BFD_HOST_64_BIT_DEFINED=0
 BFD_HOST_64_BIT=
 BFD_HOST_U_64_BIT=
+BFD_HOSTPTR_T = "unsigned long"
 
 AC_MSG_CHECKING([for long long])
 AC_CACHE_VAL(bfd_cv_has_long_long,
@@ -113,12 +115,21 @@
   AC_CHECK_SIZEOF(long long)
 fi
 
+AC_CHECK_SIZEOF(void *)
 AC_CHECK_SIZEOF(long)
-if test "x${ac_cv_sizeof_long}" = "x8"; then
+
+if test "x${ac_cv_sizeof_void_p}" = "x8"; then
   host64=true
+  if test "x${ac_cv_sizeof_long}" = "x8"; then
   BFD_HOST_64BIT_LONG=1
   test -n "${HOST_64BIT_TYPE}" || HOST_64BIT_TYPE="long"
   test -n "${HOST_U_64BIT_TYPE}" || HOST_U_64BIT_TYPE="unsigned long"
+  elif test "x${ac_cv_sizeof_long_long}" = "x8"; then
+    BFD_HOST_64BIT_LONG_LONG=1
+    test -n "${HOST_64BIT_TYPE}" || HOST_64BIT_TYPE="long long"
+    test -n "${HOST_U_64BIT_TYPE}" || HOST_U_64BIT_TYPE="unsigned long long"
+    BFD_HOSTPTR_T="unsigned long long"
+  fi
 elif test "x${ac_cv_sizeof_long_long}" = "x8"; then
   test -n "${HOST_64BIT_TYPE}" || HOST_64BIT_TYPE="long long"
   test -n "${HOST_U_64BIT_TYPE}" || HOST_U_64BIT_TYPE="unsigned long long"
@@ -131,10 +142,12 @@
 fi
 
 AC_SUBST(BFD_HOST_64BIT_LONG)
+AC_SUBST(BFD_HOST_64BIT_LONG_LONG)
 AC_SUBST(BFD_HOST_LONG_LONG)
 AC_SUBST(BFD_HOST_64_BIT_DEFINED)
 AC_SUBST(BFD_HOST_64_BIT)
 AC_SUBST(BFD_HOST_U_64_BIT)
+AC_SUBST(BFD_HOSTPTR_T)
 
 BFD_CC_FOR_BUILD
 
Index: bfd/elf-eh-frame.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-eh-frame.c,v
retrieving revision 1.54
diff -b -u -r1.54 elf-eh-frame.c
--- bfd/elf-eh-frame.c	4 Jan 2007 13:30:39 -0000	1.54
+++ bfd/elf-eh-frame.c	18 Apr 2007 09:15:16 -0000
@@ -917,7 +917,7 @@
       {
 	if (!ent->cie)
 	  {
-	    ecie = ecies + (unsigned long) ent->cie_inf;
+	    ecie = ecies + (bfd_hostptr_t) ent->cie_inf;
 	    ent->cie_inf = ecie->cie.cie_inf;
 	  }
 	ent->new_offset = offset;
Index: bfd/peicode.h
===================================================================
RCS file: /cvs/src/src/bfd/peicode.h,v
retrieving revision 1.50
diff -b -u -r1.50 peicode.h
--- bfd/peicode.h	20 Sep 2006 11:35:07 -0000	1.50
+++ bfd/peicode.h	18 Apr 2007 09:15:17 -0000
@@ -565,7 +565,7 @@
   /* Initialise the internal symbol structure.  */
   ent->u.syment.n_sclass          = sclass;
   ent->u.syment.n_scnum           = section->target_index;
-  ent->u.syment._n._n_n._n_offset = (long) sym;
+  ent->u.syment._n._n_n._n_offset = (bfd_hostptr_t) sym;
 
   sym->symbol.the_bfd = vars->abfd;
   sym->symbol.name    = vars->string_ptr;
Index: gas/symbols.c
===================================================================
RCS file: /cvs/src/src/gas/symbols.c,v
retrieving revision 1.83
diff -b -u -r1.83 symbols.c
--- gas/symbols.c	15 Mar 2007 12:11:49 -0000	1.83
+++ gas/symbols.c	18 Apr 2007 09:15:27 -0000
@@ -2728,14 +2728,19 @@
   const char *name = S_GET_NAME (sym);
   if (!name || !name[0])
     name = "(unnamed)";
-  fprintf (file, "sym %lx %s", (unsigned long) sym, name);
+  fprintf (file, "sym ");
+  fprintf_vma (file, (bfd_vma) ((bfd_hostptr_t) sym));
+  fprintf (file, " %s", name);
 
   if (LOCAL_SYMBOL_CHECK (sym))
     {
       struct local_symbol *locsym = (struct local_symbol *) sym;
       if (local_symbol_get_frag (locsym) != &zero_address_frag
 	  && local_symbol_get_frag (locsym) != NULL)
-	fprintf (file, " frag %lx", (long) local_symbol_get_frag (locsym));
+	{
+	  fprintf (file, " frag ");
+	  fprintf_vma (file, (bfd_vma) ((bfd_hostptr_t) local_symbol_get_frag (locsym)));
+        }
       if (local_symbol_resolved_p (locsym))
 	fprintf (file, " resolved");
       fprintf (file, " local");
@@ -2743,7 +2748,10 @@
   else
     {
       if (sym->sy_frag != &zero_address_frag)
-	fprintf (file, " frag %lx", (long) sym->sy_frag);
+	{
+	  fprintf (file, " frag ");
+	  fprintf_vma (file, (bfd_vma) ((bfd_hostptr_t) sym->sy_frag));
+	}
       if (sym->written)
 	fprintf (file, " written");
       if (sym->sy_resolved)
@@ -2817,7 +2825,9 @@
 void
 print_expr_1 (FILE *file, expressionS *exp)
 {
-  fprintf (file, "expr %lx ", (long) exp);
+  fprintf (file, "expr ");
+  fprintf_vma (file, (bfd_vma) ((bfd_hostptr_t) exp));
+  fprintf (file, " ");
   switch (exp->X_op)
     {
     case O_illegal:
Index: gas/write.c
===================================================================
RCS file: /cvs/src/src/gas/write.c,v
retrieving revision 1.112
diff -b -u -r1.112 write.c
--- gas/write.c	26 Mar 2007 12:23:48 -0000	1.112
+++ gas/write.c	18 Apr 2007 09:15:29 -0000
@@ -2486,7 +2486,9 @@
 print_fixup (fixS *fixp)
 {
   indent_level = 1;
-  fprintf (stderr, "fix %lx %s:%d", (long) fixp, fixp->fx_file, fixp->fx_line);
+  fprintf (stderr, "fix ");
+  fprintf_vma (stderr, (bfd_vma)((bfd_hostptr_t) fixp));
+  fprintf (stderr, " %s:%d",fixp->fx_file, fixp->fx_line);
   if (fixp->fx_pcrel)
     fprintf (stderr, " pcrel");
   if (fixp->fx_pcrel_adjust)
@@ -2503,8 +2505,10 @@
     fprintf (stderr, " tcbit");
   if (fixp->fx_done)
     fprintf (stderr, " done");
-  fprintf (stderr, "\n    size=%d frag=%lx where=%ld offset=%lx addnumber=%lx",
-	   fixp->fx_size, (long) fixp->fx_frag, (long) fixp->fx_where,
+  fprintf (stderr, "\n    size=%d frag=", fixp->fx_size);
+  fprintf_vma (stderr, (bfd_vma) ((bfd_hostptr_t) fixp->fx_frag));
+  fprintf (stderr, " where=%ld offset=%lx addnumber=%lx",
+	   (long) fixp->fx_where,
 	   (long) fixp->fx_offset, (long) fixp->fx_addnumber);
   fprintf (stderr, "\n    %s (%d)", bfd_get_reloc_code_name (fixp->fx_r_type),
 	   fixp->fx_r_type);
Index: gprof/cg_print.c
===================================================================
RCS file: /cvs/src/src/gprof/cg_print.c,v
retrieving revision 1.12
diff -b -u -r1.12 cg_print.c
--- gprof/cg_print.c	9 May 2005 06:55:24 -0000	1.12
+++ gprof/cg_print.c	18 Apr 2007 09:15:42 -0000
@@ -76,7 +76,7 @@
     }
 
   printf (_("\ngranularity: each sample hit covers %ld byte(s)"),
-	  (long) hist_scale * sizeof (UNIT));
+	  (long) hist_scale * (long) sizeof (UNIT));
 
   if (print_time > 0.0)
     printf (_(" for %.2f%% of %.2f seconds\n\n"),
Index: gprof/hist.c
===================================================================
RCS file: /cvs/src/src/gprof/hist.c,v
retrieving revision 1.17
diff -b -u -r1.17 hist.c
--- gprof/hist.c	10 Apr 2007 08:47:50 -0000	1.17
+++ gprof/hist.c	18 Apr 2007 09:15:43 -0000
@@ -464,7 +464,7 @@
   if (bsd_style_output)
     {
       printf (_("\ngranularity: each sample hit covers %ld byte(s)"),
-	      (long) hist_scale * sizeof (UNIT));
+	      (long) hist_scale * (long) sizeof (UNIT));
       if (total_time > 0.0)
 	{
 	  printf (_(" for %.2f%% of %.2f %s\n\n"),
Index: include/splay-tree.h
===================================================================
RCS file: /cvs/src/src/include/splay-tree.h,v
retrieving revision 1.13
diff -b -u -r1.13 splay-tree.h
--- include/splay-tree.h	10 May 2005 10:21:08 -0000	1.13
+++ include/splay-tree.h	18 Apr 2007 09:15:43 -0000
@@ -36,6 +36,14 @@
 
 #include "ansidecl.h"
 
+#ifndef _WIN64
+  typedef unsigned long int libi_uhostptr_t;
+  typedef long int libi_shostptr_t;
+#else
+  typedef unsigned long long libi_uhostptr_t;
+  typedef long long libi_shostptr_t;
+#endif
+
 #ifndef GTY
 #define GTY(X)
 #endif
@@ -44,8 +52,8 @@
    these types, if necessary.  These types should be sufficiently wide
    that any pointer or scalar can be cast to these types, and then
    cast back, without loss of precision.  */
-typedef unsigned long int splay_tree_key;
-typedef unsigned long int splay_tree_value;
+typedef libi_uhostptr_t splay_tree_key;
+typedef libi_uhostptr_t splay_tree_value;
 
 /* Forward declaration for a node in the tree.  */
 typedef struct splay_tree_node_s *splay_tree_node;
Index: include/coff/internal.h
===================================================================
RCS file: /cvs/src/src/include/coff/internal.h,v
retrieving revision 1.21
diff -b -u -r1.21 internal.h
--- include/coff/internal.h	19 Mar 2007 23:06:06 -0000	1.21
+++ include/coff/internal.h	18 Apr 2007 09:15:45 -0000
@@ -419,8 +419,8 @@
     char _n_name[SYMNMLEN];	/* old COFF version	*/
     struct
     {
-      long _n_zeroes;		/* new == 0		*/
-      long _n_offset;		/* offset into string table */
+      bfd_hostptr_t _n_zeroes;		/* new == 0		*/
+      bfd_hostptr_t _n_offset;		/* offset into string table */
     }      _n_n;
     char *_n_nptr[2];		/* allows for overlaying	*/
   }     _n;
Index: libiberty/strerror.c
===================================================================
RCS file: /cvs/src/src/libiberty/strerror.c,v
retrieving revision 1.12
diff -b -u -r1.12 strerror.c
--- libiberty/strerror.c	28 Mar 2005 02:09:01 -0000	1.12
+++ libiberty/strerror.c	18 Apr 2007 09:15:55 -0000
@@ -469,6 +469,9 @@
 
 #else
 
+#undef sys_nerr
+#undef sys_errlist
+
 extern int sys_nerr;
 extern char *sys_errlist[];
 
=

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-18  9:49                           ` H. J. Lu
@ 2007-04-20 13:34                             ` Kai Tietz
  2007-04-20 13:35                               ` H. J. Lu
  2007-04-20 13:40                               ` Dave Korn
  0 siblings, 2 replies; 48+ messages in thread
From: Kai Tietz @ 2007-04-20 13:34 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

"H. J. Lu" <hjl@lucon.org> wrote on 18.04.2007 06:56:38:

> On Wed, Apr 18, 2007 at 12:09:59AM -0400, Christopher Faylor wrote:
> > On Tue, Apr 17, 2007 at 09:32:30AM +0200, Kai Tietz wrote:
> > >"H. J. Lu" <hjl@lucon.org> wrote on 16.04.2007 23:58:49:
> > >>On Mon, Apr 16, 2007 at 05:07:10PM -0400, Christopher Faylor wrote:
> > >>>If you are assuming that int means 32 bits, wouldn't it make sense 
to
> > >>>use a type like u_int32_t which explicitly spells that out?
> > >>
> > >>u_int32_t is a good idea if it doesn't require extra change since 
this
> > >>is a temporary patch until windres can be rewritten properly.
> > >
> > >Such a types as u_int32_t, u_int16_t, ...  are really a good idea, 
but
> > >that these types are not available on all platforms in sys/types.h. 
:(
> > >So this would need some further work on a temporary thing.  But I
> > >think, it would be a good idea to introduce those kind of types to 
bfd.
> > >E.g. bfd_uint32_t, bfd_int32, bfd_int16, ...
> > 
> > We've all had experience with "temporary" changes, though, so I think 
it
> > makes sense to do this the right way.  Doesn't configure provide a way 
to
> > determine the size of ints/longs?
> 
> I don't think binutils will work at all if sizeof int < 32.  I am not
> sure if we should worry about int > 32 here. In anycase, as I said
> before, the proper thing to do is to use unsigned char [4]:
> 
> http://sourceware.org/ml/binutils/2007-04/msg00154.html
> 
> Anything less is temporary.

I agree to that. I am now nearly through to extend windres by some missing 
(or new) resource types as MANIFEST, DLGINIT, TOOLBAR, ANICURSOR, ANIICON, 
etc. Also I near through to produce a re-compilable RC dump (e.g. 
bitmaps).
I rewrote the rclex as just c lexer not using flex anymore. It seems to be 
much faster and a more flexible way to implement this kind of tokenizer. 
Also the lexer and the yacc file now will support unicode strings by L"" 
too.
I isolated the resource definition structures and I will begin now to 
rewrite the internal structure representation.
The endian test I generalized to be setup in windres.c on startup globally 
by using two global as "host_is_big_endian" and "target_is_big_endian" to 
cover more easily the endian stuff.

I think I will have completed with that next midweek AFAICS.

Do you have may some helpful suggestions or some additons ?

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-20 13:34                             ` Kai Tietz
@ 2007-04-20 13:35                               ` H. J. Lu
  2007-04-20 13:54                                 ` Kai Tietz
  2007-04-20 13:40                               ` Dave Korn
  1 sibling, 1 reply; 48+ messages in thread
From: H. J. Lu @ 2007-04-20 13:35 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Fri, Apr 20, 2007 at 03:27:51PM +0200, Kai Tietz wrote:
> The endian test I generalized to be setup in windres.c on startup globally 
> by using two global as "host_is_big_endian" and "target_is_big_endian" to 
> cover more easily the endian stuff.
> 

Can you use BFD for I/O? It has endian independent I/O routines.


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* RE: PATCH: windres
  2007-04-20 13:34                             ` Kai Tietz
  2007-04-20 13:35                               ` H. J. Lu
@ 2007-04-20 13:40                               ` Dave Korn
  2007-04-20 13:51                                 ` Kai Tietz
  1 sibling, 1 reply; 48+ messages in thread
From: Dave Korn @ 2007-04-20 13:40 UTC (permalink / raw)
  To: 'Kai Tietz', 'H. J. Lu'; +Cc: binutils

On 20 April 2007 14:28, Kai Tietz wrote:



> Do you have may some helpful suggestions or some additons ?


  Accept underscores in identifiers!  (See previous post!)


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 48+ messages in thread

* RE: PATCH: windres
  2007-04-20 13:40                               ` Dave Korn
@ 2007-04-20 13:51                                 ` Kai Tietz
  2007-04-20 13:58                                   ` Dave Korn
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-20 13:51 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils, 'H. J. Lu'

binutils-owner@sourceware.org wrote on 20.04.2007 15:34:38:

> On 20 April 2007 14:28, Kai Tietz wrote:
> 
> 
> 
> > Do you have may some helpful suggestions or some additons ?
> 
> 
>   Accept underscores in identifiers!  (See previous post!)

The new lexer is capable for underscores. I missed to mention that.
May it would be worth to sent the new lexer infront of the update ?
I think I could separate it easily from the rest of the update.

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-20 13:35                               ` H. J. Lu
@ 2007-04-20 13:54                                 ` Kai Tietz
  2007-04-20 14:03                                   ` H. J. Lu
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-20 13:54 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

"H. J. Lu" <hjl@lucon.org> wrote on 20.04.2007 15:34:24:

> On Fri, Apr 20, 2007 at 03:27:51PM +0200, Kai Tietz wrote:
> > The endian test I generalized to be setup in windres.c on startup 
globally 
> > by using two global as "host_is_big_endian" and "target_is_big_endian" 
to 
> > cover more easily the endian stuff.
> > 
> 
> Can you use BFD for I/O? It has endian independent I/O routines.

I do, if you mean bfd_getb16, bfd_getl16, etc.

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


^ permalink raw reply	[flat|nested] 48+ messages in thread

* RE: PATCH: windres
  2007-04-20 13:51                                 ` Kai Tietz
@ 2007-04-20 13:58                                   ` Dave Korn
  2007-04-23 12:26                                     ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: Dave Korn @ 2007-04-20 13:58 UTC (permalink / raw)
  To: 'Kai Tietz'; +Cc: binutils, 'H. J. Lu'

On 20 April 2007 14:49, Kai Tietz wrote:

>>> Do you have may some helpful suggestions or some additons ?
>> 
>> 
>>   Accept underscores in identifiers!  (See previous post!)
> 
> The new lexer is capable for underscores. I missed to mention that.
> May it would be worth to sent the new lexer infront of the update ?
> I think I could separate it easily from the rest of the update.

  That's probably a good idea, multiple smaller patches relating to isolated areas of functionality make for better testability and less risk of breakage.


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-20 13:54                                 ` Kai Tietz
@ 2007-04-20 14:03                                   ` H. J. Lu
  0 siblings, 0 replies; 48+ messages in thread
From: H. J. Lu @ 2007-04-20 14:03 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Fri, Apr 20, 2007 at 03:50:21PM +0200, Kai Tietz wrote:
> "H. J. Lu" <hjl@lucon.org> wrote on 20.04.2007 15:34:24:
> 
> > On Fri, Apr 20, 2007 at 03:27:51PM +0200, Kai Tietz wrote:
> > > The endian test I generalized to be setup in windres.c on startup 
> globally 
> > > by using two global as "host_is_big_endian" and "target_is_big_endian" 
> to 
> > > cover more easily the endian stuff.
> > > 
> > 
> > Can you use BFD for I/O? It has endian independent I/O routines.
> 
> I do, if you mean bfd_getb16, bfd_getl16, etc.
> 

I meant bfd_get_16, bfd_put_16, .....



H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* RE: PATCH: windres
  2007-04-20 13:58                                   ` Dave Korn
@ 2007-04-23 12:26                                     ` Kai Tietz
  2007-04-23 12:44                                       ` Christopher Faylor
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-23 12:26 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils, 'H. J. Lu'

[-- Attachment #1: Type: text/plain, Size: 1864 bytes --]

Hello,

This is my suggested patch for replacing the windres resource file lexer.
The lexer has the same feature set as the prior one, but also supports 
underscores, dollars, and digits in resource identifiers.

ChangeLog:

2007-04-23  Kai Tietz  <Kai.Tietz@onevision.com>

        * binutils/rclex.c: New file.
        * binutils/rclex.l: Remove file.
        * binutils/Makefile.am: Replaced rclex.l by rclex.c.
        * binutils/Makefile.in: Regenerated.



Regards,
 i.A. Kai Tietz




------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger

binutils-owner@sourceware.org wrote on 20.04.2007 15:54:00:

> On 20 April 2007 14:49, Kai Tietz wrote:
> 
> >>> Do you have may some helpful suggestions or some additons ?
> >> 
> >> 
> >>   Accept underscores in identifiers!  (See previous post!)
> > 
> > The new lexer is capable for underscores. I missed to mention that.
> > May it would be worth to sent the new lexer infront of the update ?
> > I think I could separate it easily from the rest of the update.
> 
>   That's probably a good idea, multiple smaller patches relating to 
> isolated areas of functionality make for better testability and less
> risk of breakage.
> 
> 
>     cheers,
>       DaveK
> -- 
> Can't think of a witty .sigline today....
> 
> 


[-- Attachment #2: rclex.c --]
[-- Type: application/octet-stream, Size: 16682 bytes --]

/* rclex.c -- lexer for Windows rc files parser  */

/* Copyright 1997, 1998, 1999, 2001, 2002, 2003, 2005, 2006
   Free Software Foundation, Inc.
   Written by Ian Lance Taylor, Cygnus Support.

   This file is part of GNU Binutils.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */

/* This is a lexer used by the Windows rc file parser.  It basically
   just recognized a bunch of keywords.  */

#include "bfd.h"
#include "bucomm.h"
#include "libiberty.h"
#include "safe-ctype.h"
#include "windres.h"
#include "rcparse.h"

#include <assert.h>

/* Lexer input stream.  */
FILE *yyin = NULL;

/* Whether we are in rcdata mode, in which we returns the lengths of
   strings.  */

static int rcdata_mode;

/* Whether we are supressing lines from cpp (including windows.h or
   headers from your C sources may bring in externs and typedefs).
   When active, we return IGNORED_TOKEN, which lets us ignore these
   outside of resource constructs.  Thus, it isn't required to protect
   all the non-preprocessor lines in your header files with #ifdef
   RC_INVOKED.  It also means your RC file can't include other RC
   files if they're named "*.h".  Sorry.  Name them *.rch or whatever.  */

static int suppress_cpp_data;

#define MAYBE_IGNORE(x) (suppress_cpp_data ? IGNORED_TOKEN : (x))

/* The first filename we detect in the cpp output.  We use this to
   tell included files from the original file.  */

static char *initial_fn;

/* List of allocated strings.  */

struct alloc_string
{
  struct alloc_string *next;
  char *s;
};

static struct alloc_string *strings;

/* List of keywords detected by the lexer.  */
struct rclex_keywords
{
  const char *name;
  int tok;
};

static int rclex_translatekeyword (const char *);

static const struct rclex_keywords keywds[] =
{
  { "ACCELERATORS", ACCELERATORS },
  { "ALT", ALT },
#if 0
  { "ANICURSOR", ANICURSOR }, /* RT_ANICURSOR (21) */
  { "ANIICON", ANIICON }, /* RT_ANIICON (22) */
#endif
  { "ASCII", ASCII },
  { "AUTO3STATE", AUTO3STATE },
  { "AUTOCHECKBOX", AUTOCHECKBOX },
  { "AUTORADIOBUTTON", AUTORADIOBUTTON },
  { "BEDIT", BEDIT },
  { "BEGIN", BEG },
  { "BITMAP", BITMAP },
  { "BLOCK", BLOCK },
#if 0
  { "BUTTON", BUTTON },
#endif
  { "CAPTION", CAPTION },
  { "CHARACTERISTICS", CHARACTERISTICS },
  { "CHECKBOX", CHECKBOX },
  { "CHECKED", CHECKED },
  { "CLASS", CLASS },
  { "COMBOBOX", COMBOBOX },
  { "CONTROL", CONTROL },
  { "CTEXT", CTEXT },
  { "CURSOR", CURSOR },
  { "DEFPUSHBUTTON", DEFPUSHBUTTON },
  { "DIALOG", DIALOG },
  { "DIALOGEX", DIALOGEX },
  { "DISCARDABLE", DISCARDABLE },
#if 0
  { "DLGINCLUDE", DLGINCLUDE },
  { "DLGINIT", DLGINIT },
#endif
  { "EDITTEXT", EDITTEXT },
  { "END", END },
  { "EXSTYLE", EXSTYLE },
  { "FILEFLAGS", FILEFLAGS },
  { "FILEFLAGSMASK", FILEFLAGSMASK },
  { "FILEOS", FILEOS },
  { "FILESUBTYPE", FILESUBTYPE },
  { "FILETYPE", FILETYPE },
  { "FILEVERSION", FILEVERSION },
  { "FIXED", FIXED },
  { "FONT", FONT },
#if 0
  { "FONTDIR", FONTDIR },
#endif
  { "GRAYED", GRAYED },
  { "GROUP_CURSOR", RT_GROUP_CURSOR},
  { "GROUP_ICON", RT_GROUP_ICON },
  { "GROUPBOX", GROUPBOX },
  { "HEDIT", HEDIT },
  { "HELP", HELP },
#if 0
  { "HTML", HTML }, /* RT_HTML (23) */
#endif
  { "ICON", ICON },
  { "IEDIT", IEDIT },
  { "IMPURE", IMPURE },
  { "INACTIVE", INACTIVE },
  { "LANGUAGE", LANGUAGE },
  { "LISTBOX", LISTBOX },
  { "LOADONCALL", LOADONCALL },
  { "LTEXT", LTEXT },
#if 0
  { "MANIFEST", MANIFEST }, /* RT_MANIFEST (24) */
#endif
  { "MENU", MENU },
  { "MENUBARBREAK", MENUBARBREAK },
  { "MENUBREAK", MENUBREAK },
  { "MENUEX", MENUEX },
  { "MENUITEM", MENUITEM },
  { "MESSAGETABLE", MESSAGETABLE },
  { "MOVEABLE", MOVEABLE },
  { "NOINVERT", NOINVERT },
  { "NOT", NOT },
#if 0
  { "PLUGPLAY", PLUGPLAY }, /* RT_PLUGPLAY (19) */
#endif
  { "POPUP", POPUP },
  { "PRELOAD", PRELOAD },
  { "PRODUCTVERSION", PRODUCTVERSION },
  { "PURE", PURE },
  { "PUSHBOX", PUSHBOX },
  { "PUSHBUTTON", PUSHBUTTON },
  { "RADIOBUTTON", RADIOBUTTON },
  { "RCDATA", RCDATA },
  { "RTEXT", RTEXT },
  { "SCROLLBAR", SCROLLBAR },
  { "SEPARATOR", SEPARATOR },
  { "SHIFT", SHIFT },
  { "STATE3", STATE3 },
  { "STRINGTABLE", STRINGTABLE },
  { "STYLE", STYLE },
#if 0
  { "TOOLBAR", TOOLBAR },
#endif
  { "USERBUTTON", USERBUTTON },
  { "VALUE", VALUE },
  { "VERSION", VERSIONK },
  { "VERSIONINFO", VERSIONINFO },
  { "VIRTKEY", VIRTKEY },
#if 0
  { "VXD", VXD }, /* RT_VXD 20 */
#endif
  { NULL, 0 },
};

/* Lexical scanner helpers.  */
static int rclex_lastch = -1;
static size_t rclex_tok_max = 0;
static size_t rclex_tok_pos = 0;
static char *rclex_tok_cur = NULL;

/* Local functions.  */

static void cpp_line (const char *);
static char *handle_quotes (const char *, unsigned long *);
static char *get_string (int);
static void rclex_backch (int);
static int rclex_readch (void);
static int rclex_peekch (void);
static void rclex_append_char_tok (int);
static void rclex_cleartok (void);
static void rclex_delelete_char_tok (void);

/* The lexer function called by yyparse.  */
int yylex(void)
{
  int ch;
  do
    {
      do
	{
	  rclex_cleartok();
	  ch = rclex_readch ();
	  if (ch == -1)
	    return -1;
	  if (ch == '\n')
	    ++rc_lineno;
	}
      while (ch >= 0 && ch <= 0x20);

      switch ( ch )
	{
	case '#':
	  while ((ch = rclex_peekch()) != -1 && ch != '\n')
	    rclex_readch();
	  cpp_line (rclex_tok_cur);
	  ch = IGNORED_TOKEN;
	  break;
	case '{':
	  ch = MAYBE_IGNORE (BEG); break;
	case '}':
	  ch = MAYBE_IGNORE (END); break;
	case '0': case '1': case '2': case '3': case '4':
	case '5': case '6': case '7': case '8': case '9':
	  ch = rclex_peekch ();
	  if (ch == 'x' || ch == 'X')
	    rclex_readch();
	  while ((ch = rclex_peekch ()) != -1)
	    {
	      if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z')
		  || (ch >='a' && ch <= 'f'))
		{
		  rclex_readch ();
		}
	      else
		break;
	    }
	  yylval.i.val = strtoul (rclex_tok_cur, 0, 0);
	  if (ch == 'L' || ch == 'l')
	    {
	      yylval.i.dword = 1;
	      rclex_readch ();
	    }
	  else
	    yylval.i.dword = 0;
	  ch = MAYBE_IGNORE (NUMBER);
	  break;
	case '"':
	  while ((ch = rclex_peekch()) != -1)
	    {
	      if (ch == '\r' || ch == '\n')
		break;
	      if (ch == '\\')
		{
		  rclex_readch();
		  ch = rclex_peekch();
		  if (ch == 0 || ch == -1)
		    break;
		  if (ch == '\r' || ch == '\n')
		    {
		      rclex_delelete_char_tok(); /* Remove backslash from input.  */
		      rclex_readch();
		      if (ch == '\r')
			{
			  ch = rclex_peekch();
			  if (ch == '\n')
			    rclex_readch();
			}
		    }
		  else
		    {
		      rclex_readch();
		    }
		}
	      else
	      {
		rclex_readch();
		if (ch == '"')
		  break;
	      }
	    }
	  ch = MAYBE_IGNORE ((! rcdata_mode ? QUOTEDSTRING : SIZEDSTRING));
	  if (ch != IGNORED_TOKEN)
	    {
	      char *s;
	      unsigned long length;

	      s = handle_quotes (rclex_tok_cur, &length);
	      if (! rcdata_mode)
		yylval.s = s;
	      else
		{
		  yylval.ss.length = length;
		  yylval.ss.s = s;
		}
	    }
	  break;
	default:
	  if ((ch >='a' && ch <='z') || (ch >='A' && ch <= 'Z') || ch=='_' || ch=='$')
	    {
	      ch = rclex_peekch ();
	      while ((ch >='a' && ch <='z') || (ch >='A' && ch <= 'Z') || ch == '_' || ch == '$'
		      || (ch >='0' && ch <='9'))
		{
		  rclex_readch ();
		  ch = rclex_peekch ();
		}
	      ch = rclex_translatekeyword (rclex_tok_cur);
	      ch = MAYBE_IGNORE (ch);
	      if (ch == STRING)
		{
		  char *s;
		  s = get_string (strlen (rclex_tok_cur) + 1);
		  strcpy (s, rclex_tok_cur);
		  yylval.s = s;
		}
	      else if (ch == BLOCK)
	      {
		int saved_rc_data = rcdata_mode;
		int lextok;
		rcdata_mode = 0; /* Force to scan strings */
		lextok = yylex();
		rcdata_mode = saved_rc_data;
		
		if (lextok != STRING && lextok != QUOTEDSTRING)
		  {
		    rcparse_warning ("BLOCK expects a string as argument.");
		    yylval.s = "";
		  }
		if (!strcmp (yylval.s, "StringFileInfo"))
		  ch = BLOCKSTRINGFILEINFO;
		else if (!strcmp(yylval.s, "VarFileInfo"))
		  ch =BLOCKVARFILEINFO;
	      }
	      break;
	    }
	  ch = MAYBE_IGNORE (ch);
	  break;
	}
    }
  while (ch == IGNORED_TOKEN);
  return ch;
}

/* Find a keyword and return its ident.  */

static int
rclex_translatekeyword (const char *key)
{
  const struct rclex_keywords *kw = &keywds[0];
  if (!key || *key == 0 || !(key[0] >= 'A' && key[0] <= 'Z'))
    return STRING;
  while (kw->name != NULL)
    {
      if (strcmp(kw->name, key) == 0)
	return kw->tok;
      ++kw;
    }
  return STRING;
}

/* Handle a C preprocessor line.  */

static void
cpp_line (const char *s)
{
  int line;
  char *send, *fn;

  ++s;
  while (ISSPACE (*s))
    ++s;
  
  line = strtol (s, &send, 0);
  if (*send != '\0' && ! ISSPACE (*send))
    return;

  /* Subtract 1 because we are about to count the newline.  */
  rc_lineno = line - 1;

  s = send;
  while (ISSPACE (*s))
    ++s;

  if (*s != '"')
    return;

  ++s;
  send = strchr (s, '"');
  if (send == NULL)
    return;

  fn = (char *) xmalloc (send - s + 1);
  strncpy (fn, s, send - s);
  fn[send - s] = '\0';

  free (rc_filename);
  rc_filename = fn;

  if (!initial_fn)
    {
      initial_fn = xmalloc (strlen (fn) + 1);
      strcpy (initial_fn, fn);
    }

  /* Allow the initial file, regardless of name.  Suppress all other
     files if they end in ".h" (this allows included "*.rc").  */
  if (strcmp (initial_fn, fn) == 0
      || strcmp (fn + strlen (fn) - 2, ".h") != 0)
    suppress_cpp_data = 0;
  else
    suppress_cpp_data = 1;
}

/* Handle a quoted string.  The quotes are stripped.  A pair of quotes
   in a string are turned into a single quote.  Adjacent strings are
   merged separated by whitespace are merged, as in C.  */

static char *
handle_quotes (const char *input, unsigned long *len)
{
  char *ret, *s;
  const char *t;
  int ch;
  int num_xdigits;

  ret = get_string (strlen (input) + 1);

  s = ret;
  t = input;
  if (*t == '"')
    ++t;
  while (*t != '\0')
    {
      if (*t == '\\')
	{
	  ++t;
	  switch (*t)
	    {
	    case '\0':
	      rcparse_warning ("backslash at end of string");
	      break;

	    case '\"':
	      rcparse_warning ("use \"\" to put \" in a string");
	      break;

	    case 'a':
	      *s++ = ESCAPE_B; /* Strange, but true...  */
	      ++t;
	      break;

	    case 'b':
	      *s++ = ESCAPE_B;
	      ++t;
	      break;

	    case 'f':
	      *s++ = ESCAPE_F;
	      ++t;
	      break;

	    case 'n':
	      *s++ = ESCAPE_N;
	      ++t;
	      break;

	    case 'r':
	      *s++ = ESCAPE_R;
	      ++t;
	      break;

	    case 't':
	      *s++ = ESCAPE_T;
	      ++t;
	      break;

	    case 'v':
	      *s++ = ESCAPE_V;
	      ++t;
	      break;

	    case '\\':
	      *s++ = *t++;
	      break;

	    case '0': case '1': case '2': case '3':
	    case '4': case '5': case '6': case '7':
	      ch = *t - '0';
	      ++t;
	      if (*t >= '0' && *t <= '7')
		{
		  ch = (ch << 3) | (*t - '0');
		  ++t;
		  if (*t >= '0' && *t <= '7')
		    {
		      ch = (ch << 3) | (*t - '0');
		      ++t;
		    }
		}
	      *s++ = ch;
	      break;

	    case 'x':
	      ++t;
	      ch = 0;
	      /* We only handle single byte chars here.  Make sure
		 we finish an escape sequence like "/xB0ABC" after
		 the first two digits.  */
              num_xdigits = 2;
 	      while (num_xdigits--)
		{
		  if (*t >= '0' && *t <= '9')
		    ch = (ch << 4) | (*t - '0');
		  else if (*t >= 'a' && *t <= 'f')
		    ch = (ch << 4) | (*t - 'a' + 10);
		  else if (*t >= 'A' && *t <= 'F')
		    ch = (ch << 4) | (*t - 'A' + 10);
		  else
		    break;
		  ++t;
		}
	      *s++ = ch;
	      break;

	    default:
	      rcparse_warning ("unrecognized escape sequence");
	      *s++ = '\\';
	      *s++ = *t++;
	      break;
	    }
	}
      else if (*t != '"')
	*s++ = *t++;
      else if (t[1] == '\0')
	break;
      else if (t[1] == '"')
	{
	  *s++ = '"';
	  t += 2;
	}
      else
	{
	  ++t;
	  assert (ISSPACE (*t));
	  while (ISSPACE (*t))
	    {
	      if ((*t) == '\n')
		++rc_lineno;
	      ++t;
	    }
	  if (*t == '\0')
	    break;
	  assert (*t == '"');
	  ++t;
	}
    }

  *s = '\0';

  *len = s - ret;

  return ret;
}

/* Allocate a string of a given length.  */
static char *
get_string (int len)
{
  struct alloc_string *as;

  as = (struct alloc_string *) xmalloc (sizeof *as);
  as->s = xmalloc (len);

  as->next = strings;
  strings = as;

  return as->s;
}

/* Discard all the strings we have allocated.  The parser calls this
   when it no longer needs them.  */

void
rcparse_discard_strings (void)
{
  struct alloc_string *as;

  as = strings;
  while (as != NULL)
    {
      struct alloc_string *n;

      free (as->s);
      n = as->next;
      free (as);
      as = n;
    }

  strings = NULL;
}

/* Enter rcdata mode.  */

void
rcparse_rcdata (void)
{
  rcdata_mode = 1;
}

/* Go back to normal mode from rcdata mode.  */

void
rcparse_normal (void)
{
  rcdata_mode = 0;
}

/* Add a character to end of token buffer.  */

static void
rclex_append_char_tok (int ch)
{
  if (!rclex_tok_cur || rclex_tok_max <= rclex_tok_pos)
    {
      char *h = (char *) xmalloc (rclex_tok_max + 9);
      if (!h)
	abort ();
      if (rclex_tok_cur)
	{
	  memcpy (h, rclex_tok_cur, rclex_tok_pos + 1);
	  free (rclex_tok_cur);
	}
      rclex_tok_max += 8;
      rclex_tok_cur = h;
    }
  if (ch != -1 && ch != 0)
    rclex_tok_cur[rclex_tok_pos++] = (char) ch;
  rclex_tok_cur[rclex_tok_pos] = 0;
}

/* Clear token buffer.  */

static void
rclex_cleartok (void)
{
  rclex_tok_pos=0;
  
  /* Force token-buffer initialization.  */
  if (!rclex_tok_cur)
    rclex_append_char_tok (0);
  rclex_tok_pos=0;
  rclex_tok_cur[0] = 0;
}

/* Remove - if present - a character from token buffer right-hand
   side.  */

static void
rclex_delelete_char_tok (void)
{
  /* Force token-buffer initialization.  */
  if (!rclex_tok_cur)
    rclex_append_char_tok (0);
  if (rclex_tok_pos > 0)
    rclex_tok_cur[--rclex_tok_pos] = 0;
}

/* Read next to be processed character from input stream.
   If there is no further character to be processed, return
   -1 to indicate end of stream.  */

static int
rclex_peekch (void)
{
  int ch;
  if (rclex_lastch != -1)
    return rclex_lastch;

  ch = rclex_readch ();
  rclex_backch (ch);
  return ch;
}

/* Put the character back to input stream to be processed
   by next call to rclex_readch.
   Ignore character, if it is EOF or zero.
   Additionally remove one position in token buffer.  */

static void
rclex_backch (int ch)
{
  if (ch == -1 || ch == 0)
    return;
  if (rclex_lastch != -1)
    rcparse_warning ("rclex: Warning buffer underflow.\n");
  rclex_lastch = ch;
  rclex_delelete_char_tok ();
}

/* Read a character from input stream yyin or back-buffer.
   If there is no character left, return -1 to indicate
   end of input stream.
   Additionally put this character into the token buffer.  */

static int
rclex_readch (void)
{
  int ret = -1;

  if (rclex_lastch != -1)
    {
      ret = rclex_lastch;
      rclex_lastch = -1;
    }
  else
    {
      do
        {
          char ch;
	  
	  if (!yyin || feof (yyin))
	    break;
	  if (fread (&ch, 1, 1,yyin) != 1)
	    break;
	  ret = ((int) ch)&0xff;
        }
      while (ret == 0 || ret == '\r');
  }
  rclex_append_char_tok (ret);
  return ret;
}

[-- Attachment #3: windres_lex.txt --]
[-- Type: text/plain, Size: 3936 bytes --]

Index: binutils/Makefile.am
===================================================================
RCS file: /cvs/src/src/binutils/Makefile.am,v
retrieving revision 1.89
diff -b -u -r1.89 Makefile.am
--- binutils/Makefile.am	19 Apr 2007 10:43:47 -0000	1.89
+++ binutils/Makefile.am	23 Apr 2007 11:48:23 -0000
@@ -91,14 +91,14 @@
 	ieee.c is-ranlib.c is-strip.c maybe-ranlib.c maybe-strip.c \
 	nlmconv.c nm.c not-ranlib.c not-strip.c \
 	objcopy.c objdump.c prdbg.c \
-	rdcoff.c rddbg.c readelf.c rename.c \
+	rclex.c rdcoff.c rddbg.c readelf.c rename.c \
 	resbin.c rescoff.c resrc.c resres.c \
 	size.c srconv.c stabs.c strings.c sysdump.c version.c \
 	windres.c winduni.c wrstabs.c
 
 GENERATED_CFILES = \
 	arparse.c arlex.c sysroff.c sysinfo.c syslex.c \
-	defparse.c deflex.c nlmheader.c rcparse.c rclex.c
+	defparse.c deflex.c nlmheader.c rcparse.c
 
 DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
 WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
@@ -333,7 +333,7 @@
 
 nlmconv_SOURCES = nlmconv.c nlmheader.y $(BULIBS)
 
-windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.l \
+windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.c \
 	winduni.c resres.c $(BULIBS)
 windres_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL)
 
@@ -342,7 +342,7 @@
 
 
 EXTRA_DIST = arparse.c arparse.h arlex.c nlmheader.c sysinfo.c sysinfo.h \
-	syslex.c deflex.c defparse.h defparse.c rclex.c rcparse.h rcparse.c
+	syslex.c deflex.c defparse.h defparse.c rcparse.h rcparse.c
 
 diststuff: $(EXTRA_DIST) info
 all: info
Index: binutils/Makefile.in
===================================================================
RCS file: /cvs/src/src/binutils/Makefile.in,v
retrieving revision 1.100
diff -b -u -r1.100 Makefile.in
--- binutils/Makefile.in	19 Apr 2007 10:43:47 -0000	1.100
+++ binutils/Makefile.in	23 Apr 2007 11:48:24 -0000
@@ -52,7 +52,7 @@
 	$(srcdir)/config.in $(srcdir)/../mkinstalldirs \
 	$(top_srcdir)/po/Make-in arparse.h arparse.c arlex.c \
 	defparse.h defparse.c deflex.c nlmheader.h nlmheader.c \
-	arparse.h arparse.c arlex.c rcparse.h rcparse.c rclex.c \
+	arparse.h arparse.c arlex.c rcparse.h rcparse.c \
 	$(srcdir)/../ylwrap $(srcdir)/../ltmain.sh \
 	$(srcdir)/../config.guess $(srcdir)/../config.sub
 subdir = .
@@ -389,14 +389,14 @@
 	ieee.c is-ranlib.c is-strip.c maybe-ranlib.c maybe-strip.c \
 	nlmconv.c nm.c not-ranlib.c not-strip.c \
 	objcopy.c objdump.c prdbg.c \
-	rdcoff.c rddbg.c readelf.c rename.c \
+	rclex.c rdcoff.c rddbg.c readelf.c rename.c \
 	resbin.c rescoff.c resrc.c resres.c \
 	size.c srconv.c stabs.c strings.c sysdump.c version.c \
 	windres.c winduni.c wrstabs.c
 
 GENERATED_CFILES = \
 	arparse.c arlex.c sysroff.c sysinfo.c syslex.c \
-	defparse.c deflex.c nlmheader.c rcparse.c rclex.c
+	defparse.c deflex.c nlmheader.c rcparse.c
 
 DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
 WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
@@ -472,14 +472,14 @@
 coffdump_SOURCES = coffdump.c coffgrok.c $(BULIBS)
 sysdump_SOURCES = sysdump.c $(BULIBS)
 nlmconv_SOURCES = nlmconv.c nlmheader.y $(BULIBS)
-windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.l \
+windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.c \
 	winduni.c resres.c $(BULIBS)
 
 windres_LDADD = $(BFDLIB) $(LIBIBERTY) @LEXLIB@ $(LIBINTL)
 dllwrap_SOURCES = dllwrap.c version.c
 dllwrap_LDADD = $(LIBIBERTY) $(LIBINTL)
 EXTRA_DIST = arparse.c arparse.h arlex.c nlmheader.c sysinfo.c sysinfo.h \
-	syslex.c deflex.c defparse.h defparse.c rclex.c rcparse.h rcparse.c
+	syslex.c deflex.c defparse.h defparse.c rcparse.h rcparse.c
 
 DISTCLEANFILES = sysroff.c sysroff.h site.exp site.bak
 
@@ -864,7 +864,6 @@
 	-rm -f defparse.h
 	-rm -f nlmheader.c
 	-rm -f nlmheader.h
-	-rm -f rclex.c
 	-rm -f rcparse.c
 	-rm -f rcparse.h
 clean: clean-recursive
=

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-23 12:26                                     ` Kai Tietz
@ 2007-04-23 12:44                                       ` Christopher Faylor
  2007-04-23 13:51                                         ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: Christopher Faylor @ 2007-04-23 12:44 UTC (permalink / raw)
  To: Kai Tietz, binutils

On Mon, Apr 23, 2007 at 01:58:52PM +0200, Kai Tietz wrote:
>Hello,
>
>This is my suggested patch for replacing the windres resource file lexer.
>The lexer has the same feature set as the prior one, but also supports 
>underscores, dollars, and digits in resource identifiers.
>
>ChangeLog:
>
>2007-04-23  Kai Tietz  <Kai.Tietz@onevision.com>
>
>        * binutils/rclex.c: New file.
>        * binutils/rclex.l: Remove file.
>        * binutils/Makefile.am: Replaced rclex.l by rclex.c.
>        * binutils/Makefile.in: Regenerated.

I'm sorry that I missed this before but what was the rationale for
replacing the (f)lex file with a .c file?  That seems like a step backwards
to me.

You also have \r\n endings in the file that you provided.  It's a minor
issue but, as long as I'm here...

cgf

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-23 12:44                                       ` Christopher Faylor
@ 2007-04-23 13:51                                         ` Kai Tietz
  2007-04-23 14:23                                           ` Christopher Faylor
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-23 13:51 UTC (permalink / raw)
  To: Christopher Faylor; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1294 bytes --]

binutils-owner@sourceware.org wrote on 23.04.2007 14:25:54:

> I'm sorry that I missed this before but what was the rationale for
> replacing the (f)lex file with a .c file?  That seems like a step 
backwards
> to me.

The use of flex looks more professional, but at a closer look a pure c 
lexer is getting
easier to maintain and more efficant. E.g. gcc use now for a long term no 
flex anymore to
implement the c token scanner. To use flex is sometimes as to break a fly 
on the wheel.
 
> You also have \r\n endings in the file that you provided.  It's a minor
> issue but, as long as I'm here...

Upps. Corrected it, see attachment ;)

Regards,
 i.A. Kai Tietz



------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


[-- Attachment #2: rclex.c --]
[-- Type: application/octet-stream, Size: 15935 bytes --]

/* rclex.c -- lexer for Windows rc files parser  */

/* Copyright 1997, 1998, 1999, 2001, 2002, 2003, 2005, 2006
   Free Software Foundation, Inc.
   Written by Ian Lance Taylor, Cygnus Support.

   This file is part of GNU Binutils.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */

/* This is a lexer used by the Windows rc file parser.  It basically
   just recognized a bunch of keywords.  */

#include "bfd.h"
#include "bucomm.h"
#include "libiberty.h"
#include "safe-ctype.h"
#include "windres.h"
#include "rcparse.h"

#include <assert.h>

/* Lexer input stream.  */
FILE *yyin = NULL;

/* Whether we are in rcdata mode, in which we returns the lengths of
   strings.  */

static int rcdata_mode;

/* Whether we are supressing lines from cpp (including windows.h or
   headers from your C sources may bring in externs and typedefs).
   When active, we return IGNORED_TOKEN, which lets us ignore these
   outside of resource constructs.  Thus, it isn't required to protect
   all the non-preprocessor lines in your header files with #ifdef
   RC_INVOKED.  It also means your RC file can't include other RC
   files if they're named "*.h".  Sorry.  Name them *.rch or whatever.  */

static int suppress_cpp_data;

#define MAYBE_IGNORE(x) (suppress_cpp_data ? IGNORED_TOKEN : (x))

/* The first filename we detect in the cpp output.  We use this to
   tell included files from the original file.  */

static char *initial_fn;

/* List of allocated strings.  */

struct alloc_string
{
  struct alloc_string *next;
  char *s;
};

static struct alloc_string *strings;

/* List of keywords detected by the lexer.  */
struct rclex_keywords
{
  const char *name;
  int tok;
};

static int rclex_translatekeyword (const char *);

static const struct rclex_keywords keywds[] =
{
  { "ACCELERATORS", ACCELERATORS },
  { "ALT", ALT },
#if 0
  { "ANICURSOR", ANICURSOR }, /* RT_ANICURSOR (21) */
  { "ANIICON", ANIICON }, /* RT_ANIICON (22) */
#endif
  { "ASCII", ASCII },
  { "AUTO3STATE", AUTO3STATE },
  { "AUTOCHECKBOX", AUTOCHECKBOX },
  { "AUTORADIOBUTTON", AUTORADIOBUTTON },
  { "BEDIT", BEDIT },
  { "BEGIN", BEG },
  { "BITMAP", BITMAP },
  { "BLOCK", BLOCK },
#if 0
  { "BUTTON", BUTTON },
#endif
  { "CAPTION", CAPTION },
  { "CHARACTERISTICS", CHARACTERISTICS },
  { "CHECKBOX", CHECKBOX },
  { "CHECKED", CHECKED },
  { "CLASS", CLASS },
  { "COMBOBOX", COMBOBOX },
  { "CONTROL", CONTROL },
  { "CTEXT", CTEXT },
  { "CURSOR", CURSOR },
  { "DEFPUSHBUTTON", DEFPUSHBUTTON },
  { "DIALOG", DIALOG },
  { "DIALOGEX", DIALOGEX },
  { "DISCARDABLE", DISCARDABLE },
#if 0
  { "DLGINCLUDE", DLGINCLUDE },
  { "DLGINIT", DLGINIT },
#endif
  { "EDITTEXT", EDITTEXT },
  { "END", END },
  { "EXSTYLE", EXSTYLE },
  { "FILEFLAGS", FILEFLAGS },
  { "FILEFLAGSMASK", FILEFLAGSMASK },
  { "FILEOS", FILEOS },
  { "FILESUBTYPE", FILESUBTYPE },
  { "FILETYPE", FILETYPE },
  { "FILEVERSION", FILEVERSION },
  { "FIXED", FIXED },
  { "FONT", FONT },
#if 0
  { "FONTDIR", FONTDIR },
#endif
  { "GRAYED", GRAYED },
  { "GROUP_CURSOR", RT_GROUP_CURSOR},
  { "GROUP_ICON", RT_GROUP_ICON },
  { "GROUPBOX", GROUPBOX },
  { "HEDIT", HEDIT },
  { "HELP", HELP },
#if 0
  { "HTML", HTML }, /* RT_HTML (23) */
#endif
  { "ICON", ICON },
  { "IEDIT", IEDIT },
  { "IMPURE", IMPURE },
  { "INACTIVE", INACTIVE },
  { "LANGUAGE", LANGUAGE },
  { "LISTBOX", LISTBOX },
  { "LOADONCALL", LOADONCALL },
  { "LTEXT", LTEXT },
#if 0
  { "MANIFEST", MANIFEST }, /* RT_MANIFEST (24) */
#endif
  { "MENU", MENU },
  { "MENUBARBREAK", MENUBARBREAK },
  { "MENUBREAK", MENUBREAK },
  { "MENUEX", MENUEX },
  { "MENUITEM", MENUITEM },
  { "MESSAGETABLE", MESSAGETABLE },
  { "MOVEABLE", MOVEABLE },
  { "NOINVERT", NOINVERT },
  { "NOT", NOT },
#if 0
  { "PLUGPLAY", PLUGPLAY }, /* RT_PLUGPLAY (19) */
#endif
  { "POPUP", POPUP },
  { "PRELOAD", PRELOAD },
  { "PRODUCTVERSION", PRODUCTVERSION },
  { "PURE", PURE },
  { "PUSHBOX", PUSHBOX },
  { "PUSHBUTTON", PUSHBUTTON },
  { "RADIOBUTTON", RADIOBUTTON },
  { "RCDATA", RCDATA },
  { "RTEXT", RTEXT },
  { "SCROLLBAR", SCROLLBAR },
  { "SEPARATOR", SEPARATOR },
  { "SHIFT", SHIFT },
  { "STATE3", STATE3 },
  { "STRINGTABLE", STRINGTABLE },
  { "STYLE", STYLE },
#if 0
  { "TOOLBAR", TOOLBAR },
#endif
  { "USERBUTTON", USERBUTTON },
  { "VALUE", VALUE },
  { "VERSION", VERSIONK },
  { "VERSIONINFO", VERSIONINFO },
  { "VIRTKEY", VIRTKEY },
#if 0
  { "VXD", VXD }, /* RT_VXD 20 */
#endif
  { NULL, 0 },
};

/* Lexical scanner helpers.  */
static int rclex_lastch = -1;
static size_t rclex_tok_max = 0;
static size_t rclex_tok_pos = 0;
static char *rclex_tok_cur = NULL;

/* Local functions.  */

static void cpp_line (const char *);
static char *handle_quotes (const char *, unsigned long *);
static char *get_string (int);
static void rclex_backch (int);
static int rclex_readch (void);
static int rclex_peekch (void);
static void rclex_append_char_tok (int);
static void rclex_cleartok (void);
static void rclex_delelete_char_tok (void);

/* The lexer function called by yyparse.  */
int yylex(void)
{
  int ch;
  do
    {
      do
	{
	  rclex_cleartok();
	  ch = rclex_readch ();
	  if (ch == -1)
	    return -1;
	  if (ch == '\n')
	    ++rc_lineno;
	}
      while (ch >= 0 && ch <= 0x20);

      switch ( ch )
	{
	case '#':
	  while ((ch = rclex_peekch()) != -1 && ch != '\n')
	    rclex_readch();
	  cpp_line (rclex_tok_cur);
	  ch = IGNORED_TOKEN;
	  break;
	case '{':
	  ch = MAYBE_IGNORE (BEG); break;
	case '}':
	  ch = MAYBE_IGNORE (END); break;
	case '0': case '1': case '2': case '3': case '4':
	case '5': case '6': case '7': case '8': case '9':
	  ch = rclex_peekch ();
	  if (ch == 'x' || ch == 'X')
	    rclex_readch();
	  while ((ch = rclex_peekch ()) != -1)
	    {
	      if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z')
		  || (ch >='a' && ch <= 'f'))
		{
		  rclex_readch ();
		}
	      else
		break;
	    }
	  yylval.i.val = strtoul (rclex_tok_cur, 0, 0);
	  if (ch == 'L' || ch == 'l')
	    {
	      yylval.i.dword = 1;
	      rclex_readch ();
	    }
	  else
	    yylval.i.dword = 0;
	  ch = MAYBE_IGNORE (NUMBER);
	  break;
	case '"':
	  while ((ch = rclex_peekch()) != -1)
	    {
	      if (ch == '\r' || ch == '\n')
		break;
	      if (ch == '\\')
		{
		  rclex_readch();
		  ch = rclex_peekch();
		  if (ch == 0 || ch == -1)
		    break;
		  if (ch == '\r' || ch == '\n')
		    {
		      rclex_delelete_char_tok(); /* Remove backslash from input.  */
		      rclex_readch();
		      if (ch == '\r')
			{
			  ch = rclex_peekch();
			  if (ch == '\n')
			    rclex_readch();
			}
		    }
		  else
		    {
		      rclex_readch();
		    }
		}
	      else
	      {
		rclex_readch();
		if (ch == '"')
		  break;
	      }
	    }
	  ch = MAYBE_IGNORE ((! rcdata_mode ? QUOTEDSTRING : SIZEDSTRING));
	  if (ch != IGNORED_TOKEN)
	    {
	      char *s;
	      unsigned long length;

	      s = handle_quotes (rclex_tok_cur, &length);
	      if (! rcdata_mode)
		yylval.s = s;
	      else
		{
		  yylval.ss.length = length;
		  yylval.ss.s = s;
		}
	    }
	  break;
	default:
	  if ((ch >='a' && ch <='z') || (ch >='A' && ch <= 'Z') || ch=='_' || ch=='$')
	    {
	      ch = rclex_peekch ();
	      while ((ch >='a' && ch <='z') || (ch >='A' && ch <= 'Z') || ch == '_' || ch == '$'
		      || (ch >='0' && ch <='9'))
		{
		  rclex_readch ();
		  ch = rclex_peekch ();
		}
	      ch = rclex_translatekeyword (rclex_tok_cur);
	      ch = MAYBE_IGNORE (ch);
	      if (ch == STRING)
		{
		  char *s;
		  s = get_string (strlen (rclex_tok_cur) + 1);
		  strcpy (s, rclex_tok_cur);
		  yylval.s = s;
		}
	      else if (ch == BLOCK)
	      {
		int saved_rc_data = rcdata_mode;
		int lextok;
		rcdata_mode = 0; /* Force to scan strings */
		lextok = yylex();
		rcdata_mode = saved_rc_data;
		
		if (lextok != STRING && lextok != QUOTEDSTRING)
		  {
		    rcparse_warning ("BLOCK expects a string as argument.");
		    yylval.s = "";
		  }
		if (!strcmp (yylval.s, "StringFileInfo"))
		  ch = BLOCKSTRINGFILEINFO;
		else if (!strcmp(yylval.s, "VarFileInfo"))
		  ch =BLOCKVARFILEINFO;
	      }
	      break;
	    }
	  ch = MAYBE_IGNORE (ch);
	  break;
	}
    }
  while (ch == IGNORED_TOKEN);
  return ch;
}

/* Find a keyword and return its ident.  */

static int
rclex_translatekeyword (const char *key)
{
  const struct rclex_keywords *kw = &keywds[0];
  if (!key || *key == 0 || !(key[0] >= 'A' && key[0] <= 'Z'))
    return STRING;
  while (kw->name != NULL)
    {
      if (strcmp(kw->name, key) == 0)
	return kw->tok;
      ++kw;
    }
  return STRING;
}

/* Handle a C preprocessor line.  */

static void
cpp_line (const char *s)
{
  int line;
  char *send, *fn;

  ++s;
  while (ISSPACE (*s))
    ++s;
  
  line = strtol (s, &send, 0);
  if (*send != '\0' && ! ISSPACE (*send))
    return;

  /* Subtract 1 because we are about to count the newline.  */
  rc_lineno = line - 1;

  s = send;
  while (ISSPACE (*s))
    ++s;

  if (*s != '"')
    return;

  ++s;
  send = strchr (s, '"');
  if (send == NULL)
    return;

  fn = (char *) xmalloc (send - s + 1);
  strncpy (fn, s, send - s);
  fn[send - s] = '\0';

  free (rc_filename);
  rc_filename = fn;

  if (!initial_fn)
    {
      initial_fn = xmalloc (strlen (fn) + 1);
      strcpy (initial_fn, fn);
    }

  /* Allow the initial file, regardless of name.  Suppress all other
     files if they end in ".h" (this allows included "*.rc").  */
  if (strcmp (initial_fn, fn) == 0
      || strcmp (fn + strlen (fn) - 2, ".h") != 0)
    suppress_cpp_data = 0;
  else
    suppress_cpp_data = 1;
}

/* Handle a quoted string.  The quotes are stripped.  A pair of quotes
   in a string are turned into a single quote.  Adjacent strings are
   merged separated by whitespace are merged, as in C.  */

static char *
handle_quotes (const char *input, unsigned long *len)
{
  char *ret, *s;
  const char *t;
  int ch;
  int num_xdigits;

  ret = get_string (strlen (input) + 1);

  s = ret;
  t = input;
  if (*t == '"')
    ++t;
  while (*t != '\0')
    {
      if (*t == '\\')
	{
	  ++t;
	  switch (*t)
	    {
	    case '\0':
	      rcparse_warning ("backslash at end of string");
	      break;

	    case '\"':
	      rcparse_warning ("use \"\" to put \" in a string");
	      break;

	    case 'a':
	      *s++ = ESCAPE_B; /* Strange, but true...  */
	      ++t;
	      break;

	    case 'b':
	      *s++ = ESCAPE_B;
	      ++t;
	      break;

	    case 'f':
	      *s++ = ESCAPE_F;
	      ++t;
	      break;

	    case 'n':
	      *s++ = ESCAPE_N;
	      ++t;
	      break;

	    case 'r':
	      *s++ = ESCAPE_R;
	      ++t;
	      break;

	    case 't':
	      *s++ = ESCAPE_T;
	      ++t;
	      break;

	    case 'v':
	      *s++ = ESCAPE_V;
	      ++t;
	      break;

	    case '\\':
	      *s++ = *t++;
	      break;

	    case '0': case '1': case '2': case '3':
	    case '4': case '5': case '6': case '7':
	      ch = *t - '0';
	      ++t;
	      if (*t >= '0' && *t <= '7')
		{
		  ch = (ch << 3) | (*t - '0');
		  ++t;
		  if (*t >= '0' && *t <= '7')
		    {
		      ch = (ch << 3) | (*t - '0');
		      ++t;
		    }
		}
	      *s++ = ch;
	      break;

	    case 'x':
	      ++t;
	      ch = 0;
	      /* We only handle single byte chars here.  Make sure
		 we finish an escape sequence like "/xB0ABC" after
		 the first two digits.  */
              num_xdigits = 2;
 	      while (num_xdigits--)
		{
		  if (*t >= '0' && *t <= '9')
		    ch = (ch << 4) | (*t - '0');
		  else if (*t >= 'a' && *t <= 'f')
		    ch = (ch << 4) | (*t - 'a' + 10);
		  else if (*t >= 'A' && *t <= 'F')
		    ch = (ch << 4) | (*t - 'A' + 10);
		  else
		    break;
		  ++t;
		}
	      *s++ = ch;
	      break;

	    default:
	      rcparse_warning ("unrecognized escape sequence");
	      *s++ = '\\';
	      *s++ = *t++;
	      break;
	    }
	}
      else if (*t != '"')
	*s++ = *t++;
      else if (t[1] == '\0')
	break;
      else if (t[1] == '"')
	{
	  *s++ = '"';
	  t += 2;
	}
      else
	{
	  ++t;
	  assert (ISSPACE (*t));
	  while (ISSPACE (*t))
	    {
	      if ((*t) == '\n')
		++rc_lineno;
	      ++t;
	    }
	  if (*t == '\0')
	    break;
	  assert (*t == '"');
	  ++t;
	}
    }

  *s = '\0';

  *len = s - ret;

  return ret;
}

/* Allocate a string of a given length.  */
static char *
get_string (int len)
{
  struct alloc_string *as;

  as = (struct alloc_string *) xmalloc (sizeof *as);
  as->s = xmalloc (len);

  as->next = strings;
  strings = as;

  return as->s;
}

/* Discard all the strings we have allocated.  The parser calls this
   when it no longer needs them.  */

void
rcparse_discard_strings (void)
{
  struct alloc_string *as;

  as = strings;
  while (as != NULL)
    {
      struct alloc_string *n;

      free (as->s);
      n = as->next;
      free (as);
      as = n;
    }

  strings = NULL;
}

/* Enter rcdata mode.  */

void
rcparse_rcdata (void)
{
  rcdata_mode = 1;
}

/* Go back to normal mode from rcdata mode.  */

void
rcparse_normal (void)
{
  rcdata_mode = 0;
}

/* Add a character to end of token buffer.  */

static void
rclex_append_char_tok (int ch)
{
  if (!rclex_tok_cur || rclex_tok_max <= rclex_tok_pos)
    {
      char *h = (char *) xmalloc (rclex_tok_max + 9);
      if (!h)
	abort ();
      if (rclex_tok_cur)
	{
	  memcpy (h, rclex_tok_cur, rclex_tok_pos + 1);
	  free (rclex_tok_cur);
	}
      rclex_tok_max += 8;
      rclex_tok_cur = h;
    }
  if (ch != -1 && ch != 0)
    rclex_tok_cur[rclex_tok_pos++] = (char) ch;
  rclex_tok_cur[rclex_tok_pos] = 0;
}

/* Clear token buffer.  */

static void
rclex_cleartok (void)
{
  rclex_tok_pos=0;
  
  /* Force token-buffer initialization.  */
  if (!rclex_tok_cur)
    rclex_append_char_tok (0);
  rclex_tok_pos=0;
  rclex_tok_cur[0] = 0;
}

/* Remove - if present - a character from token buffer right-hand
   side.  */

static void
rclex_delelete_char_tok (void)
{
  /* Force token-buffer initialization.  */
  if (!rclex_tok_cur)
    rclex_append_char_tok (0);
  if (rclex_tok_pos > 0)
    rclex_tok_cur[--rclex_tok_pos] = 0;
}

/* Read next to be processed character from input stream.
   If there is no further character to be processed, return
   -1 to indicate end of stream.  */

static int
rclex_peekch (void)
{
  int ch;
  if (rclex_lastch != -1)
    return rclex_lastch;

  ch = rclex_readch ();
  rclex_backch (ch);
  return ch;
}

/* Put the character back to input stream to be processed
   by next call to rclex_readch.
   Ignore character, if it is EOF or zero.
   Additionally remove one position in token buffer.  */

static void
rclex_backch (int ch)
{
  if (ch == -1 || ch == 0)
    return;
  if (rclex_lastch != -1)
    rcparse_warning ("rclex: Warning buffer underflow.\n");
  rclex_lastch = ch;
  rclex_delelete_char_tok ();
}

/* Read a character from input stream yyin or back-buffer.
   If there is no character left, return -1 to indicate
   end of input stream.
   Additionally put this character into the token buffer.  */

static int
rclex_readch (void)
{
  int ret = -1;

  if (rclex_lastch != -1)
    {
      ret = rclex_lastch;
      rclex_lastch = -1;
    }
  else
    {
      do
        {
          char ch;
	  
	  if (!yyin || feof (yyin))
	    break;
	  if (fread (&ch, 1, 1,yyin) != 1)
	    break;
	  ret = ((int) ch)&0xff;
        }
      while (ret == 0 || ret == '\r');
  }
  rclex_append_char_tok (ret);
  return ret;
}

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-23 13:51                                         ` Kai Tietz
@ 2007-04-23 14:23                                           ` Christopher Faylor
  2007-04-23 14:36                                             ` Dave Korn
  0 siblings, 1 reply; 48+ messages in thread
From: Christopher Faylor @ 2007-04-23 14:23 UTC (permalink / raw)
  To: binutils, Kai Tietz

On Mon, Apr 23, 2007 at 02:56:03PM +0200, Kai Tietz wrote:
>binutils-owner@sourceware.org wrote on 23.04.2007 14:25:54:
>>I'm sorry that I missed this before but what was the rationale for
>>replacing the (f)lex file with a .c file?  That seems like a step
>>backwards to me.
>
>The use of flex looks more professional, but at a closer look a pure c
>lexer is getting easier to maintain and more efficant.  E.g.  gcc use
>now for a long term no flex anymore to implement the c token scanner.
>To use flex is sometimes as to break a fly on the wheel.

Speed is not really an issue in this case but, regardless, *claims* of
efficiency are not really useful unless they are accompanied by actual
data.

Your implementation is ~4K larger than the .l version and, since it is
is a complete reimplementation, there is no way to tell what regressions
there may be.  Have you tried running the test suite on your version,
anemic as the windres test may be?

Changing the current version of the lexer to accept more characters seems
like it would be trivial, FWIW.

cgf

^ permalink raw reply	[flat|nested] 48+ messages in thread

* RE: PATCH: windres
  2007-04-23 14:23                                           ` Christopher Faylor
@ 2007-04-23 14:36                                             ` Dave Korn
  2007-04-23 14:46                                               ` Kai Tietz
  0 siblings, 1 reply; 48+ messages in thread
From: Dave Korn @ 2007-04-23 14:36 UTC (permalink / raw)
  To: binutils, 'Kai Tietz'

On 23 April 2007 14:52, Christopher Faylor wrote:

> Your implementation is ~4K larger than the .l version 

  Source or compiled-down object?

> Changing the current version of the lexer to accept more characters seems
> like it would be trivial, FWIW.

  Certainly was.


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 48+ messages in thread

* RE: PATCH: windres
  2007-04-23 14:36                                             ` Dave Korn
@ 2007-04-23 14:46                                               ` Kai Tietz
  2007-04-23 14:50                                                 ` Christopher Faylor
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-23 14:46 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils

binutils-owner@sourceware.org wrote on 23.04.2007 16:22:40:

> On 23 April 2007 14:52, Christopher Faylor wrote:
> 
> > Your implementation is ~4K larger than the .l version 
> 
>   Source or compiled-down object?

Origin rclex.l as source 12k, after flex 66k, obj code 106k.
New rclex.c as source 16k, obj code 89k.

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: windres
  2007-04-23 14:46                                               ` Kai Tietz
@ 2007-04-23 14:50                                                 ` Christopher Faylor
  0 siblings, 0 replies; 48+ messages in thread
From: Christopher Faylor @ 2007-04-23 14:50 UTC (permalink / raw)
  To: binutils, Kai Tietz

On Mon, Apr 23, 2007 at 04:36:25PM +0200, Kai Tietz wrote:
>binutils-owner@sourceware.org wrote on 23.04.2007 16:22:40:
>>On 23 April 2007 14:52, Christopher Faylor wrote:
>>
>>>Your implementation is ~4K larger than the .l version
>>
>>Source or compiled-down object?
>
>Origin rclex.l as source 12k, after flex 66k, obj code 106k.  New
>rclex.c as source 16k, obj code 89k.

IMO, object size doesn't mean much.  It's the maintainability of the
source code that is at issue.  There is 4k more source code to maintain
in the .c version.

If this version provided some other benefits like improved error
checking, demonstrated improved robustness, or more features, I could
buy those as a reason to move to it.  AFAICT, the only rationale you've
given is that gcc doesn't use a lex parser.

cgf

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-18 11:59     ` PATCH: w64 native support Kai Tietz
@ 2007-06-29  5:37       ` NightStrike
  2007-07-12  7:30       ` Nick Clifton
  1 sibling, 0 replies; 48+ messages in thread
From: NightStrike @ 2007-06-29  5:37 UTC (permalink / raw)
  To: Kai Tietz; +Cc: H. J. Lu, binutils

On 4/18/07, Kai Tietz <Kai.Tietz@onevision.com> wrote:
> "H. J. Lu" <hjl@lucon.org> wrote on 11.04.2007 16:07:40:
>
> > We do need a new type when casting from pointer to integer. But
> > it should be determined in autoconf. You can use AC_CHECK_SIZEOF.
>
> I adjust my patch not using the printf macro and using configure.in in bfd
> to find the proper type for bfd_hostptr_t. Also I adjust the autodetection
> of 64 bit in configure by using the size of a "void *" == 8 for detection.
>
> ChangeLog:
>
> 2007-04-18  Kai Tietz   <kai.tietz@onevision.com>
>
>        * bfd/bfd-in.h: (BFD_HOST_64BIT_LONG_LONG): New
>        as equivalent for BFD_HOST_64BIT_LONG.
>        (BFD_HOSTPTR_T): Host pointer type for casting a
>        pointer to an integer type.
>        (bfd_hostptr_t): The typedef of BFD_HOSTPTR_T.
>        (sprintf_vma, fprintf_vma): Add support for long long prints.
>        * bfd/bfd-in2.h: Regenerate.
>        * bfd/configure.in: (BFD_HOST_64BIT_LONG_LONG): New
>        as equivalent for BFD_HOST_64BIT_LONG.
>        (BFD_HOSTPTR_T): Host pointer type for casting a
>        pointer to an integer type. Defauls is "unsigned long".
>        (AC_CHECK_SIZEOF(void *)): New.
>        (host64): Set it if the pointer size is 8.
>        * bfd/configure: Regenerate.
>        * bfd/config.in: Add macro SIZEOF_VOID_P.
>        * bfd/coffcode.h: Replace host ptr type assuming "long" to
>        bfd_hostptr_t type.
>        * bfd/coffgen.c: Likewise.
>        * bfd/elf-eh-frame.c: Likewise.
>        * bfd/peicode.h: Likewise.
>        * gas/symbols.c: Print bfd_hostptr_t to file via fprintf_vma.
>        * gas/write.c: Likewise.
>        * gprof/cg_print.c: Force cast of sizeof to be a long.
>        * gprof/hist.c: Likewise.
>        * include/splay-tree.h: New type libi_uhostptr_t needed for
>        w64 when a long is not wide enought for a pointer for
>        splay_tree_key and splay_tree_value..
>        (splay_tree_key, splay_tree_value): As above, see comment.
>        * include/coff/internal.h:  Replace host ptr type assuming "long"
>        to bfd_hostptr_t type.
>        * libiberty/strerror.c: Undefine sys_nerr and sys_errlist if
>        allready defined in front by runtime headers.
>
> Regards,
>  i.A. Kai Tietz

Please correct me if I am wrong, but it appears that this was never
committed.  Is it going to be?

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-18 11:59     ` PATCH: w64 native support Kai Tietz
  2007-06-29  5:37       ` NightStrike
@ 2007-07-12  7:30       ` Nick Clifton
  2007-07-24  8:00         ` NightStrike
  1 sibling, 1 reply; 48+ messages in thread
From: Nick Clifton @ 2007-07-12  7:30 UTC (permalink / raw)
  To: Kai Tietz; +Cc: H. J. Lu, binutils

Hi Kai,

   In the better late than never category we have...

> 2007-04-18  Kai Tietz   <kai.tietz@onevision.com>
> 
>         * bfd/bfd-in.h: (BFD_HOST_64BIT_LONG_LONG): New
>         as equivalent for BFD_HOST_64BIT_LONG.
>         (BFD_HOSTPTR_T): Host pointer type for casting a
>         pointer to an integer type.
>         (bfd_hostptr_t): The typedef of BFD_HOSTPTR_T.
>         (sprintf_vma, fprintf_vma): Add support for long long prints.
>         * bfd/bfd-in2.h: Regenerate.
>         * bfd/configure.in: (BFD_HOST_64BIT_LONG_LONG): New
>         as equivalent for BFD_HOST_64BIT_LONG.
>         (BFD_HOSTPTR_T): Host pointer type for casting a
>         pointer to an integer type. Defauls is "unsigned long".
>         (AC_CHECK_SIZEOF(void *)): New.
>         (host64): Set it if the pointer size is 8.
>         * bfd/configure: Regenerate.
>         * bfd/config.in: Add macro SIZEOF_VOID_P.
>         * bfd/coffcode.h: Replace host ptr type assuming "long" to
>         bfd_hostptr_t type.
>         * bfd/coffgen.c: Likewise.
>         * bfd/elf-eh-frame.c: Likewise.
>         * bfd/peicode.h: Likewise.
>         * gas/symbols.c: Print bfd_hostptr_t to file via fprintf_vma.
>         * gas/write.c: Likewise.
>         * gprof/cg_print.c: Force cast of sizeof to be a long.
>         * gprof/hist.c: Likewise.
>         * include/splay-tree.h: New type libi_uhostptr_t needed for
>         w64 when a long is not wide enought for a pointer for
>         splay_tree_key and splay_tree_value..
>         (splay_tree_key, splay_tree_value): As above, see comment.
>         * include/coff/internal.h:  Replace host ptr type assuming "long"
>         to bfd_hostptr_t type.
>         * libiberty/strerror.c: Undefine sys_nerr and sys_errlist if
>         allready defined in front by runtime headers.

I have now checked all of this patch in, apart from the change to 
libiberty.  You will need to submit that one separately to the libiberty 
maintainers.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-07-12  7:30       ` Nick Clifton
@ 2007-07-24  8:00         ` NightStrike
  0 siblings, 0 replies; 48+ messages in thread
From: NightStrike @ 2007-07-24  8:00 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Kai Tietz, H. J. Lu, binutils

On 7/12/07, Nick Clifton <nickc@redhat.com> wrote:
> Hi Kai,
>
>   In the better late than never category we have...
>
> > 2007-04-18  Kai Tietz   <kai.tietz@onevision.com>
> >
> >         * bfd/bfd-in.h: (BFD_HOST_64BIT_LONG_LONG): New
> >         as equivalent for BFD_HOST_64BIT_LONG.
> >         (BFD_HOSTPTR_T): Host pointer type for casting a
> >         pointer to an integer type.
> >         (bfd_hostptr_t): The typedef of BFD_HOSTPTR_T.
> >         (sprintf_vma, fprintf_vma): Add support for long long prints.
> >         * bfd/bfd-in2.h: Regenerate.
> >         * bfd/configure.in: (BFD_HOST_64BIT_LONG_LONG): New
> >         as equivalent for BFD_HOST_64BIT_LONG.
> >         (BFD_HOSTPTR_T): Host pointer type for casting a
> >         pointer to an integer type. Defauls is "unsigned long".
> >         (AC_CHECK_SIZEOF(void *)): New.
> >         (host64): Set it if the pointer size is 8.
> >         * bfd/configure: Regenerate.
> >         * bfd/config.in: Add macro SIZEOF_VOID_P.
> >         * bfd/coffcode.h: Replace host ptr type assuming "long" to
> >         bfd_hostptr_t type.
> >         * bfd/coffgen.c: Likewise.
> >         * bfd/elf-eh-frame.c: Likewise.
> >         * bfd/peicode.h: Likewise.
> >         * gas/symbols.c: Print bfd_hostptr_t to file via fprintf_vma.
> >         * gas/write.c: Likewise.
> >         * gprof/cg_print.c: Force cast of sizeof to be a long.
> >         * gprof/hist.c: Likewise.
> >         * include/splay-tree.h: New type libi_uhostptr_t needed for
> >         w64 when a long is not wide enought for a pointer for
> >         splay_tree_key and splay_tree_value..
> >         (splay_tree_key, splay_tree_value): As above, see comment.
> >         * include/coff/internal.h:  Replace host ptr type assuming "long"
> >         to bfd_hostptr_t type.
> >         * libiberty/strerror.c: Undefine sys_nerr and sys_errlist if
> >         allready defined in front by runtime headers.
>
> I have now checked all of this patch in, apart from the change to
> libiberty.  You will need to submit that one separately to the libiberty
> maintainers.
>
> Cheers
>   Nick
>

Does anyone know if this made it into libiberty?

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-10 19:35         ` H. J. Lu
@ 2007-04-11  3:40           ` H. J. Lu
  0 siblings, 0 replies; 48+ messages in thread
From: H. J. Lu @ 2007-04-11  3:40 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Tue, Apr 10, 2007 at 12:35:08PM -0700, H. J. Lu wrote:
> On Tue, Apr 10, 2007 at 07:51:21PM +0200, Kai Tietz wrote:
> > "H. J. Lu" <hjl@lucon.org> wrote on 10.04.2007 19:18:28:
> > 
> > > On Tue, Apr 10, 2007 at 07:00:14PM +0200, Kai Tietz wrote:
> > > > "H. J. Lu" <hjl@lucon.org> wrote on 10.04.2007 18:12:45:
> > > > 
> > > > > Have you looked at
> > > > > 
> > > > > http://sources.redhat.com/bugzilla/show_bug.cgi?id=2737
> > > > > 
> > > > > Does windres work for x64?
> > > > 
> > > > 
> > > > I replaced in all structures of windres.h the type "unsigned long" by 
> > > > "unsigned int" for test and patched the dependent files to use not 
> > long 
> > > > type-specifier in printf methods. It works that way, but I am not 
> > certain, 
> > > > if this would break an other target, where "int" isn't 4 bytes long ? 
> > >                 ^^^^^
> > >                 It should be host, not target.
> > > 
> > > It is better than what we have today. You can add
> > > 
> > >    assert (sizeof (int) == 4);
> > > 
> > > somewhere.
> > 
> > Ok, I on that.
> > 
> > But I noticed, while bootstrap my patch on it on cygwin, that the 
> > replacement of long to bfd_vma does not work as explected for 32-bit hosts 
> > and using --enable-64-bit-bfd. Gcc claims, that pointer size and integer 
> > size are not fitting.
> > I think, we have to introduce a type bfd_hostptr_t or something like that 
> > to solve this problem ?
> > 
> 
> I don't think it is needed. --enable-64-bit-bfd works fine for
> Linux/x86. If --enable-64-bit-bfd doesn't work for cygwin, it
> should be fixed.

I think the main problem of the PE port may be there is no clear
line bewteen internal and external data structure so that it is very
hard to cross compile a PE target on a differnt endian or 64bit host.


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-10 17:18     ` H. J. Lu
  2007-04-10 17:52       ` Kai Tietz
@ 2007-04-10 20:55       ` Paul Koning
  1 sibling, 0 replies; 48+ messages in thread
From: Paul Koning @ 2007-04-10 20:55 UTC (permalink / raw)
  To: hjl; +Cc: binutils

>>>>> "H" == H J Lu <hjl@lucon.org> writes:

 H> On Tue, Apr 10, 2007 at 07:00:14PM +0200, Kai Tietz wrote:
 >> "H. J. Lu" <hjl@lucon.org> wrote on 10.04.2007 18:12:45:
 >> 
 >> > Have you looked at
 >> > 
 >> > http://sources.redhat.com/bugzilla/show_bug.cgi?id=2737
 >> > 
 >> > Does windres work for x64?
 >> 
 >> 
 >> I replaced in all structures of windres.h the type "unsigned long"
 >> by "unsigned int" for test and patched the dependent files to use
 >> not long type-specifier in printf methods. It works that way, but
 >> I am not certain, if this would break an other target, where "int"
 >> isn't 4 bytes long ?
 H> ^^^^^ It should be host, not target.

 H> It is better than what we have today. You can add

 H> assert (sizeof (int) == 4);

Ok, I'll ask a dump question.

Isn't this the sort of platform specific type stuff that "configure"
was invented for?

    paul

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-10 17:52       ` Kai Tietz
@ 2007-04-10 19:35         ` H. J. Lu
  2007-04-11  3:40           ` H. J. Lu
  0 siblings, 1 reply; 48+ messages in thread
From: H. J. Lu @ 2007-04-10 19:35 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Tue, Apr 10, 2007 at 07:51:21PM +0200, Kai Tietz wrote:
> "H. J. Lu" <hjl@lucon.org> wrote on 10.04.2007 19:18:28:
> 
> > On Tue, Apr 10, 2007 at 07:00:14PM +0200, Kai Tietz wrote:
> > > "H. J. Lu" <hjl@lucon.org> wrote on 10.04.2007 18:12:45:
> > > 
> > > > Have you looked at
> > > > 
> > > > http://sources.redhat.com/bugzilla/show_bug.cgi?id=2737
> > > > 
> > > > Does windres work for x64?
> > > 
> > > 
> > > I replaced in all structures of windres.h the type "unsigned long" by 
> > > "unsigned int" for test and patched the dependent files to use not 
> long 
> > > type-specifier in printf methods. It works that way, but I am not 
> certain, 
> > > if this would break an other target, where "int" isn't 4 bytes long ? 
> >                 ^^^^^
> >                 It should be host, not target.
> > 
> > It is better than what we have today. You can add
> > 
> >    assert (sizeof (int) == 4);
> > 
> > somewhere.
> 
> Ok, I on that.
> 
> But I noticed, while bootstrap my patch on it on cygwin, that the 
> replacement of long to bfd_vma does not work as explected for 32-bit hosts 
> and using --enable-64-bit-bfd. Gcc claims, that pointer size and integer 
> size are not fitting.
> I think, we have to introduce a type bfd_hostptr_t or something like that 
> to solve this problem ?
> 

I don't think it is needed. --enable-64-bit-bfd works fine for
Linux/x86. If --enable-64-bit-bfd doesn't work for cygwin, it
should be fixed.


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-10 17:18     ` H. J. Lu
@ 2007-04-10 17:52       ` Kai Tietz
  2007-04-10 19:35         ` H. J. Lu
  2007-04-10 20:55       ` Paul Koning
  1 sibling, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-10 17:52 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

"H. J. Lu" <hjl@lucon.org> wrote on 10.04.2007 19:18:28:

> On Tue, Apr 10, 2007 at 07:00:14PM +0200, Kai Tietz wrote:
> > "H. J. Lu" <hjl@lucon.org> wrote on 10.04.2007 18:12:45:
> > 
> > > Have you looked at
> > > 
> > > http://sources.redhat.com/bugzilla/show_bug.cgi?id=2737
> > > 
> > > Does windres work for x64?
> > 
> > 
> > I replaced in all structures of windres.h the type "unsigned long" by 
> > "unsigned int" for test and patched the dependent files to use not 
long 
> > type-specifier in printf methods. It works that way, but I am not 
certain, 
> > if this would break an other target, where "int" isn't 4 bytes long ? 
>                 ^^^^^
>                 It should be host, not target.
> 
> It is better than what we have today. You can add
> 
>    assert (sizeof (int) == 4);
> 
> somewhere.

Ok, I on that.

But I noticed, while bootstrap my patch on it on cygwin, that the 
replacement of long to bfd_vma does not work as explected for 32-bit hosts 
and using --enable-64-bit-bfd. Gcc claims, that pointer size and integer 
size are not fitting.
I think, we have to introduce a type bfd_hostptr_t or something like that 
to solve this problem ?

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-10 17:01   ` Kai Tietz
@ 2007-04-10 17:18     ` H. J. Lu
  2007-04-10 17:52       ` Kai Tietz
  2007-04-10 20:55       ` Paul Koning
  0 siblings, 2 replies; 48+ messages in thread
From: H. J. Lu @ 2007-04-10 17:18 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Tue, Apr 10, 2007 at 07:00:14PM +0200, Kai Tietz wrote:
> "H. J. Lu" <hjl@lucon.org> wrote on 10.04.2007 18:12:45:
> 
> > Have you looked at
> > 
> > http://sources.redhat.com/bugzilla/show_bug.cgi?id=2737
> > 
> > Does windres work for x64?
> 
> 
> I replaced in all structures of windres.h the type "unsigned long" by 
> "unsigned int" for test and patched the dependent files to use not long 
> type-specifier in printf methods. It works that way, but I am not certain, 
> if this would break an other target, where "int" isn't 4 bytes long ? 
			       ^^^^^
			       It should be host, not target.

It is better than what we have today. You can add

	assert (sizeof (int) == 4);

somewhere.


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-10 16:13 ` H. J. Lu
  2007-04-10 16:23   ` Kai Tietz
@ 2007-04-10 17:01   ` Kai Tietz
  2007-04-10 17:18     ` H. J. Lu
  1 sibling, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-10 17:01 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

"H. J. Lu" <hjl@lucon.org> wrote on 10.04.2007 18:12:45:

> Have you looked at
> 
> http://sources.redhat.com/bugzilla/show_bug.cgi?id=2737
> 
> Does windres work for x64?


I replaced in all structures of windres.h the type "unsigned long" by 
"unsigned int" for test and patched the dependent files to use not long 
type-specifier in printf methods. It works that way, but I am not certain, 
if this would break an other target, where "int" isn't 4 bytes long ? 

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-10 16:13 ` H. J. Lu
@ 2007-04-10 16:23   ` Kai Tietz
  2007-04-10 17:01   ` Kai Tietz
  1 sibling, 0 replies; 48+ messages in thread
From: Kai Tietz @ 2007-04-10 16:23 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

binutils-owner@sourceware.org wrote on 10.04.2007 18:12:45:

> On Tue, Apr 10, 2007 at 06:05:35PM +0200, Kai Tietz wrote:
> > Hello,
> > 
> > trying to build libbfd and the other binutils tools native for x86_64 
> > mingw, I noticed some bugs in libbfd and other places, where the type 
> > "long" was used instead of the bfd_vma type for may pointer values. 
Also I 
> > introduced for libiberty "splay-tree.h" a necessary patch about 
> > pointer/long sizes.
> > 
> 
> Have you looked at
> 
> http://sources.redhat.com/bugzilla/show_bug.cgi?id=2737
> 
> Does windres work for x64?

For x64 mingw yes, because the type long remains 32-bit in MS ABI. This 
bug seems to be more a bug of mingw headers for x64 linux. Because on x64 
linux the long becomes 64-bit wide, but for MS abi this isn't true. May 
the types of this defines as DWORD should be retyped as "unsigned int" ? 
On MS Abi there is a new type DWORD64 for 64-bit width.

Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: PATCH: w64 native support
  2007-04-10 16:06 Kai Tietz
@ 2007-04-10 16:13 ` H. J. Lu
  2007-04-10 16:23   ` Kai Tietz
  2007-04-10 17:01   ` Kai Tietz
  0 siblings, 2 replies; 48+ messages in thread
From: H. J. Lu @ 2007-04-10 16:13 UTC (permalink / raw)
  To: Kai Tietz; +Cc: binutils

On Tue, Apr 10, 2007 at 06:05:35PM +0200, Kai Tietz wrote:
> Hello,
> 
> trying to build libbfd and the other binutils tools native for x86_64 
> mingw, I noticed some bugs in libbfd and other places, where the type 
> "long" was used instead of the bfd_vma type for may pointer values. Also I 
> introduced for libiberty "splay-tree.h" a necessary patch about 
> pointer/long sizes.
> 

Have you looked at

http://sources.redhat.com/bugzilla/show_bug.cgi?id=2737

Does windres work for x64?


H.J.

^ permalink raw reply	[flat|nested] 48+ messages in thread

* PATCH: w64 native support
@ 2007-04-10 16:06 Kai Tietz
  2007-04-10 16:13 ` H. J. Lu
  0 siblings, 1 reply; 48+ messages in thread
From: Kai Tietz @ 2007-04-10 16:06 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 2166 bytes --]

Hello,

trying to build libbfd and the other binutils tools native for x86_64 
mingw, I noticed some bugs in libbfd and other places, where the type 
"long" was used instead of the bfd_vma type for may pointer values. Also I 
introduced for libiberty "splay-tree.h" a necessary patch about 
pointer/long sizes.

ChangeLogs:

For bfd:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * bfd/coffcode.h: Replace use of long by bfd_vma.
        * bfd/coffgen.c: Likewise.
        * bfd/elf-eh-frame.c: Likewise.
        * bfd/peicode.h: Likewise.

For binutils:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * binutils/resres.c: Cast sizeof explicit to type "long".

For gas:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * gas/symbols.c: Replace use of long by bfd_vma and
          print via fprintf_vma.
        * gas/write.c: Likewise.

For gprof:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * gprof/cg_print.c: Explict cast sizeof to long.
        * gprof/hist.c: Likewise.

For include:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * include/splay-tree.h: (libi_uhostptr_t): New type.
        (libi_shostptr_t): New type.
        (splay_tree_key, splay_tree_value): Use libi_uhostptr_t type.
        * include/coff/internal.h: (_n_zeroes, _n_offset): Type vma_bfd.


For libiberty:

2007-04-10 Kai Tietz  <kai.tietz@onevision.com>

        * libiberty/strerror.c: Undefine sys_nerr and sys_errlist for w64 
sake.

Regards,
 i.A. Kai Tietz



------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger

[-- Attachment #2: bfd-w64-native.txt --]
[-- Type: text/plain, Size: 12393 bytes --]

Index: bfd/coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.136
diff -b -u -r1.136 coffcode.h
--- bfd/coffcode.h	26 Mar 2007 12:22:59 -0000	1.136
+++ bfd/coffcode.h	10 Apr 2007 15:48:23 -0000
@@ -4380,7 +4380,7 @@
 
 	  dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
 	  /* We use the native name field to point to the cached field.  */
-	  src->u.syment._n._n_n._n_zeroes = (long) dst;
+	  src->u.syment._n._n_n._n_zeroes = (bfd_vma) dst;
 	  dst->symbol.section = coff_section_from_bfd_index (abfd,
 						     src->u.syment.n_scnum);
 	  dst->symbol.flags = 0;
Index: bfd/coffgen.c
===================================================================
RCS file: /cvs/src/src/bfd/coffgen.c,v
retrieving revision 1.56
diff -b -u -r1.56 coffgen.c
--- bfd/coffgen.c	2 Apr 2007 16:51:13 -0000	1.56
+++ bfd/coffgen.c	10 Apr 2007 15:48:24 -0000
@@ -726,7 +726,7 @@
 	      /* FIXME: We should use a union here.  */
 	      s->u.syment.n_value =
 		(bfd_vma)((combined_entry_type *)
-			  ((unsigned long) s->u.syment.n_value))->offset;
+			  ((bfd_vma) s->u.syment.n_value))->offset;
 	      s->fix_value = 0;
 	    }
 	  if (s->fix_line)
@@ -1640,7 +1640,7 @@
 		}
 
 	      internal_ptr->u.syment._n._n_n._n_offset =
-		((long)
+		((bfd_vma)
 		 (string_table
 		  + (internal_ptr + 1)->u.auxent.x_file.x_n.x_offset));
 	    }
@@ -1652,13 +1652,13 @@
 	      if (internal_ptr->u.syment.n_numaux > 1
 		  && coff_data (abfd)->pe)
 		internal_ptr->u.syment._n._n_n._n_offset =
-		  ((long)
+		  ((bfd_vma)
 		   copy_name (abfd,
 			      (internal_ptr + 1)->u.auxent.x_file.x_fname,
 			      internal_ptr->u.syment.n_numaux * symesz));
 	      else
 		internal_ptr->u.syment._n._n_n._n_offset =
-		  ((long)
+		  ((bfd_vma)
 		   copy_name (abfd,
 			      (internal_ptr + 1)->u.auxent.x_file.x_fname,
 			      (size_t) bfd_coff_filnmlen (abfd)));
@@ -1682,11 +1682,11 @@
 	      if (newstring == NULL)
 		return NULL;
 	      strncpy (newstring, internal_ptr->u.syment._n._n_name, i);
-	      internal_ptr->u.syment._n._n_n._n_offset = (long int) newstring;
+	      internal_ptr->u.syment._n._n_n._n_offset = (bfd_vma) newstring;
 	      internal_ptr->u.syment._n._n_n._n_zeroes = 0;
 	    }
 	  else if (internal_ptr->u.syment._n._n_n._n_offset == 0)
-	    internal_ptr->u.syment._n._n_n._n_offset = (long int) "";
+	    internal_ptr->u.syment._n._n_n._n_offset = (bfd_vma) "";
 	  else if (!bfd_coff_symname_in_debug (abfd, &internal_ptr->u.syment))
 	    {
 	      /* Long name already.  Point symbol at the string in the
@@ -1698,7 +1698,7 @@
 		    return NULL;
 		}
 	      internal_ptr->u.syment._n._n_n._n_offset =
-		((long int)
+		((bfd_vma)
 		 (string_table
 		  + internal_ptr->u.syment._n._n_n._n_offset));
 	    }
@@ -1707,7 +1707,7 @@
 	      /* Long name in debug section.  Very similar.  */
 	      if (debug_section == NULL)
 		debug_section = build_debug_section (abfd);
-	      internal_ptr->u.syment._n._n_n._n_offset = (long int)
+	      internal_ptr->u.syment._n._n_n._n_offset = (bfd_vma)
 		(debug_section + internal_ptr->u.syment._n._n_n._n_offset);
 	    }
 	}
@@ -1784,7 +1784,7 @@
   if (coffsymbol (symbol)->native != NULL
       && coffsymbol (symbol)->native->fix_value)
     ret->value = coffsymbol (symbol)->native->u.syment.n_value -
-      (unsigned long) obj_raw_syments (abfd);
+      (bfd_vma) obj_raw_syments (abfd);
 }
 
 /* Return the COFF syment for a symbol.  */
@@ -1807,7 +1807,7 @@
 
   if (csym->native->fix_value)
     psyment->n_value = psyment->n_value -
-      (unsigned long) obj_raw_syments (abfd);
+      (bfd_vma) obj_raw_syments (abfd);
 
   /* FIXME: We should handle fix_line here.  */
 
@@ -1893,7 +1893,7 @@
 	  if (! combined->fix_value)
 	    val = (bfd_vma) combined->u.syment.n_value;
 	  else
-	    val = combined->u.syment.n_value - (unsigned long) root;
+	    val = combined->u.syment.n_value - (bfd_vma) root;
 
 	  fprintf (file, "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x",
 		   combined->u.syment.n_scnum,
Index: bfd/elf-eh-frame.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-eh-frame.c,v
retrieving revision 1.54
diff -b -u -r1.54 elf-eh-frame.c
--- bfd/elf-eh-frame.c	4 Jan 2007 13:30:39 -0000	1.54
+++ bfd/elf-eh-frame.c	10 Apr 2007 15:48:25 -0000
@@ -917,7 +917,7 @@
       {
 	if (!ent->cie)
 	  {
-	    ecie = ecies + (unsigned long) ent->cie_inf;
+	    ecie = ecies + (bfd_vma) ent->cie_inf;
 	    ent->cie_inf = ecie->cie.cie_inf;
 	  }
 	ent->new_offset = offset;
Index: bfd/peicode.h
===================================================================
RCS file: /cvs/src/src/bfd/peicode.h,v
retrieving revision 1.50
diff -b -u -r1.50 peicode.h
--- bfd/peicode.h	20 Sep 2006 11:35:07 -0000	1.50
+++ bfd/peicode.h	10 Apr 2007 15:48:26 -0000
@@ -565,7 +565,7 @@
   /* Initialise the internal symbol structure.  */
   ent->u.syment.n_sclass          = sclass;
   ent->u.syment.n_scnum           = section->target_index;
-  ent->u.syment._n._n_n._n_offset = (long) sym;
+  ent->u.syment._n._n_n._n_offset = (bfd_vma) sym;
 
   sym->symbol.the_bfd = vars->abfd;
   sym->symbol.name    = vars->string_ptr;
Index: binutils/resres.c
===================================================================
RCS file: /cvs/src/src/binutils/resres.c,v
retrieving revision 1.7
diff -b -u -r1.7 resres.c
--- binutils/resres.c	16 Jun 2005 09:18:19 -0000	1.7
+++ binutils/resres.c	10 Apr 2007 15:48:27 -0000
@@ -475,7 +475,7 @@
   else
     /* named id */
     {
-      if (fseek (fres, -sizeof (ord), SEEK_CUR) != 0)
+      if (fseek (fres, - ((long) sizeof (ord)), SEEK_CUR) != 0)
 	fatal ("%s: %s: could not seek in file", program_name, filename);
       id_s = read_unistring (&len);
       id->named = 1;
Index: gas/symbols.c
===================================================================
RCS file: /cvs/src/src/gas/symbols.c,v
retrieving revision 1.83
diff -b -u -r1.83 symbols.c
--- gas/symbols.c	15 Mar 2007 12:11:49 -0000	1.83
+++ gas/symbols.c	10 Apr 2007 15:48:29 -0000
@@ -2728,14 +2728,20 @@
   const char *name = S_GET_NAME (sym);
   if (!name || !name[0])
     name = "(unnamed)";
-  fprintf (file, "sym %lx %s", (unsigned long) sym, name);
+
+  fprintf (file, "sym ");
+  fprintf_vma (file, (bfd_vma) sym);
+  fprintf (file, " %s", name);
 
   if (LOCAL_SYMBOL_CHECK (sym))
     {
       struct local_symbol *locsym = (struct local_symbol *) sym;
       if (local_symbol_get_frag (locsym) != &zero_address_frag
 	  && local_symbol_get_frag (locsym) != NULL)
-	fprintf (file, " frag %lx", (long) local_symbol_get_frag (locsym));
+        {
+	  fprintf (file, " frag ");
+	  fprintf_vma (file, (bfd_vma) local_symbol_get_frag (locsym));
+        }
       if (local_symbol_resolved_p (locsym))
 	fprintf (file, " resolved");
       fprintf (file, " local");
@@ -2743,7 +2749,10 @@
   else
     {
       if (sym->sy_frag != &zero_address_frag)
-	fprintf (file, " frag %lx", (long) sym->sy_frag);
+        {
+	  fprintf (file, " frag ");
+	  fprintf_vma (file, (bfd_vma) sym->sy_frag);
+        }
       if (sym->written)
 	fprintf (file, " written");
       if (sym->sy_resolved)
@@ -2817,7 +2826,9 @@
 void
 print_expr_1 (FILE *file, expressionS *exp)
 {
-  fprintf (file, "expr %lx ", (long) exp);
+  fprintf (file, "expr ");
+  fprintf_vma (file,(bfd_vma) exp);
+  fprintf (file, " ");
   switch (exp->X_op)
     {
     case O_illegal:
Index: gas/write.c
===================================================================
RCS file: /cvs/src/src/gas/write.c,v
retrieving revision 1.112
diff -b -u -r1.112 write.c
--- gas/write.c	26 Mar 2007 12:23:48 -0000	1.112
+++ gas/write.c	10 Apr 2007 15:48:31 -0000
@@ -2486,7 +2486,9 @@
 print_fixup (fixS *fixp)
 {
   indent_level = 1;
-  fprintf (stderr, "fix %lx %s:%d", (long) fixp, fixp->fx_file, fixp->fx_line);
+  fprintf (stderr, "fix ");
+  fprintf_vma (stderr, (bfd_vma) fixp);
+  fprintf (stderr, " %s:%d", fixp->fx_file, fixp->fx_line);
   if (fixp->fx_pcrel)
     fprintf (stderr, " pcrel");
   if (fixp->fx_pcrel_adjust)
@@ -2503,8 +2505,11 @@
     fprintf (stderr, " tcbit");
   if (fixp->fx_done)
     fprintf (stderr, " done");
-  fprintf (stderr, "\n    size=%d frag=%lx where=%ld offset=%lx addnumber=%lx",
-	   fixp->fx_size, (long) fixp->fx_frag, (long) fixp->fx_where,
+  fprintf (stderr, "\n    size=%d frag=",
+	   fixp->fx_size);
+  fprintf_vma (stderr, (bfd_vma) fixp->fx_frag);
+  fprintf (stderr, " where=%ld offset=%lx addnumber=%lx",
+	   (long) fixp->fx_where,
 	   (long) fixp->fx_offset, (long) fixp->fx_addnumber);
   fprintf (stderr, "\n    %s (%d)", bfd_get_reloc_code_name (fixp->fx_r_type),
 	   fixp->fx_r_type);
Index: gprof/cg_print.c
===================================================================
RCS file: /cvs/src/src/gprof/cg_print.c,v
retrieving revision 1.12
diff -b -u -r1.12 cg_print.c
--- gprof/cg_print.c	9 May 2005 06:55:24 -0000	1.12
+++ gprof/cg_print.c	10 Apr 2007 15:48:40 -0000
@@ -76,7 +76,7 @@
     }
 
   printf (_("\ngranularity: each sample hit covers %ld byte(s)"),
-	  (long) hist_scale * sizeof (UNIT));
+	  (long) hist_scale * (long) sizeof (UNIT));
 
   if (print_time > 0.0)
     printf (_(" for %.2f%% of %.2f seconds\n\n"),
Index: gprof/hist.c
===================================================================
RCS file: /cvs/src/src/gprof/hist.c,v
retrieving revision 1.17
diff -b -u -r1.17 hist.c
--- gprof/hist.c	10 Apr 2007 08:47:50 -0000	1.17
+++ gprof/hist.c	10 Apr 2007 15:48:40 -0000
@@ -464,7 +464,7 @@
   if (bsd_style_output)
     {
       printf (_("\ngranularity: each sample hit covers %ld byte(s)"),
-	      (long) hist_scale * sizeof (UNIT));
+	      (long) hist_scale * (long) sizeof (UNIT));
       if (total_time > 0.0)
 	{
 	  printf (_(" for %.2f%% of %.2f %s\n\n"),
Index: include/splay-tree.h
===================================================================
RCS file: /cvs/src/src/include/splay-tree.h,v
retrieving revision 1.13
diff -b -u -r1.13 splay-tree.h
--- include/splay-tree.h	10 May 2005 10:21:08 -0000	1.13
+++ include/splay-tree.h	10 Apr 2007 15:48:40 -0000
@@ -36,6 +36,14 @@
 
 #include "ansidecl.h"
 
+#ifndef _WIN64
+  typedef unsigned long int libi_uhostptr_t;
+  typedef long int libi_shostptr_t;
+#else
+  typedef unsigned long long libi_uhostptr_t;
+  typedef long long libi_shostptr_t;
+#endif
+
 #ifndef GTY
 #define GTY(X)
 #endif
@@ -44,8 +52,8 @@
    these types, if necessary.  These types should be sufficiently wide
    that any pointer or scalar can be cast to these types, and then
    cast back, without loss of precision.  */
-typedef unsigned long int splay_tree_key;
-typedef unsigned long int splay_tree_value;
+typedef libi_uhostptr_t splay_tree_key;
+typedef libi_uhostptr_t splay_tree_value;
 
 /* Forward declaration for a node in the tree.  */
 typedef struct splay_tree_node_s *splay_tree_node;
Index: include/coff/internal.h
===================================================================
RCS file: /cvs/src/src/include/coff/internal.h,v
retrieving revision 1.21
diff -b -u -r1.21 internal.h
--- include/coff/internal.h	19 Mar 2007 23:06:06 -0000	1.21
+++ include/coff/internal.h	10 Apr 2007 15:48:40 -0000
@@ -419,8 +419,8 @@
     char _n_name[SYMNMLEN];	/* old COFF version	*/
     struct
     {
-      long _n_zeroes;		/* new == 0		*/
-      long _n_offset;		/* offset into string table */
+      bfd_vma _n_zeroes;		/* new == 0		*/
+      bfd_vma _n_offset;		/* offset into string table */
     }      _n_n;
     char *_n_nptr[2];		/* allows for overlaying	*/
   }     _n;
Index: libiberty/strerror.c
===================================================================
RCS file: /cvs/src/src/libiberty/strerror.c,v
retrieving revision 1.12
diff -b -u -r1.12 strerror.c
--- libiberty/strerror.c	28 Mar 2005 02:09:01 -0000	1.12
+++ libiberty/strerror.c	10 Apr 2007 15:48:44 -0000
@@ -469,6 +469,9 @@
 
 #else
 
+#undef sys_nerr
+#undef sys_errlist
+
 extern int sys_nerr;
 extern char *sys_errlist[];
 
=

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2007-07-24  4:22 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-11 13:43 PATCH: w64 native support Kai Tietz
2007-04-11 13:58 ` H. J. Lu
2007-04-11 14:07   ` H. J. Lu
2007-04-11 18:22     ` PATCH: windres Kai Tietz
2007-04-12 15:55       ` H. J. Lu
2007-04-12 16:51         ` Kai Tietz
2007-04-12 18:03           ` H. J. Lu
2007-04-13 14:41             ` Kai Tietz
2007-04-13 14:49               ` H. J. Lu
2007-04-16 10:05                 ` Kai Tietz
2007-04-16 21:59                   ` Christopher Faylor
2007-04-16 22:20                     ` H. J. Lu
2007-04-17 10:59                       ` Kai Tietz
2007-04-18  4:34                         ` Christopher Faylor
2007-04-18  9:49                           ` H. J. Lu
2007-04-20 13:34                             ` Kai Tietz
2007-04-20 13:35                               ` H. J. Lu
2007-04-20 13:54                                 ` Kai Tietz
2007-04-20 14:03                                   ` H. J. Lu
2007-04-20 13:40                               ` Dave Korn
2007-04-20 13:51                                 ` Kai Tietz
2007-04-20 13:58                                   ` Dave Korn
2007-04-23 12:26                                     ` Kai Tietz
2007-04-23 12:44                                       ` Christopher Faylor
2007-04-23 13:51                                         ` Kai Tietz
2007-04-23 14:23                                           ` Christopher Faylor
2007-04-23 14:36                                             ` Dave Korn
2007-04-23 14:46                                               ` Kai Tietz
2007-04-23 14:50                                                 ` Christopher Faylor
2007-04-18 11:59     ` PATCH: w64 native support Kai Tietz
2007-06-29  5:37       ` NightStrike
2007-07-12  7:30       ` Nick Clifton
2007-07-24  8:00         ` NightStrike
2007-04-11 14:57   ` Kai Tietz
2007-04-11 15:17     ` Daniel Jacobowitz
2007-04-11 15:24       ` Kai Tietz
2007-04-11 15:43         ` Daniel Jacobowitz
2007-04-11 15:49           ` Kai Tietz
2007-04-11 17:34             ` Daniel Jacobowitz
  -- strict thread matches above, loose matches on Subject: below --
2007-04-10 16:06 Kai Tietz
2007-04-10 16:13 ` H. J. Lu
2007-04-10 16:23   ` Kai Tietz
2007-04-10 17:01   ` Kai Tietz
2007-04-10 17:18     ` H. J. Lu
2007-04-10 17:52       ` Kai Tietz
2007-04-10 19:35         ` H. J. Lu
2007-04-11  3:40           ` H. J. Lu
2007-04-10 20:55       ` Paul Koning

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).