01264be
http://sourceware.org/ml/binutils/2016-03/msg00119.html
01264be
Subject: [patch] aout+coff: Fix strict-aliasing rules error
01264be
01264be
01264be
--IJpNTDwzlM2Ie8A6
01264be
Content-Type: text/plain; charset=us-ascii
01264be
Content-Disposition: inline
01264be
01264be
Hi,
01264be
01264be
https://bugzilla.redhat.com/show_bug.cgi?id=1315191 by Dan Horak
01264be
gcc (GCC) 6.0.0 20160308 (experimental)
01264be
gcc-6.0.0-0.15.fc24
01264be
gcc-6.0.0-0.15.fc25
01264be
It did compile with:
01264be
gcc-6.0.0-0.14.fc24
01264be
01264be
aoutx.h:2504:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
       int type_code = aout_symbol (symbol)->type & 0xff;
01264be
       ^~~
01264be
coffcode.h:1817:3: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
   coffsymbol (section->symbol)->native = native;
01264be
   ^~~~~~~~~~
01264be
01264be
Full log attached.
01264be
01264be
This fix is probably wrong as it drops the type safety.  But ({ statements as
01264be
expressions }) are probably not allowed in GDB.
01264be
01264be
01264be
Jan
01264be
01264be
--IJpNTDwzlM2Ie8A6
01264be
Content-Type: text/plain; charset=us-ascii
01264be
Content-Disposition: inline; filename=1
01264be
01264be
bfd/
01264be
2016-03-08  Jan Kratochvil  <jan.kratochvil@redhat.com>
01264be
01264be
	Fix strict-aliasing rules compilation error.
01264be
	* libaout.h (aout_symbol): Remove type safe indirection.
01264be
	* libcoff-in.h (coffsymbol): Likewise.
01264be
	* libcoff.h: Regenerate.
01264be
01264be
diff --git a/bfd/libaout.h b/bfd/libaout.h
01264be
index 8b70a9f..b60c40c 100644
01264be
--- a/bfd/libaout.h
01264be
+++ b/bfd/libaout.h
01264be
@@ -448,9 +448,7 @@ struct  aout_data_struct
01264be
 #define obj_aout_sym_hashes(bfd)           (adata (bfd).sym_hashes)
01264be
 #define obj_aout_dynamic_info(bfd)         (adata (bfd).dynamic_info)
01264be
 
01264be
-/* We take the address of the first element of an asymbol to ensure that the
01264be
-   macro is only ever applied to an asymbol.  */
01264be
-#define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd))
01264be
+#define aout_symbol(asymbol) ((aout_symbol_type *) (asymbol))
01264be
 
01264be
 /* Information we keep for each a.out section.  This is currently only
01264be
    used by the a.out backend linker.  */
01264be
diff --git a/bfd/libcoff-in.h b/bfd/libcoff-in.h
01264be
index 80f999d..fa1e9ac 100644
01264be
--- a/bfd/libcoff-in.h
01264be
+++ b/bfd/libcoff-in.h
01264be
@@ -188,9 +188,7 @@ struct xcoff_tdata
01264be
 
01264be
 #define xcoff_data(abfd) ((abfd)->tdata.xcoff_obj_data)
01264be
 
01264be
-/* We take the address of the first element of an asymbol to ensure that the
01264be
-   macro is only ever applied to an asymbol.  */
01264be
-#define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd)))
01264be
+#define coffsymbol(asymbol) ((coff_symbol_type *) (asymbol))
01264be
 
01264be
 /* Tdata for sections in XCOFF files.  This is used by the linker.  */
01264be
 
01264be
diff --git a/bfd/libcoff.h b/bfd/libcoff.h
01264be
index bbed3e0..8ce525b 100644
01264be
--- a/bfd/libcoff.h
01264be
+++ b/bfd/libcoff.h
01264be
@@ -192,9 +192,7 @@ struct xcoff_tdata
01264be
 
01264be
 #define xcoff_data(abfd) ((abfd)->tdata.xcoff_obj_data)
01264be
 
01264be
-/* We take the address of the first element of an asymbol to ensure that the
01264be
-   macro is only ever applied to an asymbol.  */
01264be
-#define coffsymbol(asymbol) ((coff_symbol_type *)(&((asymbol)->the_bfd)))
01264be
+#define coffsymbol(asymbol) ((coff_symbol_type *) (asymbol))
01264be
 
01264be
 /* Tdata for sections in XCOFF files.  This is used by the linker.  */
01264be
 
01264be
01264be
--IJpNTDwzlM2Ie8A6
01264be
Content-Type: text/plain; charset=iso-2022-jp
01264be
Content-Disposition: inline; filename=2
01264be
01264be
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -I. -I./../include -DHAVE_x86_64_elf64_vec -DHAVE_i386_elf32_vec -DHAVE_iamcu_elf32_vec -DHAVE_x86_64_elf32_vec -DHAVE_i386_aout_linux_vec -DHAVE_i386_pei_vec -DHAVE_x86_64_pei_vec -DHAVE_l1om_elf64_vec -DHAVE_k1om_elf64_vec -DHAVE_elf64_le_vec -DHAVE_elf64_be_vec -DHAVE_elf32_le_vec -DHAVE_elf32_be_vec -DHAVE_plugin_vec -DBINDIR=\"/usr/local/bin\" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -I./../zlib -g -O2 -MT aout32.lo -MD -MP -MF .deps/aout32.Tpo -c aout32.c -o aout32.o
01264be
In file included from aout32.c:24:0:
01264be
aoutx.h: In function ‘aout_32_write_syms’:
01264be
aoutx.h:1871:4: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
    H_PUT_16 (abfd, aout_symbol (g)->desc,  nsp.e_desc);
01264be
    ^~~~~~~~
01264be
aoutx.h:1872:4: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
    H_PUT_8  (abfd, aout_symbol (g)->other, nsp.e_other);
01264be
    ^~~~~~~
01264be
aoutx.h:1873:4: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
    H_PUT_8  (abfd, aout_symbol (g)->type,  nsp.e_type);
01264be
    ^~~~~~~
01264be
aoutx.h: In function ‘aout_32_get_symbol_info’:
01264be
aoutx.h:2504:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
       int type_code = aout_symbol (symbol)->type & 0xff;
01264be
       ^~~
01264be
aoutx.h:2515:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
       ret->stab_other = (unsigned) (aout_symbol (symbol)->other & 0xff);
01264be
       ^~~
01264be
aoutx.h:2516:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
       ret->stab_desc = (unsigned) (aout_symbol (symbol)->desc & 0xffff);
01264be
       ^~~
01264be
aoutx.h: In function ‘aout_32_print_symbol’:
01264be
aoutx.h:2537:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
         (unsigned) (aout_symbol (symbol)->desc & 0xffff),
01264be
         ^
01264be
aoutx.h:2538:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
         (unsigned) (aout_symbol (symbol)->other & 0xff),
01264be
         ^
01264be
aoutx.h:2539:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
         (unsigned) (aout_symbol (symbol)->type));
01264be
         ^
01264be
aoutx.h:2549:4: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
    (unsigned) (aout_symbol (symbol)->desc & 0xffff),
01264be
    ^
01264be
aoutx.h:2550:4: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
    (unsigned) (aout_symbol (symbol)->other & 0xff),
01264be
    ^
01264be
aoutx.h:2551:4: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
    (unsigned) (aout_symbol (symbol)->type & 0xff));
01264be
    ^
01264be
cc1: all warnings being treated as errors
01264be
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -I. -I./../include -DHAVE_x86_64_elf64_vec -DHAVE_i386_elf32_vec -DHAVE_iamcu_elf32_vec -DHAVE_x86_64_elf32_vec -DHAVE_i386_aout_linux_vec -DHAVE_i386_pei_vec -DHAVE_x86_64_pei_vec -DHAVE_l1om_elf64_vec -DHAVE_k1om_elf64_vec -DHAVE_elf64_le_vec -DHAVE_elf64_be_vec -DHAVE_elf32_le_vec -DHAVE_elf32_be_vec -DHAVE_plugin_vec -DBINDIR=\"/usr/local/bin\" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -I./../zlib -g -O2 -MT pei-i386.lo -MD -MP -MF .deps/pei-i386.Tpo -c pei-i386.c -o pei-i386.o
01264be
In file included from coff-i386.c:614:0,
01264be
                 from pei-i386.c:45:
01264be
coffcode.h: In function ‘coff_new_section_hook’:
01264be
coffcode.h:1817:3: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
   coffsymbol (section->symbol)->native = native;
01264be
   ^~~~~~~~~~
01264be
cc1: all warnings being treated as errors
01264be
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -I. -I./../include -DHAVE_x86_64_elf64_vec -DHAVE_i386_elf32_vec -DHAVE_iamcu_elf32_vec -DHAVE_x86_64_elf32_vec -DHAVE_i386_aout_linux_vec -DHAVE_i386_pei_vec -DHAVE_x86_64_pei_vec -DHAVE_l1om_elf64_vec -DHAVE_k1om_elf64_vec -DHAVE_elf64_le_vec -DHAVE_elf64_be_vec -DHAVE_elf32_le_vec -DHAVE_elf32_be_vec -DHAVE_plugin_vec -DBINDIR=\"/usr/local/bin\" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -I./../zlib -g -O2 -MT coffgen.lo -MD -MP -MF .deps/coffgen.Tpo -c coffgen.c -o coffgen.o
01264be
coffgen.c: In function ‘coff_get_lineno’:
01264be
coffgen.c:1510:3: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
   return coffsymbol (symbol)->lineno;
01264be
   ^~~~~~
01264be
coffgen.c: In function ‘coff_get_symbol_info’:
01264be
coffgen.c:2034:3: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
   if (coffsymbol (symbol)->native != NULL
01264be
   ^~
01264be
coffgen.c:2035:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
       && coffsymbol (symbol)->native->fix_value
01264be
       ^~
01264be
coffgen.c:2036:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
       && coffsymbol (symbol)->native->is_sym)
01264be
       ^~
01264be
coffgen.c:2037:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
     ret->value = coffsymbol (symbol)->native->u.syment.n_value -
01264be
     ^~~
01264be
coffgen.c: In function ‘coff_print_symbol’:
01264be
coffgen.c:2059:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
         coffsymbol (symbol)->native ? "n" : "g",
01264be
         ^~~~~~~~~~
01264be
coffgen.c:2060:9: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
         coffsymbol (symbol)->lineno ? "l" : " ");
01264be
         ^~~~~~~~~~
01264be
coffgen.c:2064:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
       if (coffsymbol (symbol)->native)
01264be
       ^~
01264be
coffgen.c:2068:4: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
    combined_entry_type *combined = coffsymbol (symbol)->native;
01264be
    ^~~~~~~~~~~~~~~~~~~
01264be
coffgen.c:2070:11: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
    struct lineno_cache_entry *l = coffsymbol (symbol)->lineno;
01264be
           ^~~~~~~~~~~~~~~~~~
01264be
coffgen.c:2191:6: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
      coffsymbol (symbol)->native ? "n" : "g",
01264be
      ^~~~~~~~~~
01264be
coffgen.c:2192:6: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
      coffsymbol (symbol)->lineno ? "l" : " ",
01264be
      ^~~~~~~~~~
01264be
cc1: all warnings being treated as errors
01264be
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -I. -I./../include -DHAVE_x86_64_elf64_vec -DHAVE_i386_elf32_vec -DHAVE_iamcu_elf32_vec -DHAVE_x86_64_elf32_vec -DHAVE_i386_aout_linux_vec -DHAVE_i386_pei_vec -DHAVE_x86_64_pei_vec -DHAVE_l1om_elf64_vec -DHAVE_k1om_elf64_vec -DHAVE_elf64_le_vec -DHAVE_elf64_be_vec -DHAVE_elf32_le_vec -DHAVE_elf32_be_vec -DHAVE_plugin_vec -DBINDIR=\"/usr/local/bin\" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -I./../zlib -g -O2 -MT pei-x86_64.lo -MD -MP -MF .deps/pei-x86_64.Tpo -c pei-x86_64.c -o pei-x86_64.o
01264be
In file included from coff-x86_64.c:741:0,
01264be
                 from pei-x86_64.c:763:
01264be
coffcode.h: In function ‘coff_new_section_hook’:
01264be
coffcode.h:1817:3: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
01264be
   coffsymbol (section->symbol)->native = native;
01264be
   ^~~~~~~~~~
01264be
cc1: all warnings being treated as errors
01264be
01264be
--IJpNTDwzlM2Ie8A6--
01264be