Fix aliasing warning in aoutf1.h

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fix aliasing warning in aoutf1.h

Andreas Schwab
The c_regs members of struct external_sparc_core and struct
external_solaris_bcp_core are struct regs in essence and only used as
such.  Using the real type avoids an aliasing warning.  This change
required to fiddle with expressions that should have used offsetof in the
first place, so I have also fixed all other non-uses of offsetof in this
file.

Andreas.

2005-11-24  Andreas Schwab  <[hidden email]>

        * aoutf1.h (struct external_sparc_core): Change to of c_regs to
        struct regs.
        (struct external_solaris_bcp_core): Likewise.
        (swapcore_sun3): Use offsetof instead of trying to do it by hand.
        (swapcore_sparc): Likewise.  Remove now unneeded cast that
        triggers an aliasing warning.
        (swapcore_solaris_bcp): Likewise.

--- bfd/aoutf1.h.~1.16.~ 2005-08-18 11:06:29.000000000 +0200
+++ bfd/aoutf1.h 2005-11-24 11:44:28.000000000 +0100
@@ -286,7 +286,7 @@ struct external_sparc_core
   int c_magic; /* Corefile magic number.  */
   int c_len; /* Sizeof (struct core).  */
 #define SPARC_CORE_LEN 432
-  int c_regs[19]; /* General purpose registers -- MACHDEP SIZE.  */
+  struct regs c_regs; /* General purpose registers -- MACHDEP SIZE.  */
   struct external_exec c_aouthdr; /* A.out header.  */
   int c_signo; /* Killing signal, if any.  */
   int c_tsize; /* Text size (bytes).  */
@@ -309,7 +309,7 @@ struct external_solaris_bcp_core
   int c_magic; /* Corefile magic number.  */
   int c_len; /* Sizeof (struct core).  */
 #define SOLARIS_BCP_CORE_LEN 456
-  int c_regs[19]; /* General purpose registers -- MACHDEP SIZE.  */
+  struct regs c_regs; /* General purpose registers -- MACHDEP SIZE.  */
   int c_exdata_vp; /* Exdata structure.  */
   int c_exdata_tsize;
   int c_exdata_dsize;
@@ -387,7 +387,7 @@ swapcore_sun3 (bfd *abfd, char *ext, str
 
   intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
   intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
-  intcore->c_regs_pos = (long) (((struct external_sun3_core *) 0)->c_regs);
+  intcore->c_regs_pos = offsetof (struct external_sun3_core, c_regs);
   intcore->c_regs_size = sizeof (extcore->c_regs);
 #if ARCH_SIZE == 64
   aout_64_swap_exec_header_in
@@ -401,10 +401,10 @@ swapcore_sun3 (bfd *abfd, char *ext, str
   intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr);
   intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
   memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
-  intcore->fp_stuff_pos = (long) (((struct external_sun3_core *) 0)->fp_stuff);
+  intcore->fp_stuff_pos = offsetof (struct external_sun3_core, fp_stuff);
   /* FP stuff takes up whole rest of struct, except c_ucode.  */
   intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
-    (file_ptr) (((struct external_sun3_core *) 0)->fp_stuff);
+    offsetof (struct external_sun3_core, fp_stuff);
   /* Ucode is the last thing in the struct -- just before the end.  */
   intcore->c_ucode = H_GET_32 (abfd,
        (intcore->c_len
@@ -422,7 +422,7 @@ swapcore_sparc (bfd *abfd, char *ext, st
 
   intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
   intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
-  intcore->c_regs_pos = (long) (((struct external_sparc_core *) 0)->c_regs);
+  intcore->c_regs_pos = offsetof (struct external_sparc_core, c_regs);
   intcore->c_regs_size = sizeof (extcore->c_regs);
 #if ARCH_SIZE == 64
   aout_64_swap_exec_header_in
@@ -436,10 +436,10 @@ swapcore_sparc (bfd *abfd, char *ext, st
   intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr);
   intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
   memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
-  intcore->fp_stuff_pos = (long) (((struct external_sparc_core *) 0)->fp_stuff);
+  intcore->fp_stuff_pos = offsetof (struct external_sparc_core, fp_stuff);
   /* FP stuff takes up whole rest of struct, except c_ucode.  */
   intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
-    (file_ptr) (((struct external_sparc_core *) 0)->fp_stuff);
+    offsetof (struct external_sparc_core, fp_stuff);
   /* Ucode is the last thing in the struct -- just before the end.  */
   intcore->c_ucode = H_GET_32 (abfd,
        (intcore->c_len
@@ -462,7 +462,7 @@ swapcore_sparc (bfd *abfd, char *ext, st
 #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
 #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
   {
-    bfd_vma sp = H_GET_32 (abfd, &((struct regs *) &extcore->c_regs[0])->r_o6);
+    bfd_vma sp = H_GET_32 (abfd, &extcore->c_regs.r_o6);
     if (sp < SPARC_USRSTACK_SPARC10)
       intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
     else
@@ -480,7 +480,7 @@ swapcore_solaris_bcp (bfd *abfd, char *e
 
   intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
   intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
-  intcore->c_regs_pos = (long) (((struct external_solaris_bcp_core *) 0)->c_regs);
+  intcore->c_regs_pos = offsetof (struct external_solaris_bcp_core, c_regs);
   intcore->c_regs_size = sizeof (extcore->c_regs);
 
   /* The Solaris BCP exdata structure does not contain an a_syms field,
@@ -501,10 +501,10 @@ swapcore_solaris_bcp (bfd *abfd, char *e
   intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
   memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
   intcore->fp_stuff_pos =
-    (long) (((struct external_solaris_bcp_core *) 0)->fp_stuff);
+    offsetof (struct external_solaris_bcp_core, fp_stuff);
   /* FP stuff takes up whole rest of struct, except c_ucode.  */
   intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
-    (file_ptr) (((struct external_solaris_bcp_core *) 0)->fp_stuff);
+    offsetof (struct external_solaris_bcp_core, fp_stuff);
   /* Ucode is the last thing in the struct -- just before the end */
   intcore->c_ucode = H_GET_32 (abfd,
        (intcore->c_len
@@ -527,7 +527,7 @@ swapcore_solaris_bcp (bfd *abfd, char *e
 #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
 #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
   {
-    bfd_vma sp = H_GET_32 (abfd, &((struct regs *) &extcore->c_regs[0])->r_o6);
+    bfd_vma sp = H_GET_32 (abfd, &extcore->c_regs.r_o6);
     if (sp < SPARC_USRSTACK_SPARC10)
       intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
     else

--
Andreas Schwab, SuSE Labs, [hidden email]
SuSE Linux Products GmbH, Maxfeldstra?e 5, 90409 N?rnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Reply | Threaded
Open this post in threaded view
|

Re: Fix aliasing warning in aoutf1.h

Alan Modra
On Thu, Nov 24, 2005 at 03:58:25PM +0100, Andreas Schwab wrote:
> 2005-11-24  Andreas Schwab  <[hidden email]>
>
> * aoutf1.h (struct external_sparc_core): Change to of c_regs to
> struct regs.
> (struct external_solaris_bcp_core): Likewise.
> (swapcore_sun3): Use offsetof instead of trying to do it by hand.
> (swapcore_sparc): Likewise.  Remove now unneeded cast that
> triggers an aliasing warning.
> (swapcore_solaris_bcp): Likewise.

This is OK.  Thanks!

--
Alan Modra
IBM OzLabs - Linux Technology Centre