[patch] aout+coff: Fix strict-aliasing rules error
Pedro Alves
palves@redhat.com
Tue Mar 8 14:36:00 GMT 2016
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
More information about the Binutils
mailing list