Bug 69881 - with gcc-6 of today building gcc-4.9 fails
Summary: with gcc-6 of today building gcc-4.9 fails
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-20 06:13 UTC by Bernd Edlinger
Modified: 2016-02-23 16:07 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
preprocessed source code (407.81 KB, application/gzip)
2016-02-20 06:13 UTC, Bernd Edlinger
Details
prerequisite patch to make c_std headers compile (3.95 KB, patch)
2016-02-21 21:29 UTC, Bernd Edlinger
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bernd Edlinger 2016-02-20 06:13:33 UTC
Created attachment 37742 [details]
preprocessed source code

g++ -c   -g -DIN_GCC    -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fno-common  -DHAVE_CONFIG_H -I. -I. -I../../gcc-4.9-branch/gcc -I../../gcc-4.9-branch/gcc/. -I../../gcc-4.9-branch/gcc/../include -I../../gcc-4.9-branch/gcc/../libcpp/include -I/home/ed/gnu/gcc-build2/./gmp -I/home/ed/gnu/gcc-4.9-branch/gmp -I/home/ed/gnu/gcc-build2/./mpfr -I/home/ed/gnu/gcc-4.9-branch/mpfr -I/home/ed/gnu/gcc-4.9-branch/mpc/src  -I../../gcc-4.9-branch/gcc/../libdecnumber -I../../gcc-4.9-branch/gcc/../libdecnumber/bid -I../libdecnumber -I../../gcc-4.9-branch/gcc/../libbacktrace -DCLOOG_INT_GMP -I/home/ed/gnu/gcc-build2/./cloog/include -I/home/ed/gnu/gcc-4.9-branch/cloog/include -I../gcc-4.9-branch/cloog/include  -I/home/ed/gnu/gcc-build2/./isl/include -I/home/ed/gnu/gcc-4.9-branch/isl/include  -o graphite.o -MT graphite.o -MMD -MP -MF ./.deps/graphite.TPo ../../gcc-4.9-branch/gcc/graphite.c
...
In file included from /home/ed/gnu/gcc-build2/./gmp/gmp.h:51:0,
                 from /home/ed/gnu/gcc-4.9-branch/isl/include/isl/int.h:15,
                 from /home/ed/gnu/gcc-4.9-branch/isl/include/isl/ctx.h:16,
                 from /home/ed/gnu/gcc-4.9-branch/isl/include/isl/list.h:13,
                 from /home/ed/gnu/gcc-4.9-branch/isl/include/isl/aff_type.h:4,
                 from /home/ed/gnu/gcc-4.9-branch/isl/include/isl/local_space.h:4,
                 from /home/ed/gnu/gcc-4.9-branch/isl/include/isl/constraint.h:13,
                 from ../../gcc-4.9-branch/gcc/graphite.c:38:
/home/ed/gnu/install/include/c++/6.0.0/cstddef:51:11: error: '::max_align_t' has not been declared
   using ::max_align_t;
           ^~~~~~~~~~~
Comment 1 Bernd Edlinger 2016-02-20 06:16:18 UTC
note: back-porting r233572 will still be necessary to build 4.9 with gcc-6
but the build fails earlier than that.
Comment 2 Bernd Edlinger 2016-02-20 07:25:08 UTC
Something like that might be needed?

Index: c_global/cstddef
===================================================================
--- c_global/cstddef	(Revision 233574)
+++ c_global/cstddef	(Arbeitskopie)
@@ -41,6 +41,13 @@
 
 #pragma GCC system_header
 
+#if defined(__need_wchar_t) || defined(__need_size_t) \
+    || defined(__need_ptrdiff_t) || defined(__need_NULL) \
+    || defined(__need_wint_t)
+
+#include <stddef.h>
+
+#else
 #include <bits/c++config.h>
 #include <stddef.h>
 
@@ -51,5 +58,6 @@
   using ::max_align_t;
 }
 #endif
+#endif
 
 #endif // _GLIBCXX_CSTDDEF
Index: c_std/cstddef
===================================================================
--- c_std/cstddef	(Revision 233574)
+++ c_std/cstddef	(Arbeitskopie)
@@ -41,6 +41,13 @@
 
 #pragma GCC system_header
 
+#if defined(__need_wchar_t) || defined(__need_size_t) \
+    || defined(__need_ptrdiff_t) || defined(__need_NULL) \
+    || defined(__need_wint_t)
+
+#include <stddef.h>
+
+#else
 #include <bits/c++config.h>
 #include <stddef.h>
 
@@ -51,5 +58,6 @@
   using ::max_align_t;
 }
 #endif
+#endif
 
 #endif // _GLIBCXX_CSTDDEF


Question:

why are the both files different?
diff c_global/cstddef c_std/cstddef
26c26
<  *  This is a Standard C++ Library file.  You should @c \#include this file
---
>  *  This is a Standard C++ Library file.  You should @c #include this file
Comment 3 Bernd Edlinger 2016-02-20 10:25:58 UTC
or 

#undef all these __need_XXX before including stddef.h,
after all it is a bit bogus ghat gmp.h does:

#define __need_size_t  /* tell gcc stddef.h we only want size_t */
#include <cstddef>     /* for size_t */

is cstddef supposed to honor __need_size_t at all?
Comment 4 Jonathan Wakely 2016-02-20 10:31:17 UTC
The patch seems wrong, your new sections don't add anything to namespace std.
Comment 5 Jonathan Wakely 2016-02-20 10:32:17 UTC
(In reply to Bernd Edlinger from comment #3)
> or 
> 
> #undef all these __need_XXX before including stddef.h,
> after all it is a bit bogus ghat gmp.h does:
> 
> #define __need_size_t  /* tell gcc stddef.h we only want size_t */
> #include <cstddef>     /* for size_t */

That is bogus.

> is cstddef supposed to honor __need_size_t at all?

No.
Comment 6 Bernd Edlinger 2016-02-20 10:40:39 UTC
(In reply to Jonathan Wakely from comment #4)
> The patch seems wrong, your new sections don't add anything to namespace std.

yes.  I think probably cstddef is free to ignore __need_size_t. right?

Then it would be better to #undef all of them, just in case.

cat test.cc
#define __need_size_t
#include <cstddef>

gcc -c test.cc
In file included from test.cc:2:0:
/home/ed/gnu/install/include/c++/6.0.0/cstddef:51:11: error: '::max_align_t' has not been declared
   using ::max_align_t;
           ^~~~~~~~~~~
Comment 7 Bernd Edlinger 2016-02-20 10:49:58 UTC
Index: include/c_global/cstddef
===================================================================
--- include/c_global/cstddef	(revision 233581)
+++ include/c_global/cstddef	(working copy)
@@ -41,6 +41,12 @@
 
 #pragma GCC system_header
 
+#undef __need_wchar_t
+#undef __need_size_t
+#undef __need_ptrdiff_t
+#undef __need_NULL
+#undef __need_wint_t
+
 #include <bits/c++config.h>
 #include <stddef.h>
 
Index: include/c_std/cstddef
===================================================================
--- include/c_std/cstddef	(revision 233581)
+++ include/c_std/cstddef	(working copy)
@@ -41,6 +41,12 @@
 
 #pragma GCC system_header
 
+#undef __need_wchar_t
+#undef __need_size_t
+#undef __need_ptrdiff_t
+#undef __need_NULL
+#undef __need_wint_t
+
 #include <bits/c++config.h>
 #include <stddef.h>
 
like this?
Comment 8 Bernd Edlinger 2016-02-20 11:03:04 UTC
BTW:

the free-standing cstddef is also buggy:

#define __need_size_t
#define __need_ptrdiff_t
#define __need_NULL
#define __need_offsetof
#include_next <stddef.h>

but GCC's stddef.h does not implement __need_offsetof.
in the contrary, offsetof is not defined when any of the implemented
__need_XXX macros is set.

$prefix/lib/gcc/x86_64-pc-linux-gnu/6.0.0/include/stddef.h:

#ifdef _STDDEF_H

/* Offset of member MEMBER in a struct of type TYPE. */
#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
Comment 9 Bernd Edlinger 2016-02-20 11:25:29 UTC
right now I am trying to boot-strap this:

Index: c/cstddef
===================================================================
--- c/cstddef	(revision 233581)
+++ c/cstddef	(working copy)
@@ -31,10 +31,11 @@
 
 #pragma GCC system_header
 
-#define __need_size_t
-#define __need_ptrdiff_t
-#define __need_NULL
-#define __need_offsetof
+#undef __need_wchar_t
+#undef __need_size_t
+#undef __need_ptrdiff_t
+#undef __need_NULL
+#undef __need_wint_t
 #include_next <stddef.h>
 
 #endif
Index: c_global/cstddef
===================================================================
--- c_global/cstddef	(revision 233581)
+++ c_global/cstddef	(working copy)
@@ -41,6 +41,11 @@
 
 #pragma GCC system_header
 
+#undef __need_wchar_t
+#undef __need_size_t
+#undef __need_ptrdiff_t
+#undef __need_NULL
+#undef __need_wint_t
 #include <bits/c++config.h>
 #include <stddef.h>
 
Index: c_std/cstddef
===================================================================
--- c_std/cstddef	(revision 233581)
+++ c_std/cstddef	(working copy)
@@ -41,6 +41,11 @@
 
 #pragma GCC system_header
 
+#undef __need_wchar_t
+#undef __need_size_t
+#undef __need_ptrdiff_t
+#undef __need_NULL
+#undef __need_wint_t
 #include <bits/c++config.h>
 #include <stddef.h>
Comment 10 Jakub Jelinek 2016-02-20 12:30:21 UTC
Why should libstdc++ try to workaround a bug in gmp.h?  Just fix gmp.h...
Comment 11 Bernd Edlinger 2016-02-20 12:45:07 UTC
(In reply to Jakub Jelinek from comment #10)
> Why should libstdc++ try to workaround a bug in gmp.h?  Just fix gmp.h...

Yes, and probably it is already fixed with gmp-6.1.0, I did not check.

I am trying to bootstrap gcc-4.9 plus the cfns.h patch from yesterday
together with a fixed gmp-4.3.2 which is just what download_prerequisites
installed.

IMHO libstdc++ is just fragile if it lets those __need_-thingies
pass through and then assumes that max_align_t must be defined.

And the free-standing cstdlib is simply not defining offsetof
when it apparently tries to.
Comment 12 Jonathan Wakely 2016-02-20 17:18:44 UTC
(In reply to Bernd Edlinger from comment #9)
> right now I am trying to boot-strap this:
> 
> Index: c/cstddef
> ===================================================================
> --- c/cstddef	(revision 233581)
> +++ c/cstddef	(working copy)
> @@ -31,10 +31,11 @@
>  
>  #pragma GCC system_header
>  
> -#define __need_size_t
> -#define __need_ptrdiff_t
> -#define __need_NULL
> -#define __need_offsetof
> +#undef __need_wchar_t
> +#undef __need_size_t
> +#undef __need_ptrdiff_t
> +#undef __need_NULL
> +#undef __need_wint_t
>  #include_next <stddef.h>


How do you plan to test this change? Do you have a target that uses this header?


>  #endif
> Index: c_global/cstddef
> ===================================================================
> --- c_global/cstddef	(revision 233581)
> +++ c_global/cstddef	(working copy)
> @@ -41,6 +41,11 @@
>  
>  #pragma GCC system_header
>  
> +#undef __need_wchar_t
> +#undef __need_size_t
> +#undef __need_ptrdiff_t
> +#undef __need_NULL
> +#undef __need_wint_t
>  #include <bits/c++config.h>
>  #include <stddef.h>

This isn't incorrect, but it should not be necessary. This macros are internal implementation details of the standard library headers, and user code (like GMP) should not be defining those macros. If GMP wants size_t it should include <stddef.h> and if it wants std::size_t it should include <cstddef>, and it should not try to play silly games to only get part of the header.



> Index: c_std/cstddef
> ===================================================================
> --- c_std/cstddef	(revision 233581)
> +++ c_std/cstddef	(working copy)
> @@ -41,6 +41,11 @@
>  
>  #pragma GCC system_header
>  
> +#undef __need_wchar_t
> +#undef __need_size_t
> +#undef __need_ptrdiff_t
> +#undef __need_NULL
> +#undef __need_wint_t
>  #include <bits/c++config.h>
>  #include <stddef.h>

How do you plan to test this?
Comment 13 Bernd Edlinger 2016-02-20 18:38:08 UTC
(In reply to Jonathan Wakely from comment #12)
> (In reply to Bernd Edlinger from comment #9)
> > right now I am trying to boot-strap this:
> > 
> > Index: c/cstddef
> > ===================================================================
> > --- c/cstddef	(revision 233581)
> > +++ c/cstddef	(working copy)
> > @@ -31,10 +31,11 @@
> >  
> >  #pragma GCC system_header
> >  
> > -#define __need_size_t
> > -#define __need_ptrdiff_t
> > -#define __need_NULL
> > -#define __need_offsetof
> > +#undef __need_wchar_t
> > +#undef __need_size_t
> > +#undef __need_ptrdiff_t
> > +#undef __need_NULL
> > +#undef __need_wint_t
> >  #include_next <stddef.h>
> 
> 
> How do you plan to test this change? Do you have a target that uses this
> header?
> 

Yes, I do have such targets.
We use eCos at Softing as real time O/S a lot.

I think I will build an ecos cross compiler, did so last year with
gcc-5.1, (and had quite a lot of trouble with the bugs in
ecos headers)

./gcc-5.1.0/configure --prefix=/home/ed/gnu/arm-eabi --target=arm-eabi --with-newlib --enable-languages=c,c++ --disable-hosted-libstdcxx --disable-__cxa-atexit --disable-libquadmath --disable-decimal-float

> 
> >  #endif
> > Index: c_global/cstddef
> > ===================================================================
> > --- c_global/cstddef	(revision 233581)
> > +++ c_global/cstddef	(working copy)
> > @@ -41,6 +41,11 @@
> >  
> >  #pragma GCC system_header
> >  
> > +#undef __need_wchar_t
> > +#undef __need_size_t
> > +#undef __need_ptrdiff_t
> > +#undef __need_NULL
> > +#undef __need_wint_t
> >  #include <bits/c++config.h>
> >  #include <stddef.h>
> 
> This isn't incorrect, but it should not be necessary. This macros are
> internal implementation details of the standard library headers, and user
> code (like GMP) should not be defining those macros. If GMP wants size_t it
> should include <stddef.h> and if it wants std::size_t it should include
> <cstddef>, and it should not try to play silly games to only get part of the
> header.
> 
> 

Yeah, shit happens.
Anyway boot-strap & reg-testing OK on x86_64-pc-linux-gnu.
gcc-4.9 builds successfully (minus Ada, see pr69883 :()

> 
> > Index: c_std/cstddef
> > ===================================================================
> > --- c_std/cstddef	(revision 233581)
> > +++ c_std/cstddef	(working copy)
> > @@ -41,6 +41,11 @@
> >  
> >  #pragma GCC system_header
> >  
> > +#undef __need_wchar_t
> > +#undef __need_size_t
> > +#undef __need_ptrdiff_t
> > +#undef __need_NULL
> > +#undef __need_wint_t
> >  #include <bits/c++config.h>
> >  #include <stddef.h>
> 
> How do you plan to test this?

no idea yet.
under what condition is that header used?

Why does it only differ in the comment from the
previous header?

why are the both files different?
diff c_global/cstddef c_std/cstddef
26c26
<  *  This is a Standard C++ Library file.  You should @c \#include this file
---
>  *  This is a Standard C++ Library file.  You should @c #include this file

is this a mistake?
Comment 14 Bernd Edlinger 2016-02-21 08:10:35 UTC
OK, I built the ecos cross compiler now.
It works.  But eCos headers don't work well with C99 because of
duplicate symbols with inline functions, so I have to use -std=c89,
but that started with gcc-5, so that was no surprise.  The new C++
standard does not make any problems at least.

confirmed, that offsetof is defined by including <cstddef> now,
but not by this for instance:

#define __need_NULL
#define __need_offsetof
#include <stddef.h>
Comment 15 Bernd Edlinger 2016-02-21 17:04:29 UTC
(In reply to Jonathan Wakely from comment #12)
> > Index: c_std/cstddef
> > ===================================================================
> > --- c_std/cstddef	(revision 233581)
> > +++ c_std/cstddef	(working copy)
> > @@ -41,6 +41,11 @@
> >  
> >  #pragma GCC system_header
> >  
> > +#undef __need_wchar_t
> > +#undef __need_size_t
> > +#undef __need_ptrdiff_t
> > +#undef __need_NULL
> > +#undef __need_wint_t
> >  #include <bits/c++config.h>
> >  #include <stddef.h>
> 
> How do you plan to test this?

I tried:
../gcc-trunk/configure --prefix=/home/ed/gnu/install --enable-languages=c,c++ --enable-cheaders=c_std --disable-multilib

But it does not look like the c_std headers are currently working.
I've got symlinks to non-existing c_std header files:

  ccomplex
  cfenv
  cinttypes
  cstdalign
  cstdbool
  cstdint
  ctgmath

and c_std/cmath is missing the _GLIBCXX_USE_C99_FENV_TR1 stuff.
which I need, because my math.h supports that.

Once I fix these bugs the boot-strap seems to work.
Let's see if the libstdc++ testsuite has complaints.

Probably it will, there are many more differences
between c_global/cmath and c_std/cmath like:

-#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
-  inline _GLIBCXX_CONSTEXPR double
+  inline double
   abs(double __x)
   { return __builtin_fabs(__x); }
-#endif
 

but these dont make the boot-strap fail.
Comment 16 Bernd Edlinger 2016-02-21 20:24:51 UTC
> But it does not look like the c_std headers are currently working.
> I've got symlinks to non-existing c_std header files:
> 
>   ccomplex
>   cfenv
>   cinttypes
>   cstdalign
>   cstdbool
>   cstdint
>   ctgmath
> 
> and c_std/cmath is missing the _GLIBCXX_USE_C99_FENV_TR1 stuff.
> which I need, because my math.h supports that.
> 
> Once I fix these bugs the boot-strap seems to work.
> Let's see if the libstdc++ testsuite has complaints.
> 
> Probably it will, there are many more differences
> between c_global/cmath and c_std/cmath like:
> 
> -#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
> -  inline _GLIBCXX_CONSTEXPR double
> +  inline double
>    abs(double __x)
>    { return __builtin_fabs(__x); }
> -#endif
>  
> 
> but these dont make the boot-strap fail.

not too bad:

                === libstdc++ tests ===


Running target unix
FAIL: 17_intro/freestanding.cc (test for excess errors)
UNRESOLVED: 17_intro/freestanding.cc compilation failed to produce executable
FAIL: 17_intro/headers/c++1998/complex.cc (test for excess errors)
FAIL: 26_numerics/headers/cmath/14608.cc (test for excess errors)
FAIL: 26_numerics/headers/cmath/60401.cc (test for excess errors)
FAIL: 26_numerics/headers/cmath/c99_classification_macros_c++11.cc (test for excess errors)
FAIL: 26_numerics/headers/cmath/c99_classification_macros_c.cc (test for excess errors)
FAIL: 26_numerics/headers/cmath/dr550.cc (test for excess errors)
UNRESOLVED: 26_numerics/headers/cmath/dr550.cc compilation failed to produce executable
FAIL: 26_numerics/headers/cstdlib/60401.cc (test for excess errors)
FAIL: experimental/numeric/gcd.cc (test for excess errors)
FAIL: experimental/numeric/lcm.cc (test for excess errors)
FAIL: special_functions/01_assoc_laguerre/compile_2.cc (test for excess errors)
FAIL: special_functions/02_assoc_legendre/compile_2.cc (test for excess errors)
FAIL: special_functions/03_beta/compile_2.cc (test for excess errors)
FAIL: special_functions/04_comp_ellint_1/compile_2.cc (test for excess errors)
FAIL: special_functions/05_comp_ellint_2/compile_2.cc (test for excess errors)
FAIL: special_functions/06_comp_ellint_3/compile_2.cc (test for excess errors)
FAIL: special_functions/07_cyl_bessel_i/compile_2.cc (test for excess errors)
FAIL: special_functions/08_cyl_bessel_j/compile_2.cc (test for excess errors)
FAIL: special_functions/09_cyl_bessel_k/compile_2.cc (test for excess errors)
FAIL: special_functions/10_cyl_neumann/compile_2.cc (test for excess errors)
FAIL: special_functions/11_ellint_1/compile_2.cc (test for excess errors)
FAIL: special_functions/12_ellint_2/compile_2.cc (test for excess errors)
FAIL: special_functions/13_ellint_3/compile_2.cc (test for excess errors)
FAIL: special_functions/14_expint/compile_2.cc (test for excess errors)
FAIL: special_functions/15_hermite/compile_2.cc (test for excess errors)
FAIL: special_functions/16_laguerre/compile_2.cc (test for excess errors)
FAIL: special_functions/17_legendre/compile_2.cc (test for excess errors)
FAIL: special_functions/18_riemann_zeta/compile_2.cc (test for excess errors)
FAIL: special_functions/19_sph_bessel/compile_2.cc (test for excess errors)
FAIL: special_functions/20_sph_legendre/compile_2.cc (test for excess errors)
FAIL: special_functions/21_sph_neumann/compile_2.cc (test for excess errors)
FAIL: tr1/8_c_compatibility/cmath/overloads.cc (test for excess errors)

                === libstdc++ Summary ===

# of expected passes            10514
# of unexpected failures        32
# of expected failures          67
# of unresolved testcases       2
# of unsupported tests          540
Comment 17 Bernd Edlinger 2016-02-21 21:29:15 UTC
Created attachment 37749 [details]
prerequisite patch to make c_std headers compile

not perfect, but probably an improvement...
Comment 18 Jonathan Wakely 2016-02-22 11:19:03 UTC
(In reply to Bernd Edlinger from comment #13)
> (In reply to Jonathan Wakely from comment #12)
> > (In reply to Bernd Edlinger from comment #9)
> > > right now I am trying to boot-strap this:
> > > 
> > > Index: c/cstddef
> > > ===================================================================
> > > --- c/cstddef	(revision 233581)
> > > +++ c/cstddef	(working copy)
> > > @@ -31,10 +31,11 @@
> > >  
> > >  #pragma GCC system_header
> > >  
> > > -#define __need_size_t
> > > -#define __need_ptrdiff_t
> > > -#define __need_NULL
> > > -#define __need_offsetof
> > > +#undef __need_wchar_t
> > > +#undef __need_size_t
> > > +#undef __need_ptrdiff_t
> > > +#undef __need_NULL
> > > +#undef __need_wint_t
> > >  #include_next <stddef.h>
> > 
> > 
> > How do you plan to test this change? Do you have a target that uses this
> > header?
> > 
> 
> Yes, I do have such targets.
> We use eCos at Softing as real time O/S a lot.

Great, that's good to know.

> I think I will build an ecos cross compiler, did so last year with
> gcc-5.1, (and had quite a lot of trouble with the bugs in
> ecos headers)
> 
> ./gcc-5.1.0/configure --prefix=/home/ed/gnu/arm-eabi --target=arm-eabi
> --with-newlib --enable-languages=c,c++ --disable-hosted-libstdcxx
> --disable-__cxa-atexit --disable-libquadmath --disable-decimal-float
> 
> > 
> > >  #endif
> > > Index: c_global/cstddef
> > > ===================================================================
> > > --- c_global/cstddef	(revision 233581)
> > > +++ c_global/cstddef	(working copy)
> > > @@ -41,6 +41,11 @@
> > >  
> > >  #pragma GCC system_header
> > >  
> > > +#undef __need_wchar_t
> > > +#undef __need_size_t
> > > +#undef __need_ptrdiff_t
> > > +#undef __need_NULL
> > > +#undef __need_wint_t
> > >  #include <bits/c++config.h>
> > >  #include <stddef.h>
> > 
> > This isn't incorrect, but it should not be necessary. This macros are
> > internal implementation details of the standard library headers, and user
> > code (like GMP) should not be defining those macros. If GMP wants size_t it
> > should include <stddef.h> and if it wants std::size_t it should include
> > <cstddef>, and it should not try to play silly games to only get part of the
> > header.
> > 
> > 
> 
> Yeah, shit happens.
> Anyway boot-strap & reg-testing OK on x86_64-pc-linux-gnu.
> gcc-4.9 builds successfully (minus Ada, see pr69883 :()

I'm in two minds whether we should fix that shit in the library or not.

> > > Index: c_std/cstddef
> > > ===================================================================
> > > --- c_std/cstddef	(revision 233581)
> > > +++ c_std/cstddef	(working copy)
> > > @@ -41,6 +41,11 @@
> > >  
> > >  #pragma GCC system_header
> > >  
> > > +#undef __need_wchar_t
> > > +#undef __need_size_t
> > > +#undef __need_ptrdiff_t
> > > +#undef __need_NULL
> > > +#undef __need_wint_t
> > >  #include <bits/c++config.h>
> > >  #include <stddef.h>
> > 
> > How do you plan to test this?
> 
> no idea yet.
> under what condition is that header used?

For targets that choose to use it or with --enable-cheaders=c_std, but I don't know of any targets where that is the default or needed, so don't know how to test it. It is to be expected that you can't just use --enable-cheaders=c_std on a target where that isn't usually used (and I'm not surprised if those headers are also currently broken).


> Why does it only differ in the comment from the
> previous header?
> 
> why are the both files different?
> diff c_global/cstddef c_std/cstddef
> 26c26
> <  *  This is a Standard C++ Library file.  You should @c \#include this file
> ---
> >  *  This is a Standard C++ Library file.  You should @c #include this file
> 
> is this a mistake?


Maybe. It's only a comment, I'm not very concerned.
Comment 19 Bernd Edlinger 2016-02-22 11:46:23 UTC
(In reply to Jonathan Wakely from comment #18)
> > Yes, I do have such targets.
> > We use eCos at Softing as real time O/S a lot.
> 
> Great, that's good to know.
>
> > I think I will build an ecos cross compiler, did so last year with
> > gcc-5.1, (and had quite a lot of trouble with the bugs in
> > ecos headers)
> > 
> > ./gcc-5.1.0/configure --prefix=/home/ed/gnu/arm-eabi --target=arm-eabi
> > --with-newlib --enable-languages=c,c++ --disable-hosted-libstdcxx
> > --disable-__cxa-atexit --disable-libquadmath --disable-decimal-float
> > 

Actually when I look closely, it used c_global but w/o hosted-libstdcxx:

ed@w-ed:~/gnu/gcc-build-arm/arm-eabi/libstdc++-v3/include$ ls -ls cstddef
4 lrwxrwxrwx 1 ed ed 65 Feb 21 08:32 cstddef -> /home/ed/gnu/gcc-6-20160214/libs

So at the moment I am not sure how to test the c/stddef.

But I am sure that #define __need_offsetof can simply not work.

I am not sure if it can compile at all, because if I try
there are the same bogus symlinks to missing c/-headers.

But before the build reaches the point where that matters,
the cstdlib simply includes <stdlib.h> which fails to declare
std::abort.

Is this c/cstdlib intended for targets that have C++ aware stdlib.h?


> > > 
> > > >  #endif
> > > > Index: c_global/cstddef
> > > > ===================================================================
> > > > --- c_global/cstddef	(revision 233581)
> > > > +++ c_global/cstddef	(working copy)
> > > > @@ -41,6 +41,11 @@
> > > >  
> > > >  #pragma GCC system_header
> > > >  
> > > > +#undef __need_wchar_t
> > > > +#undef __need_size_t
> > > > +#undef __need_ptrdiff_t
> > > > +#undef __need_NULL
> > > > +#undef __need_wint_t
> > > >  #include <bits/c++config.h>
> > > >  #include <stddef.h>
> > > 
> > > This isn't incorrect, but it should not be necessary. This macros are
> > > internal implementation details of the standard library headers, and user
> > > code (like GMP) should not be defining those macros. If GMP wants size_t it
> > > should include <stddef.h> and if it wants std::size_t it should include
> > > <cstddef>, and it should not try to play silly games to only get part of the
> > > header.
> > > 
> > > 
> > 
> > Yeah, shit happens.
> > Anyway boot-strap & reg-testing OK on x86_64-pc-linux-gnu.
> > gcc-4.9 builds successfully (minus Ada, see pr69883 :()
> 
> I'm in two minds whether we should fix that shit in the library or not.
> 

When we leave it as it is, everyone will point with the finger
on us, because it looks like a gcc-bug.

Alternative would be to detect that any of the 6 known
__need_-defines are present when invoking cstddef and
give an explicit #error, but this mis-use worked previously.
Or maybe a #warning would be a compromise?

What do you think?

> 
> For targets that choose to use it or with --enable-cheaders=c_std, but I
> don't know of any targets where that is the default or needed, so don't know
> how to test it. It is to be expected that you can't just use
> --enable-cheaders=c_std on a target where that isn't usually used (and I'm
> not surprised if those headers are also currently broken).
> 

What I tried yesterday, that's probably worth fixing too.


Bernd.
Comment 20 Jonathan Wakely 2016-02-22 12:38:30 UTC
(In reply to Bernd Edlinger from comment #19)
> But I am sure that #define __need_offsetof can simply not work.

So don't define that. It's undefined behaviour.

> I am not sure if it can compile at all, because if I try
> there are the same bogus symlinks to missing c/-headers.
> 
> But before the build reaches the point where that matters,
> the cstdlib simply includes <stdlib.h> which fails to declare
> std::abort.
> 
> Is this c/cstdlib intended for targets that have C++ aware stdlib.h?

Yes.

> When we leave it as it is, everyone will point with the finger
> on us, because it looks like a gcc-bug.
> 
> Alternative would be to detect that any of the 6 known
> __need_-defines are present when invoking cstddef and
> give an explicit #error, but this mis-use worked previously.
> Or maybe a #warning would be a compromise?
> 
> What do you think?

I think if we do anything then I prefer your original suggestion to just #undef them.

But I'm not yet convinced we should do anything. This already failed with old versions of GCC:

// get size_t
#define __need_size_t
#include <cstddef>
// get everything else
#include <cstddef>
std::max_align_t m;
Comment 21 Bernd Edlinger 2016-02-22 12:59:22 UTC
(In reply to Jonathan Wakely from comment #20)
> (In reply to Bernd Edlinger from comment #19)
> > But I am sure that #define __need_offsetof can simply not work.
> 
> So don't define that. It's undefined behaviour.
> 


hmmm...

I am not sure it I tried to ride on a dead horse here...

Maybe I should just leave the c/* and c_std/* headers as they are.
I should just leave the attachment here, if some one has use for
c_std/* headers.


> > I am not sure if it can compile at all, because if I try
> > there are the same bogus symlinks to missing c/-headers.
> > 
> > But before the build reaches the point where that matters,
> > the cstdlib simply includes <stdlib.h> which fails to declare
> > std::abort.
> > 
> > Is this c/cstdlib intended for targets that have C++ aware stdlib.h?
> 
> Yes.
> 
> > When we leave it as it is, everyone will point with the finger
> > on us, because it looks like a gcc-bug.
> > 
> > Alternative would be to detect that any of the 6 known
> > __need_-defines are present when invoking cstddef and
> > give an explicit #error, but this mis-use worked previously.
> > Or maybe a #warning would be a compromise?
> > 
> > What do you think?
> 
> I think if we do anything then I prefer your original suggestion to just
> #undef them.
> 
> But I'm not yet convinced we should do anything. This already failed with
> old versions of GCC:
> 
> // get size_t
> #define __need_size_t
> #include <cstddef>
> // get everything else
> #include <cstddef>
> std::max_align_t m;

Yes, but I don't know how often I've boot-strapped gcc-4.9 already
and I never noticed anything of that undefined behaviour until now.

The problem is that header A can define __need_size_t, and include
the wrong system header file.  That leaks into header B
which includes <cstddef> and now we get a cryptic error,
while previously we just did not have the std::max_align_t,
which is also bad, if you need it but if you don't need it,
you will never know.


BTW: we have a similar problem with cstdarg:

#define __need___va_list
#include <cstdarg>

fails to compile.

and c/cstdarg has:
#undef __need___va_list
#include_next <stdarg.h>


I would like to add this to c_global/cstdarg:

 #pragma GCC system_header
 
+#ifdef __need___va_list
+#warning __need___va_list is not supported in cstdarg
+#undef __need___va_list
+#endif
 #include <bits/c++config.h>
 #include <stdarg.h>

that would be rather comfortable for the user.
Comment 22 Bernd Edlinger 2016-02-22 16:30:55 UTC
yes, I would really have liked the warning, but...

/../gcc-trunk/gcc/../libdecnumber/bid -I../libdecnumber -I../../gcc-trunk/gcc/../libbacktrace -I/home/ed/gnu/gcc-build/./isl/include -I/home/ed/gnu/gcc-trunk/isl/include  -o c/c-lang.o -MT c/c-lang.o -MMD -MP -MF c/.deps/c-lang.TPo ../../gcc-trunk/gcc/c/c-lang.c
In file included from /home/ed/gnu/gcc-build/./gmp/gmp.h:51:0,
                 from ../../gcc-trunk/gcc/system.h:669,
                 from ../../gcc-trunk/gcc/c/c-lang.c:22:
/home/ed/gnu/gcc-build/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/cstddef:53:2: error: #warning __need_size_t is not supported in cstddef [-Werror=cpp]
 #warning __need_size_t is not supported in cstddef
  ^~~~~~~
cc1plus: all warnings being treated as errors

...but it would force us to update all of gmp/mpfr/mpc immediately.

anyway that move is probably overdue now, but that should definitely
be on our gcc-7 to-do list.  Jakub?

BTW: From the gmp-6.1.0/ChangeLog I see:
2013-10-08  Marc Glisse  <marc.glisse@inria.fr>

        * doc/mdate-sh, doc/texinfo.tex, install-sh, missing, ylwrap: Remove.
        * .bootstrap: Use autoreconf (and in particular automake -a).

        * gmp-h.in: Remove __need_size_t. Include <stddef.h>, not <cstddef>.

        * tests/mpf/reuse.c (main): Use small numbers as exponents.
Comment 23 Bernd Edlinger 2016-02-23 15:57:41 UTC
Author: edlinger
Date: Tue Feb 23 15:57:09 2016
New Revision: 233636

URL: https://gcc.gnu.org/viewcvs?rev=233636&root=gcc&view=rev
Log:
2016-02-23  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        PR libstdc++/69881
        * include/c_global/cstdarg: Undefine __need___va_list.
        * include/c_global/cstddef: Undefine all kinds of __need_*.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/c_global/cstdarg
    trunk/libstdc++-v3/include/c_global/cstddef
Comment 24 Bernd Edlinger 2016-02-23 16:07:35 UTC
fixed.