2021-03-08 08:48:40

by Valdis Klētnieks

[permalink] [raw]
Subject: [PATCH RESEND] 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.

Signed-off-by: Valdis Kletnieks <[email protected]>
Fixes: 27c287b41659 ("gcc-plugins: fix gcc 11 indigestion with plugins...")
---
diff --git a/scripts/gcc-plugins/Makefile b/scripts/gcc-plugins/Makefile
index b5487cce69e8..cc779973724a 100644
--- a/scripts/gcc-plugins/Makefile
+++ b/scripts/gcc-plugins/Makefile
@@ -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



2021-03-18 05:54:52

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc

On Mon, Mar 08, 2021 at 03:40:21AM -0500, Valdis Klētnieks wrote:
> 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

>
> Signed-off-by: Valdis Kletnieks <[email protected]>
> Fixes: 27c287b41659 ("gcc-plugins: fix gcc 11 indigestion with plugins...")
> ---
> diff --git a/scripts/gcc-plugins/Makefile b/scripts/gcc-plugins/Makefile
> index b5487cce69e8..cc779973724a 100644
> --- a/scripts/gcc-plugins/Makefile
> +++ b/scripts/gcc-plugins/Makefile
> @@ -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
>
>

--
Kees Cook

2021-03-18 06:03:52

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc

On Wed, 17 Mar 2021 22:52:56 -0700, Kees Cook said:
> On Mon, Mar 08, 2021 at 03:40:21AM -0500, Valdis Klētnieks wrote:
> > 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....


Attachments:
(No filename) (849.00 B)

2021-03-18 06:28:16

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc

On Thu, Mar 18, 2021 at 7:03 AM Valdis Klētnieks
<[email protected]> wrote:
>
> 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

2021-03-18 09:12:06

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc

On Thu, Mar 18, 2021 at 3:26 PM Miguel Ojeda
<[email protected]> wrote:
>
> On Thu, Mar 18, 2021 at 7:03 AM Valdis Klētnieks
> <[email protected]> wrote:
> >
> > 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


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.


--- a/scripts/gcc-plugins/Kconfig
+++ b/scripts/gcc-plugins/Kconfig
@@ -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++11
GCC_VERSION < 11 : -std=gnu++98




--
Best Regards
Masahiro Yamada

2021-03-18 11:43:29

by David Laight

[permalink] [raw]
Subject: RE: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc

From: Valdis Kletnieks
> Sent: 18 March 2021 06:02
>
> On Wed, 17 Mar 2021 22:52:56 -0700, Kees Cook said:
> > On Mon, Mar 08, 2021 at 03:40:21AM -0500, Valdis KlDtnieks wrote:
> > > 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..

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)

2021-03-18 11:48:48

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc

On Thu, 18 Mar 2021 18:07:28 +0900, Masahiro Yamada said:

> 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)

> 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++11
> GCC_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.


Attachments:
(No filename) (849.00 B)

2021-03-18 11:57:35

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc

On Thu, 18 Mar 2021 11:41:29 -0000, David Laight said:

> 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:
>> /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:

> 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.html

> The 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...



Attachments:
(No filename) (849.00 B)

2021-03-18 13:40:31

by David Laight

[permalink] [raw]
Subject: RE: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc

From: Valdis Kletnieks
> Sent: 18 March 2021 11:56
>
> On Thu, 18 Mar 2021 11:41:29 -0000, David Laight said:
>
> > 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:
> >> /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...
...

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)