This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [patch] aout+coff: Fix strict-aliasing rules error
- From: Pedro Alves <palves at redhat dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>, binutils at sourceware dot org
- Date: Tue, 8 Mar 2016 14:36:18 +0000
- Subject: Re: [patch] aout+coff: Fix strict-aliasing rules error
- Authentication-results: sourceware.org; auth=none
- References: <20160308135706 dot GA3994 at host1 dot jankratochvil dot net>
On 03/08/2016 01:57 PM, Jan Kratochvil wrote:
> Hi,
>
> https://bugzilla.redhat.com/show_bug.cgi?id=1315191 by Dan Horak
> gcc (GCC) 6.0.0 20160308 (experimental)
> gcc-6.0.0-0.15.fc24
> gcc-6.0.0-0.15.fc25
> It did compile with:
> gcc-6.0.0-0.14.fc24
>
> aoutx.h:2504:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
> int type_code = aout_symbol (symbol)->type & 0xff;
> ^~~
> coffcode.h:1817:3: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
> coffsymbol (section->symbol)->native = native;
> ^~~~~~~~~~
>
> Full log attached.
>
> This fix is probably wrong as it drops the type safety. But ({ statements as
> expressions }) are probably not allowed in GDB.
Not clear to me why this is producing a warning. This seems like a gcc trunk
regression that should be reported and fixed in gcc instead. It's valid
to cast the pointer to a struct to a pointer to its initial member and back.
See C99 6.7.2.1 point 13 [1], or C11 6.7.2.1 point 15 [2].
"A pointer to a structure object, suitably converted, points to its
initial member (...), and vice versa."
[1] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
[2] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf
Thanks,
Pedro Alves