gcc-plugins: avoid errors with -std=gnu++11 on old gcc
PATCH RESEND 1/1 gcc-plugins: avoid errors with -std=gnu++11 on old gcc
It turns out that older gcc (4.9 and 5.4) have gnu++11 support, but due to a gcc bug fixed in gcc6, throw errors during the build. The relevant gcc bug is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
Version the option based on what gcc we're using.
---
scripts/gcc-plugins/Makefile +4 -1
@@ -21,8 +21,11 @@ always-y += $(GCC_PLUGIN) GCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin) +# need gnu++11 for gcc 11, but 4.9 and 5.4 need gnu++98 +GCC_FLAVOR = $(call cc-ifversion, -ge, 1100, 11, 98) + plugin_cxxflags = -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \ - -I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++11 \ + -I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++$(GCC_FLAVOR) \ -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \ -ggdb -Wno-narrowing -Wno-unused-variable \ -Wno-format-diag
Quoted 5 lines · Valdis Klētnieks
It turns out that older gcc (4.9 and 5.4) have gnu++11 support, but due to a gcc bug fixed in gcc6, throw errors during the build. The relevant gcc bug is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
Version the option based on what gcc we're using.
Is there a better way to detect this than with version checking?
-Kees
Quoted 23 lines
Signed-off-by Valdis Kletnieks <[email protected]>Fixes 27c287b41659 ("gcc-plugins: fix gcc 11 indigestion with plugins...")---
scripts/gcc-plugins/Makefile +4
-1@@ -21,8 +21,11 @@ always-y += $(GCC_PLUGIN) GCC_PLUGINS_DIR = $(shell $(CC) -print-file-name=plugin) +# need gnu++11 for gcc 11, but 4.9 and 5.4 need gnu++98 +GCC_FLAVOR = $(call cc-ifversion, -ge, 1100, 11, 98) + plugin_cxxflags = -Wp,-MMD,$(depfile) $(KBUILD_HOSTCXXFLAGS) -fPIC \ - -I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++11 \ + -I $(GCC_PLUGINS_DIR)/include -I $(obj) -std=gnu++$(GCC_FLAVOR) \ -fno-rtti -fno-exceptions -fasynchronous-unwind-tables \ -ggdb -Wno-narrowing -Wno-unused-variable \ -Wno-format-diag
Signature · 1 line
Kees Cook
Quoted 8 lines · Kees Cook
Quoted 5 lines · Valdis KlÄ“tnieks
It turns out that older gcc (4.9 and 5.4) have gnu++11 support, but due to a gcc bug fixed in gcc6, throw errors during the build. The relevant gcc bug is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
Version the option based on what gcc we're using.
Is there a better way to detect this than with version checking?
Not really. gcc 11 needs --std=gnu++11 to build it. And although gcc4 and gcc5 *claim* to support it, there's a known bug, so we *can't* feed gnu++11 to them. We can check versions..
Or heave gcc-plugins over the side entirely..
Or declare that gcc6 is the minimum for building the kernel.
But if we support gcc4/5 *and* gcc11 to build gcc-plugins, we have to version-check.
(Unrelated - the patch has grown a merge conflict since I sent it, let me know if you want an updated one, or if it's OK as is....
Quoted 2 lines · Valdis Klētnieks
Or declare that gcc6 is the minimum for building the kernel.
Cc'ing some interested people in raising GCC's version for one reason or another, so that we put this as another one in the pile of reasons :-)
https://lore.kernel.org/lkml/CAHk-=wjgvt1Ei72BTrEH5fgfqykVH-AYt56-7yBT8Lcprj7bEg@mail.gmail.com/
Cheers,
Miguel
Quoted 6 lines · Miguel Ojeda
Quoted 2 lines · Valdis Klētnieks
Or declare that gcc6 is the minimum for building the kernel.
Quoted 8 lines
Cc'ing some interested people in raising GCC's version for one reason or another, so that we put this as another one in the pile of reasons :-)
https://lore.kernel.org/lkml/CAHk-=wjgvt1Ei72BTrEH5fgfqykVH-AYt56-7yBT8Lcprj7bEg@mail.gmail.com/
Cheers,
Miguel
Previously we were discussing raising the min GCC version 5.x, but not further at this point of time.
We can require GCC 6+ for building GCC plugins.
scripts/gcc-plugins/Kconfig +1 -2
@@ -8,7 +8,7 @@ config HAVE_GCC_PLUGINS menuconfig GCC_PLUGINS bool "GCC plugins" depends on HAVE_GCC_PLUGINS - depends on CC_IS_GCC + depends on CC_IS_GCC && GCC_VERSION >= 60000 depends on $(success,test -e $(shell,$(CC) -print-file-name=plugin)/include/plugin-version.h) default y
help
BTW, the commit message mentions that
the issues only happen on GCC 4 and 5, but the added code was:
GCC_FLAVOR = $(call cc-ifversion, -ge, 1100, 11, 98)
instead of
GCC_FLAVOR = $(call cc-ifversion, -ge, 600, 11, 98)
So, this patch is also requiring to cover two standards:
GCC_VERSION >= 11 : -std=gnu++11GCC_VERSION < 11 : -std=gnu++98
Signature · 2 lines
Best Regards Masahiro Yamada
From: Valdis Kletnieks
Quoted 8 lines
Sent: 18 March 2021 06:02
Quoted 5 lines · Kees Cook
Quoted 4 lines · Valdis KlDtnieks
It turns out that older gcc (4.9 and 5.4) have gnu++11 support, but due to a gcc bug fixed in gcc6, throw errors during the build. The relevant gcc bug is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Version the option based on what gcc we're using.
Is there a better way to detect this than with version checking?
Not really. gcc 11 needs --std=gnu++11 to build it. And although gcc4 and gcc5 *claim* to support it, there's a known bug, so we *can't* feed gnu++11 to them. We can check versions..
That gcc bug just implies you need a space after "xxx". That is easily fixable in the sources.
Is there another problem?
(Apart from the standards committee breaking everything again.)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 3 lines · Masahiro Yamada
We can require GCC 6+ for building GCC plugins.
+ depends on
CC_IS_GCC&&GCC_VERSION>= 60000
I'd be OK with that personally, but the question is whether any gcc 4.9 or 5.x users are using plugins. That's a bit above my pay grade. Kees? Do we have any data on that? (All I know is that there is at least one, because they tripped over the GCC bug that prompted the second patch)
Quoted 6 lines
BTW, the commit message mentions that
the issues only happen on GCC 4 and 5,
but the added code was:
GCC_FLAVOR= $(call cc-ifversion, -ge, 1100, 11, 98)
Quoted 8 lines
instead of
GCC_FLAVOR= $(call cc-ifversion, -ge, 600, 11, 98)So, this patch is also requiring to cover two standards:
GCC_VERSION>= 11 : -std=gnu++11GCC_VERSION< 11 : -std=gnu++98
I chose 1100 so that everything from 4.9 to 10 would keep getting handed gnu++98 the way they had been, and only change it for gcc11.
Quoted 2 lines · David Laight
That gcc bug just implies you need a space after "xxx". That is easily fixable in the sources.
It's not quite that simple.
In file included from /usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/tm.h:27,
from /usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gcc-plugin.h:31,
from /usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/plugin.h:23,
from scripts/gcc-plugins/gcc-common.h:9,
from scripts/gcc-plugins/latent_entropy_plugin.c:78:Quoted 1 line
Quoted 1 line
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/config/elfos.h:102:21: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
fprintf ((FILE), "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n",\
The problem isn't in a kernel source file... To quote an earlier message of mine:
Quoted 11 lines
It looks like it's not a kernel source tree issue, it's a g++ issue fixed in g++ 6 and later.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959
And it looks like there was an intent to backport it to 4.9 and 5.4:
https://gcc.gnu.org/legacy-ml/gcc-patches/2016-02/msg01409.htmlThe bugtracker doesn't show an equivalent for 69959 being closed against 4.9.x or 5.[56],
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63254 has a patch for one of the gcc-supplied files that tosses the warning, but that way lies madness...
From: Valdis Kletnieks
Quoted 14 lines
Sent: 18 March 2021 11:56
Quoted 2 lines · David Laight
That gcc bug just implies you need a space after "xxx". That is easily fixable in the sources.
It's not quite that simple.
In file included from /usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/tm.h:27, from /usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/gcc-plugin.h:31, from /usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/plugin.h:23, from scripts/gcc-plugins/gcc-common.h:9, from scripts/gcc-plugins/latent_entropy_plugin.c:78:
Quoted 5 lines
Quoted 1 line
Quoted 1 line
/usr/lib/gcc/x86_64-linux-gnu/5/plugin/include/config/elfos.h:102:21: warning: invalid suffix onliteral; C++11 requires a space between literal and string macro [-Wliteral-suffix]
fprintf ((FILE), "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n",\The problem isn't in a kernel source file...
...
Could you pass -Wno-literal-suffix on plugin builds?
Might be less faff than changing the -std=xxx' parameter.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)