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