https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111639

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Blocks|                            |79700
   Last reconfirmed|                            |2023-09-29
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This blocks the fix for PR 79700 because of these lying macros.

The crossconfig.m4 changes were made in 2016 by
g:6649ad7efdd583d84099beb5ee2b03a0ed28b9ee purportedly to fix duplicate
definitions in math_stubs_float.cc, e.g.

In file included from
/home/jwakely/src/gcc/build-avr/gcc-obj/avr/libstdc++-v3/include/cmath:47,
                 from
/home/jwakely/src/gcc/gcc/libstdc++-v3/src/c++98/math_stubs_float.cc:25:
/home/jwakely/src/gcc/gcc/libstdc++-v3/src/c++98/math_stubs_float.cc:35:3:
error: conflicting declaration of C function 'float fabs(float)'
   35 |   fabsf(float x)
      |   ^~~~~
/usr/avr/include/math.h:146:15: note: previous declaration 'double
fabs(double)'
  146 | extern double fabs(double __x) __ATTR_CONST__;
      |               ^~~~


But these are caused by the macros in avr <math.h>, which mean that we end up
defining another fabs instead of the intended fabsf.

I think the correct fix is to remove the crossconfig.m4 changes and do this
instead:

--- a/libstdc++-v3/src/c++98/math_stubs_float.cc
+++ b/libstdc++-v3/src/c++98/math_stubs_float.cc
@@ -31,6 +31,7 @@
 extern "C"
 {
 #ifndef _GLIBCXX_HAVE_FABSF
+#undef fabsf
   float
   fabsf(float x)
   {

And similarly for the other functions in that file.

If defining those functions bloats libstdc++ too much for avr, then we can
consider defining the float and long double stubs as aliases of each other
(since float, double and long double all seem to be the same size on avr).

We could even define them inline in headers, instead of in the lib:

extern "C" inline float fabs(float __x) { return fabs((double)__x); }

But the first priority should be to remove the bogus HAVE_FABSF definitions in
crossconfig.m4


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79700
[Bug 79700] std::fabsf and std::fabsl missing from <cmath>

Reply via email to