Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Ulrich Weigand <uweigand@de.ibm.com>
Cc: Yao Qi <qiyaoltc@gmail.com>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH 3/2] Add some more casts (2/2)
Date: Wed, 30 Sep 2015 14:53:00 -0000	[thread overview]
Message-ID: <560BF780.30004@ericsson.com> (raw)
In-Reply-To: <5609756F.9030903@ericsson.com>

On 15-09-28 01:14 PM, Simon Marchi wrote:
> On 15-09-28 11:45 AM, Ulrich Weigand wrote:
>> Simon Marchi wrote:
>>
>>> @@ -1350,7 +1352,7 @@ ppu2spu_sniffer (const struct frame_unwind *self,
>>>        info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
>>>        info.byte_order = BFD_ENDIAN_BIG;
>>>        info.osabi = GDB_OSABI_LINUX;
>>> -      info.tdep_info = (void *) &data.id;
>>> +      info.tdep_info = (struct gdbarch_tdep_info *) &data.id;
>>>        data.gdbarch = gdbarch_find_by_info (info);
>>>        if (!data.gdbarch)
>>>  	return 0;
>>
>> This causes compilation to fail (with the RHEL5 system compiler):
>>
>> gdb/ppc-linux-tdep.c: In function 'ppu2spu_sniffer':
>> gdb/ppc-linux-tdep.c:1355: warning: type-punning to incomplete type might break strict-aliasing rules
>>
>> The problem seems to be that "struct gdbarch_tdep_info" actually
>> does not exist and is not defined anywhere.  The info.tdep_info
>> field is used as a generic pointer; different architectures use
>> it for diffferent purposes.
>>
>> Maybe in this case the correct fix would be to leave the (void *)
>> casts in place and actually change the type of the field to void * ...
>>
>> Bye,
>> Ulrich
> 
> Thanks for pointing this out.  I was able to reproduce it using a Centos 5
> docker container.
> 
> Changing the field and the cast to void* is ok to me.  I don't see any real
> value in casting to a pointer to a type that doesn't exist.  Any other
> opinions?

Here is the proposed fix. Ok to push?


From 6878d6f114544cc58f5065b66026a706108debc5 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Wed, 30 Sep 2015 10:14:09 -0400
Subject: [PATCH] gdbarch.h: Change gdbarch_info::tdep_info's type to void *

As reported by Ulrich here:

  https://sourceware.org/ml/gdb-patches/2015-09/msg00604.html

The system compiler (gcc 4.1) in Centos 5 doesn't like that we cast to a
pointer to a type that doesn't exist.  I see no real value in using this
kind iof construct over just using void *.  So this patch changes the
tdep_info field to void * and removes the casts.  Even in C++, we
should not need an explicit cast when assigning to a void *.

gdb/ChangeLog:

	* gdbarch.sh (struct gdbarch_info): Change tdep_info's type to void *.
	* gdbarch.h: Regenerate.
	* i386-tdep.c (i386_gdbarch_init): Remove cast to
	struct gdbarch_tdep_info *.
	* mips-tdep.c (mips_gdbarch_init): Likewise.
	* ppc-linux-tdep (ppu2spu_sniffer): Likewise.
	* rs6000-tdep.c (rs6000_gdbarch_init): Likewise.
	* spu-multiarch.c (spu_gdbarch): Likewise.
---
 gdb/gdbarch.h        | 2 +-
 gdb/gdbarch.sh       | 2 +-
 gdb/i386-tdep.c      | 2 +-
 gdb/mips-tdep.c      | 2 +-
 gdb/ppc-linux-tdep.c | 2 +-
 gdb/rs6000-tdep.c    | 2 +-
 gdb/spu-multiarch.c  | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 82e0259..2e4ed3e 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -1561,7 +1561,7 @@ struct gdbarch_info
   bfd *abfd;

   /* Use default: NULL (ZERO).  */
-  struct gdbarch_tdep_info *tdep_info;
+  void *tdep_info;

   /* Use default: GDB_OSABI_UNINITIALIZED (-1).  */
   enum gdb_osabi osabi;
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 388920f..a13d9b9 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1429,7 +1429,7 @@ struct gdbarch_info
   bfd *abfd;

   /* Use default: NULL (ZERO).  */
-  struct gdbarch_tdep_info *tdep_info;
+  void *tdep_info;

   /* Use default: GDB_OSABI_UNINITIALIZED (-1).  */
   enum gdb_osabi osabi;
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 2ac2f15..92f60fd 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -8478,7 +8478,7 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_insn_is_jump (gdbarch, i386_insn_is_jump);

   /* Hook in ABI-specific overrides, if they have been registered.  */
-  info.tdep_info = (struct gdbarch_tdep_info *) tdesc_data;
+  info.tdep_info = tdesc_data;
   gdbarch_init_osabi (info, gdbarch);

   if (!i386_validate_tdesc_p (tdep, tdesc_data))
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 388513e..2275138 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -8898,7 +8898,7 @@ mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   mips_register_g_packet_guesses (gdbarch);

   /* Hook in OS ABI-specific overrides, if they have been registered.  */
-  info.tdep_info = (struct gdbarch_tdep_info *) tdesc_data;
+  info.tdep_info = tdesc_data;
   gdbarch_init_osabi (info, gdbarch);

   /* The hook may have adjusted num_regs, fetch the final value and
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index ae5edc2..460c503 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -1352,7 +1352,7 @@ ppu2spu_sniffer (const struct frame_unwind *self,
       info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
       info.byte_order = BFD_ENDIAN_BIG;
       info.osabi = GDB_OSABI_LINUX;
-      info.tdep_info = (struct gdbarch_tdep_info *) &data.id;
+      info.tdep_info = &data.id;
       data.gdbarch = gdbarch_find_by_info (info);
       if (!data.gdbarch)
 	return 0;
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index b37e862..baf6b67 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -5993,7 +5993,7 @@ rs6000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)

   /* Hook in ABI-specific overrides, if they have been registered.  */
   info.target_desc = tdesc;
-  info.tdep_info = (struct gdbarch_tdep_info *) tdesc_data;
+  info.tdep_info = tdesc_data;
   gdbarch_init_osabi (info, gdbarch);

   switch (info.osabi)
diff --git a/gdb/spu-multiarch.c b/gdb/spu-multiarch.c
index c61b271..73acdae 100644
--- a/gdb/spu-multiarch.c
+++ b/gdb/spu-multiarch.c
@@ -107,7 +107,7 @@ spu_gdbarch (int spufs_fd)
   info.bfd_arch_info = bfd_lookup_arch (bfd_arch_spu, bfd_mach_spu);
   info.byte_order = BFD_ENDIAN_BIG;
   info.osabi = GDB_OSABI_LINUX;
-  info.tdep_info = (struct gdbarch_tdep_info *) &spufs_fd;
+  info.tdep_info = &spufs_fd;
   return gdbarch_find_by_info (info);
 }

-- 
2.5.1




  reply	other threads:[~2015-09-30 14:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-23 19:31 [PATCH 2/2] Add some more casts (1/2) Simon Marchi
2015-09-23 19:31 ` [PATCH 3/2] Add some more casts (2/2) Simon Marchi
2015-09-25 13:20   ` Yao Qi
2015-09-25 18:19     ` Simon Marchi
2015-09-28 15:45       ` Ulrich Weigand
2015-09-28 17:14         ` Simon Marchi
2015-09-30 14:53           ` Simon Marchi [this message]
2015-09-30 15:16             ` Ulrich Weigand
2015-09-30 15:25               ` Simon Marchi
2015-09-25 13:17 ` [PATCH 2/2] Add some more casts (1/2) Yao Qi
2015-09-25 13:29   ` Simon Marchi
2015-09-25 18:18   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=560BF780.30004@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    --cc=uweigand@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox