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
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libm/current/ChangeLog,v
retrieving revision 1.28
diff -u -5 -p -r1.28 ChangeLog
--- ChangeLog 29 Jan 2009 17:49:54 -0000 1.28
+++ ChangeLog 15 May 2010 16:32:08 -0000
@@ -1,5 +1,11 @@
+2010-05-15 Jonathan Larmour <j...@jifvik.org>
+
+ * cdl/libm.cdl (CYGPKG_LIBM_CFLAGS_ADD): Compile with
+ -fno-strict-aliasing to avoid miscompilation. Workaround for a more
+ fundamental problem with CYG_LIBM_HI/LO.
+
2008-11-20 Jonathan Larmour <j...@ecoscentric.com>
* cdl/libm.cdl: Rename X_TLOSS CDL option to match normal convention.
2007-09-04 Stephen Finney <s...@pfinc.com>
@@ -811,11 +817,11 @@ Fri Jun 5 07:07:03 1998 Jonathan Larmo
//===========================================================================
// ####GPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
-// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2007, 2008, 2010 Free
Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 or (at your option) any
// later version.
Index: cdl/libm.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libm/current/cdl/libm.cdl,v
retrieving revision 1.8
diff -u -5 -p -r1.8 libm.cdl
--- cdl/libm.cdl 29 Jan 2009 17:49:54 -0000 1.8
+++ cdl/libm.cdl 15 May 2010 16:32:08 -0000
@@ -6,11 +6,11 @@
#
# ====================================================================
## ####ECOSGPLCOPYRIGHTBEGIN####
## -------------------------------------------
## This file is part of eCos, the Embedded Configurable Operating System.
-## Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+## Copyright (C) 1998, 1999, 2000, 2001, 2002, 2010 Free Software Foundation,
Inc.
##
## eCos is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free
## Software Foundation; either version 2 or (at your option) any later
## version.
@@ -227,11 +227,12 @@ cdl_package CYGPKG_LIBM {
cdl_option CYGPKG_LIBM_CFLAGS_ADD {
display "Additional compiler flags"
flavor data
no_define
- default_value { ((0 == CYGPKG_HAL_I386) && (0 ==
CYGPKG_HAL_SYNTH_I386)) ? "" : "-ffloat-store" }
+ default_value { "-fno-strict-aliasing " . \
+ ((0 == CYGPKG_HAL_I386) && (0 ==
CYGPKG_HAL_SYNTH_I386)) ? "" : "-ffloat-store" }
description "
This option modifies the set of compiler flags for
building the math library. These flags are used in addition
to the set of global flags."
}
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss