gcc: update to allow compiling different versions
[feed/packages.git] / devel / gcc / patches / 11.2.0 / 980-add-nostdinc++.patch
1 From: Jonathan Wakely <jwakely@redhat.com>
2 Date: Fri, 7 Jan 2022 15:21:03 +0000 (+0000)
3 Subject: libstdc++: Add -nostdinc++ for c++17 sources [PR100017]
4 X-Git-Tag: releases/gcc-11.3.0~445
5 X-Git-Url: https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff_plain;h=01a70ccd723eb9a479186fe37c972b0d0f8676cf
6
7 libstdc++: Add -nostdinc++ for c++17 sources [PR100017]
8
9 When building a build!=host compiler, the just-built gcc can't be used
10 to build the target libstdc++ (because it is built for the host triplet,
11 not the build triplet). The top-level configure.ac sets up the build
12 flags for libstdc++ (and other "raw_cxx" libs) like this:
13
14 GCC_TARGET_TOOL(c++ for libstdc++, RAW_CXX_FOR_TARGET, CXX,
15 [gcc/xgcc -shared-libgcc -B$$r/$(HOST_SUBDIR)/gcc -nostdinc++ -L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src -L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src/.libs -L$$r/$(TARGET_SUBDIR)/libstdc++-v3/libsupc++/.libs],
16 c++)
17
18 The -nostdinc++ flag is only used for the IN-TREE-TOOL, i.e. when using
19 the just-built gcc/xgcc compiler. This means that the cross-compiler
20 used to build libstdc++ will add its own libstdc++ headers to the
21 include path. That results in the #include <cfenv> in
22 src/c++17/floating_to_chars.cc and src/c++17/floating_from_chars.cc
23 doing #include_next <fenv.h> and finding the libstdc++ fenv.h wrapper
24 from the host compiler. Because that has the same include guard as the
25 <fenv.h> in the libstdc++ we're trying to build, we never reach the
26 underlying <fenv.h> from libc. That results in several errors of the
27 form:
28
29 error: 'fenv_t' has not been declared in '::'
30
31 The most correct fix would be to add -nostdinc++ to the
32 RAW_CXX_FOR_TARGET variable in configure.ac, or the
33 RAW_CXX_TARGET_EXPORTS variable in Makefile.tpl.
34
35 Another solution would be to make the libstdc++ <fenv.h> wrapper use
36 _GLIBCXX_INCLUDE_NEXT_C_HEADERS like our <stdlib.h> and other C header
37 wrappers.
38
39 For now though, the simplest and safest solution is to just add
40 -nostdinc++ to the CXXFLAGS used for src/c++17/*.cc, which is what this
41 does.
42
43 libstdc++-v3/ChangeLog:
44
45 PR libstdc++/100017
46 * src/c++17/Makefile.am (AM_CXXFLAGS): Add -nostdinc++.
47 * src/c++17/Makefile.in: Regenerate.
48
49 (cherry picked from commit 4fde88e5dd152fe866a97b12e0f8229970d15cb3)
50 ---
51
52 --- a/libstdc++-v3/src/c++17/Makefile.am
53 +++ b/libstdc++-v3/src/c++17/Makefile.am
54 @@ -79,7 +79,7 @@ endif
55 # OPTIMIZE_CXXFLAGS on the compile line so that -O2 can be overridden
56 # as the occasion calls for it.
57 AM_CXXFLAGS = \
58 - -std=gnu++17 \
59 + -std=gnu++17 -nostdinc++ \
60 $(glibcxx_lt_pic_flag) $(glibcxx_compiler_shared_flag) \
61 $(XTEMPLATE_FLAGS) $(VTV_CXXFLAGS) \
62 $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) \
63 --- a/libstdc++-v3/src/c++17/Makefile.in
64 +++ b/libstdc++-v3/src/c++17/Makefile.in
65 @@ -455,7 +455,7 @@ libc__17convenience_la_SOURCES = $(sourc
66 # OPTIMIZE_CXXFLAGS on the compile line so that -O2 can be overridden
67 # as the occasion calls for it.
68 AM_CXXFLAGS = \
69 - -std=gnu++17 \
70 + -std=gnu++17 -nostdinc++ \
71 $(glibcxx_lt_pic_flag) $(glibcxx_compiler_shared_flag) \
72 $(XTEMPLATE_FLAGS) $(VTV_CXXFLAGS) \
73 $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS) \