[ECOS] strict aliasing problem?
Jonathan Larmour
jifl@jifvik.org
Tue May 18 13:00:00 GMT 2010
Will Lentz wrote:
> Hi,
>
> I'm using GCC 4.4.1 on an MPC5200 target and I was getting incorrect
> results from:
> libm/current/src/double/ieee754-core/e_exp.c
>
> Once I pass -fno-strict-aliasing to the math library, everything works
> fine. (On a side note, everything works fine either way with GCC 3.3)
>
> It looks like e_exp.c accesses the double "x" through CYG_LIBM_HI():
> #define CYG_LIBM_HI(__x) (((Cyg_libm_ieee_double_shape_type
> *)&__x)->parts.msw)
> where Cyg_libm_ieee_double_shape_type is a union type.
>
> According to:
>
> http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Optimize-Options.html#index-
> fstrict_002daliasing-750
> code such as the following results in undefined behavior:
> union a_union {
> int i;
> double d;
> };
> int f() {
> double d = 3.0;
> return ((union a_union *) &d)->i;
> }
>
> Should all targets use -fno-strict-aliasing when building the math
> library for safety?
Looks like it in that case. I've applied the attached patch for this.
Really it should be updated to be based on a newer libm from newlib, which
has other feature improvements. (I know eCosCentric did this because I did
it!). But this workaround will have to do for now.
Jifl
--
------["The best things in life aren't things."]------ Opinions==mine
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: libm.no.strict.aliasing.patch.txt
URL: <http://sourceware.org/pipermail/ecos-discuss/attachments/20100518/e0e6dc69/attachment.txt>
-------------- next part --------------
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
More information about the Ecos-discuss
mailing list