linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc
@ 2021-03-08  8:40 Valdis Klētnieks
  2021-03-18  5:52 ` Kees Cook
  0 siblings, 1 reply; 9+ messages in thread
From: Valdis Klētnieks @ 2021-03-08  8:40 UTC (permalink / raw)
  To: Kees Cook, Josh Poimboeuf, Geert Uytterhoeven
  Cc: linux-hardening, Linux Kernel Mailing List

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 <valdis.kletnieks@vt.edu>
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



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc
  2021-03-08  8:40 [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc Valdis Klētnieks
@ 2021-03-18  5:52 ` Kees Cook
  2021-03-18  6:02   ` Valdis Klētnieks
  0 siblings, 1 reply; 9+ messages in thread
From: Kees Cook @ 2021-03-18  5:52 UTC (permalink / raw)
  To: Valdis Klētnieks
  Cc: Josh Poimboeuf, Geert Uytterhoeven, linux-hardening,
	Linux Kernel Mailing List

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 <valdis.kletnieks@vt.edu>
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc
  2021-03-18  5:52 ` Kees Cook
@ 2021-03-18  6:02   ` Valdis Klētnieks
  2021-03-18  6:26     ` Miguel Ojeda
  2021-03-18 11:41     ` David Laight
  0 siblings, 2 replies; 9+ messages in thread
From: Valdis Klētnieks @ 2021-03-18  6:02 UTC (permalink / raw)
  To: Kees Cook
  Cc: Josh Poimboeuf, Geert Uytterhoeven, linux-hardening,
	Linux Kernel Mailing List

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 979 bytes --]

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

[-- Attachment #2: Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc
  2021-03-18  6:02   ` Valdis Klētnieks
@ 2021-03-18  6:26     ` Miguel Ojeda
  2021-03-18  9:07       ` Masahiro Yamada
  2021-03-18 11:41     ` David Laight
  1 sibling, 1 reply; 9+ messages in thread
From: Miguel Ojeda @ 2021-03-18  6:26 UTC (permalink / raw)
  To: Valdis Klētnieks
  Cc: Kees Cook, Josh Poimboeuf, Geert Uytterhoeven, linux-hardening,
	Linux Kernel Mailing List, Nick Desaulniers, Joe Perches,
	Masahiro Yamada

On Thu, Mar 18, 2021 at 7:03 AM Valdis Klētnieks
<valdis.kletnieks@vt.edu> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc
  2021-03-18  6:26     ` Miguel Ojeda
@ 2021-03-18  9:07       ` Masahiro Yamada
  2021-03-18 11:47         ` Valdis Klētnieks
  0 siblings, 1 reply; 9+ messages in thread
From: Masahiro Yamada @ 2021-03-18  9:07 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Valdis Klētnieks, Kees Cook, Josh Poimboeuf,
	Geert Uytterhoeven, linux-hardening, Linux Kernel Mailing List,
	Nick Desaulniers, Joe Perches

On Thu, Mar 18, 2021 at 3:26 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, Mar 18, 2021 at 7:03 AM Valdis Klētnieks
> <valdis.kletnieks@vt.edu> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc
  2021-03-18  6:02   ` Valdis Klētnieks
  2021-03-18  6:26     ` Miguel Ojeda
@ 2021-03-18 11:41     ` David Laight
  2021-03-18 11:55       ` Valdis Klētnieks
  1 sibling, 1 reply; 9+ messages in thread
From: David Laight @ 2021-03-18 11:41 UTC (permalink / raw)
  To: 'Valdis Klētnieks', Kees Cook
  Cc: Josh Poimboeuf, Geert Uytterhoeven, linux-hardening,
	Linux Kernel Mailing List

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 KlD\x13tnieks 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)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc
  2021-03-18  9:07       ` Masahiro Yamada
@ 2021-03-18 11:47         ` Valdis Klētnieks
  0 siblings, 0 replies; 9+ messages in thread
From: Valdis Klētnieks @ 2021-03-18 11:47 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Miguel Ojeda, Kees Cook, Josh Poimboeuf, Geert Uytterhoeven,
	linux-hardening, Linux Kernel Mailing List, Nick Desaulniers,
	Joe Perches

[-- Attachment #1: Type: text/plain, Size: 963 bytes --]

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.

[-- Attachment #2: Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc
  2021-03-18 11:41     ` David Laight
@ 2021-03-18 11:55       ` Valdis Klētnieks
  2021-03-18 13:38         ` David Laight
  0 siblings, 1 reply; 9+ messages in thread
From: Valdis Klētnieks @ 2021-03-18 11:55 UTC (permalink / raw)
  To: David Laight
  Cc: Kees Cook, Josh Poimboeuf, Geert Uytterhoeven, linux-hardening,
	Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 1445 bytes --]

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



[-- Attachment #2: Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc
  2021-03-18 11:55       ` Valdis Klētnieks
@ 2021-03-18 13:38         ` David Laight
  0 siblings, 0 replies; 9+ messages in thread
From: David Laight @ 2021-03-18 13:38 UTC (permalink / raw)
  To: 'Valdis Klētnieks'
  Cc: Kees Cook, Josh Poimboeuf, Geert Uytterhoeven, linux-hardening,
	Linux Kernel Mailing List

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)


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-18 13:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08  8:40 [PATCH RESEND] gcc-plugins: avoid errors with -std=gnu++11 on old gcc Valdis Klētnieks
2021-03-18  5:52 ` Kees Cook
2021-03-18  6:02   ` Valdis Klētnieks
2021-03-18  6:26     ` Miguel Ojeda
2021-03-18  9:07       ` Masahiro Yamada
2021-03-18 11:47         ` Valdis Klētnieks
2021-03-18 11:41     ` David Laight
2021-03-18 11:55       ` Valdis Klētnieks
2021-03-18 13:38         ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).