public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC][02/19] Target FP: Simplify floatformat_from_type
@ 2017-09-05 18:20 Ulrich Weigand
  2017-09-17 15:29 ` Simon Marchi
  0 siblings, 1 reply; 11+ messages in thread
From: Ulrich Weigand @ 2017-09-05 18:20 UTC (permalink / raw)
  To: gdb-patches

[RFC][02/19] Target FP: Simplify floatformat_from_type

For historical reasons, the TYPE_FLOATFORMAT element is still set to hold
an array of two floatformat structs, one for big-endian and the other for
little-endian.  When accessing the element via floatformat_from_type,
the code would check the type's byte order and return the appropriate
floatformat.

However, these days this is quite unnecessary, since the type's byte order
is already known at the time the type is allocated and the floatformat is
installed into TYPE_FLOATFORMAT.  Therefore, we can just install the correct
version here.

Also, moved the (now trivially simple) floatformat_from_type accessor to
gdbtypes.{c,h}, since it doesn't really need to be in doublest.c now.

Bye,
Ulrich

ChangeLog:

	* doublest.h (floatformat_from_type): Move to gdbtypes.h.
	* doublest.c (floatformat_from_type): Move to gdbtypes.c.

	* gdbtypes.h (union type_specific): Make field floatformat hold
	just a single struct floatformat, not an array.
	(floatformat_from_type): Move here.
	* gdbtypes.c (floatformat_from_type): Move here.  Update to
	changed TYPE_FLOATFORMAT definition.
	(verify_floatformat): Update to changed TYPE_FLOATFORMAT.
	(recursive_dump_type): Likewise.
	(init_float_type): Install correct floatformat for byte order.
	(arch_float_type): Likewise.


Index: binutils-gdb/gdb/doublest.c
===================================================================
--- binutils-gdb.orig/gdb/doublest.c
+++ binutils-gdb/gdb/doublest.c
@@ -770,22 +770,6 @@ floatformat_from_doublest (const struct
 }
 
 \f
-/* Return the floating-point format for a floating-point variable of
-   type TYPE.  */
-
-const struct floatformat *
-floatformat_from_type (const struct type *type)
-{
-  struct gdbarch *gdbarch = get_type_arch (type);
-  const struct floatformat *fmt;
-
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
-  gdb_assert (TYPE_FLOATFORMAT (type));
-  fmt = TYPE_FLOATFORMAT (type)[gdbarch_byte_order (gdbarch)];
-  gdb_assert (TYPE_LENGTH (type) >= floatformat_totalsize_bytes (fmt));
-  return fmt;
-}
-
 /* Extract a floating-point number of type TYPE from a target-order
    byte-stream at ADDR.  Returns the value as type DOUBLEST.  */
 
Index: binutils-gdb/gdb/doublest.h
===================================================================
--- binutils-gdb.orig/gdb/doublest.h
+++ binutils-gdb/gdb/doublest.h
@@ -71,12 +71,6 @@ extern enum float_kind floatformat_class
 extern const char *floatformat_mantissa (const struct floatformat *,
 					 const bfd_byte *);
 
-/* Given TYPE, return its floatformat.  TYPE_FLOATFORMAT() may return
-   NULL.  type_floatformat() detects that and returns a floatformat
-   based on the type size when FLOATFORMAT is NULL.  */
-
-const struct floatformat *floatformat_from_type (const struct type *type);
-
 /* Return the floatformat's total size in host bytes.  */
 
 extern size_t floatformat_totalsize_bytes (const struct floatformat *fmt);
Index: binutils-gdb/gdb/gdbtypes.c
===================================================================
--- binutils-gdb.orig/gdb/gdbtypes.c
+++ binutils-gdb/gdb/gdbtypes.c
@@ -2735,22 +2735,31 @@ set_type_code (struct type *type, enum t
    determined by the floatformat.  Returns size to be used.  */
 
 static int
-verify_floatformat (int bit, const struct floatformat **floatformats)
+verify_floatformat (int bit, const struct floatformat *floatformat)
 {
-  gdb_assert (floatformats != NULL);
-  gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
+  gdb_assert (floatformat != NULL);
 
   if (bit == -1)
-    bit = floatformats[0]->totalsize;
+    bit = floatformat->totalsize;
   gdb_assert (bit >= 0);
 
   size_t len = bit / TARGET_CHAR_BIT;
-  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0]));
-  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1]));
+  gdb_assert (len * TARGET_CHAR_BIT >= floatformat->totalsize);
 
   return bit;
 }
 
+/* Return the floating-point format for a floating-point variable of
+   type TYPE.  */
+
+const struct floatformat *
+floatformat_from_type (const struct type *type)
+{
+  gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
+  gdb_assert (TYPE_FLOATFORMAT (type));
+  return TYPE_FLOATFORMAT (type);
+}
+
 /* Helper function to initialize the standard scalar types.
 
    If NAME is non-NULL, then it is used to initialize the type name.
@@ -2842,11 +2851,13 @@ init_float_type (struct objfile *objfile
 		 int bit, const char *name,
 		 const struct floatformat **floatformats)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
   struct type *t;
 
-  bit = verify_floatformat (bit, floatformats);
+  bit = verify_floatformat (bit, fmt);
   t = init_type (objfile, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
-  TYPE_FLOATFORMAT (t) = floatformats;
+  TYPE_FLOATFORMAT (t) = fmt;
 
   return t;
 }
@@ -4544,26 +4555,11 @@ recursive_dump_type (struct type *type,
 
       case TYPE_SPECIFIC_FLOATFORMAT:
 	printfi_filtered (spaces, "floatformat ");
-	if (TYPE_FLOATFORMAT (type) == NULL)
+	if (TYPE_FLOATFORMAT (type) == NULL
+	    || TYPE_FLOATFORMAT (type)->name == NULL)
 	  puts_filtered ("(null)");
 	else
-	  {
-	    puts_filtered ("{ ");
-	    if (TYPE_FLOATFORMAT (type)[0] == NULL
-		|| TYPE_FLOATFORMAT (type)[0]->name == NULL)
-	      puts_filtered ("(null)");
-	    else
-	      puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
-
-	    puts_filtered (", ");
-	    if (TYPE_FLOATFORMAT (type)[1] == NULL
-		|| TYPE_FLOATFORMAT (type)[1]->name == NULL)
-	      puts_filtered ("(null)");
-	    else
-	      puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
-
-	    puts_filtered (" }");
-	  }
+	  puts_filtered (TYPE_FLOATFORMAT (type)->name);
 	puts_filtered ("\n");
 	break;
 
@@ -4907,11 +4903,12 @@ arch_float_type (struct gdbarch *gdbarch
 		 int bit, const char *name,
 		 const struct floatformat **floatformats)
 {
+  const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
   struct type *t;
 
-  bit = verify_floatformat (bit, floatformats);
+  bit = verify_floatformat (bit, fmt);
   t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
-  TYPE_FLOATFORMAT (t) = floatformats;
+  TYPE_FLOATFORMAT (t) = fmt;
 
   return t;
 }
Index: binutils-gdb/gdb/gdbtypes.h
===================================================================
--- binutils-gdb.orig/gdb/gdbtypes.h
+++ binutils-gdb/gdb/gdbtypes.h
@@ -571,12 +571,11 @@ union type_specific
 
   struct gnat_aux_type *gnat_stuff;
 
-  /* * FLOATFORMAT is for TYPE_CODE_FLT.  It is a pointer to two
-     floatformat objects that describe the floating-point value
-     that resides within the type.  The first is for big endian
-     targets and the second is for little endian targets.  */
+  /* * FLOATFORMAT is for TYPE_CODE_FLT.  It is a pointer to a
+     floatformat object that describes the floating-point value
+     that resides within the type.  */
 
-  const struct floatformat **floatformat;
+  const struct floatformat *floatformat;
 
   /* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types.  */
 
@@ -1434,6 +1433,9 @@ extern void set_type_vptr_basetype (stru
 #define TYPE_ERROR_NAME(type) \
   (TYPE_NAME (type) ? TYPE_NAME (type) : _("<error type>"))
 
+/* Given TYPE, return its floatformat.  */
+const struct floatformat *floatformat_from_type (const struct type *type);
+
 struct builtin_type
 {
   /* Integral types.  */

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

* Re: [RFC][02/19] Target FP: Simplify floatformat_from_type
  2017-09-05 18:20 [RFC][02/19] Target FP: Simplify floatformat_from_type Ulrich Weigand
@ 2017-09-17 15:29 ` Simon Marchi
  2017-09-18 11:49   ` Ulrich Weigand
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Marchi @ 2017-09-17 15:29 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: gdb-patches

On 2017-09-05 20:20, Ulrich Weigand wrote:
> Index: binutils-gdb/gdb/gdbtypes.c
> ===================================================================
> --- binutils-gdb.orig/gdb/gdbtypes.c
> +++ binutils-gdb/gdb/gdbtypes.c
> @@ -2735,22 +2735,31 @@ set_type_code (struct type *type, enum t
>     determined by the floatformat.  Returns size to be used.  */
> 
>  static int
> -verify_floatformat (int bit, const struct floatformat **floatformats)
> +verify_floatformat (int bit, const struct floatformat *floatformat)
>  {
> -  gdb_assert (floatformats != NULL);
> -  gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
> +  gdb_assert (floatformat != NULL);
> 
>    if (bit == -1)
> -    bit = floatformats[0]->totalsize;
> +    bit = floatformat->totalsize;
>    gdb_assert (bit >= 0);
> 
>    size_t len = bit / TARGET_CHAR_BIT;
> -  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0]));
> -  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1]));
> +  gdb_assert (len * TARGET_CHAR_BIT >= floatformat->totalsize);

That looks funny now.  Is there a reason not to do

   gdb_assert (bit >= floatformat->totalsize);

directly?

Simon

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

* Re: [RFC][02/19] Target FP: Simplify floatformat_from_type
  2017-09-17 15:29 ` Simon Marchi
@ 2017-09-18 11:49   ` Ulrich Weigand
  2017-09-18 16:21     ` Simon Marchi
  0 siblings, 1 reply; 11+ messages in thread
From: Ulrich Weigand @ 2017-09-18 11:49 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Simon Marchi wrote:

> On 2017-09-05 20:20, Ulrich Weigand wrote:
> >    size_t len = bit / TARGET_CHAR_BIT;
> > -  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0]));
> > -  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1]));
> > +  gdb_assert (len * TARGET_CHAR_BIT >= floatformat->totalsize);
> 
> That looks funny now.  Is there a reason not to do
> 
>    gdb_assert (bit >= floatformat->totalsize);
> 
> directly?

Well, that would use different rounding ...   Of course, this only
matters when floatformat->totalsize is not a multiple of TARGET_CHAR_BIT,
which doesn't happen for any of the floatformats GDB supports, so it
is probably moot.  Maybe we should instead use an assert to verify that
floatformat->totalsize is in fact a multiple of TARGET_CHAR_BIT?

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* Re: [RFC][02/19] Target FP: Simplify floatformat_from_type
  2017-09-18 11:49   ` Ulrich Weigand
@ 2017-09-18 16:21     ` Simon Marchi
  2017-09-18 19:01       ` Ulrich Weigand
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Marchi @ 2017-09-18 16:21 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: gdb-patches

On 2017-09-18 13:49, Ulrich Weigand wrote:
> Simon Marchi wrote:
> 
>> On 2017-09-05 20:20, Ulrich Weigand wrote:
>> >    size_t len = bit / TARGET_CHAR_BIT;
>> > -  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0]));
>> > -  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1]));
>> > +  gdb_assert (len * TARGET_CHAR_BIT >= floatformat->totalsize);
>> 
>> That looks funny now.  Is there a reason not to do
>> 
>>    gdb_assert (bit >= floatformat->totalsize);
>> 
>> directly?
> 
> Well, that would use different rounding ...   Of course, this only
> matters when floatformat->totalsize is not a multiple of 
> TARGET_CHAR_BIT,
> which doesn't happen for any of the floatformats GDB supports, so it
> is probably moot. Maybe we should instead use an assert to verify that
> floatformat->totalsize is in fact a multiple of TARGET_CHAR_BIT?

I indeed think we should add an assert that the type size in bits is a 
multiple of TARGET_CHAR_BIT.  But it should not be in 
verify_floatformat, because it's not specific to float.  In most calls 
to arch_type/init_type, we have that division that rounds down:

   t = init_type (objfile, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);

Let's say we try to add an integer with bit == 24 and TARGET_CHAR_BIT == 
16, we'll create a type with a size of 1 target byte, and things will 
likely break down the line.  Since this is where we do the division by 
TARGET_CHAR_BIT, and therefore assume (implicitly) that bit is a 
multiple of TARGET_CHAR_BIT, I think this is where the assert should be 
added.  To avoid adding them everywhere, we could make 
arch_type/init_type take a size in bits, and do the division and assert 
there.

As long as verify_floatformat is concerned, its job is to verify (IIUC) 
that the type you want to create with BIT bits has enough room to hold a 
float of that kind.  It doesn't have to know that we'll later divide 
that value by TARGET_CHAR_BIT.  So here I think asserting "bit >= 
floatformat->totalsize)" is fine.

I don't think floatformat->totalsize has any requirement to be a 
multiple of TARGET_CHAR_BIT.  For example, my hardware could have a 
float of 29 bits, but when stored in memory it uses 32 bits (just like 
on x86 long double is an 80 bit float stored in a 96 bit data type).  
Then, bit would be 32 and floatformat->totalsize would be 29.

Simon

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

* Re: [RFC][02/19] Target FP: Simplify floatformat_from_type
  2017-09-18 16:21     ` Simon Marchi
@ 2017-09-18 19:01       ` Ulrich Weigand
  2017-09-20 13:51         ` [RFC] Make init_type/arch_type take a size in bits Ulrich Weigand
  2017-09-20 16:30         ` [RFC][02/19] Target FP: Simplify floatformat_from_type Ulrich Weigand
  0 siblings, 2 replies; 11+ messages in thread
From: Ulrich Weigand @ 2017-09-18 19:01 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Simon Marchi wrote:

> Since this is where we do the division by 
> TARGET_CHAR_BIT, and therefore assume (implicitly) that bit is a 
> multiple of TARGET_CHAR_BIT, I think this is where the assert should be 
> added.  To avoid adding them everywhere, we could make 
> arch_type/init_type take a size in bits, and do the division and assert 
> there.

I agree, this seems the best solution.  And it makes more sense for all
the type-creation interfaces to use size in bits instead of the
mixture we have now.  I'll come up with a patch to do that.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* [RFC] Make init_type/arch_type take a size in bits
  2017-09-18 19:01       ` Ulrich Weigand
@ 2017-09-20 13:51         ` Ulrich Weigand
  2017-09-20 14:40           ` Simon Marchi
  2017-09-20 16:30         ` [RFC][02/19] Target FP: Simplify floatformat_from_type Ulrich Weigand
  1 sibling, 1 reply; 11+ messages in thread
From: Ulrich Weigand @ 2017-09-20 13:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Simon Marchi wrote:

> Since this is where we do the division by 
> TARGET_CHAR_BIT, and therefore assume (implicitly) that bit is a 
> multiple of TARGET_CHAR_BIT, I think this is where the assert should be 
> added.  To avoid adding them everywhere, we could make 
> arch_type/init_type take a size in bits, and do the division and assert 
> there.

As discussed, this changes the interfaces to init_type and arch_type
to take the type length in bits as input (instead of as bytes).  The
routine asserts that the length is a multiple of TARGET_CHAR_BIT.

For consistency, arch_flags_type is changed likewise, so that now
all type creation interfaces always use length in bits.

All callers are updated in the straightforward manner.

The assert actually found a bug in stabsread.c:read_range_type, where
the init_integer_type routine was called with a wrong argument (probably
a bug introduced with the conversion to use init_integer_type).

Bye,
Ulrich


ChangeLog:

	* gdbtypes.c (init_type): Change incoming argument from
	lenght-in-bytes to lenght-in-bits.  Assert length is a
	multiple of TARGET_CHAR_BITS.
	(arch_type, arch_flags_type): Likewise.
	(init_integer_type): Update call to init_type.
	(init_character_type): Likewise.
	(init_boolean_type): Likewise.
	(init_float_type): Likewise.
	(init_decfloat_type): Likewise.
	(init_complex_type): Likewise.
	(init_pointer_type): Likewise.
	(objfile_type): Likewise.
	(arch_integer_type): Update call to arch_type.
	(arch_character_type): Likewise.
	(arch_boolean_type): Likewise.
	(arch_float_type): Likewise.
	(arch_decfloat_type): Likewise.
	(arch_complex_type): Likewise.
	(arch_pointer_type): Likewise.
	(gdbtypes_post_init): Likewise.

	* dwarf2read.c (dwarf2_init_float_type): Update call to init_type.
	(read_base_type): Likewise.
	* mdebugread.c (basic_type): Likewise.
	* stabsread.c (dbx_init_float_type): Likewise.
	(rs6000_builtin_type): Likewise.
	(read_range_type): Likewise.  Also, fix call to init_integer_type
	with erroneous length argument.

	* ada-lang.c (ada_language_arch_info): Update call to arch_type.
	* d-lang.c (build_d_types): Likewise.
	* f-lang.c (build_fortran_types): Likewise.
	* go-lang.c (build_go_types): Likewise.
	* opencl-lang.c (build_opencl_types): Likewise.
	* jit.c (finalize_symtab): Likewise.
	* gnu-v3-abi.c (build_std_type_info_type): Likewise.
	* target-descriptions.c (tdesc_gdb_type): Likewise.  Also,
	update call to arch_flags_type.

	* linux-tdep.c (linux_get_siginfo_type_with_fields): Update call to
	arch_type.
	* fbsd-tdep.c (fbsd_get_siginfo_type): Likewise.
	* windows-tdep.c (windows_get_tlb_type): Likewise.

	* avr-tdep.c (avr_gdbarch_init): Update call to arch_type.
	* ft32-tdep.c (ft32_gdbarch_init): Likewise.
	* m32c-tdep.c (make_types): Likewise.
	* rl78-tdep.c (rl78_gdbarch_init): Likewise.
	(rl78_psw_type): Update call to arch_flags_type.
	* m68k-tdep.c (m68k_ps_type): Update call to arch_flags_type.
	* rx-tdep.c (rx_psw_type): Likewise.
	(rx_fpsw_type): Likewise.
	* sparc-tdep.c (sparc_psr_type): Likewise.
	(sparc_fsr_type): Likewise.
	* sparc64-tdep.c (sparc64_pstate_type): Likewise.
	(sparc64_ccr_type): Likewise.
	(sparc64_fsr_type): Likewise.
	(sparc64_fprs_type): Likewise.

Index: binutils-gdb/gdb/gdbtypes.h
===================================================================
--- binutils-gdb.orig/gdb/gdbtypes.h
+++ binutils-gdb/gdb/gdbtypes.h
@@ -1683,7 +1683,7 @@ struct field *append_composite_type_fiel
    type is created using arch_flag_type().  Flags are then added using
    append_flag_type_field() and append_flag_type_flag().  */
 extern struct type *arch_flags_type (struct gdbarch *gdbarch,
-				     const char *name, int length);
+				     const char *name, int bit);
 extern void append_flags_type_field (struct type *type,
 				     int start_bitpos, int nr_bits,
 				     struct type *field_type, const char *name);
Index: binutils-gdb/gdb/gdbtypes.c
===================================================================
--- binutils-gdb.orig/gdb/gdbtypes.c
+++ binutils-gdb/gdb/gdbtypes.c
@@ -2758,14 +2758,15 @@ verify_floatformat (int bit, const struc
    least as long as OBJFILE.  */
 
 struct type *
-init_type (struct objfile *objfile, enum type_code code, int length,
+init_type (struct objfile *objfile, enum type_code code, int bit,
 	   const char *name)
 {
   struct type *type;
 
   type = alloc_type (objfile);
   set_type_code (type, code);
-  TYPE_LENGTH (type) = length;
+  gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
+  TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
   TYPE_NAME (type) = name;
 
   return type;
@@ -2791,7 +2792,7 @@ init_integer_type (struct objfile *objfi
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_INT, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -2808,7 +2809,7 @@ init_character_type (struct objfile *obj
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_CHAR, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -2825,7 +2826,7 @@ init_boolean_type (struct objfile *objfi
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_BOOL, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -2845,7 +2846,7 @@ init_float_type (struct objfile *objfile
   struct type *t;
 
   bit = verify_floatformat (bit, floatformats);
-  t = init_type (objfile, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_FLT, bit, name);
   TYPE_FLOATFORMAT (t) = floatformats;
 
   return t;
@@ -2859,7 +2860,7 @@ init_decfloat_type (struct objfile *objf
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_DECFLOAT, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_DECFLOAT, bit, name);
   return t;
 }
 
@@ -2873,7 +2874,7 @@ init_complex_type (struct objfile *objfi
   struct type *t;
 
   t = init_type (objfile, TYPE_CODE_COMPLEX,
-		 2 * TYPE_LENGTH (target_type), name);
+		 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
   TYPE_TARGET_TYPE (t) = target_type;
   return t;
 }
@@ -2889,7 +2890,7 @@ init_pointer_type (struct objfile *objfi
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_PTR, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_PTR, bit, name);
   TYPE_TARGET_TYPE (t) = target_type;
   TYPE_UNSIGNED (t) = 1;
   return t;
@@ -4832,13 +4833,14 @@ copy_type (const struct type *type)
 
 struct type *
 arch_type (struct gdbarch *gdbarch,
-	   enum type_code code, int length, const char *name)
+	   enum type_code code, int bit, const char *name)
 {
   struct type *type;
 
   type = alloc_type_arch (gdbarch);
   set_type_code (type, code);
-  TYPE_LENGTH (type) = length;
+  gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
+  TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
 
   if (name)
     TYPE_NAME (type) = gdbarch_obstack_strdup (gdbarch, name);
@@ -4856,7 +4858,7 @@ arch_integer_type (struct gdbarch *gdbar
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_INT, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -4873,7 +4875,7 @@ arch_character_type (struct gdbarch *gdb
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_CHAR, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -4890,7 +4892,7 @@ arch_boolean_type (struct gdbarch *gdbar
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_BOOL, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -4910,7 +4912,7 @@ arch_float_type (struct gdbarch *gdbarch
   struct type *t;
 
   bit = verify_floatformat (bit, floatformats);
-  t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_FLT, bit, name);
   TYPE_FLOATFORMAT (t) = floatformats;
 
   return t;
@@ -4924,7 +4926,7 @@ arch_decfloat_type (struct gdbarch *gdba
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_DECFLOAT, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_DECFLOAT, bit, name);
   return t;
 }
 
@@ -4938,7 +4940,7 @@ arch_complex_type (struct gdbarch *gdbar
   struct type *t;
 
   t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
-		 2 * TYPE_LENGTH (target_type), name);
+		 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
   TYPE_TARGET_TYPE (t) = target_type;
   return t;
 }
@@ -4954,27 +4956,26 @@ arch_pointer_type (struct gdbarch *gdbar
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_PTR, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name);
   TYPE_TARGET_TYPE (t) = target_type;
   TYPE_UNSIGNED (t) = 1;
   return t;
 }
 
 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
-   NAME is the type name.  LENGTH is the size of the flag word in bytes.  */
+   NAME is the type name.  BIT is the size of the flag word in bits.  */
 
 struct type *
-arch_flags_type (struct gdbarch *gdbarch, const char *name, int length)
+arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit)
 {
-  int max_nfields = length * TARGET_CHAR_BIT;
   struct type *type;
 
-  type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name);
+  type = arch_type (gdbarch, TYPE_CODE_FLAGS, bit, name);
   TYPE_UNSIGNED (type) = 1;
   TYPE_NFIELDS (type) = 0;
   /* Pre-allocate enough space assuming every field is one bit.  */
   TYPE_FIELDS (type)
-    = (struct field *) TYPE_ZALLOC (type, max_nfields * sizeof (struct field));
+    = (struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field));
 
   return type;
 }
@@ -5119,7 +5120,7 @@ gdbtypes_post_init (struct gdbarch *gdba
 
   /* Basic types.  */
   builtin_type->builtin_void
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   builtin_type->builtin_char
     = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
 			 !gdbarch_char_signed (gdbarch), "char");
@@ -5170,9 +5171,9 @@ gdbtypes_post_init (struct gdbarch *gdba
     = arch_complex_type (gdbarch, "double complex",
 			 builtin_type->builtin_double);
   builtin_type->builtin_string
-    = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string");
+    = arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
   builtin_type->builtin_bool
-    = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool");
+    = arch_type (gdbarch, TYPE_CODE_BOOL, TARGET_CHAR_BIT, "bool");
 
   /* The following three are about decimal floating point types, which
      are 32-bits, 64-bits and 128-bits respectively.  */
@@ -5269,7 +5270,7 @@ objfile_type (struct objfile *objfile)
 
   /* Basic types.  */
   objfile_type->builtin_void
-    = init_type (objfile, TYPE_CODE_VOID, 1, "void");
+    = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   objfile_type->builtin_char
     = init_integer_type (objfile, TARGET_CHAR_BIT,
 			 !gdbarch_char_signed (gdbarch), "char");
@@ -5321,10 +5322,10 @@ objfile_type (struct objfile *objfile)
   /* The following set of types is used for symbols with no
      debug information.  */
   objfile_type->nodebug_text_symbol
-    = init_type (objfile, TYPE_CODE_FUNC, 1,
+    = init_type (objfile, TYPE_CODE_FUNC, TARGET_CHAR_BIT,
 		 "<text variable, no debug info>");
   objfile_type->nodebug_text_gnu_ifunc_symbol
-    = init_type (objfile, TYPE_CODE_FUNC, 1,
+    = init_type (objfile, TYPE_CODE_FUNC, TARGET_CHAR_BIT,
 		 "<text gnu-indirect-function variable, no debug info>");
   /* Ifunc resolvers return a function address.  */
   TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
Index: binutils-gdb/gdb/dwarf2read.c
===================================================================
--- binutils-gdb.orig/gdb/dwarf2read.c
+++ binutils-gdb/gdb/dwarf2read.c
@@ -15211,7 +15211,7 @@ dwarf2_init_float_type (struct objfile *
   if (format)
     type = init_float_type (objfile, bits, name, format);
   else
-    type = init_type (objfile, TYPE_CODE_ERROR, bits / TARGET_CHAR_BIT, name);
+    type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
 
   return type;
 }
@@ -15249,7 +15249,7 @@ read_base_type (struct die_info *die, st
     {
       case DW_ATE_address:
 	/* Turn DW_ATE_address into a void * pointer.  */
-	type = init_type (objfile, TYPE_CODE_VOID, 1, NULL);
+	type = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
 	type = init_pointer_type (objfile, bits, name, type);
 	break;
       case DW_ATE_boolean:
@@ -15315,8 +15315,7 @@ read_base_type (struct die_info *die, st
       default:
 	complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
 		   dwarf_type_encoding_name (encoding));
-	type = init_type (objfile, TYPE_CODE_ERROR,
-			  bits / TARGET_CHAR_BIT, name);
+	type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
 	break;
     }
 
Index: binutils-gdb/gdb/mdebugread.c
===================================================================
--- binutils-gdb.orig/gdb/mdebugread.c
+++ binutils-gdb/gdb/mdebugread.c
@@ -1469,14 +1469,13 @@ basic_type (int bt, struct objfile *objf
 
     case btFloatDec:
       tp = init_type (objfile, TYPE_CODE_ERROR,
-		      gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT,
-		      "floating decimal");
+		      gdbarch_double_bit (gdbarch), "floating decimal");
       break;
 
     case btString:
       /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
 	 FIXME.  */
-      tp = init_type (objfile, TYPE_CODE_STRING, 1, "string");
+      tp = init_type (objfile, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
       break;
 
     case btVoid:
Index: binutils-gdb/gdb/stabsread.c
===================================================================
--- binutils-gdb.orig/gdb/stabsread.c
+++ binutils-gdb/gdb/stabsread.c
@@ -368,7 +368,7 @@ dbx_init_float_type (struct objfile *obj
   if (format)
     type = init_float_type (objfile, bits, NULL, format);
   else
-    type = init_type (objfile, TYPE_CODE_ERROR, bits / TARGET_CHAR_BIT, NULL);
+    type = init_type (objfile, TYPE_CODE_ERROR, bits, NULL);
 
   return type;
 }
@@ -2153,7 +2153,7 @@ rs6000_builtin_type (int typenum, struct
       rettype = init_integer_type (objfile, 32, 1, "unsigned long");
       break;
     case 11:
-      rettype = init_type (objfile, TYPE_CODE_VOID, 1, "void");
+      rettype = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
       break;
     case 12:
       /* IEEE single precision (32 bit).  */
@@ -3835,7 +3835,8 @@ read_sun_builtin_type (const char **pp,
 
   if (type_bits == 0)
     {
-      struct type *type = init_type (objfile, TYPE_CODE_VOID, 1, NULL);
+      struct type *type = init_type (objfile, TYPE_CODE_VOID,
+				     TARGET_CHAR_BIT, NULL);
       if (unsigned_type)
         TYPE_UNSIGNED (type) = 1;
       return type;
@@ -4147,7 +4148,7 @@ read_range_type (const char **pp, int ty
 
   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
   if (self_subrange && n2 == 0 && n3 == 0)
-    return init_type (objfile, TYPE_CODE_VOID, 1, NULL);
+    return init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
 
   /* If n3 is zero and n2 is positive, we want a floating type, and n2
      is the width in bytes.
@@ -4193,7 +4194,8 @@ read_range_type (const char **pp, int ty
      itself with range 0-127.  */
   else if (self_subrange && n2 == 0 && n3 == 127)
     {
-      struct type *type = init_integer_type (objfile, 1, 0, NULL);
+      struct type *type = init_integer_type (objfile, TARGET_CHAR_BIT,
+					     0, NULL);
       TYPE_NOSIGN (type) = 1;
       return type;
     }
Index: binutils-gdb/gdb/ada-lang.c
===================================================================
--- binutils-gdb.orig/gdb/ada-lang.c
+++ binutils-gdb/gdb/ada-lang.c
@@ -13859,7 +13859,8 @@ ada_language_arch_info (struct gdbarch *
     = builtin->builtin_void;
 
   lai->primitive_type_vector [ada_primitive_type_system_address]
-    = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"));
+    = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
+				      "void"));
   TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
     = "system__address";
 
Index: binutils-gdb/gdb/d-lang.c
===================================================================
--- binutils-gdb.orig/gdb/d-lang.c
+++ binutils-gdb/gdb/d-lang.c
@@ -263,7 +263,7 @@ build_d_types (struct gdbarch *gdbarch)
 
   /* Basic types.  */
   builtin_d_type->builtin_void
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   builtin_d_type->builtin_bool
     = arch_boolean_type (gdbarch, 8, 1, "bool");
   builtin_d_type->builtin_byte
Index: binutils-gdb/gdb/f-lang.c
===================================================================
--- binutils-gdb.orig/gdb/f-lang.c
+++ binutils-gdb/gdb/f-lang.c
@@ -304,7 +304,7 @@ build_fortran_types (struct gdbarch *gdb
     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_f_type);
 
   builtin_f_type->builtin_void
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "VOID");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "VOID");
 
   builtin_f_type->builtin_character
     = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
Index: binutils-gdb/gdb/go-lang.c
===================================================================
--- binutils-gdb.orig/gdb/go-lang.c
+++ binutils-gdb/gdb/go-lang.c
@@ -621,7 +621,7 @@ build_go_types (struct gdbarch *gdbarch)
     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_go_type);
 
   builtin_go_type->builtin_void
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   builtin_go_type->builtin_char
     = arch_character_type (gdbarch, 8, 1, "char");
   builtin_go_type->builtin_bool
Index: binutils-gdb/gdb/opencl-lang.c
===================================================================
--- binutils-gdb.orig/gdb/opencl-lang.c
+++ binutils-gdb/gdb/opencl-lang.c
@@ -1171,7 +1171,7 @@ build_opencl_types (struct gdbarch *gdba
   types[opencl_primitive_type_uintptr_t]
     = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "uintptr_t");
   types[opencl_primitive_type_void]
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
 
   return types;
 }
Index: binutils-gdb/gdb/jit.c
===================================================================
--- binutils-gdb.orig/gdb/jit.c
+++ binutils-gdb/gdb/jit.c
@@ -698,7 +698,7 @@ finalize_symtab (struct gdb_symtab *stab
       struct symbol *block_name = allocate_symbol (objfile);
       struct type *block_type = arch_type (get_objfile_arch (objfile),
 					   TYPE_CODE_VOID,
-					   1,
+					   TARGET_CHAR_BIT,
 					   "void");
 
       BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
Index: binutils-gdb/gdb/gnu-v3-abi.c
===================================================================
--- binutils-gdb.orig/gdb/gnu-v3-abi.c
+++ binutils-gdb/gdb/gnu-v3-abi.c
@@ -1024,7 +1024,7 @@ build_std_type_info_type (struct gdbarch
 
   gdb_assert (field == (field_list + 2));
 
-  t = arch_type (arch, TYPE_CODE_STRUCT, offset, NULL);
+  t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
   TYPE_NFIELDS (t) = field - field_list;
   TYPE_FIELDS (t) = field_list;
   TYPE_TAG_NAME (t) = "gdb_gnu_v3_type_info";
Index: binutils-gdb/gdb/target-descriptions.c
===================================================================
--- binutils-gdb.orig/gdb/target-descriptions.c
+++ binutils-gdb/gdb/target-descriptions.c
@@ -1072,7 +1072,7 @@ tdesc_gdb_type (struct gdbarch *gdbarch,
 	int ix;
 
 	type = arch_flags_type (gdbarch, tdesc_type->name,
-				tdesc_type->u.u.size);
+				tdesc_type->u.u.size * TARGET_CHAR_BIT);
 	for (ix = 0;
 	     VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
 	     ix++)
@@ -1095,7 +1095,8 @@ tdesc_gdb_type (struct gdbarch *gdbarch,
 	int ix;
 
 	type = arch_type (gdbarch, TYPE_CODE_ENUM,
-			  tdesc_type->u.u.size, tdesc_type->name);
+			  tdesc_type->u.u.size * TARGET_CHAR_BIT,
+			  tdesc_type->name);
 	TYPE_UNSIGNED (type) = 1;
 	for (ix = 0;
 	     VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
Index: binutils-gdb/gdb/linux-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/linux-tdep.c
+++ binutils-gdb/gdb/linux-tdep.c
@@ -279,19 +279,20 @@ linux_get_siginfo_type_with_fields (stru
 
   /* __pid_t */
   pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			TYPE_LENGTH (int_type), "__pid_t");
+			TYPE_LENGTH (int_type) * TARGET_CHAR_BIT, "__pid_t");
   TYPE_TARGET_TYPE (pid_type) = int_type;
   TYPE_TARGET_STUB (pid_type) = 1;
 
   /* __uid_t */
   uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			TYPE_LENGTH (uint_type), "__uid_t");
+			TYPE_LENGTH (uint_type) * TARGET_CHAR_BIT, "__uid_t");
   TYPE_TARGET_TYPE (uid_type) = uint_type;
   TYPE_TARGET_STUB (uid_type) = 1;
 
   /* __clock_t */
   clock_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			  TYPE_LENGTH (long_type), "__clock_t");
+			  TYPE_LENGTH (long_type) * TARGET_CHAR_BIT,
+			  "__clock_t");
   TYPE_TARGET_TYPE (clock_type) = long_type;
   TYPE_TARGET_STUB (clock_type) = 1;
 
Index: binutils-gdb/gdb/fbsd-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/fbsd-tdep.c
+++ binutils-gdb/gdb/fbsd-tdep.c
@@ -432,13 +432,14 @@ fbsd_get_siginfo_type (struct gdbarch *g
 
   /* __pid_t */
   pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			TYPE_LENGTH (int32_type), "__pid_t");
+			TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t");
   TYPE_TARGET_TYPE (pid_type) = int32_type;
   TYPE_TARGET_STUB (pid_type) = 1;
 
   /* __uid_t */
   uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			TYPE_LENGTH (uint32_type), "__uid_t");
+			TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT,
+			"__uid_t");
   TYPE_TARGET_TYPE (uid_type) = uint32_type;
   TYPE_TARGET_STUB (uid_type) = 1;
 
Index: binutils-gdb/gdb/windows-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/windows-tdep.c
+++ binutils-gdb/gdb/windows-tdep.c
@@ -143,7 +143,8 @@ windows_get_tlb_type (struct gdbarch *gd
   TYPE_NAME (seh_type) = xstrdup ("seh");
 
   seh_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
-			    TYPE_LENGTH (void_ptr_type), NULL);
+			    TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
+			    NULL);
   TYPE_TARGET_TYPE (seh_ptr_type) = seh_type;
 
   append_composite_type_field (seh_type, "next_seh", seh_ptr_type);
@@ -163,7 +164,8 @@ windows_get_tlb_type (struct gdbarch *gd
   append_composite_type_field (peb_ldr_type, "entry_in_progress",
 			       void_ptr_type);
   peb_ldr_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
-			    TYPE_LENGTH (void_ptr_type), NULL);
+				TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
+				NULL);
   TYPE_TARGET_TYPE (peb_ldr_ptr_type) = peb_ldr_type;
 
 
@@ -181,7 +183,8 @@ windows_get_tlb_type (struct gdbarch *gd
   append_composite_type_field (peb_type, "process_heap", void_ptr_type);
   append_composite_type_field (peb_type, "fast_peb_lock", void_ptr_type);
   peb_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
-			    TYPE_LENGTH (void_ptr_type), NULL);
+			    TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
+			    NULL);
   TYPE_TARGET_TYPE (peb_ptr_type) = peb_type;
 
 
@@ -224,7 +227,8 @@ windows_get_tlb_type (struct gdbarch *gd
   append_composite_type_field (tib_type, "last_error_number", dword_ptr_type);
 
   tib_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
-			    TYPE_LENGTH (void_ptr_type), NULL);
+			    TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
+			    NULL);
   TYPE_TARGET_TYPE (tib_ptr_type) = tib_type;
 
   last_tlb_type = tib_ptr_type;
Index: binutils-gdb/gdb/avr-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/avr-tdep.c
+++ binutils-gdb/gdb/avr-tdep.c
@@ -1460,7 +1460,8 @@ avr_gdbarch_init (struct gdbarch_info in
 
   /* Create a type for PC.  We can't use builtin types here, as they may not
      be defined.  */
-  tdep->void_type = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+  tdep->void_type = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
+			       "void");
   tdep->func_void_type = make_function_type (tdep->void_type, NULL);
   tdep->pc_type = arch_pointer_type (gdbarch, 4 * TARGET_CHAR_BIT, NULL,
 				     tdep->func_void_type);
Index: binutils-gdb/gdb/ft32-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/ft32-tdep.c
+++ binutils-gdb/gdb/ft32-tdep.c
@@ -598,7 +598,7 @@ ft32_gdbarch_init (struct gdbarch_info i
 
   /* Create a type for PC.  We can't use builtin types here, as they may not
      be defined.  */
-  void_type = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+  void_type = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   func_void_type = make_function_type (void_type, NULL);
   tdep->pc_type = arch_pointer_type (gdbarch, 4 * TARGET_CHAR_BIT, NULL,
 				     func_void_type);
Index: binutils-gdb/gdb/m32c-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/m32c-tdep.c
+++ binutils-gdb/gdb/m32c-tdep.c
@@ -190,7 +190,7 @@ make_types (struct gdbarch *arch)
 
   /* The builtin_type_mumble variables are sometimes uninitialized when
      this is called, so we avoid using them.  */
-  tdep->voyd = arch_type (arch, TYPE_CODE_VOID, 1, "void");
+  tdep->voyd = arch_type (arch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   tdep->ptr_voyd
     = arch_pointer_type (arch, gdbarch_ptr_bit (arch), NULL, tdep->voyd);
   tdep->func_voyd = lookup_function_type (tdep->voyd);
Index: binutils-gdb/gdb/rl78-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/rl78-tdep.c
+++ binutils-gdb/gdb/rl78-tdep.c
@@ -271,7 +271,7 @@ rl78_psw_type (struct gdbarch *gdbarch)
   if (tdep->rl78_psw_type == NULL)
     {
       tdep->rl78_psw_type = arch_flags_type (gdbarch,
-					     "builtin_type_rl78_psw", 1);
+					     "builtin_type_rl78_psw", 8);
       append_flags_type_flag (tdep->rl78_psw_type, 0, "CY");
       append_flags_type_flag (tdep->rl78_psw_type, 1, "ISP0");
       append_flags_type_flag (tdep->rl78_psw_type, 2, "ISP1");
@@ -1417,7 +1417,8 @@ rl78_gdbarch_init (struct gdbarch_info i
   tdep->elf_flags = elf_flags;
 
   /* Initialize types.  */
-  tdep->rl78_void = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+  tdep->rl78_void = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
+			       "void");
   tdep->rl78_uint8 = arch_integer_type (gdbarch, 8, 1, "uint8_t");
   tdep->rl78_int8 = arch_integer_type (gdbarch, 8, 0, "int8_t");
   tdep->rl78_uint16 = arch_integer_type (gdbarch, 16, 1, "uint16_t");
Index: binutils-gdb/gdb/m68k-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/m68k-tdep.c
+++ binutils-gdb/gdb/m68k-tdep.c
@@ -73,7 +73,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_m68k_ps", 4);
+      type = arch_flags_type (gdbarch, "builtin_type_m68k_ps", 32);
       append_flags_type_flag (type, 0, "C");
       append_flags_type_flag (type, 1, "V");
       append_flags_type_flag (type, 2, "Z");
Index: binutils-gdb/gdb/rx-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/rx-tdep.c
+++ binutils-gdb/gdb/rx-tdep.c
@@ -159,7 +159,7 @@ rx_psw_type (struct gdbarch *gdbarch)
 
   if (tdep->rx_psw_type == NULL)
     {
-      tdep->rx_psw_type = arch_flags_type (gdbarch, "rx_psw_type", 4);
+      tdep->rx_psw_type = arch_flags_type (gdbarch, "rx_psw_type", 32);
       append_flags_type_flag (tdep->rx_psw_type, 0, "C");
       append_flags_type_flag (tdep->rx_psw_type, 1, "Z");
       append_flags_type_flag (tdep->rx_psw_type, 2, "S");
@@ -184,7 +184,7 @@ rx_fpsw_type (struct gdbarch *gdbarch)
 
   if (tdep->rx_fpsw_type == NULL)
     {
-      tdep->rx_fpsw_type = arch_flags_type (gdbarch, "rx_fpsw_type", 4);
+      tdep->rx_fpsw_type = arch_flags_type (gdbarch, "rx_fpsw_type", 32);
       append_flags_type_flag (tdep->rx_fpsw_type, 0, "RM0");
       append_flags_type_flag (tdep->rx_fpsw_type, 1, "RM1");
       append_flags_type_flag (tdep->rx_fpsw_type, 2, "CV");
Index: binutils-gdb/gdb/sparc-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/sparc-tdep.c
+++ binutils-gdb/gdb/sparc-tdep.c
@@ -409,7 +409,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc_psr", 4);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc_psr", 32);
       append_flags_type_flag (type, 5, "ET");
       append_flags_type_flag (type, 6, "PS");
       append_flags_type_flag (type, 7, "S");
@@ -431,7 +431,7 @@ sparc_fsr_type (struct gdbarch *gdbarch)
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc_fsr", 4);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc_fsr", 32);
       append_flags_type_flag (type, 0, "NXA");
       append_flags_type_flag (type, 1, "DZA");
       append_flags_type_flag (type, 2, "UFA");
Index: binutils-gdb/gdb/sparc64-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/sparc64-tdep.c
+++ binutils-gdb/gdb/sparc64-tdep.c
@@ -665,7 +665,7 @@ sparc64_pstate_type (struct gdbarch *gdb
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 8);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 64);
       append_flags_type_flag (type, 0, "AG");
       append_flags_type_flag (type, 1, "IE");
       append_flags_type_flag (type, 2, "PRIV");
@@ -692,7 +692,7 @@ sparc64_ccr_type (struct gdbarch *gdbarc
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc64_ccr", 8);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc64_ccr", 64);
       append_flags_type_flag (type, 0, "icc.c");
       append_flags_type_flag (type, 1, "icc.v");
       append_flags_type_flag (type, 2, "icc.z");
@@ -717,7 +717,7 @@ sparc64_fsr_type (struct gdbarch *gdbarc
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 8);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 64);
       append_flags_type_flag (type, 0, "NXC");
       append_flags_type_flag (type, 1, "DZC");
       append_flags_type_flag (type, 2, "UFC");
@@ -750,7 +750,7 @@ sparc64_fprs_type (struct gdbarch *gdbar
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 8);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 64);
       append_flags_type_flag (type, 0, "DL");
       append_flags_type_flag (type, 1, "DU");
       append_flags_type_flag (type, 2, "FEF");

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* Re: [RFC] Make init_type/arch_type take a size in bits
  2017-09-20 13:51         ` [RFC] Make init_type/arch_type take a size in bits Ulrich Weigand
@ 2017-09-20 14:40           ` Simon Marchi
  2017-09-20 16:28             ` Ulrich Weigand
  0 siblings, 1 reply; 11+ messages in thread
From: Simon Marchi @ 2017-09-20 14:40 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: gdb-patches

On 2017-09-20 15:51, Ulrich Weigand wrote:
> Simon Marchi wrote:
> 
>> Since this is where we do the division by
>> TARGET_CHAR_BIT, and therefore assume (implicitly) that bit is a
>> multiple of TARGET_CHAR_BIT, I think this is where the assert should 
>> be
>> added.  To avoid adding them everywhere, we could make
>> arch_type/init_type take a size in bits, and do the division and 
>> assert
>> there.
> 
> As discussed, this changes the interfaces to init_type and arch_type
> to take the type length in bits as input (instead of as bytes).  The
> routine asserts that the length is a multiple of TARGET_CHAR_BIT.
> 
> For consistency, arch_flags_type is changed likewise, so that now
> all type creation interfaces always use length in bits.
> 
> All callers are updated in the straightforward manner.
> 
> The assert actually found a bug in stabsread.c:read_range_type, where
> the init_integer_type routine was called with a wrong argument 
> (probably
> a bug introduced with the conversion to use init_integer_type).

I took a quick look, it looks good to me.  Just one comment below.

> Index: binutils-gdb/gdb/gnu-v3-abi.c
> ===================================================================
> --- binutils-gdb.orig/gdb/gnu-v3-abi.c
> +++ binutils-gdb/gdb/gnu-v3-abi.c
> @@ -1024,7 +1024,7 @@ build_std_type_info_type (struct gdbarch
> 
>    gdb_assert (field == (field_list + 2));
> 
> -  t = arch_type (arch, TYPE_CODE_STRUCT, offset, NULL);
> +  t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, 
> NULL);
>    TYPE_NFIELDS (t) = field - field_list;
>    TYPE_FIELDS (t) = field_list;
>    TYPE_TAG_NAME (t) = "gdb_gnu_v3_type_info";

In gnu-v3-abi.c, there seems to be another call to arch_type that needs 
adjusting in build_gdb_vtable_type:

   t = arch_type (arch, TYPE_CODE_STRUCT, offset, NULL);

Simon

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

* Re: [RFC] Make init_type/arch_type take a size in bits
  2017-09-20 14:40           ` Simon Marchi
@ 2017-09-20 16:28             ` Ulrich Weigand
  2017-09-27 17:08               ` Ulrich Weigand
  0 siblings, 1 reply; 11+ messages in thread
From: Ulrich Weigand @ 2017-09-20 16:28 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

Simon Marchi wrote:
> On 2017-09-20 15:51, Ulrich Weigand wrote:
> > As discussed, this changes the interfaces to init_type and arch_type
> > to take the type length in bits as input (instead of as bytes).  The
> > routine asserts that the length is a multiple of TARGET_CHAR_BIT.
[...]
> 
> I took a quick look, it looks good to me.  Just one comment below.
 
> In gnu-v3-abi.c, there seems to be another call to arch_type that needs 
> adjusting in build_gdb_vtable_type:
> 
>    t = arch_type (arch, TYPE_CODE_STRUCT, offset, NULL);

Good catch, thanks!

Updated patch below.

Bye,
Ulrich

ChangeLog:

	* gdbtypes.c (init_type): Change incoming argument from
	lenght-in-bytes to lenght-in-bits.  Assert length is a
	multiple of TARGET_CHAR_BITS.
	(arch_type, arch_flags_type): Likewise.
	(init_integer_type): Update call to init_type.
	(init_character_type): Likewise.
	(init_boolean_type): Likewise.
	(init_float_type): Likewise.
	(init_decfloat_type): Likewise.
	(init_complex_type): Likewise.
	(init_pointer_type): Likewise.
	(objfile_type): Likewise.
	(arch_integer_type): Update call to arch_type.
	(arch_character_type): Likewise.
	(arch_boolean_type): Likewise.
	(arch_float_type): Likewise.
	(arch_decfloat_type): Likewise.
	(arch_complex_type): Likewise.
	(arch_pointer_type): Likewise.
	(gdbtypes_post_init): Likewise.

	* dwarf2read.c (dwarf2_init_float_type): Update call to init_type.
	(read_base_type): Likewise.
	* mdebugread.c (basic_type): Likewise.
	* stabsread.c (dbx_init_float_type): Likewise.
	(rs6000_builtin_type): Likewise.
	(read_range_type): Likewise.  Also, fix call to init_integer_type
	with erroneous length argument.

	* ada-lang.c (ada_language_arch_info): Update call to arch_type.
	* d-lang.c (build_d_types): Likewise.
	* f-lang.c (build_fortran_types): Likewise.
	* go-lang.c (build_go_types): Likewise.
	* opencl-lang.c (build_opencl_types): Likewise.
	* jit.c (finalize_symtab): Likewise.
	* gnu-v3-abi.c (build_gdb_vtable_type): Likewise.
	(build_std_type_info_type): Likewise.
	* target-descriptions.c (tdesc_gdb_type): Likewise.  Also,
	update call to arch_flags_type.

	* linux-tdep.c (linux_get_siginfo_type_with_fields): Update call to
	arch_type.
	* fbsd-tdep.c (fbsd_get_siginfo_type): Likewise.
	* windows-tdep.c (windows_get_tlb_type): Likewise.

	* avr-tdep.c (avr_gdbarch_init): Update call to arch_type.
	* ft32-tdep.c (ft32_gdbarch_init): Likewise.
	* m32c-tdep.c (make_types): Likewise.
	* rl78-tdep.c (rl78_gdbarch_init): Likewise.
	(rl78_psw_type): Update call to arch_flags_type.
	* m68k-tdep.c (m68k_ps_type): Update call to arch_flags_type.
	* rx-tdep.c (rx_psw_type): Likewise.
	(rx_fpsw_type): Likewise.
	* sparc-tdep.c (sparc_psr_type): Likewise.
	(sparc_fsr_type): Likewise.
	* sparc64-tdep.c (sparc64_pstate_type): Likewise.
	(sparc64_ccr_type): Likewise.
	(sparc64_fsr_type): Likewise.
	(sparc64_fprs_type): Likewise.

Index: binutils-gdb/gdb/gdbtypes.h
===================================================================
--- binutils-gdb.orig/gdb/gdbtypes.h
+++ binutils-gdb/gdb/gdbtypes.h
@@ -1683,7 +1683,7 @@ struct field *append_composite_type_fiel
    type is created using arch_flag_type().  Flags are then added using
    append_flag_type_field() and append_flag_type_flag().  */
 extern struct type *arch_flags_type (struct gdbarch *gdbarch,
-				     const char *name, int length);
+				     const char *name, int bit);
 extern void append_flags_type_field (struct type *type,
 				     int start_bitpos, int nr_bits,
 				     struct type *field_type, const char *name);
Index: binutils-gdb/gdb/gdbtypes.c
===================================================================
--- binutils-gdb.orig/gdb/gdbtypes.c
+++ binutils-gdb/gdb/gdbtypes.c
@@ -2758,14 +2758,15 @@ verify_floatformat (int bit, const struc
    least as long as OBJFILE.  */
 
 struct type *
-init_type (struct objfile *objfile, enum type_code code, int length,
+init_type (struct objfile *objfile, enum type_code code, int bit,
 	   const char *name)
 {
   struct type *type;
 
   type = alloc_type (objfile);
   set_type_code (type, code);
-  TYPE_LENGTH (type) = length;
+  gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
+  TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
   TYPE_NAME (type) = name;
 
   return type;
@@ -2791,7 +2792,7 @@ init_integer_type (struct objfile *objfi
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_INT, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -2808,7 +2809,7 @@ init_character_type (struct objfile *obj
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_CHAR, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -2825,7 +2826,7 @@ init_boolean_type (struct objfile *objfi
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_BOOL, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -2845,7 +2846,7 @@ init_float_type (struct objfile *objfile
   struct type *t;
 
   bit = verify_floatformat (bit, floatformats);
-  t = init_type (objfile, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_FLT, bit, name);
   TYPE_FLOATFORMAT (t) = floatformats;
 
   return t;
@@ -2859,7 +2860,7 @@ init_decfloat_type (struct objfile *objf
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_DECFLOAT, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_DECFLOAT, bit, name);
   return t;
 }
 
@@ -2873,7 +2874,7 @@ init_complex_type (struct objfile *objfi
   struct type *t;
 
   t = init_type (objfile, TYPE_CODE_COMPLEX,
-		 2 * TYPE_LENGTH (target_type), name);
+		 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
   TYPE_TARGET_TYPE (t) = target_type;
   return t;
 }
@@ -2889,7 +2890,7 @@ init_pointer_type (struct objfile *objfi
 {
   struct type *t;
 
-  t = init_type (objfile, TYPE_CODE_PTR, bit / TARGET_CHAR_BIT, name);
+  t = init_type (objfile, TYPE_CODE_PTR, bit, name);
   TYPE_TARGET_TYPE (t) = target_type;
   TYPE_UNSIGNED (t) = 1;
   return t;
@@ -4832,13 +4833,14 @@ copy_type (const struct type *type)
 
 struct type *
 arch_type (struct gdbarch *gdbarch,
-	   enum type_code code, int length, const char *name)
+	   enum type_code code, int bit, const char *name)
 {
   struct type *type;
 
   type = alloc_type_arch (gdbarch);
   set_type_code (type, code);
-  TYPE_LENGTH (type) = length;
+  gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
+  TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
 
   if (name)
     TYPE_NAME (type) = gdbarch_obstack_strdup (gdbarch, name);
@@ -4856,7 +4858,7 @@ arch_integer_type (struct gdbarch *gdbar
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_INT, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -4873,7 +4875,7 @@ arch_character_type (struct gdbarch *gdb
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_CHAR, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -4890,7 +4892,7 @@ arch_boolean_type (struct gdbarch *gdbar
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_BOOL, bit, name);
   if (unsigned_p)
     TYPE_UNSIGNED (t) = 1;
 
@@ -4910,7 +4912,7 @@ arch_float_type (struct gdbarch *gdbarch
   struct type *t;
 
   bit = verify_floatformat (bit, floatformats);
-  t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_FLT, bit, name);
   TYPE_FLOATFORMAT (t) = floatformats;
 
   return t;
@@ -4924,7 +4926,7 @@ arch_decfloat_type (struct gdbarch *gdba
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_DECFLOAT, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_DECFLOAT, bit, name);
   return t;
 }
 
@@ -4938,7 +4940,7 @@ arch_complex_type (struct gdbarch *gdbar
   struct type *t;
 
   t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
-		 2 * TYPE_LENGTH (target_type), name);
+		 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
   TYPE_TARGET_TYPE (t) = target_type;
   return t;
 }
@@ -4954,27 +4956,26 @@ arch_pointer_type (struct gdbarch *gdbar
 {
   struct type *t;
 
-  t = arch_type (gdbarch, TYPE_CODE_PTR, bit / TARGET_CHAR_BIT, name);
+  t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name);
   TYPE_TARGET_TYPE (t) = target_type;
   TYPE_UNSIGNED (t) = 1;
   return t;
 }
 
 /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
-   NAME is the type name.  LENGTH is the size of the flag word in bytes.  */
+   NAME is the type name.  BIT is the size of the flag word in bits.  */
 
 struct type *
-arch_flags_type (struct gdbarch *gdbarch, const char *name, int length)
+arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit)
 {
-  int max_nfields = length * TARGET_CHAR_BIT;
   struct type *type;
 
-  type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name);
+  type = arch_type (gdbarch, TYPE_CODE_FLAGS, bit, name);
   TYPE_UNSIGNED (type) = 1;
   TYPE_NFIELDS (type) = 0;
   /* Pre-allocate enough space assuming every field is one bit.  */
   TYPE_FIELDS (type)
-    = (struct field *) TYPE_ZALLOC (type, max_nfields * sizeof (struct field));
+    = (struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field));
 
   return type;
 }
@@ -5119,7 +5120,7 @@ gdbtypes_post_init (struct gdbarch *gdba
 
   /* Basic types.  */
   builtin_type->builtin_void
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   builtin_type->builtin_char
     = arch_integer_type (gdbarch, TARGET_CHAR_BIT,
 			 !gdbarch_char_signed (gdbarch), "char");
@@ -5170,9 +5171,9 @@ gdbtypes_post_init (struct gdbarch *gdba
     = arch_complex_type (gdbarch, "double complex",
 			 builtin_type->builtin_double);
   builtin_type->builtin_string
-    = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string");
+    = arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
   builtin_type->builtin_bool
-    = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool");
+    = arch_type (gdbarch, TYPE_CODE_BOOL, TARGET_CHAR_BIT, "bool");
 
   /* The following three are about decimal floating point types, which
      are 32-bits, 64-bits and 128-bits respectively.  */
@@ -5269,7 +5270,7 @@ objfile_type (struct objfile *objfile)
 
   /* Basic types.  */
   objfile_type->builtin_void
-    = init_type (objfile, TYPE_CODE_VOID, 1, "void");
+    = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   objfile_type->builtin_char
     = init_integer_type (objfile, TARGET_CHAR_BIT,
 			 !gdbarch_char_signed (gdbarch), "char");
@@ -5321,10 +5322,10 @@ objfile_type (struct objfile *objfile)
   /* The following set of types is used for symbols with no
      debug information.  */
   objfile_type->nodebug_text_symbol
-    = init_type (objfile, TYPE_CODE_FUNC, 1,
+    = init_type (objfile, TYPE_CODE_FUNC, TARGET_CHAR_BIT,
 		 "<text variable, no debug info>");
   objfile_type->nodebug_text_gnu_ifunc_symbol
-    = init_type (objfile, TYPE_CODE_FUNC, 1,
+    = init_type (objfile, TYPE_CODE_FUNC, TARGET_CHAR_BIT,
 		 "<text gnu-indirect-function variable, no debug info>");
   /* Ifunc resolvers return a function address.  */
   TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
Index: binutils-gdb/gdb/dwarf2read.c
===================================================================
--- binutils-gdb.orig/gdb/dwarf2read.c
+++ binutils-gdb/gdb/dwarf2read.c
@@ -15211,7 +15211,7 @@ dwarf2_init_float_type (struct objfile *
   if (format)
     type = init_float_type (objfile, bits, name, format);
   else
-    type = init_type (objfile, TYPE_CODE_ERROR, bits / TARGET_CHAR_BIT, name);
+    type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
 
   return type;
 }
@@ -15249,7 +15249,7 @@ read_base_type (struct die_info *die, st
     {
       case DW_ATE_address:
 	/* Turn DW_ATE_address into a void * pointer.  */
-	type = init_type (objfile, TYPE_CODE_VOID, 1, NULL);
+	type = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
 	type = init_pointer_type (objfile, bits, name, type);
 	break;
       case DW_ATE_boolean:
@@ -15315,8 +15315,7 @@ read_base_type (struct die_info *die, st
       default:
 	complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
 		   dwarf_type_encoding_name (encoding));
-	type = init_type (objfile, TYPE_CODE_ERROR,
-			  bits / TARGET_CHAR_BIT, name);
+	type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
 	break;
     }
 
Index: binutils-gdb/gdb/mdebugread.c
===================================================================
--- binutils-gdb.orig/gdb/mdebugread.c
+++ binutils-gdb/gdb/mdebugread.c
@@ -1469,14 +1469,13 @@ basic_type (int bt, struct objfile *objf
 
     case btFloatDec:
       tp = init_type (objfile, TYPE_CODE_ERROR,
-		      gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT,
-		      "floating decimal");
+		      gdbarch_double_bit (gdbarch), "floating decimal");
       break;
 
     case btString:
       /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
 	 FIXME.  */
-      tp = init_type (objfile, TYPE_CODE_STRING, 1, "string");
+      tp = init_type (objfile, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
       break;
 
     case btVoid:
Index: binutils-gdb/gdb/stabsread.c
===================================================================
--- binutils-gdb.orig/gdb/stabsread.c
+++ binutils-gdb/gdb/stabsread.c
@@ -368,7 +368,7 @@ dbx_init_float_type (struct objfile *obj
   if (format)
     type = init_float_type (objfile, bits, NULL, format);
   else
-    type = init_type (objfile, TYPE_CODE_ERROR, bits / TARGET_CHAR_BIT, NULL);
+    type = init_type (objfile, TYPE_CODE_ERROR, bits, NULL);
 
   return type;
 }
@@ -2153,7 +2153,7 @@ rs6000_builtin_type (int typenum, struct
       rettype = init_integer_type (objfile, 32, 1, "unsigned long");
       break;
     case 11:
-      rettype = init_type (objfile, TYPE_CODE_VOID, 1, "void");
+      rettype = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
       break;
     case 12:
       /* IEEE single precision (32 bit).  */
@@ -3835,7 +3835,8 @@ read_sun_builtin_type (const char **pp,
 
   if (type_bits == 0)
     {
-      struct type *type = init_type (objfile, TYPE_CODE_VOID, 1, NULL);
+      struct type *type = init_type (objfile, TYPE_CODE_VOID,
+				     TARGET_CHAR_BIT, NULL);
       if (unsigned_type)
         TYPE_UNSIGNED (type) = 1;
       return type;
@@ -4147,7 +4148,7 @@ read_range_type (const char **pp, int ty
 
   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
   if (self_subrange && n2 == 0 && n3 == 0)
-    return init_type (objfile, TYPE_CODE_VOID, 1, NULL);
+    return init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
 
   /* If n3 is zero and n2 is positive, we want a floating type, and n2
      is the width in bytes.
@@ -4193,7 +4194,8 @@ read_range_type (const char **pp, int ty
      itself with range 0-127.  */
   else if (self_subrange && n2 == 0 && n3 == 127)
     {
-      struct type *type = init_integer_type (objfile, 1, 0, NULL);
+      struct type *type = init_integer_type (objfile, TARGET_CHAR_BIT,
+					     0, NULL);
       TYPE_NOSIGN (type) = 1;
       return type;
     }
Index: binutils-gdb/gdb/ada-lang.c
===================================================================
--- binutils-gdb.orig/gdb/ada-lang.c
+++ binutils-gdb/gdb/ada-lang.c
@@ -13859,7 +13859,8 @@ ada_language_arch_info (struct gdbarch *
     = builtin->builtin_void;
 
   lai->primitive_type_vector [ada_primitive_type_system_address]
-    = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"));
+    = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
+				      "void"));
   TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
     = "system__address";
 
Index: binutils-gdb/gdb/d-lang.c
===================================================================
--- binutils-gdb.orig/gdb/d-lang.c
+++ binutils-gdb/gdb/d-lang.c
@@ -263,7 +263,7 @@ build_d_types (struct gdbarch *gdbarch)
 
   /* Basic types.  */
   builtin_d_type->builtin_void
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   builtin_d_type->builtin_bool
     = arch_boolean_type (gdbarch, 8, 1, "bool");
   builtin_d_type->builtin_byte
Index: binutils-gdb/gdb/f-lang.c
===================================================================
--- binutils-gdb.orig/gdb/f-lang.c
+++ binutils-gdb/gdb/f-lang.c
@@ -304,7 +304,7 @@ build_fortran_types (struct gdbarch *gdb
     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_f_type);
 
   builtin_f_type->builtin_void
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "VOID");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "VOID");
 
   builtin_f_type->builtin_character
     = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
Index: binutils-gdb/gdb/go-lang.c
===================================================================
--- binutils-gdb.orig/gdb/go-lang.c
+++ binutils-gdb/gdb/go-lang.c
@@ -621,7 +621,7 @@ build_go_types (struct gdbarch *gdbarch)
     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_go_type);
 
   builtin_go_type->builtin_void
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   builtin_go_type->builtin_char
     = arch_character_type (gdbarch, 8, 1, "char");
   builtin_go_type->builtin_bool
Index: binutils-gdb/gdb/opencl-lang.c
===================================================================
--- binutils-gdb.orig/gdb/opencl-lang.c
+++ binutils-gdb/gdb/opencl-lang.c
@@ -1171,7 +1171,7 @@ build_opencl_types (struct gdbarch *gdba
   types[opencl_primitive_type_uintptr_t]
     = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "uintptr_t");
   types[opencl_primitive_type_void]
-    = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+    = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
 
   return types;
 }
Index: binutils-gdb/gdb/jit.c
===================================================================
--- binutils-gdb.orig/gdb/jit.c
+++ binutils-gdb/gdb/jit.c
@@ -698,7 +698,7 @@ finalize_symtab (struct gdb_symtab *stab
       struct symbol *block_name = allocate_symbol (objfile);
       struct type *block_type = arch_type (get_objfile_arch (objfile),
 					   TYPE_CODE_VOID,
-					   1,
+					   TARGET_CHAR_BIT,
 					   "void");
 
       BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
Index: binutils-gdb/gdb/gnu-v3-abi.c
===================================================================
--- binutils-gdb.orig/gdb/gnu-v3-abi.c
+++ binutils-gdb/gdb/gnu-v3-abi.c
@@ -161,7 +161,7 @@ build_gdb_vtable_type (struct gdbarch *a
   /* We assumed in the allocation above that there were four fields.  */
   gdb_assert (field == (field_list + 4));
 
-  t = arch_type (arch, TYPE_CODE_STRUCT, offset, NULL);
+  t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
   TYPE_NFIELDS (t) = field - field_list;
   TYPE_FIELDS (t) = field_list;
   TYPE_TAG_NAME (t) = "gdb_gnu_v3_abi_vtable";
@@ -1024,7 +1024,7 @@ build_std_type_info_type (struct gdbarch
 
   gdb_assert (field == (field_list + 2));
 
-  t = arch_type (arch, TYPE_CODE_STRUCT, offset, NULL);
+  t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
   TYPE_NFIELDS (t) = field - field_list;
   TYPE_FIELDS (t) = field_list;
   TYPE_TAG_NAME (t) = "gdb_gnu_v3_type_info";
Index: binutils-gdb/gdb/target-descriptions.c
===================================================================
--- binutils-gdb.orig/gdb/target-descriptions.c
+++ binutils-gdb/gdb/target-descriptions.c
@@ -1072,7 +1072,7 @@ tdesc_gdb_type (struct gdbarch *gdbarch,
 	int ix;
 
 	type = arch_flags_type (gdbarch, tdesc_type->name,
-				tdesc_type->u.u.size);
+				tdesc_type->u.u.size * TARGET_CHAR_BIT);
 	for (ix = 0;
 	     VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
 	     ix++)
@@ -1095,7 +1095,8 @@ tdesc_gdb_type (struct gdbarch *gdbarch,
 	int ix;
 
 	type = arch_type (gdbarch, TYPE_CODE_ENUM,
-			  tdesc_type->u.u.size, tdesc_type->name);
+			  tdesc_type->u.u.size * TARGET_CHAR_BIT,
+			  tdesc_type->name);
 	TYPE_UNSIGNED (type) = 1;
 	for (ix = 0;
 	     VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
Index: binutils-gdb/gdb/linux-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/linux-tdep.c
+++ binutils-gdb/gdb/linux-tdep.c
@@ -279,19 +279,20 @@ linux_get_siginfo_type_with_fields (stru
 
   /* __pid_t */
   pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			TYPE_LENGTH (int_type), "__pid_t");
+			TYPE_LENGTH (int_type) * TARGET_CHAR_BIT, "__pid_t");
   TYPE_TARGET_TYPE (pid_type) = int_type;
   TYPE_TARGET_STUB (pid_type) = 1;
 
   /* __uid_t */
   uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			TYPE_LENGTH (uint_type), "__uid_t");
+			TYPE_LENGTH (uint_type) * TARGET_CHAR_BIT, "__uid_t");
   TYPE_TARGET_TYPE (uid_type) = uint_type;
   TYPE_TARGET_STUB (uid_type) = 1;
 
   /* __clock_t */
   clock_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			  TYPE_LENGTH (long_type), "__clock_t");
+			  TYPE_LENGTH (long_type) * TARGET_CHAR_BIT,
+			  "__clock_t");
   TYPE_TARGET_TYPE (clock_type) = long_type;
   TYPE_TARGET_STUB (clock_type) = 1;
 
Index: binutils-gdb/gdb/fbsd-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/fbsd-tdep.c
+++ binutils-gdb/gdb/fbsd-tdep.c
@@ -432,13 +432,14 @@ fbsd_get_siginfo_type (struct gdbarch *g
 
   /* __pid_t */
   pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			TYPE_LENGTH (int32_type), "__pid_t");
+			TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t");
   TYPE_TARGET_TYPE (pid_type) = int32_type;
   TYPE_TARGET_STUB (pid_type) = 1;
 
   /* __uid_t */
   uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
-			TYPE_LENGTH (uint32_type), "__uid_t");
+			TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT,
+			"__uid_t");
   TYPE_TARGET_TYPE (uid_type) = uint32_type;
   TYPE_TARGET_STUB (uid_type) = 1;
 
Index: binutils-gdb/gdb/windows-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/windows-tdep.c
+++ binutils-gdb/gdb/windows-tdep.c
@@ -143,7 +143,8 @@ windows_get_tlb_type (struct gdbarch *gd
   TYPE_NAME (seh_type) = xstrdup ("seh");
 
   seh_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
-			    TYPE_LENGTH (void_ptr_type), NULL);
+			    TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
+			    NULL);
   TYPE_TARGET_TYPE (seh_ptr_type) = seh_type;
 
   append_composite_type_field (seh_type, "next_seh", seh_ptr_type);
@@ -163,7 +164,8 @@ windows_get_tlb_type (struct gdbarch *gd
   append_composite_type_field (peb_ldr_type, "entry_in_progress",
 			       void_ptr_type);
   peb_ldr_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
-			    TYPE_LENGTH (void_ptr_type), NULL);
+				TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
+				NULL);
   TYPE_TARGET_TYPE (peb_ldr_ptr_type) = peb_ldr_type;
 
 
@@ -181,7 +183,8 @@ windows_get_tlb_type (struct gdbarch *gd
   append_composite_type_field (peb_type, "process_heap", void_ptr_type);
   append_composite_type_field (peb_type, "fast_peb_lock", void_ptr_type);
   peb_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
-			    TYPE_LENGTH (void_ptr_type), NULL);
+			    TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
+			    NULL);
   TYPE_TARGET_TYPE (peb_ptr_type) = peb_type;
 
 
@@ -224,7 +227,8 @@ windows_get_tlb_type (struct gdbarch *gd
   append_composite_type_field (tib_type, "last_error_number", dword_ptr_type);
 
   tib_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
-			    TYPE_LENGTH (void_ptr_type), NULL);
+			    TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
+			    NULL);
   TYPE_TARGET_TYPE (tib_ptr_type) = tib_type;
 
   last_tlb_type = tib_ptr_type;
Index: binutils-gdb/gdb/avr-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/avr-tdep.c
+++ binutils-gdb/gdb/avr-tdep.c
@@ -1460,7 +1460,8 @@ avr_gdbarch_init (struct gdbarch_info in
 
   /* Create a type for PC.  We can't use builtin types here, as they may not
      be defined.  */
-  tdep->void_type = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+  tdep->void_type = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
+			       "void");
   tdep->func_void_type = make_function_type (tdep->void_type, NULL);
   tdep->pc_type = arch_pointer_type (gdbarch, 4 * TARGET_CHAR_BIT, NULL,
 				     tdep->func_void_type);
Index: binutils-gdb/gdb/ft32-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/ft32-tdep.c
+++ binutils-gdb/gdb/ft32-tdep.c
@@ -598,7 +598,7 @@ ft32_gdbarch_init (struct gdbarch_info i
 
   /* Create a type for PC.  We can't use builtin types here, as they may not
      be defined.  */
-  void_type = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+  void_type = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   func_void_type = make_function_type (void_type, NULL);
   tdep->pc_type = arch_pointer_type (gdbarch, 4 * TARGET_CHAR_BIT, NULL,
 				     func_void_type);
Index: binutils-gdb/gdb/m32c-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/m32c-tdep.c
+++ binutils-gdb/gdb/m32c-tdep.c
@@ -190,7 +190,7 @@ make_types (struct gdbarch *arch)
 
   /* The builtin_type_mumble variables are sometimes uninitialized when
      this is called, so we avoid using them.  */
-  tdep->voyd = arch_type (arch, TYPE_CODE_VOID, 1, "void");
+  tdep->voyd = arch_type (arch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
   tdep->ptr_voyd
     = arch_pointer_type (arch, gdbarch_ptr_bit (arch), NULL, tdep->voyd);
   tdep->func_voyd = lookup_function_type (tdep->voyd);
Index: binutils-gdb/gdb/rl78-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/rl78-tdep.c
+++ binutils-gdb/gdb/rl78-tdep.c
@@ -271,7 +271,7 @@ rl78_psw_type (struct gdbarch *gdbarch)
   if (tdep->rl78_psw_type == NULL)
     {
       tdep->rl78_psw_type = arch_flags_type (gdbarch,
-					     "builtin_type_rl78_psw", 1);
+					     "builtin_type_rl78_psw", 8);
       append_flags_type_flag (tdep->rl78_psw_type, 0, "CY");
       append_flags_type_flag (tdep->rl78_psw_type, 1, "ISP0");
       append_flags_type_flag (tdep->rl78_psw_type, 2, "ISP1");
@@ -1417,7 +1417,8 @@ rl78_gdbarch_init (struct gdbarch_info i
   tdep->elf_flags = elf_flags;
 
   /* Initialize types.  */
-  tdep->rl78_void = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+  tdep->rl78_void = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT,
+			       "void");
   tdep->rl78_uint8 = arch_integer_type (gdbarch, 8, 1, "uint8_t");
   tdep->rl78_int8 = arch_integer_type (gdbarch, 8, 0, "int8_t");
   tdep->rl78_uint16 = arch_integer_type (gdbarch, 16, 1, "uint16_t");
Index: binutils-gdb/gdb/m68k-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/m68k-tdep.c
+++ binutils-gdb/gdb/m68k-tdep.c
@@ -73,7 +73,7 @@ m68k_ps_type (struct gdbarch *gdbarch)
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_m68k_ps", 4);
+      type = arch_flags_type (gdbarch, "builtin_type_m68k_ps", 32);
       append_flags_type_flag (type, 0, "C");
       append_flags_type_flag (type, 1, "V");
       append_flags_type_flag (type, 2, "Z");
Index: binutils-gdb/gdb/rx-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/rx-tdep.c
+++ binutils-gdb/gdb/rx-tdep.c
@@ -159,7 +159,7 @@ rx_psw_type (struct gdbarch *gdbarch)
 
   if (tdep->rx_psw_type == NULL)
     {
-      tdep->rx_psw_type = arch_flags_type (gdbarch, "rx_psw_type", 4);
+      tdep->rx_psw_type = arch_flags_type (gdbarch, "rx_psw_type", 32);
       append_flags_type_flag (tdep->rx_psw_type, 0, "C");
       append_flags_type_flag (tdep->rx_psw_type, 1, "Z");
       append_flags_type_flag (tdep->rx_psw_type, 2, "S");
@@ -184,7 +184,7 @@ rx_fpsw_type (struct gdbarch *gdbarch)
 
   if (tdep->rx_fpsw_type == NULL)
     {
-      tdep->rx_fpsw_type = arch_flags_type (gdbarch, "rx_fpsw_type", 4);
+      tdep->rx_fpsw_type = arch_flags_type (gdbarch, "rx_fpsw_type", 32);
       append_flags_type_flag (tdep->rx_fpsw_type, 0, "RM0");
       append_flags_type_flag (tdep->rx_fpsw_type, 1, "RM1");
       append_flags_type_flag (tdep->rx_fpsw_type, 2, "CV");
Index: binutils-gdb/gdb/sparc-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/sparc-tdep.c
+++ binutils-gdb/gdb/sparc-tdep.c
@@ -409,7 +409,7 @@ sparc_psr_type (struct gdbarch *gdbarch)
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc_psr", 4);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc_psr", 32);
       append_flags_type_flag (type, 5, "ET");
       append_flags_type_flag (type, 6, "PS");
       append_flags_type_flag (type, 7, "S");
@@ -431,7 +431,7 @@ sparc_fsr_type (struct gdbarch *gdbarch)
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc_fsr", 4);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc_fsr", 32);
       append_flags_type_flag (type, 0, "NXA");
       append_flags_type_flag (type, 1, "DZA");
       append_flags_type_flag (type, 2, "UFA");
Index: binutils-gdb/gdb/sparc64-tdep.c
===================================================================
--- binutils-gdb.orig/gdb/sparc64-tdep.c
+++ binutils-gdb/gdb/sparc64-tdep.c
@@ -665,7 +665,7 @@ sparc64_pstate_type (struct gdbarch *gdb
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 8);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 64);
       append_flags_type_flag (type, 0, "AG");
       append_flags_type_flag (type, 1, "IE");
       append_flags_type_flag (type, 2, "PRIV");
@@ -692,7 +692,7 @@ sparc64_ccr_type (struct gdbarch *gdbarc
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc64_ccr", 8);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc64_ccr", 64);
       append_flags_type_flag (type, 0, "icc.c");
       append_flags_type_flag (type, 1, "icc.v");
       append_flags_type_flag (type, 2, "icc.z");
@@ -717,7 +717,7 @@ sparc64_fsr_type (struct gdbarch *gdbarc
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 8);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 64);
       append_flags_type_flag (type, 0, "NXC");
       append_flags_type_flag (type, 1, "DZC");
       append_flags_type_flag (type, 2, "UFC");
@@ -750,7 +750,7 @@ sparc64_fprs_type (struct gdbarch *gdbar
     {
       struct type *type;
 
-      type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 8);
+      type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 64);
       append_flags_type_flag (type, 0, "DL");
       append_flags_type_flag (type, 1, "DU");
       append_flags_type_flag (type, 2, "FEF");

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* Re: [RFC][02/19] Target FP: Simplify floatformat_from_type
  2017-09-18 19:01       ` Ulrich Weigand
  2017-09-20 13:51         ` [RFC] Make init_type/arch_type take a size in bits Ulrich Weigand
@ 2017-09-20 16:30         ` Ulrich Weigand
  2017-09-27 17:08           ` Ulrich Weigand
  1 sibling, 1 reply; 11+ messages in thread
From: Ulrich Weigand @ 2017-09-20 16:30 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Simon Marchi wrote:

> Since this is where we do the division by 
> TARGET_CHAR_BIT, and therefore assume (implicitly) that bit is a 
> multiple of TARGET_CHAR_BIT, I think this is where the assert should be 
> added.  To avoid adding them everywhere, we could make 
> arch_type/init_type take a size in bits, and do the division and assert 
> there.

And here's the updated floatformat_from_type patch, assuming the
above change is in.

Bye,
Ulrich

ChangeLog:

	* doublest.h (floatformat_from_type): Move to gdbtypes.h.
	* doublest.c (floatformat_from_type): Move to gdbtypes.c.

	* gdbtypes.h (union type_specific): Make field floatformat hold
	just a single struct floatformat, not an array.
	(floatformat_from_type): Move here.
	* gdbtypes.c (floatformat_from_type): Move here.  Update to
	changed TYPE_FLOATFORMAT definition.
	(verify_floatformat): Update to changed TYPE_FLOATFORMAT.
	(recursive_dump_type): Likewise.
	(init_float_type): Install correct floatformat for byte order.
	(arch_float_type): Likewise.


Index: binutils-gdb/gdb/doublest.c
===================================================================
--- binutils-gdb.orig/gdb/doublest.c
+++ binutils-gdb/gdb/doublest.c
@@ -770,22 +770,6 @@ floatformat_from_doublest (const struct
 }
 
 \f
-/* Return the floating-point format for a floating-point variable of
-   type TYPE.  */
-
-const struct floatformat *
-floatformat_from_type (const struct type *type)
-{
-  struct gdbarch *gdbarch = get_type_arch (type);
-  const struct floatformat *fmt;
-
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
-  gdb_assert (TYPE_FLOATFORMAT (type));
-  fmt = TYPE_FLOATFORMAT (type)[gdbarch_byte_order (gdbarch)];
-  gdb_assert (TYPE_LENGTH (type) >= floatformat_totalsize_bytes (fmt));
-  return fmt;
-}
-
 /* Extract a floating-point number of type TYPE from a target-order
    byte-stream at ADDR.  Returns the value as type DOUBLEST.  */
 
Index: binutils-gdb/gdb/doublest.h
===================================================================
--- binutils-gdb.orig/gdb/doublest.h
+++ binutils-gdb/gdb/doublest.h
@@ -71,12 +71,6 @@ extern enum float_kind floatformat_class
 extern const char *floatformat_mantissa (const struct floatformat *,
 					 const bfd_byte *);
 
-/* Given TYPE, return its floatformat.  TYPE_FLOATFORMAT() may return
-   NULL.  type_floatformat() detects that and returns a floatformat
-   based on the type size when FLOATFORMAT is NULL.  */
-
-const struct floatformat *floatformat_from_type (const struct type *type);
-
 /* Return the floatformat's total size in host bytes.  */
 
 extern size_t floatformat_totalsize_bytes (const struct floatformat *fmt);
Index: binutils-gdb/gdb/gdbtypes.c
===================================================================
--- binutils-gdb.orig/gdb/gdbtypes.c
+++ binutils-gdb/gdb/gdbtypes.c
@@ -2735,22 +2735,30 @@ set_type_code (struct type *type, enum t
    determined by the floatformat.  Returns size to be used.  */
 
 static int
-verify_floatformat (int bit, const struct floatformat **floatformats)
+verify_floatformat (int bit, const struct floatformat *floatformat)
 {
-  gdb_assert (floatformats != NULL);
-  gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
+  gdb_assert (floatformat != NULL);
 
   if (bit == -1)
-    bit = floatformats[0]->totalsize;
-  gdb_assert (bit >= 0);
+    bit = floatformat->totalsize;
 
-  size_t len = bit / TARGET_CHAR_BIT;
-  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0]));
-  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1]));
+  gdb_assert (bit >= 0);
+  gdb_assert (bit >= floatformat->totalsize);
 
   return bit;
 }
 
+/* Return the floating-point format for a floating-point variable of
+   type TYPE.  */
+
+const struct floatformat *
+floatformat_from_type (const struct type *type)
+{
+  gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
+  gdb_assert (TYPE_FLOATFORMAT (type));
+  return TYPE_FLOATFORMAT (type);
+}
+
 /* Helper function to initialize the standard scalar types.
 
    If NAME is non-NULL, then it is used to initialize the type name.
@@ -2843,11 +2851,13 @@ init_float_type (struct objfile *objfile
 		 int bit, const char *name,
 		 const struct floatformat **floatformats)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
   struct type *t;
 
-  bit = verify_floatformat (bit, floatformats);
+  bit = verify_floatformat (bit, fmt);
   t = init_type (objfile, TYPE_CODE_FLT, bit, name);
-  TYPE_FLOATFORMAT (t) = floatformats;
+  TYPE_FLOATFORMAT (t) = fmt;
 
   return t;
 }
@@ -4545,26 +4555,11 @@ recursive_dump_type (struct type *type,
 
       case TYPE_SPECIFIC_FLOATFORMAT:
 	printfi_filtered (spaces, "floatformat ");
-	if (TYPE_FLOATFORMAT (type) == NULL)
+	if (TYPE_FLOATFORMAT (type) == NULL
+	    || TYPE_FLOATFORMAT (type)->name == NULL)
 	  puts_filtered ("(null)");
 	else
-	  {
-	    puts_filtered ("{ ");
-	    if (TYPE_FLOATFORMAT (type)[0] == NULL
-		|| TYPE_FLOATFORMAT (type)[0]->name == NULL)
-	      puts_filtered ("(null)");
-	    else
-	      puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
-
-	    puts_filtered (", ");
-	    if (TYPE_FLOATFORMAT (type)[1] == NULL
-		|| TYPE_FLOATFORMAT (type)[1]->name == NULL)
-	      puts_filtered ("(null)");
-	    else
-	      puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
-
-	    puts_filtered (" }");
-	  }
+	  puts_filtered (TYPE_FLOATFORMAT (type)->name);
 	puts_filtered ("\n");
 	break;
 
@@ -4909,11 +4904,12 @@ arch_float_type (struct gdbarch *gdbarch
 		 int bit, const char *name,
 		 const struct floatformat **floatformats)
 {
+  const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
   struct type *t;
 
-  bit = verify_floatformat (bit, floatformats);
+  bit = verify_floatformat (bit, fmt);
   t = arch_type (gdbarch, TYPE_CODE_FLT, bit, name);
-  TYPE_FLOATFORMAT (t) = floatformats;
+  TYPE_FLOATFORMAT (t) = fmt;
 
   return t;
 }
Index: binutils-gdb/gdb/gdbtypes.h
===================================================================
--- binutils-gdb.orig/gdb/gdbtypes.h
+++ binutils-gdb/gdb/gdbtypes.h
@@ -571,12 +571,11 @@ union type_specific
 
   struct gnat_aux_type *gnat_stuff;
 
-  /* * FLOATFORMAT is for TYPE_CODE_FLT.  It is a pointer to two
-     floatformat objects that describe the floating-point value
-     that resides within the type.  The first is for big endian
-     targets and the second is for little endian targets.  */
+  /* * FLOATFORMAT is for TYPE_CODE_FLT.  It is a pointer to a
+     floatformat object that describes the floating-point value
+     that resides within the type.  */
 
-  const struct floatformat **floatformat;
+  const struct floatformat *floatformat;
 
   /* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types.  */
 
@@ -1434,6 +1433,9 @@ extern void set_type_vptr_basetype (stru
 #define TYPE_ERROR_NAME(type) \
   (TYPE_NAME (type) ? TYPE_NAME (type) : _("<error type>"))
 
+/* Given TYPE, return its floatformat.  */
+const struct floatformat *floatformat_from_type (const struct type *type);
+
 struct builtin_type
 {
   /* Integral types.  */

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* Re: [RFC] Make init_type/arch_type take a size in bits
  2017-09-20 16:28             ` Ulrich Weigand
@ 2017-09-27 17:08               ` Ulrich Weigand
  0 siblings, 0 replies; 11+ messages in thread
From: Ulrich Weigand @ 2017-09-27 17:08 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: Simon Marchi, gdb-patches

> ChangeLog:
> 
> 	* gdbtypes.c (init_type): Change incoming argument from
> 	lenght-in-bytes to lenght-in-bits.  Assert length is a
> 	multiple of TARGET_CHAR_BITS.
> 	(arch_type, arch_flags_type): Likewise.
> 	(init_integer_type): Update call to init_type.
> 	(init_character_type): Likewise.
> 	(init_boolean_type): Likewise.
> 	(init_float_type): Likewise.
> 	(init_decfloat_type): Likewise.
> 	(init_complex_type): Likewise.
> 	(init_pointer_type): Likewise.
> 	(objfile_type): Likewise.
> 	(arch_integer_type): Update call to arch_type.
> 	(arch_character_type): Likewise.
> 	(arch_boolean_type): Likewise.
> 	(arch_float_type): Likewise.
> 	(arch_decfloat_type): Likewise.
> 	(arch_complex_type): Likewise.
> 	(arch_pointer_type): Likewise.
> 	(gdbtypes_post_init): Likewise.
> 
> 	* dwarf2read.c (dwarf2_init_float_type): Update call to init_type.
> 	(read_base_type): Likewise.
> 	* mdebugread.c (basic_type): Likewise.
> 	* stabsread.c (dbx_init_float_type): Likewise.
> 	(rs6000_builtin_type): Likewise.
> 	(read_range_type): Likewise.  Also, fix call to init_integer_type
> 	with erroneous length argument.
> 
> 	* ada-lang.c (ada_language_arch_info): Update call to arch_type.
> 	* d-lang.c (build_d_types): Likewise.
> 	* f-lang.c (build_fortran_types): Likewise.
> 	* go-lang.c (build_go_types): Likewise.
> 	* opencl-lang.c (build_opencl_types): Likewise.
> 	* jit.c (finalize_symtab): Likewise.
> 	* gnu-v3-abi.c (build_gdb_vtable_type): Likewise.
> 	(build_std_type_info_type): Likewise.
> 	* target-descriptions.c (tdesc_gdb_type): Likewise.  Also,
> 	update call to arch_flags_type.
> 
> 	* linux-tdep.c (linux_get_siginfo_type_with_fields): Update call to
> 	arch_type.
> 	* fbsd-tdep.c (fbsd_get_siginfo_type): Likewise.
> 	* windows-tdep.c (windows_get_tlb_type): Likewise.
> 
> 	* avr-tdep.c (avr_gdbarch_init): Update call to arch_type.
> 	* ft32-tdep.c (ft32_gdbarch_init): Likewise.
> 	* m32c-tdep.c (make_types): Likewise.
> 	* rl78-tdep.c (rl78_gdbarch_init): Likewise.
> 	(rl78_psw_type): Update call to arch_flags_type.
> 	* m68k-tdep.c (m68k_ps_type): Update call to arch_flags_type.
> 	* rx-tdep.c (rx_psw_type): Likewise.
> 	(rx_fpsw_type): Likewise.
> 	* sparc-tdep.c (sparc_psr_type): Likewise.
> 	(sparc_fsr_type): Likewise.
> 	* sparc64-tdep.c (sparc64_pstate_type): Likewise.
> 	(sparc64_ccr_type): Likewise.
> 	(sparc64_fsr_type): Likewise.
> 	(sparc64_fprs_type): Likewise.

I've pushed this now.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

* Re: [RFC][02/19] Target FP: Simplify floatformat_from_type
  2017-09-20 16:30         ` [RFC][02/19] Target FP: Simplify floatformat_from_type Ulrich Weigand
@ 2017-09-27 17:08           ` Ulrich Weigand
  0 siblings, 0 replies; 11+ messages in thread
From: Ulrich Weigand @ 2017-09-27 17:08 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: gdb-patches, Simon Marchi

> ChangeLog:
> 
> 	* doublest.h (floatformat_from_type): Move to gdbtypes.h.
> 	* doublest.c (floatformat_from_type): Move to gdbtypes.c.
> 
> 	* gdbtypes.h (union type_specific): Make field floatformat hold
> 	just a single struct floatformat, not an array.
> 	(floatformat_from_type): Move here.
> 	* gdbtypes.c (floatformat_from_type): Move here.  Update to
> 	changed TYPE_FLOATFORMAT definition.
> 	(verify_floatformat): Update to changed TYPE_FLOATFORMAT.
> 	(recursive_dump_type): Likewise.
> 	(init_float_type): Install correct floatformat for byte order.
> 	(arch_float_type): Likewise.

I've pushed this now.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

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

end of thread, other threads:[~2017-09-27 17:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05 18:20 [RFC][02/19] Target FP: Simplify floatformat_from_type Ulrich Weigand
2017-09-17 15:29 ` Simon Marchi
2017-09-18 11:49   ` Ulrich Weigand
2017-09-18 16:21     ` Simon Marchi
2017-09-18 19:01       ` Ulrich Weigand
2017-09-20 13:51         ` [RFC] Make init_type/arch_type take a size in bits Ulrich Weigand
2017-09-20 14:40           ` Simon Marchi
2017-09-20 16:28             ` Ulrich Weigand
2017-09-27 17:08               ` Ulrich Weigand
2017-09-20 16:30         ` [RFC][02/19] Target FP: Simplify floatformat_from_type Ulrich Weigand
2017-09-27 17:08           ` Ulrich Weigand

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).