Linux kernel -stable discussions
 help / color / mirror / Atom feed
* + headers-add-check-for-c-standard-version.patch added to mm-hotfixes-unstable branch
@ 2025-10-26 23:56 Andrew Morton
  2025-10-27  2:31 ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2025-10-26 23:56 UTC (permalink / raw)
  To: mm-commits, stable, kees, gustavoars, david.hunter.linux, arnd,
	hannelotta, akpm

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3217 bytes --]


The patch titled
     Subject: headers: add check for C standard version
has been added to the -mm mm-hotfixes-unstable branch.  Its filename is
     headers-add-check-for-c-standard-version.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/headers-add-check-for-c-standard-version.patch

This patch will later appear in the mm-hotfixes-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Hanne-Lotta Mäenpää <hannelotta@gmail.com>
Subject: headers: add check for C standard version
Date: Sun, 26 Oct 2025 21:58:46 +0200

Compiling the kernel with GCC 15 results in errors, as with GCC 15 the
default language version for C compilation has been changed from
-std=gnu17 to -std=gnu23 - unless the language version has been changed
using

    KBUILD_CFLAGS += -std=gnu17

or earlier.

C23 includes new keywords 'bool', 'true' and 'false', which cause
compilation errors in Linux headers:

    ./include/linux/types.h:30:33: error: `bool' cannot be defined
        via `typedef'

    ./include/linux/stddef.h:11:9: error: cannot use keyword `false'
        as enumeration constant

Add check for C Standard's version in the header files to be able to
compile the kernel with C23.

Link: https://lkml.kernel.org/r/20251026195846.69740-1-hannelotta@gmail.com
Signed-off-by: Hanne-Lotta Mäenpää <hannelotta@gmail.com>
Cc: David Hunter <david.hunter.linux@gmail.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Kees Cook <kees@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/stddef.h |    2 ++
 include/linux/types.h  |    2 ++
 2 files changed, 4 insertions(+)

--- a/include/linux/stddef.h~headers-add-check-for-c-standard-version
+++ a/include/linux/stddef.h
@@ -7,10 +7,12 @@
 #undef NULL
 #define NULL ((void *)0)
 
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
 enum {
 	false	= 0,
 	true	= 1
 };
+#endif
 
 #undef offsetof
 #define offsetof(TYPE, MEMBER)	__builtin_offsetof(TYPE, MEMBER)
--- a/include/linux/types.h~headers-add-check-for-c-standard-version
+++ a/include/linux/types.h
@@ -32,7 +32,9 @@ typedef __kernel_timer_t	timer_t;
 typedef __kernel_clockid_t	clockid_t;
 typedef __kernel_mqd_t		mqd_t;
 
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
 typedef _Bool			bool;
+#endif
 
 typedef __kernel_uid32_t	uid_t;
 typedef __kernel_gid32_t	gid_t;
_

Patches currently in -mm which might be from hannelotta@gmail.com are

headers-add-check-for-c-standard-version.patch


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

* Re: + headers-add-check-for-c-standard-version.patch added to mm-hotfixes-unstable branch
  2025-10-26 23:56 + headers-add-check-for-c-standard-version.patch added to mm-hotfixes-unstable branch Andrew Morton
@ 2025-10-27  2:31 ` Kees Cook
  2025-10-27  7:02   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2025-10-27  2:31 UTC (permalink / raw)
  To: Andrew Morton, mm-commits, stable, gustavoars, david.hunter.linux,
	arnd, hannelotta, akpm



On October 26, 2025 4:56:30 PM PDT, Andrew Morton <akpm@linux-foundation.org> wrote:
>
>The patch titled
>     Subject: headers: add check for C standard version
>has been added to the -mm mm-hotfixes-unstable branch.  Its filename is
>     headers-add-check-for-c-standard-version.patch
>
>This patch will shortly appear at
>     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/headers-add-check-for-c-standard-version.patch
>
>This patch will later appear in the mm-hotfixes-unstable branch at
>    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
>
>Before you just go and hit "reply", please:
>   a) Consider who else should be cc'ed
>   b) Prefer to cc a suitable mailing list as well
>   c) Ideally: find the original patch on the mailing list and do a
>      reply-to-all to that, adding suitable additional cc's
>
>*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
>
>The -mm tree is included into linux-next via the mm-everything
>branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
>and is updated there every 2-3 working days
>
>------------------------------------------------------
>From: Hanne-Lotta M��enp���� <hannelotta@gmail.com>
>Subject: headers: add check for C standard version
>Date: Sun, 26 Oct 2025 21:58:46 +0200
>
>Compiling the kernel with GCC 15 results in errors, as with GCC 15 the
>default language version for C compilation has been changed from
>-std=gnu17 to -std=gnu23 - unless the language version has been changed
>using
>
>    KBUILD_CFLAGS += -std=gnu17
>
>or earlier.
>
>C23 includes new keywords 'bool', 'true' and 'false', which cause
>compilation errors in Linux headers:
>
>    ./include/linux/types.h:30:33: error: `bool' cannot be defined
>        via `typedef'
>
>    ./include/linux/stddef.h:11:9: error: cannot use keyword `false'
>        as enumeration constant
>
>Add check for C Standard's version in the header files to be able to
>compile the kernel with C23.

What? These are internal headers, not UAPI. We build Linux with -std=gnu11. Let's not add meaningless version checks.

-Kees

>
>Link: https://lkml.kernel.org/r/20251026195846.69740-1-hannelotta@gmail.com
>Signed-off-by: Hanne-Lotta M��enp���� <hannelotta@gmail.com>
>Cc: David Hunter <david.hunter.linux@gmail.com>
>Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
>Cc: Kees Cook <kees@kernel.org>
>Cc: Arnd Bergmann <arnd@arndb.de>
>Cc: <stable@vger.kernel.org>
>Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
>---
>
> include/linux/stddef.h |    2 ++
> include/linux/types.h  |    2 ++
> 2 files changed, 4 insertions(+)
>
>--- a/include/linux/stddef.h~headers-add-check-for-c-standard-version
>+++ a/include/linux/stddef.h
>@@ -7,10 +7,12 @@
> #undef NULL
> #define NULL ((void *)0)
> 
>+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
> enum {
> 	false	= 0,
> 	true	= 1
> };
>+#endif
> 
> #undef offsetof
> #define offsetof(TYPE, MEMBER)	__builtin_offsetof(TYPE, MEMBER)
>--- a/include/linux/types.h~headers-add-check-for-c-standard-version
>+++ a/include/linux/types.h
>@@ -32,7 +32,9 @@ typedef __kernel_timer_t	timer_t;
> typedef __kernel_clockid_t	clockid_t;
> typedef __kernel_mqd_t		mqd_t;
> 
>+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
> typedef _Bool			bool;
>+#endif
> 
> typedef __kernel_uid32_t	uid_t;
> typedef __kernel_gid32_t	gid_t;
>_
>
>Patches currently in -mm which might be from hannelotta@gmail.com are
>
>headers-add-check-for-c-standard-version.patch
>

-- 
Kees Cook

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

* Re: + headers-add-check-for-c-standard-version.patch added to mm-hotfixes-unstable branch
  2025-10-27  2:31 ` Kees Cook
@ 2025-10-27  7:02   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2025-10-27  7:02 UTC (permalink / raw)
  To: Kees Cook, Andrew Morton, mm-commits, stable, Gustavo A. R. Silva,
	david.hunter.linux, hannelotta

On Mon, Oct 27, 2025, at 03:31, Kees Cook wrote:
> On October 26, 2025 4:56:30 PM PDT, Andrew Morton 
> <akpm@linux-foundation.org> wrote:

>>------------------------------------------------------
>>From: Hanne-Lotta M��enp���� <hannelotta@gmail.com>
>>Subject: headers: add check for C standard version
>>Date: Sun, 26 Oct 2025 21:58:46 +0200
>>
>>Compiling the kernel with GCC 15 results in errors, as with GCC 15 the
>>default language version for C compilation has been changed from
>>-std=gnu17 to -std=gnu23 - unless the language version has been changed
>>using
>>
>>    KBUILD_CFLAGS += -std=gnu17
>>
>>or earlier.
>>
>>C23 includes new keywords 'bool', 'true' and 'false', which cause
>>compilation errors in Linux headers:
>>
>>    ./include/linux/types.h:30:33: error: `bool' cannot be defined
>>        via `typedef'
>>
>>    ./include/linux/stddef.h:11:9: error: cannot use keyword `false'
>>        as enumeration constant
>>
>>Add check for C Standard's version in the header files to be able to
>>compile the kernel with C23.
>
> What? These are internal headers, not UAPI. We build Linux with 
> -std=gnu11. Let's not add meaningless version checks.

I have a similar patch in my own testing tree but in the end
decided not to send it because supporting std=gnu23 doesn't actually
add any features we want.

The next time we raise the compiler version from gcc-8 to anything
newer, we can change the version selection to use --std=gnu2x
unconditionally.

      Arnd

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

end of thread, other threads:[~2025-10-27  7:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-26 23:56 + headers-add-check-for-c-standard-version.patch added to mm-hotfixes-unstable branch Andrew Morton
2025-10-27  2:31 ` Kees Cook
2025-10-27  7:02   ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox