All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] [v3] Kbuild: move to -std=gnu11
@ 2022-03-01 14:52 Arnd Bergmann
  2022-03-01 14:52 ` [PATCH 2/3] treewide: use -Wdeclaration-after-statement Arnd Bergmann
                   ` (5 more replies)
  0 siblings, 6 replies; 28+ messages in thread
From: Arnd Bergmann @ 2022-03-01 14:52 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Arnd Bergmann, Linus Torvalds, Marco Elver, Jani Nikula,
	David Sterba, Alex Shi, Nick Desaulniers, Miguel Ojeda,
	Mark Rutland, linux-kbuild, llvm, linux-doc, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

During a patch discussion, Linus brought up the option of changing
the C standard version from gnu89 to gnu99, which allows using variable
declaration inside of a for() loop. While the C99, C11 and later standards
introduce many other features, most of these are already available in
gnu89 as GNU extensions as well.

An earlier attempt to do this when gcc-5 started defaulting to
-std=gnu11 failed because at the time that caused warnings about
designated initializers with older compilers. Now that gcc-5.1 is
the minimum compiler version used for building kernels, that is no
longer a concern. Similarly, the behavior of 'inline' functions changes
between gnu89 using gnu_inline behavior and gnu11 using standard c99+
behavior, but this was taken care of by defining 'inline' to include
__attribute__((gnu_inline)) in order to allow building with clang a
while ago.

One minor issue that remains is an added gcc warning for shifts of
negative integers when building with -Wextra, which happens with the
'make W=1' option, as well as for three drivers in the kernel that always
enable -Wextra, but it was only observed with the i915 driver so far.
To be on the safe side, add -Wno-shift-negative-value to any -Wextra
in a Makefile.

Nathan Chancellor reported an additional -Wdeclaration-after-statement
warning that appears in a system header on arm, this still needs a
workaround.

The differences between gnu99, gnu11, gnu1x and gnu17 are fairly
minimal and mainly impact warnings at the -Wpedantic level that the
kernel never enables. Between these, gnu11 is the newest version
that is supported by all supported compiler versions, though it is
only the default on gcc-5, while all other supported versions of
gcc or clang default to gnu1x/gnu17.

Link: https://lore.kernel.org/lkml/CAHk-=wiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpcovt8fYbVFW3TA@mail.gmail.com/
Link: https://github.com/ClangBuiltLinux/linux/issues/1603
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Marco Elver <elver@google.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Acked-by: David Sterba <dsterba@suse.com>
Reviewed-by: Alex Shi <alexs@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: linux-kbuild@vger.kernel.org
Cc: llvm@lists.linux.dev
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
[v3]
 - split out USERCFLAGS to a separate patch
 - add -Wdeclaration-after-statement patch from Mark Rutland
 - leave out C17 reference
 - more rewording the descrption

[v2]
 - added -std=gnu11 back, rather than just relying on the default
 - minor changes to changelog text
---
 Documentation/process/programming-language.rst              | 6 +++---
 .../translations/it_IT/process/programming-language.rst     | 4 ++--
 .../translations/zh_CN/process/programming-language.rst     | 3 +--
 .../translations/zh_TW/process/programming-language.rst     | 3 +--
 Makefile                                                    | 4 ++--
 arch/arm64/kernel/vdso32/Makefile                           | 2 +-
 drivers/gpu/drm/i915/Makefile                               | 1 +
 drivers/staging/greybus/tools/Makefile                      | 3 ++-
 fs/btrfs/Makefile                                           | 1 +
 scripts/Makefile.extrawarn                                  | 1 +
 10 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/Documentation/process/programming-language.rst b/Documentation/process/programming-language.rst
index ec474a70a02f..5fc9160ca1fa 100644
--- a/Documentation/process/programming-language.rst
+++ b/Documentation/process/programming-language.rst
@@ -5,9 +5,9 @@ Programming Language
 
 The kernel is written in the C programming language [c-language]_.
 More precisely, the kernel is typically compiled with ``gcc`` [gcc]_
-under ``-std=gnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90
-(including some C99 features). ``clang`` [clang]_ is also supported, see
-docs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
+under ``-std=gnu11`` [gcc-c-dialect-options]_: the GNU dialect of ISO C11.
+``clang`` [clang]_ is also supported, see docs on
+:ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
 
 This dialect contains many extensions to the language [gnu-extensions]_,
 and many of them are used within the kernel as a matter of course.
diff --git a/Documentation/translations/it_IT/process/programming-language.rst b/Documentation/translations/it_IT/process/programming-language.rst
index 41db2598ce11..c1a9b481a6f9 100644
--- a/Documentation/translations/it_IT/process/programming-language.rst
+++ b/Documentation/translations/it_IT/process/programming-language.rst
@@ -10,8 +10,8 @@ Linguaggio di programmazione
 
 Il kernel è scritto nel linguaggio di programmazione C [it-c-language]_.
 Più precisamente, il kernel viene compilato con ``gcc`` [it-gcc]_ usando
-l'opzione ``-std=gnu89`` [it-gcc-c-dialect-options]_: il dialetto GNU
-dello standard ISO C90 (con l'aggiunta di alcune funzionalità da C99).
+l'opzione ``-std=gnu11`` [it-gcc-c-dialect-options]_: il dialetto GNU
+dello standard ISO C11.
 Linux supporta anche ``clang`` [it-clang]_, leggete la documentazione
 :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
 
diff --git a/Documentation/translations/zh_CN/process/programming-language.rst b/Documentation/translations/zh_CN/process/programming-language.rst
index 2a47a1d2ec20..fabdc338dbfb 100644
--- a/Documentation/translations/zh_CN/process/programming-language.rst
+++ b/Documentation/translations/zh_CN/process/programming-language.rst
@@ -9,8 +9,7 @@
 ============
 
 内核是用C语言 :ref:`c-language <cn_c-language>` 编写的。更准确地说,内核通常是用 :ref:`gcc <cn_gcc>`
-在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C90的 GNU 方言(
-包括一些C99特性)
+在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C11的 GNU 方言
 
 这种方言包含对语言 :ref:`gnu-extensions <cn_gnu-extensions>` 的许多扩展,当然,它们许多都在内核中使用。
 
diff --git a/Documentation/translations/zh_TW/process/programming-language.rst b/Documentation/translations/zh_TW/process/programming-language.rst
index 54e3699eadf8..144bdaf81a41 100644
--- a/Documentation/translations/zh_TW/process/programming-language.rst
+++ b/Documentation/translations/zh_TW/process/programming-language.rst
@@ -12,8 +12,7 @@
 ============
 
 內核是用C語言 :ref:`c-language <tw_c-language>` 編寫的。更準確地說,內核通常是用 :ref:`gcc <tw_gcc>`
-在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C90的 GNU 方言(
-包括一些C99特性)
+在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C11的 GNU 方言
 
 這種方言包含對語言 :ref:`gnu-extensions <tw_gnu-extensions>` 的許多擴展,當然,它們許多都在內核中使用。
 
diff --git a/Makefile b/Makefile
index 289ce2be8032..94fa9a849a7a 100644
--- a/Makefile
+++ b/Makefile
@@ -515,7 +515,7 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
 		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
 		   -Werror=implicit-function-declaration -Werror=implicit-int \
 		   -Werror=return-type -Wno-format-security \
-		   -std=gnu89
+		   -std=gnu11
 KBUILD_CPPFLAGS := -D__KERNEL__
 KBUILD_AFLAGS_KERNEL :=
 KBUILD_CFLAGS_KERNEL :=
@@ -782,7 +782,7 @@ KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
 
 ifdef CONFIG_CC_IS_CLANG
 KBUILD_CPPFLAGS += -Qunused-arguments
-# The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable.
+# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
 KBUILD_CFLAGS += -Wno-gnu
 # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
 # source of a reference will be _MergedGlobals and not on of the whitelisted names.
diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
index 6c01b63ff56d..9378ea055bf2 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -68,7 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                -fno-strict-aliasing -fno-common \
                -Werror-implicit-function-declaration \
                -Wno-format-security \
-               -std=gnu89
+               -std=gnu11
 VDSO_CFLAGS  += -O2
 # Some useful compiler-dependent flags from top-level Makefile
 VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
index 1b62b9f65196..1618a6e0af4e 100644
--- a/drivers/gpu/drm/i915/Makefile
+++ b/drivers/gpu/drm/i915/Makefile
@@ -17,6 +17,7 @@ subdir-ccflags-y += -Wno-unused-parameter
 subdir-ccflags-y += -Wno-type-limits
 subdir-ccflags-y += -Wno-missing-field-initializers
 subdir-ccflags-y += -Wno-sign-compare
+subdir-ccflags-y += -Wno-shift-negative-value
 subdir-ccflags-y += $(call cc-disable-warning, unused-but-set-variable)
 subdir-ccflags-y += $(call cc-disable-warning, frame-address)
 subdir-ccflags-$(CONFIG_DRM_I915_WERROR) += -Werror
diff --git a/drivers/staging/greybus/tools/Makefile b/drivers/staging/greybus/tools/Makefile
index ad0ae8053b79..a3bbd73171f2 100644
--- a/drivers/staging/greybus/tools/Makefile
+++ b/drivers/staging/greybus/tools/Makefile
@@ -12,7 +12,8 @@ CFLAGS	+= -std=gnu99 -Wall -Wextra -g \
 	    -Wredundant-decls \
 	    -Wcast-align \
 	    -Wsign-compare \
-	    -Wno-missing-field-initializers
+	    -Wno-missing-field-initializers \
+	    -Wno-shift-negative-value
 
 CC	:= $(CROSS_COMPILE)gcc
 
diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
index 4188ba3fd8c3..99f9995670ea 100644
--- a/fs/btrfs/Makefile
+++ b/fs/btrfs/Makefile
@@ -17,6 +17,7 @@ subdir-ccflags-y += $(condflags)
 subdir-ccflags-y += -Wno-missing-field-initializers
 subdir-ccflags-y += -Wno-sign-compare
 subdir-ccflags-y += -Wno-type-limits
+subdir-ccflags-y += -Wno-shift-negative-value
 
 obj-$(CONFIG_BTRFS_FS) := btrfs.o
 
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 8be892887d71..650d0b8ceec3 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -36,6 +36,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
 KBUILD_CFLAGS += -Wno-missing-field-initializers
 KBUILD_CFLAGS += -Wno-sign-compare
 KBUILD_CFLAGS += -Wno-type-limits
+KBUILD_CFLAGS += -Wno-shift-negative-value
 
 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
 
-- 
2.29.2


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

* [PATCH 2/3] treewide: use -Wdeclaration-after-statement
  2022-03-01 14:52 [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Arnd Bergmann
@ 2022-03-01 14:52 ` Arnd Bergmann
  2022-03-01 16:54   ` Nathan Chancellor
                     ` (3 more replies)
  2022-03-01 14:52 ` [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS Arnd Bergmann
                   ` (4 subsequent siblings)
  5 siblings, 4 replies; 28+ messages in thread
From: Arnd Bergmann @ 2022-03-01 14:52 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Arnd Bergmann, Linus Torvalds, Marco Elver, Jani Nikula,
	David Sterba, Alex Shi, Nick Desaulniers, Miguel Ojeda,
	Mark Rutland, linux-kbuild, llvm, linux-doc, linux-kernel

From: Mark Rutland <mark.rutland@arm.com>

In a subsequent patch we'll move the kernel from using `-std=gnu89` to
`-std=gnu11`, permitting the use of additional C11 features such as
for-loop initial declarations.

One contentious aspect of C99 is that it permits mixed declarations and
code, and for now at least, it seems preferable to enforce that
declarations must come first.

These warnings were already disabled in the kernel itself, but not
for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
a separate set of CFLAGS.

This patch fixes an existing violation in modpost.c, which is not
reported because of the missing flag in KBUILD_USERCFLAGS:

| scripts/mod/modpost.c: In function ‘match’:
| scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
|   837 |   const char *endp = p + strlen(p) - 1;
|       |   ^~~~~

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
[arnd: don't add a duplicate flag to the default set, update changelog]
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 Makefile                          | 3 ++-
 arch/arm64/kernel/vdso32/Makefile | 1 +
 scripts/mod/modpost.c             | 4 +++-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 94fa9a849a7a..37ef6a555dcd 100644
--- a/Makefile
+++ b/Makefile
@@ -432,7 +432,8 @@ HOSTCXX	= g++
 endif
 
 export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
-			      -O2 -fomit-frame-pointer -std=gnu89
+			    -O2 -fomit-frame-pointer -std=gnu89 \
+			    -Wdeclaration-after-statement
 export KBUILD_USERLDFLAGS :=
 
 KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
index 9378ea055bf2..ed181bedbffc 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                -fno-strict-aliasing -fno-common \
                -Werror-implicit-function-declaration \
                -Wno-format-security \
+               -Wdeclaration-after-statement \
                -std=gnu11
 VDSO_CFLAGS  += -O2
 # Some useful compiler-dependent flags from top-level Makefile
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 6bfa33217914..fe693304b120 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
 {
 	const char *p;
 	while (*pat) {
+		const char *endp;
+
 		p = *pat++;
-		const char *endp = p + strlen(p) - 1;
+		endp = p + strlen(p) - 1;
 
 		/* "*foo*" */
 		if (*p == '*' && *endp == '*') {
-- 
2.29.2


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

* [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-01 14:52 [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Arnd Bergmann
  2022-03-01 14:52 ` [PATCH 2/3] treewide: use -Wdeclaration-after-statement Arnd Bergmann
@ 2022-03-01 14:52 ` Arnd Bergmann
  2022-03-01 17:00   ` Nathan Chancellor
                     ` (2 more replies)
  2022-03-01 16:53 ` [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Nathan Chancellor
                   ` (3 subsequent siblings)
  5 siblings, 3 replies; 28+ messages in thread
From: Arnd Bergmann @ 2022-03-01 14:52 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Arnd Bergmann, Linus Torvalds, Marco Elver, Jani Nikula,
	David Sterba, Alex Shi, Nick Desaulniers, Miguel Ojeda,
	Mark Rutland, linux-kbuild, llvm, linux-doc, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

As we change the C language standard for the kernel from gnu89 to
gnu11, it makes sense to also update the version for user space
compilation.

Some users have older native compilers than what they use for
kernel builds, so I considered using gnu99 as the default version
for wider compatibility with gcc-4.6 and earlier.

However, testing with older compilers showed that we already require
HOSTCC version 5.1 as well because a lot of host tools include
linux/compiler.h that uses __has_attribute():

  CC      tools/objtool/exec-cmd.o
In file included from tools/include/linux/compiler_types.h:36:0,
                 from tools/include/linux/compiler.h:5,
                 from exec-cmd.c:2:
tools/include/linux/compiler-gcc.h:19:5: error: "__has_attribute" is not defined [-Werror=undef]

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 37ef6a555dcd..7c9be7f1ccd4 100644
--- a/Makefile
+++ b/Makefile
@@ -432,7 +432,7 @@ HOSTCXX	= g++
 endif
 
 export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
-			    -O2 -fomit-frame-pointer -std=gnu89 \
+			    -O2 -fomit-frame-pointer -std=gnu11 \
 			    -Wdeclaration-after-statement
 export KBUILD_USERLDFLAGS :=
 
-- 
2.29.2


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

* Re: [PATCH 1/3] [v3] Kbuild: move to -std=gnu11
  2022-03-01 14:52 [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Arnd Bergmann
  2022-03-01 14:52 ` [PATCH 2/3] treewide: use -Wdeclaration-after-statement Arnd Bergmann
  2022-03-01 14:52 ` [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS Arnd Bergmann
@ 2022-03-01 16:53 ` Nathan Chancellor
  2022-03-04  5:03   ` Masahiro Yamada
  2022-03-04 11:24 ` Sedat Dilek
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 28+ messages in thread
From: Nathan Chancellor @ 2022-03-01 16:53 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Tue, Mar 01, 2022 at 03:52:31PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> During a patch discussion, Linus brought up the option of changing
> the C standard version from gnu89 to gnu99, which allows using variable
> declaration inside of a for() loop. While the C99, C11 and later standards
> introduce many other features, most of these are already available in
> gnu89 as GNU extensions as well.
> 
> An earlier attempt to do this when gcc-5 started defaulting to
> -std=gnu11 failed because at the time that caused warnings about
> designated initializers with older compilers. Now that gcc-5.1 is
> the minimum compiler version used for building kernels, that is no
> longer a concern. Similarly, the behavior of 'inline' functions changes
> between gnu89 using gnu_inline behavior and gnu11 using standard c99+
> behavior, but this was taken care of by defining 'inline' to include
> __attribute__((gnu_inline)) in order to allow building with clang a
> while ago.
> 
> One minor issue that remains is an added gcc warning for shifts of
> negative integers when building with -Wextra, which happens with the
> 'make W=1' option, as well as for three drivers in the kernel that always
> enable -Wextra, but it was only observed with the i915 driver so far.
> To be on the safe side, add -Wno-shift-negative-value to any -Wextra
> in a Makefile.
> 
> Nathan Chancellor reported an additional -Wdeclaration-after-statement
> warning that appears in a system header on arm, this still needs a
> workaround.
> 
> The differences between gnu99, gnu11, gnu1x and gnu17 are fairly
> minimal and mainly impact warnings at the -Wpedantic level that the
> kernel never enables. Between these, gnu11 is the newest version
> that is supported by all supported compiler versions, though it is
> only the default on gcc-5, while all other supported versions of
> gcc or clang default to gnu1x/gnu17.
> 
> Link: https://lore.kernel.org/lkml/CAHk-=wiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpcovt8fYbVFW3TA@mail.gmail.com/
> Link: https://github.com/ClangBuiltLinux/linux/issues/1603
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Acked-by: Marco Elver <elver@google.com>
> Acked-by: Jani Nikula <jani.nikula@intel.com>
> Acked-by: David Sterba <dsterba@suse.com>
> Reviewed-by: Alex Shi <alexs@kernel.org>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-kbuild@vger.kernel.org
> Cc: llvm@lists.linux.dev
> Cc: linux-doc@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

One comment below.

> ---
> [v3]
>  - split out USERCFLAGS to a separate patch
>  - add -Wdeclaration-after-statement patch from Mark Rutland
>  - leave out C17 reference
>  - more rewording the descrption
> 
> [v2]
>  - added -std=gnu11 back, rather than just relying on the default
>  - minor changes to changelog text
> ---
>  Documentation/process/programming-language.rst              | 6 +++---
>  .../translations/it_IT/process/programming-language.rst     | 4 ++--
>  .../translations/zh_CN/process/programming-language.rst     | 3 +--
>  .../translations/zh_TW/process/programming-language.rst     | 3 +--
>  Makefile                                                    | 4 ++--
>  arch/arm64/kernel/vdso32/Makefile                           | 2 +-
>  drivers/gpu/drm/i915/Makefile                               | 1 +
>  drivers/staging/greybus/tools/Makefile                      | 3 ++-
>  fs/btrfs/Makefile                                           | 1 +
>  scripts/Makefile.extrawarn                                  | 1 +
>  10 files changed, 15 insertions(+), 13 deletions(-)
> 
> diff --git a/Documentation/process/programming-language.rst b/Documentation/process/programming-language.rst
> index ec474a70a02f..5fc9160ca1fa 100644
> --- a/Documentation/process/programming-language.rst
> +++ b/Documentation/process/programming-language.rst
> @@ -5,9 +5,9 @@ Programming Language
>  
>  The kernel is written in the C programming language [c-language]_.
>  More precisely, the kernel is typically compiled with ``gcc`` [gcc]_
> -under ``-std=gnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90
> -(including some C99 features). ``clang`` [clang]_ is also supported, see
> -docs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> +under ``-std=gnu11`` [gcc-c-dialect-options]_: the GNU dialect of ISO C11.
> +``clang`` [clang]_ is also supported, see docs on
> +:ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
>  
>  This dialect contains many extensions to the language [gnu-extensions]_,
>  and many of them are used within the kernel as a matter of course.
> diff --git a/Documentation/translations/it_IT/process/programming-language.rst b/Documentation/translations/it_IT/process/programming-language.rst
> index 41db2598ce11..c1a9b481a6f9 100644
> --- a/Documentation/translations/it_IT/process/programming-language.rst
> +++ b/Documentation/translations/it_IT/process/programming-language.rst
> @@ -10,8 +10,8 @@ Linguaggio di programmazione
>  
>  Il kernel è scritto nel linguaggio di programmazione C [it-c-language]_.
>  Più precisamente, il kernel viene compilato con ``gcc`` [it-gcc]_ usando
> -l'opzione ``-std=gnu89`` [it-gcc-c-dialect-options]_: il dialetto GNU
> -dello standard ISO C90 (con l'aggiunta di alcune funzionalità da C99).
> +l'opzione ``-std=gnu11`` [it-gcc-c-dialect-options]_: il dialetto GNU
> +dello standard ISO C11.
>  Linux supporta anche ``clang`` [it-clang]_, leggete la documentazione
>  :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
>  
> diff --git a/Documentation/translations/zh_CN/process/programming-language.rst b/Documentation/translations/zh_CN/process/programming-language.rst
> index 2a47a1d2ec20..fabdc338dbfb 100644
> --- a/Documentation/translations/zh_CN/process/programming-language.rst
> +++ b/Documentation/translations/zh_CN/process/programming-language.rst
> @@ -9,8 +9,7 @@
>  ============
>  
>  内核是用C语言 :ref:`c-language <cn_c-language>` 编写的。更准确地说,内核通常是用 :ref:`gcc <cn_gcc>`
> -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C90的 GNU 方言(
> -包括一些C99特性)
> +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C11的 GNU 方言
>  
>  这种方言包含对语言 :ref:`gnu-extensions <cn_gnu-extensions>` 的许多扩展,当然,它们许多都在内核中使用。
>  
> diff --git a/Documentation/translations/zh_TW/process/programming-language.rst b/Documentation/translations/zh_TW/process/programming-language.rst
> index 54e3699eadf8..144bdaf81a41 100644
> --- a/Documentation/translations/zh_TW/process/programming-language.rst
> +++ b/Documentation/translations/zh_TW/process/programming-language.rst
> @@ -12,8 +12,7 @@
>  ============
>  
>  內核是用C語言 :ref:`c-language <tw_c-language>` 編寫的。更準確地說,內核通常是用 :ref:`gcc <tw_gcc>`
> -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C90的 GNU 方言(
> -包括一些C99特性)
> +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C11的 GNU 方言
>  
>  這種方言包含對語言 :ref:`gnu-extensions <tw_gnu-extensions>` 的許多擴展,當然,它們許多都在內核中使用。
>  
> diff --git a/Makefile b/Makefile
> index 289ce2be8032..94fa9a849a7a 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -515,7 +515,7 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
>  		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
>  		   -Werror=implicit-function-declaration -Werror=implicit-int \
>  		   -Werror=return-type -Wno-format-security \
> -		   -std=gnu89
> +		   -std=gnu11
>  KBUILD_CPPFLAGS := -D__KERNEL__
>  KBUILD_AFLAGS_KERNEL :=
>  KBUILD_CFLAGS_KERNEL :=
> @@ -782,7 +782,7 @@ KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
>  
>  ifdef CONFIG_CC_IS_CLANG
>  KBUILD_CPPFLAGS += -Qunused-arguments
> -# The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable.
> +# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
>  KBUILD_CFLAGS += -Wno-gnu
>  # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
>  # source of a reference will be _MergedGlobals and not on of the whitelisted names.
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 6c01b63ff56d..9378ea055bf2 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,7 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> -               -std=gnu89
> +               -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
>  VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
> diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
> index 1b62b9f65196..1618a6e0af4e 100644
> --- a/drivers/gpu/drm/i915/Makefile
> +++ b/drivers/gpu/drm/i915/Makefile
> @@ -17,6 +17,7 @@ subdir-ccflags-y += -Wno-unused-parameter
>  subdir-ccflags-y += -Wno-type-limits
>  subdir-ccflags-y += -Wno-missing-field-initializers
>  subdir-ccflags-y += -Wno-sign-compare
> +subdir-ccflags-y += -Wno-shift-negative-value
>  subdir-ccflags-y += $(call cc-disable-warning, unused-but-set-variable)
>  subdir-ccflags-y += $(call cc-disable-warning, frame-address)
>  subdir-ccflags-$(CONFIG_DRM_I915_WERROR) += -Werror
> diff --git a/drivers/staging/greybus/tools/Makefile b/drivers/staging/greybus/tools/Makefile
> index ad0ae8053b79..a3bbd73171f2 100644
> --- a/drivers/staging/greybus/tools/Makefile
> +++ b/drivers/staging/greybus/tools/Makefile
> @@ -12,7 +12,8 @@ CFLAGS	+= -std=gnu99 -Wall -Wextra -g \
>  	    -Wredundant-decls \
>  	    -Wcast-align \
>  	    -Wsign-compare \
> -	    -Wno-missing-field-initializers
> +	    -Wno-missing-field-initializers \
> +	    -Wno-shift-negative-value

This Makefile uses its own -std= option because it is a userland tool.
Seems like this hunk could just be dropped or the -std= argument could
be bumped here too?

>  CC	:= $(CROSS_COMPILE)gcc
>  
> diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
> index 4188ba3fd8c3..99f9995670ea 100644
> --- a/fs/btrfs/Makefile
> +++ b/fs/btrfs/Makefile
> @@ -17,6 +17,7 @@ subdir-ccflags-y += $(condflags)
>  subdir-ccflags-y += -Wno-missing-field-initializers
>  subdir-ccflags-y += -Wno-sign-compare
>  subdir-ccflags-y += -Wno-type-limits
> +subdir-ccflags-y += -Wno-shift-negative-value
>  
>  obj-$(CONFIG_BTRFS_FS) := btrfs.o
>  
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 8be892887d71..650d0b8ceec3 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -36,6 +36,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
>  KBUILD_CFLAGS += -Wno-missing-field-initializers
>  KBUILD_CFLAGS += -Wno-sign-compare
>  KBUILD_CFLAGS += -Wno-type-limits
> +KBUILD_CFLAGS += -Wno-shift-negative-value
>  
>  KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
>  
> -- 
> 2.29.2
> 
> 

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

* Re: [PATCH 2/3] treewide: use -Wdeclaration-after-statement
  2022-03-01 14:52 ` [PATCH 2/3] treewide: use -Wdeclaration-after-statement Arnd Bergmann
@ 2022-03-01 16:54   ` Nathan Chancellor
  2022-03-01 19:57   ` Nick Desaulniers
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 28+ messages in thread
From: Nathan Chancellor @ 2022-03-01 16:54 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Tue, Mar 01, 2022 at 03:52:32PM +0100, Arnd Bergmann wrote:
> From: Mark Rutland <mark.rutland@arm.com>
> 
> In a subsequent patch we'll move the kernel from using `-std=gnu89` to
> `-std=gnu11`, permitting the use of additional C11 features such as
> for-loop initial declarations.
> 
> One contentious aspect of C99 is that it permits mixed declarations and
> code, and for now at least, it seems preferable to enforce that
> declarations must come first.
> 
> These warnings were already disabled in the kernel itself, but not
> for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
> a separate set of CFLAGS.
> 
> This patch fixes an existing violation in modpost.c, which is not
> reported because of the missing flag in KBUILD_USERCFLAGS:
> 
> | scripts/mod/modpost.c: In function ‘match’:
> | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
> |   837 |   const char *endp = p + strlen(p) - 1;
> |       |   ^~~~~
> 
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> [arnd: don't add a duplicate flag to the default set, update changelog]
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  Makefile                          | 3 ++-
>  arch/arm64/kernel/vdso32/Makefile | 1 +
>  scripts/mod/modpost.c             | 4 +++-
>  3 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 94fa9a849a7a..37ef6a555dcd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,8 @@ HOSTCXX	= g++
>  endif
>  
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -			      -O2 -fomit-frame-pointer -std=gnu89
> +			    -O2 -fomit-frame-pointer -std=gnu89 \
> +			    -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>  
>  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 9378ea055bf2..ed181bedbffc 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> +               -Wdeclaration-after-statement \
>                 -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6bfa33217914..fe693304b120 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
>  {
>  	const char *p;
>  	while (*pat) {
> +		const char *endp;
> +
>  		p = *pat++;
> -		const char *endp = p + strlen(p) - 1;
> +		endp = p + strlen(p) - 1;
>  
>  		/* "*foo*" */
>  		if (*p == '*' && *endp == '*') {
> -- 
> 2.29.2
> 
> 

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-01 14:52 ` [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS Arnd Bergmann
@ 2022-03-01 17:00   ` Nathan Chancellor
  2022-03-01 19:56   ` Nick Desaulniers
  2022-03-02 22:14   ` Sedat Dilek
  2 siblings, 0 replies; 28+ messages in thread
From: Nathan Chancellor @ 2022-03-01 17:00 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Tue, Mar 01, 2022 at 03:52:33PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> As we change the C language standard for the kernel from gnu89 to
> gnu11, it makes sense to also update the version for user space
> compilation.
> 
> Some users have older native compilers than what they use for
> kernel builds, so I considered using gnu99 as the default version
> for wider compatibility with gcc-4.6 and earlier.
> 
> However, testing with older compilers showed that we already require
> HOSTCC version 5.1 as well because a lot of host tools include
> linux/compiler.h that uses __has_attribute():
> 
>   CC      tools/objtool/exec-cmd.o
> In file included from tools/include/linux/compiler_types.h:36:0,
>                  from tools/include/linux/compiler.h:5,
>                  from exec-cmd.c:2:
> tools/include/linux/compiler-gcc.h:19:5: error: "__has_attribute" is not defined [-Werror=undef]

For what it's worth, I think this is a bug:

https://lore.kernel.org/r/c1b1a299-c60d-28a4-07ab-1ecd211d6da9@i-love.sakura.ne.jp/
https://lore.kernel.org/r/20220102120201.594408-1-xu.xin16@zte.com.cn/

I never got clear feedback on resolving it from the first thread and
nobody bothered to pick up the second patch.

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Nobody has yelled that loud though, so this is probably fine.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 37ef6a555dcd..7c9be7f1ccd4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,7 @@ HOSTCXX	= g++
>  endif
>  
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -			    -O2 -fomit-frame-pointer -std=gnu89 \
> +			    -O2 -fomit-frame-pointer -std=gnu11 \
>  			    -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>  
> -- 
> 2.29.2
> 
> 

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-01 14:52 ` [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS Arnd Bergmann
  2022-03-01 17:00   ` Nathan Chancellor
@ 2022-03-01 19:56   ` Nick Desaulniers
  2022-03-02 22:14   ` Sedat Dilek
  2 siblings, 0 replies; 28+ messages in thread
From: Nick Desaulniers @ 2022-03-01 19:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Miguel Ojeda, Mark Rutland,
	linux-kbuild, llvm, linux-doc, linux-kernel

On Tue, Mar 1, 2022 at 6:52 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> As we change the C language standard for the kernel from gnu89 to
> gnu11, it makes sense to also update the version for user space
> compilation.
>
> Some users have older native compilers than what they use for
> kernel builds, so I considered using gnu99 as the default version
> for wider compatibility with gcc-4.6 and earlier.
>
> However, testing with older compilers showed that we already require
> HOSTCC version 5.1 as well because a lot of host tools include
> linux/compiler.h that uses __has_attribute():
>
>   CC      tools/objtool/exec-cmd.o
> In file included from tools/include/linux/compiler_types.h:36:0,
>                  from tools/include/linux/compiler.h:5,
>                  from exec-cmd.c:2:
> tools/include/linux/compiler-gcc.h:19:5: error: "__has_attribute" is not defined [-Werror=undef]
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks for the patches!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index 37ef6a555dcd..7c9be7f1ccd4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,7 @@ HOSTCXX     = g++
>  endif
>
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -                           -O2 -fomit-frame-pointer -std=gnu89 \
> +                           -O2 -fomit-frame-pointer -std=gnu11 \
>                             -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>
> --
> 2.29.2
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH 2/3] treewide: use -Wdeclaration-after-statement
  2022-03-01 14:52 ` [PATCH 2/3] treewide: use -Wdeclaration-after-statement Arnd Bergmann
  2022-03-01 16:54   ` Nathan Chancellor
@ 2022-03-01 19:57   ` Nick Desaulniers
  2022-03-01 20:06     ` Nick Desaulniers
  2022-03-03  0:44   ` Masahiro Yamada
  2022-03-04 11:29   ` Sedat Dilek
  3 siblings, 1 reply; 28+ messages in thread
From: Nick Desaulniers @ 2022-03-01 19:57 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Miguel Ojeda, Mark Rutland,
	linux-kbuild, llvm, linux-doc, linux-kernel

On Tue, Mar 1, 2022 at 6:52 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Mark Rutland <mark.rutland@arm.com>
>
> In a subsequent patch we'll move the kernel from using `-std=gnu89` to
> `-std=gnu11`, permitting the use of additional C11 features such as
> for-loop initial declarations.
>
> One contentious aspect of C99 is that it permits mixed declarations and
> code, and for now at least, it seems preferable to enforce that
> declarations must come first.
>
> These warnings were already disabled in the kernel itself, but not
> for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
> a separate set of CFLAGS.
>
> This patch fixes an existing violation in modpost.c, which is not
> reported because of the missing flag in KBUILD_USERCFLAGS:
>
> | scripts/mod/modpost.c: In function ‘match’:
> | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
> |   837 |   const char *endp = p + strlen(p) - 1;
> |       |   ^~~~~
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> [arnd: don't add a duplicate flag to the default set, update changelog]
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks for the patches!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  Makefile                          | 3 ++-
>  arch/arm64/kernel/vdso32/Makefile | 1 +
>  scripts/mod/modpost.c             | 4 +++-
>  3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 94fa9a849a7a..37ef6a555dcd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,8 @@ HOSTCXX     = g++
>  endif
>
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -                             -O2 -fomit-frame-pointer -std=gnu89
> +                           -O2 -fomit-frame-pointer -std=gnu89 \
> +                           -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>
>  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 9378ea055bf2..ed181bedbffc 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> +               -Wdeclaration-after-statement \
>                 -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6bfa33217914..fe693304b120 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
>  {
>         const char *p;
>         while (*pat) {
> +               const char *endp;
> +
>                 p = *pat++;
> -               const char *endp = p + strlen(p) - 1;
> +               endp = p + strlen(p) - 1;
>
>                 /* "*foo*" */
>                 if (*p == '*' && *endp == '*') {
> --
> 2.29.2
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH 2/3] treewide: use -Wdeclaration-after-statement
  2022-03-01 19:57   ` Nick Desaulniers
@ 2022-03-01 20:06     ` Nick Desaulniers
  2022-03-01 20:20       ` Linus Torvalds
  0 siblings, 1 reply; 28+ messages in thread
From: Nick Desaulniers @ 2022-03-01 20:06 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Miguel Ojeda, Mark Rutland,
	linux-kbuild, llvm, linux-doc, linux-kernel

On Tue, Mar 1, 2022 at 11:57 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Tue, Mar 1, 2022 at 6:52 AM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Mark Rutland <mark.rutland@arm.com>
> >
> > In a subsequent patch we'll move the kernel from using `-std=gnu89` to
> > `-std=gnu11`, permitting the use of additional C11 features such as
> > for-loop initial declarations.
> >
> > One contentious aspect of C99 is that it permits mixed declarations and
> > code, and for now at least, it seems preferable to enforce that
> > declarations must come first.
> >
> > These warnings were already disabled in the kernel itself, but not
> > for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
> > a separate set of CFLAGS.
> >
> > This patch fixes an existing violation in modpost.c, which is not
> > reported because of the missing flag in KBUILD_USERCFLAGS:
> >
> > | scripts/mod/modpost.c: In function ‘match’:
> > | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
> > |   837 |   const char *endp = p + strlen(p) - 1;
> > |       |   ^~~~~
> >
> > Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> > [arnd: don't add a duplicate flag to the default set, update changelog]
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Thanks for the patches!
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

That said, there's a few additional places that reset KBUILD_CFLAGS.
$ git grep -rn "KBUILD_CFLAGS :=" | grep -v filter-out | grep -v subst
arch/mips/boot/compressed/Makefile:30:KBUILD_CFLAGS :=
$(KBUILD_CFLAGS) -D__KERNEL__ -D__DISABLE_EXPORTS \
arch/mips/vdso/Makefile:115:$(obj-vdso): KBUILD_CFLAGS :=
$(cflags-vdso) $(native-abi)
arch/mips/vdso/Makefile:144:$(obj-vdso-o32): KBUILD_CFLAGS :=
$(cflags-vdso) -mabi=32
arch/mips/vdso/Makefile:184:$(obj-vdso-n32): KBUILD_CFLAGS :=
$(cflags-vdso) -mabi=n32
arch/parisc/boot/compressed/Makefile:17:KBUILD_CFLAGS := -D__KERNEL__
-O2 -DBOOTLOADER
arch/s390/boot/Makefile:13:KBUILD_CFLAGS := $(KBUILD_CFLAGS_DECOMPRESSOR)
arch/s390/boot/compressed/Makefile:23:KBUILD_CFLAGS :=
$(KBUILD_CFLAGS_DECOMPRESSOR)
arch/s390/purgatory/Makefile:24:KBUILD_CFLAGS := -fno-strict-aliasing
-Wall -Wstrict-prototypes
arch/x86/boot/compressed/Makefile:35:KBUILD_CFLAGS := -m$(BITS) -O2
$(CLANG_FLAGS)

The parisc, s390, and x86 cases look like true positives to me (mips
looks fine FWICT).  I didn't want to nack the patch for being
incomplete, but it's not necessarily treewide.


>
> > ---
> >  Makefile                          | 3 ++-
> >  arch/arm64/kernel/vdso32/Makefile | 1 +
> >  scripts/mod/modpost.c             | 4 +++-
> >  3 files changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 94fa9a849a7a..37ef6a555dcd 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -432,7 +432,8 @@ HOSTCXX     = g++
> >  endif
> >
> >  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> > -                             -O2 -fomit-frame-pointer -std=gnu89
> > +                           -O2 -fomit-frame-pointer -std=gnu89 \
> > +                           -Wdeclaration-after-statement
> >  export KBUILD_USERLDFLAGS :=
> >
> >  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> > diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> > index 9378ea055bf2..ed181bedbffc 100644
> > --- a/arch/arm64/kernel/vdso32/Makefile
> > +++ b/arch/arm64/kernel/vdso32/Makefile
> > @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
> >                 -fno-strict-aliasing -fno-common \
> >                 -Werror-implicit-function-declaration \
> >                 -Wno-format-security \
> > +               -Wdeclaration-after-statement \
> >                 -std=gnu11
> >  VDSO_CFLAGS  += -O2
> >  # Some useful compiler-dependent flags from top-level Makefile
> > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > index 6bfa33217914..fe693304b120 100644
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
> > @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
> >  {
> >         const char *p;
> >         while (*pat) {
> > +               const char *endp;
> > +
> >                 p = *pat++;
> > -               const char *endp = p + strlen(p) - 1;
> > +               endp = p + strlen(p) - 1;
> >
> >                 /* "*foo*" */
> >                 if (*p == '*' && *endp == '*') {
> > --
> > 2.29.2
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers



-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH 2/3] treewide: use -Wdeclaration-after-statement
  2022-03-01 20:06     ` Nick Desaulniers
@ 2022-03-01 20:20       ` Linus Torvalds
  2022-03-01 20:28         ` Nick Desaulniers
  0 siblings, 1 reply; 28+ messages in thread
From: Linus Torvalds @ 2022-03-01 20:20 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Arnd Bergmann, Masahiro Yamada, Arnd Bergmann, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Miguel Ojeda, Mark Rutland,
	Linux Kbuild mailing list, llvm, open list:DOCUMENTATION,
	Linux Kernel Mailing List

On Tue, Mar 1, 2022 at 12:06 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> That said, there's a few additional places that reset KBUILD_CFLAGS.

Yeah, the boot code and vdso code often sets its own private flags,
because it's _so_ different.

The generic kernel CFLAGS often don't work at all, because that code
may be doing some truly horrendous things.

So I agree that this may not catch all the kernel code, but I don't
think it's much of a problem.

             Linus

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

* Re: [PATCH 2/3] treewide: use -Wdeclaration-after-statement
  2022-03-01 20:20       ` Linus Torvalds
@ 2022-03-01 20:28         ` Nick Desaulniers
  0 siblings, 0 replies; 28+ messages in thread
From: Nick Desaulniers @ 2022-03-01 20:28 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Arnd Bergmann, Masahiro Yamada, Arnd Bergmann, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Miguel Ojeda, Mark Rutland,
	Linux Kbuild mailing list, llvm, open list:DOCUMENTATION,
	Linux Kernel Mailing List

On Tue, Mar 1, 2022 at 12:20 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> On Tue, Mar 1, 2022 at 12:06 PM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > That said, there's a few additional places that reset KBUILD_CFLAGS.
>
> Yeah, the boot code and vdso code often sets its own private flags,
> because it's _so_ different.
>
> The generic kernel CFLAGS often don't work at all, because that code
> may be doing some truly horrendous things.
>
> So I agree that this may not catch all the kernel code, but I don't
> think it's much of a problem.

Agreed; they can still mirror the style imposed by
-Wdeclaration-after-statement like the rest of the codebase though.
-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-01 14:52 ` [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS Arnd Bergmann
  2022-03-01 17:00   ` Nathan Chancellor
  2022-03-01 19:56   ` Nick Desaulniers
@ 2022-03-02 22:14   ` Sedat Dilek
  2022-03-02 22:54     ` Nick Desaulniers
  2 siblings, 1 reply; 28+ messages in thread
From: Sedat Dilek @ 2022-03-02 22:14 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Wed, Mar 2, 2022 at 10:47 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> As we change the C language standard for the kernel from gnu89 to
> gnu11, it makes sense to also update the version for user space
> compilation.
>

Overdue.

Can you point me to a lore link where I can easily fetch the full 3/3
v3 patchset?

I would like to give this a try on x86-64 with my latest kernel-config
(based on the latest kernel-config v5.17-rc5 from Debian/unstable).

What Linux source base do I need?
Is Linux v5.17-rc6 good enough (patchset applicable) for testing?

Thanks, Arnd.

Regards,
- Sedat -

> Some users have older native compilers than what they use for
> kernel builds, so I considered using gnu99 as the default version
> for wider compatibility with gcc-4.6 and earlier.
>
> However, testing with older compilers showed that we already require
> HOSTCC version 5.1 as well because a lot of host tools include
> linux/compiler.h that uses __has_attribute():
>
>   CC      tools/objtool/exec-cmd.o
> In file included from tools/include/linux/compiler_types.h:36:0,
>                  from tools/include/linux/compiler.h:5,
>                  from exec-cmd.c:2:
> tools/include/linux/compiler-gcc.h:19:5: error: "__has_attribute" is not defined [-Werror=undef]
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index 37ef6a555dcd..7c9be7f1ccd4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,7 @@ HOSTCXX     = g++
>  endif
>
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -                           -O2 -fomit-frame-pointer -std=gnu89 \
> +                           -O2 -fomit-frame-pointer -std=gnu11 \
>                             -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>
> --
> 2.29.2
>

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-02 22:14   ` Sedat Dilek
@ 2022-03-02 22:54     ` Nick Desaulniers
  2022-03-03  6:26       ` Sedat Dilek
  0 siblings, 1 reply; 28+ messages in thread
From: Nick Desaulniers @ 2022-03-02 22:54 UTC (permalink / raw)
  To: sedat.dilek
  Cc: Arnd Bergmann, Masahiro Yamada, Arnd Bergmann, Linus Torvalds,
	Marco Elver, Jani Nikula, David Sterba, Alex Shi, Miguel Ojeda,
	Mark Rutland, linux-kbuild, llvm, linux-doc, linux-kernel

On Wed, Mar 2, 2022 at 2:14 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Wed, Mar 2, 2022 at 10:47 AM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > As we change the C language standard for the kernel from gnu89 to
> > gnu11, it makes sense to also update the version for user space
> > compilation.
> >
>
> Overdue.
>
> Can you point me to a lore link where I can easily fetch the full 3/3
> v3 patchset?

Hey Sedat!

$ b4 am https://lore.kernel.org/lkml/20220301145233.3689119-1-arnd@kernel.org/
-o - | git am -3

https://people.kernel.org/monsieuricon/introducing-b4-and-patch-attestation

>
> I would like to give this a try on x86-64 with my latest kernel-config
> (based on the latest kernel-config v5.17-rc5 from Debian/unstable).
>
> What Linux source base do I need?
> Is Linux v5.17-rc6 good enough (patchset applicable) for testing?

I suspect so.
-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH 2/3] treewide: use -Wdeclaration-after-statement
  2022-03-01 14:52 ` [PATCH 2/3] treewide: use -Wdeclaration-after-statement Arnd Bergmann
  2022-03-01 16:54   ` Nathan Chancellor
  2022-03-01 19:57   ` Nick Desaulniers
@ 2022-03-03  0:44   ` Masahiro Yamada
  2022-03-04 11:29   ` Sedat Dilek
  3 siblings, 0 replies; 28+ messages in thread
From: Masahiro Yamada @ 2022-03-03  0:44 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Arnd Bergmann, Linus Torvalds, Marco Elver, Jani Nikula,
	David Sterba, Alex Shi, Nick Desaulniers, Miguel Ojeda,
	Mark Rutland, Linux Kbuild mailing list, llvm,
	open list:DOCUMENTATION, Linux Kernel Mailing List

On Tue, Mar 1, 2022 at 11:52 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Mark Rutland <mark.rutland@arm.com>
>
> In a subsequent patch we'll move the kernel from using `-std=gnu89` to


Precisely speaking,
"In a subsequent patch we'll move the userspace tools ..."

The kernel part was done by 1/3.



> `-std=gnu11`, permitting the use of additional C11 features such as
> for-loop initial declarations.
>
> One contentious aspect of C99 is that it permits mixed declarations and
> code, and for now at least, it seems preferable to enforce that
> declarations must come first.
>
> These warnings were already disabled in the kernel itself, but not

Is this the opposite?

"These warnings were already _enabled_ in the kernel itself, ..."




If you have a chance to resend this,
can you please rebase on top of kbuild/for-next?

This is not applicable due to the conflict with:
https://patchwork.kernel.org/project/linux-kbuild/patch/20220201213542.2808035-1-quic_eberman@quicinc.com/






> for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
> a separate set of CFLAGS.
>
> This patch fixes an existing violation in modpost.c, which is not
> reported because of the missing flag in KBUILD_USERCFLAGS:
>
> | scripts/mod/modpost.c: In function ‘match’:
> | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
> |   837 |   const char *endp = p + strlen(p) - 1;
> |       |   ^~~~~
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> [arnd: don't add a duplicate flag to the default set, update changelog]
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  Makefile                          | 3 ++-
>  arch/arm64/kernel/vdso32/Makefile | 1 +
>  scripts/mod/modpost.c             | 4 +++-
>  3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 94fa9a849a7a..37ef6a555dcd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,8 @@ HOSTCXX     = g++
>  endif
>
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -                             -O2 -fomit-frame-pointer -std=gnu89
> +                           -O2 -fomit-frame-pointer -std=gnu89 \
> +                           -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>
>  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 9378ea055bf2..ed181bedbffc 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> +               -Wdeclaration-after-statement \
>                 -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6bfa33217914..fe693304b120 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
>  {
>         const char *p;
>         while (*pat) {
> +               const char *endp;
> +
>                 p = *pat++;
> -               const char *endp = p + strlen(p) - 1;
> +               endp = p + strlen(p) - 1;
>
>                 /* "*foo*" */
>                 if (*p == '*' && *endp == '*') {
> --
> 2.29.2
>


-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-02 22:54     ` Nick Desaulniers
@ 2022-03-03  6:26       ` Sedat Dilek
  2022-03-03 17:37         ` Nathan Chancellor
  0 siblings, 1 reply; 28+ messages in thread
From: Sedat Dilek @ 2022-03-03  6:26 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Arnd Bergmann, Masahiro Yamada, Arnd Bergmann, Linus Torvalds,
	Marco Elver, Jani Nikula, David Sterba, Alex Shi, Miguel Ojeda,
	Mark Rutland, linux-kbuild, llvm, linux-doc, linux-kernel

On Wed, Mar 2, 2022 at 11:54 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Wed, Mar 2, 2022 at 2:14 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
> >
> > On Wed, Mar 2, 2022 at 10:47 AM Arnd Bergmann <arnd@kernel.org> wrote:
> > >
> > > From: Arnd Bergmann <arnd@arndb.de>
> > >
> > > As we change the C language standard for the kernel from gnu89 to
> > > gnu11, it makes sense to also update the version for user space
> > > compilation.
> > >
> >
> > Overdue.
> >
> > Can you point me to a lore link where I can easily fetch the full 3/3
> > v3 patchset?
>
> Hey Sedat!
>
> $ b4 am https://lore.kernel.org/lkml/20220301145233.3689119-1-arnd@kernel.org/
> -o - | git am -3
>

Hey Nick!

This only applies 1/3.

$ b4 --version
0.8.0

$ b4 am https://lore.kernel.org/lkml/20220301145233.3689119-1-arnd@kernel.org/
-o - | git am -3
Analyzing 14 messages in the thread
Will use the latest revision: v3
You can pick other revisions using the -vN flag
Checking attestation on all messages, may take a moment...
---
 ✓ [PATCH v3 1/3] Kbuild: move to -std=gnu11
   ✓ Signed: DKIM/kernel.org
   + Reviewed-by: Nathan Chancellor <nathan@kernel.org> (✓ DKIM/kernel.org)
 ERROR: missing [2/3]!
 ERROR: missing [3/3]!
 ---
 NOTE: install patatt for end-to-end signature verification
---
Total patches: 1
---
WARNING: Thread incomplete!
Link: https://lore.kernel.org/r/20220301145233.3689119-1-arnd@kernel.org
Base: not specified
Wende an: Kbuild: move to -std=gnu11

- Sedat -

> https://people.kernel.org/monsieuricon/introducing-b4-and-patch-attestation
>
> >
> > I would like to give this a try on x86-64 with my latest kernel-config
> > (based on the latest kernel-config v5.17-rc5 from Debian/unstable).
> >
> > What Linux source base do I need?
> > Is Linux v5.17-rc6 good enough (patchset applicable) for testing?
>
> I suspect so.
> --
> Thanks,
> ~Nick Desaulniers

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-03  6:26       ` Sedat Dilek
@ 2022-03-03 17:37         ` Nathan Chancellor
  2022-03-04  6:47           ` Sedat Dilek
  0 siblings, 1 reply; 28+ messages in thread
From: Nathan Chancellor @ 2022-03-03 17:37 UTC (permalink / raw)
  To: Sedat Dilek
  Cc: Nick Desaulniers, Arnd Bergmann, Masahiro Yamada, Arnd Bergmann,
	Linus Torvalds, Marco Elver, Jani Nikula, David Sterba, Alex Shi,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

Hi Sedat,

On Thu, Mar 03, 2022 at 07:26:05AM +0100, Sedat Dilek wrote:
> Hey Nick!
> 
> This only applies 1/3.
> 
> $ b4 --version
> 0.8.0
> 
> $ b4 am https://lore.kernel.org/lkml/20220301145233.3689119-1-arnd@kernel.org/
> -o - | git am -3
> Analyzing 14 messages in the thread
> Will use the latest revision: v3
> You can pick other revisions using the -vN flag
> Checking attestation on all messages, may take a moment...
> ---
>  ✓ [PATCH v3 1/3] Kbuild: move to -std=gnu11
>    ✓ Signed: DKIM/kernel.org
>    + Reviewed-by: Nathan Chancellor <nathan@kernel.org> (✓ DKIM/kernel.org)
>  ERROR: missing [2/3]!
>  ERROR: missing [3/3]!
>  ---
>  NOTE: install patatt for end-to-end signature verification
> ---
> Total patches: 1
> ---
> WARNING: Thread incomplete!
> Link: https://lore.kernel.org/r/20220301145233.3689119-1-arnd@kernel.org
> Base: not specified
> Wende an: Kbuild: move to -std=gnu11

It looks like the threading somehow got broken, likely due to the [v3]
on the first patch and not the second or third:

This worked for me on v5.17-rc6:

$ for i in $(seq 1 3); do b4 shazam -P _ 20220301145233.3689119-"$i"-arnd@kernel.org; done

"b4 shazam" is the equivalent of "b4 am -o - ... | git am" and the
"-P _" tells b4 to only fetch that exact message ID, not the whole
thread.

Cheers,
Nathan

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

* Re: [PATCH 1/3] [v3] Kbuild: move to -std=gnu11
  2022-03-01 16:53 ` [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Nathan Chancellor
@ 2022-03-04  5:03   ` Masahiro Yamada
  0 siblings, 0 replies; 28+ messages in thread
From: Masahiro Yamada @ 2022-03-04  5:03 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Arnd Bergmann, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, Linux Kbuild mailing list, llvm,
	open list:DOCUMENTATION, Linux Kernel Mailing List

On Wed, Mar 2, 2022 at 1:53 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> On Tue, Mar 01, 2022 at 03:52:31PM +0100, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > During a patch discussion, Linus brought up the option of changing
> > the C standard version from gnu89 to gnu99, which allows using variable
> > declaration inside of a for() loop. While the C99, C11 and later standards
> > introduce many other features, most of these are already available in
> > gnu89 as GNU extensions as well.
> >
> > An earlier attempt to do this when gcc-5 started defaulting to
> > -std=gnu11 failed because at the time that caused warnings about
> > designated initializers with older compilers. Now that gcc-5.1 is
> > the minimum compiler version used for building kernels, that is no
> > longer a concern. Similarly, the behavior of 'inline' functions changes
> > between gnu89 using gnu_inline behavior and gnu11 using standard c99+
> > behavior, but this was taken care of by defining 'inline' to include
> > __attribute__((gnu_inline)) in order to allow building with clang a
> > while ago.
> >
> > One minor issue that remains is an added gcc warning for shifts of
> > negative integers when building with -Wextra, which happens with the
> > 'make W=1' option, as well as for three drivers in the kernel that always
> > enable -Wextra, but it was only observed with the i915 driver so far.
> > To be on the safe side, add -Wno-shift-negative-value to any -Wextra
> > in a Makefile.
> >
> > Nathan Chancellor reported an additional -Wdeclaration-after-statement
> > warning that appears in a system header on arm, this still needs a
> > workaround.
> >
> > The differences between gnu99, gnu11, gnu1x and gnu17 are fairly
> > minimal and mainly impact warnings at the -Wpedantic level that the
> > kernel never enables. Between these, gnu11 is the newest version
> > that is supported by all supported compiler versions, though it is
> > only the default on gcc-5, while all other supported versions of
> > gcc or clang default to gnu1x/gnu17.
> >
> > Link: https://lore.kernel.org/lkml/CAHk-=wiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpcovt8fYbVFW3TA@mail.gmail.com/
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1603
> > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Acked-by: Marco Elver <elver@google.com>
> > Acked-by: Jani Nikula <jani.nikula@intel.com>
> > Acked-by: David Sterba <dsterba@suse.com>
> > Reviewed-by: Alex Shi <alexs@kernel.org>
> > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> > Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
> > Cc: Masahiro Yamada <masahiroy@kernel.org>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: linux-kbuild@vger.kernel.org
> > Cc: llvm@lists.linux.dev
> > Cc: linux-doc@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Reviewed-by: Nathan Chancellor <nathan@kernel.org>
>
> One comment below.
>
> > ---
> > [v3]
> >  - split out USERCFLAGS to a separate patch
> >  - add -Wdeclaration-after-statement patch from Mark Rutland
> >  - leave out C17 reference
> >  - more rewording the descrption
> >
> > [v2]
> >  - added -std=gnu11 back, rather than just relying on the default
> >  - minor changes to changelog text
> > ---
> >  Documentation/process/programming-language.rst              | 6 +++---
> >  .../translations/it_IT/process/programming-language.rst     | 4 ++--
> >  .../translations/zh_CN/process/programming-language.rst     | 3 +--
> >  .../translations/zh_TW/process/programming-language.rst     | 3 +--
> >  Makefile                                                    | 4 ++--
> >  arch/arm64/kernel/vdso32/Makefile                           | 2 +-
> >  drivers/gpu/drm/i915/Makefile                               | 1 +
> >  drivers/staging/greybus/tools/Makefile                      | 3 ++-
> >  fs/btrfs/Makefile                                           | 1 +
> >  scripts/Makefile.extrawarn                                  | 1 +
> >  10 files changed, 15 insertions(+), 13 deletions(-)
> >
> > diff --git a/Documentation/process/programming-language.rst b/Documentation/process/programming-language.rst
> > index ec474a70a02f..5fc9160ca1fa 100644
> > --- a/Documentation/process/programming-language.rst
> > +++ b/Documentation/process/programming-language.rst
> > @@ -5,9 +5,9 @@ Programming Language
> >
> >  The kernel is written in the C programming language [c-language]_.
> >  More precisely, the kernel is typically compiled with ``gcc`` [gcc]_
> > -under ``-std=gnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90
> > -(including some C99 features). ``clang`` [clang]_ is also supported, see
> > -docs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> > +under ``-std=gnu11`` [gcc-c-dialect-options]_: the GNU dialect of ISO C11.
> > +``clang`` [clang]_ is also supported, see docs on
> > +:ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> >
> >  This dialect contains many extensions to the language [gnu-extensions]_,
> >  and many of them are used within the kernel as a matter of course.
> > diff --git a/Documentation/translations/it_IT/process/programming-language.rst b/Documentation/translations/it_IT/process/programming-language.rst
> > index 41db2598ce11..c1a9b481a6f9 100644
> > --- a/Documentation/translations/it_IT/process/programming-language.rst
> > +++ b/Documentation/translations/it_IT/process/programming-language.rst
> > @@ -10,8 +10,8 @@ Linguaggio di programmazione
> >
> >  Il kernel è scritto nel linguaggio di programmazione C [it-c-language]_.
> >  Più precisamente, il kernel viene compilato con ``gcc`` [it-gcc]_ usando
> > -l'opzione ``-std=gnu89`` [it-gcc-c-dialect-options]_: il dialetto GNU
> > -dello standard ISO C90 (con l'aggiunta di alcune funzionalità da C99).
> > +l'opzione ``-std=gnu11`` [it-gcc-c-dialect-options]_: il dialetto GNU
> > +dello standard ISO C11.
> >  Linux supporta anche ``clang`` [it-clang]_, leggete la documentazione
> >  :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> >
> > diff --git a/Documentation/translations/zh_CN/process/programming-language.rst b/Documentation/translations/zh_CN/process/programming-language.rst
> > index 2a47a1d2ec20..fabdc338dbfb 100644
> > --- a/Documentation/translations/zh_CN/process/programming-language.rst
> > +++ b/Documentation/translations/zh_CN/process/programming-language.rst
> > @@ -9,8 +9,7 @@
> >  ============
> >
> >  内核是用C语言 :ref:`c-language <cn_c-language>` 编写的。更准确地说,内核通常是用 :ref:`gcc <cn_gcc>`
> > -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C90的 GNU 方言(
> > -包括一些C99特性)
> > +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C11的 GNU 方言
> >
> >  这种方言包含对语言 :ref:`gnu-extensions <cn_gnu-extensions>` 的许多扩展,当然,它们许多都在内核中使用。
> >
> > diff --git a/Documentation/translations/zh_TW/process/programming-language.rst b/Documentation/translations/zh_TW/process/programming-language.rst
> > index 54e3699eadf8..144bdaf81a41 100644
> > --- a/Documentation/translations/zh_TW/process/programming-language.rst
> > +++ b/Documentation/translations/zh_TW/process/programming-language.rst
> > @@ -12,8 +12,7 @@
> >  ============
> >
> >  內核是用C語言 :ref:`c-language <tw_c-language>` 編寫的。更準確地說,內核通常是用 :ref:`gcc <tw_gcc>`
> > -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C90的 GNU 方言(
> > -包括一些C99特性)
> > +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C11的 GNU 方言
> >
> >  這種方言包含對語言 :ref:`gnu-extensions <tw_gnu-extensions>` 的許多擴展,當然,它們許多都在內核中使用。
> >
> > diff --git a/Makefile b/Makefile
> > index 289ce2be8032..94fa9a849a7a 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -515,7 +515,7 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
> >                  -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
> >                  -Werror=implicit-function-declaration -Werror=implicit-int \
> >                  -Werror=return-type -Wno-format-security \
> > -                -std=gnu89
> > +                -std=gnu11
> >  KBUILD_CPPFLAGS := -D__KERNEL__
> >  KBUILD_AFLAGS_KERNEL :=
> >  KBUILD_CFLAGS_KERNEL :=
> > @@ -782,7 +782,7 @@ KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
> >
> >  ifdef CONFIG_CC_IS_CLANG
> >  KBUILD_CPPFLAGS += -Qunused-arguments
> > -# The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable.
> > +# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
> >  KBUILD_CFLAGS += -Wno-gnu
> >  # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
> >  # source of a reference will be _MergedGlobals and not on of the whitelisted names.
> > diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> > index 6c01b63ff56d..9378ea055bf2 100644
> > --- a/arch/arm64/kernel/vdso32/Makefile
> > +++ b/arch/arm64/kernel/vdso32/Makefile
> > @@ -68,7 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
> >                 -fno-strict-aliasing -fno-common \
> >                 -Werror-implicit-function-declaration \
> >                 -Wno-format-security \
> > -               -std=gnu89
> > +               -std=gnu11
> >  VDSO_CFLAGS  += -O2
> >  # Some useful compiler-dependent flags from top-level Makefile
> >  VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
> > diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
> > index 1b62b9f65196..1618a6e0af4e 100644
> > --- a/drivers/gpu/drm/i915/Makefile
> > +++ b/drivers/gpu/drm/i915/Makefile
> > @@ -17,6 +17,7 @@ subdir-ccflags-y += -Wno-unused-parameter
> >  subdir-ccflags-y += -Wno-type-limits
> >  subdir-ccflags-y += -Wno-missing-field-initializers
> >  subdir-ccflags-y += -Wno-sign-compare
> > +subdir-ccflags-y += -Wno-shift-negative-value
> >  subdir-ccflags-y += $(call cc-disable-warning, unused-but-set-variable)
> >  subdir-ccflags-y += $(call cc-disable-warning, frame-address)
> >  subdir-ccflags-$(CONFIG_DRM_I915_WERROR) += -Werror
> > diff --git a/drivers/staging/greybus/tools/Makefile b/drivers/staging/greybus/tools/Makefile
> > index ad0ae8053b79..a3bbd73171f2 100644
> > --- a/drivers/staging/greybus/tools/Makefile
> > +++ b/drivers/staging/greybus/tools/Makefile
> > @@ -12,7 +12,8 @@ CFLAGS      += -std=gnu99 -Wall -Wextra -g \
> >           -Wredundant-decls \
> >           -Wcast-align \
> >           -Wsign-compare \
> > -         -Wno-missing-field-initializers
> > +         -Wno-missing-field-initializers \
> > +         -Wno-shift-negative-value
>
> This Makefile uses its own -std= option because it is a userland tool.
> Seems like this hunk could just be dropped or the -std= argument could
> be bumped here too?
>

Right, this is a userland tool.

I do not mind either way.

BTW, this makefile is somewhat corrupted
because ../greybus_protocols.h does not exist.
(but it is working, relying on the built-in rules)



If Arnd does not mind sending v4, maybe we
can split this into two paches:

1/4 : add -Wno-shift-negative-value where -Wextra is used
2/4 : Kbuild: move to -std=gnu11




1/4 adds -Wno-shift-negative-value
whether it is the kernel space or user-land.





--
Best Regards
Masahiro Yamada

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-03 17:37         ` Nathan Chancellor
@ 2022-03-04  6:47           ` Sedat Dilek
  2022-03-04  7:18             ` Sedat Dilek
  0 siblings, 1 reply; 28+ messages in thread
From: Sedat Dilek @ 2022-03-04  6:47 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nick Desaulniers, Arnd Bergmann, Masahiro Yamada, Arnd Bergmann,
	Linus Torvalds, Marco Elver, Jani Nikula, David Sterba, Alex Shi,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Thu, Mar 3, 2022 at 6:37 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> Hi Sedat,
>
> On Thu, Mar 03, 2022 at 07:26:05AM +0100, Sedat Dilek wrote:
> > Hey Nick!
> >
> > This only applies 1/3.
> >
> > $ b4 --version
> > 0.8.0
> >
> > $ b4 am https://lore.kernel.org/lkml/20220301145233.3689119-1-arnd@kernel.org/
> > -o - | git am -3
> > Analyzing 14 messages in the thread
> > Will use the latest revision: v3
> > You can pick other revisions using the -vN flag
> > Checking attestation on all messages, may take a moment...
> > ---
> >  ✓ [PATCH v3 1/3] Kbuild: move to -std=gnu11
> >    ✓ Signed: DKIM/kernel.org
> >    + Reviewed-by: Nathan Chancellor <nathan@kernel.org> (✓ DKIM/kernel.org)
> >  ERROR: missing [2/3]!
> >  ERROR: missing [3/3]!
> >  ---
> >  NOTE: install patatt for end-to-end signature verification
> > ---
> > Total patches: 1
> > ---
> > WARNING: Thread incomplete!
> > Link: https://lore.kernel.org/r/20220301145233.3689119-1-arnd@kernel.org
> > Base: not specified
> > Wende an: Kbuild: move to -std=gnu11
>
> It looks like the threading somehow got broken, likely due to the [v3]
> on the first patch and not the second or third:
>
> This worked for me on v5.17-rc6:
>
> $ for i in $(seq 1 3); do b4 shazam -P _ 20220301145233.3689119-"$i"-arnd@kernel.org; done
>
> "b4 shazam" is the equivalent of "b4 am -o - ... | git am" and the
> "-P _" tells b4 to only fetch that exact message ID, not the whole
> thread.
>

Hmm, the universe is not good to me...

$ for i in $(seq 1 3); do b4 shazam -P _
20220301145233.3689119-"$i"-arnd@kernel.org; done
usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
b4: error: argument subcmd: invalid choice: 'shazam' (choose from
'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
b4: error: argument subcmd: invalid choice: 'shazam' (choose from
'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
b4: error: argument subcmd: invalid choice: 'shazam' (choose from
'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')

Do I need a higher version of b4 (here: v0.8.0)?

Check myself... b4.git:

commit 7c1d044ff1d5235e598d4c777c4abfe60e0a09a8
("shazam: change default behaviour to be "apply-here"")

...is post-v0.8.0.

Lemme see if I can apply this patch...

# cd /usr/lib/python3/dist-packages

# LC_ALL=C git apply --check --verbose /root/b4-shazam.patch
Checking patch b4/command.py...
error: while searching for:
   sp.add_argument('-M', '--save-as-maildir', dest='maildir',
action='store_true', default=False,
                   help='Save as maildir (avoids mbox format ambiguities)')

def cmd_am_common_opts(sp):
   sp.add_argument('-v', '--use-version', dest='wantver', type=int,
default=None,
                   help='Get a specific version of the patch/series')

error: patch failed: b4/command.py:35
error: b4/command.py: patch does not apply
Checking patch b4/mbox.py...
error: while searching for:
       ifh = io.StringIO()
       b4.save_git_am_mbox(am_msgs, ifh)
       ambytes = ifh.getvalue().encode()
       if cmdargs.applyhere:
           amflags = config.get('git-am-flags', '')
           sp = shlex.shlex(amflags, posix=True)
           sp.whitespace_split = True

error: patch failed: b4/mbox.py:262
error: b4/mbox.py: patch does not apply

Nope.
Dunno if I am willing to do that manually or build-from-git.

Anyway, can you add this b4 shazam tipp/trick to our wiki, please?

Last question:

LLVM/Clang-14...
Do I need any patches to Linux v5.17-rc6 or upstream Git?
Dependent/Independent of "std-gnu-11"?

I can see on my Debian/unstable AMD64 system:

# LC_ALL=C apt-cache policy clang-14
clang-14:
 Installed: (none)
 Candidate: 1:14.0.0~++20220301114802+19149538e9a9-1~exp1~20220301234814.85
 Version table:
    1:14.0.0~++20220301114802+19149538e9a9-1~exp1~20220301234814.85 99
        99 https://apt.llvm.org/unstable llvm-toolchain-14/main amd64 Packages
    1:14.0.0~+rc1-1 99
        99 https://ftp.debian.org/debian unstable/main amd64 Packages
        99 https://deb.debian.org/debian unstable/main amd64 Packages

The one from apt.llvm.org I guess is LLVM/Clang v14.0.0-rc2?

Maybe, I wait until Masahiroy has the triple in his kbuild Git tree...

Thanks.

Have a nice Friday,
- sed@ -

[1] https://git.kernel.org/pub/scm/utils/b4/b4.git/tag/?h=v0.8.0
[2] https://git.kernel.org/pub/scm/utils/b4/b4.git/commit/?id=7c1d044ff1d5235e598d4c777c4abfe60e0a09a8
[3] https://github.com/ClangBuiltLinux/linux/wiki/Command-line-tips-and-tricks

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-04  6:47           ` Sedat Dilek
@ 2022-03-04  7:18             ` Sedat Dilek
  2022-03-04 11:12               ` Sedat Dilek
  0 siblings, 1 reply; 28+ messages in thread
From: Sedat Dilek @ 2022-03-04  7:18 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nick Desaulniers, Arnd Bergmann, Masahiro Yamada, Arnd Bergmann,
	Linus Torvalds, Marco Elver, Jani Nikula, David Sterba, Alex Shi,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Fri, Mar 4, 2022 at 7:47 AM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Thu, Mar 3, 2022 at 6:37 PM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > Hi Sedat,
> >
> > On Thu, Mar 03, 2022 at 07:26:05AM +0100, Sedat Dilek wrote:
> > > Hey Nick!
> > >
> > > This only applies 1/3.
> > >
> > > $ b4 --version
> > > 0.8.0
> > >
> > > $ b4 am https://lore.kernel.org/lkml/20220301145233.3689119-1-arnd@kernel.org/
> > > -o - | git am -3
> > > Analyzing 14 messages in the thread
> > > Will use the latest revision: v3
> > > You can pick other revisions using the -vN flag
> > > Checking attestation on all messages, may take a moment...
> > > ---
> > >  ✓ [PATCH v3 1/3] Kbuild: move to -std=gnu11
> > >    ✓ Signed: DKIM/kernel.org
> > >    + Reviewed-by: Nathan Chancellor <nathan@kernel.org> (✓ DKIM/kernel.org)
> > >  ERROR: missing [2/3]!
> > >  ERROR: missing [3/3]!
> > >  ---
> > >  NOTE: install patatt for end-to-end signature verification
> > > ---
> > > Total patches: 1
> > > ---
> > > WARNING: Thread incomplete!
> > > Link: https://lore.kernel.org/r/20220301145233.3689119-1-arnd@kernel.org
> > > Base: not specified
> > > Wende an: Kbuild: move to -std=gnu11
> >
> > It looks like the threading somehow got broken, likely due to the [v3]
> > on the first patch and not the second or third:
> >
> > This worked for me on v5.17-rc6:
> >
> > $ for i in $(seq 1 3); do b4 shazam -P _ 20220301145233.3689119-"$i"-arnd@kernel.org; done
> >
> > "b4 shazam" is the equivalent of "b4 am -o - ... | git am" and the
> > "-P _" tells b4 to only fetch that exact message ID, not the whole
> > thread.
> >
>
> Hmm, the universe is not good to me...
>
> $ for i in $(seq 1 3); do b4 shazam -P _
> 20220301145233.3689119-"$i"-arnd@kernel.org; done
> usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
> b4: error: argument subcmd: invalid choice: 'shazam' (choose from
> 'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
> usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
> b4: error: argument subcmd: invalid choice: 'shazam' (choose from
> 'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
> usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
> b4: error: argument subcmd: invalid choice: 'shazam' (choose from
> 'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
>
> Do I need a higher version of b4 (here: v0.8.0)?
>
> Check myself... b4.git:
>
> commit 7c1d044ff1d5235e598d4c777c4abfe60e0a09a8
> ("shazam: change default behaviour to be "apply-here"")
>
> ...is post-v0.8.0.
>

I brutally applied the post-v0.8.0 patches stolen from b4.git over my
local distro b4 files.

And was able to apply the triple:

$ git log --oneline --no-merges
5.17.0-rc6-1-amd64-clang13-lto..5.17.0-rc6-2-amd64-clang13-lto
96a4222bdd4c (for-5.17/kbuild-std_gnu11-arndb-20220301) Kbuild: use
-std=gnu11 for KBUILD_USERCFLAGS
c4e8cef401a8 treewide: use -Wdeclaration-after-statement
6a7cc105b238 Kbuild: move to -std=gnu11

- sed@ -

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-04  7:18             ` Sedat Dilek
@ 2022-03-04 11:12               ` Sedat Dilek
  2022-03-06 10:04                 ` Sedat Dilek
  0 siblings, 1 reply; 28+ messages in thread
From: Sedat Dilek @ 2022-03-04 11:12 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nick Desaulniers, Arnd Bergmann, Masahiro Yamada, Arnd Bergmann,
	Linus Torvalds, Marco Elver, Jani Nikula, David Sterba, Alex Shi,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Fri, Mar 4, 2022 at 8:18 AM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Fri, Mar 4, 2022 at 7:47 AM Sedat Dilek <sedat.dilek@gmail.com> wrote:
> >
> > On Thu, Mar 3, 2022 at 6:37 PM Nathan Chancellor <nathan@kernel.org> wrote:
> > >
> > > Hi Sedat,
> > >
> > > On Thu, Mar 03, 2022 at 07:26:05AM +0100, Sedat Dilek wrote:
> > > > Hey Nick!
> > > >
> > > > This only applies 1/3.
> > > >
> > > > $ b4 --version
> > > > 0.8.0
> > > >
> > > > $ b4 am https://lore.kernel.org/lkml/20220301145233.3689119-1-arnd@kernel.org/
> > > > -o - | git am -3
> > > > Analyzing 14 messages in the thread
> > > > Will use the latest revision: v3
> > > > You can pick other revisions using the -vN flag
> > > > Checking attestation on all messages, may take a moment...
> > > > ---
> > > >  ✓ [PATCH v3 1/3] Kbuild: move to -std=gnu11
> > > >    ✓ Signed: DKIM/kernel.org
> > > >    + Reviewed-by: Nathan Chancellor <nathan@kernel.org> (✓ DKIM/kernel.org)
> > > >  ERROR: missing [2/3]!
> > > >  ERROR: missing [3/3]!
> > > >  ---
> > > >  NOTE: install patatt for end-to-end signature verification
> > > > ---
> > > > Total patches: 1
> > > > ---
> > > > WARNING: Thread incomplete!
> > > > Link: https://lore.kernel.org/r/20220301145233.3689119-1-arnd@kernel.org
> > > > Base: not specified
> > > > Wende an: Kbuild: move to -std=gnu11
> > >
> > > It looks like the threading somehow got broken, likely due to the [v3]
> > > on the first patch and not the second or third:
> > >
> > > This worked for me on v5.17-rc6:
> > >
> > > $ for i in $(seq 1 3); do b4 shazam -P _ 20220301145233.3689119-"$i"-arnd@kernel.org; done
> > >
> > > "b4 shazam" is the equivalent of "b4 am -o - ... | git am" and the
> > > "-P _" tells b4 to only fetch that exact message ID, not the whole
> > > thread.
> > >
> >
> > Hmm, the universe is not good to me...
> >
> > $ for i in $(seq 1 3); do b4 shazam -P _
> > 20220301145233.3689119-"$i"-arnd@kernel.org; done
> > usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
> > b4: error: argument subcmd: invalid choice: 'shazam' (choose from
> > 'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
> > usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
> > b4: error: argument subcmd: invalid choice: 'shazam' (choose from
> > 'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
> > usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
> > b4: error: argument subcmd: invalid choice: 'shazam' (choose from
> > 'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
> >
> > Do I need a higher version of b4 (here: v0.8.0)?
> >
> > Check myself... b4.git:
> >
> > commit 7c1d044ff1d5235e598d4c777c4abfe60e0a09a8
> > ("shazam: change default behaviour to be "apply-here"")
> >
> > ...is post-v0.8.0.
> >
>
> I brutally applied the post-v0.8.0 patches stolen from b4.git over my
> local distro b4 files.
>
> And was able to apply the triple:
>
> $ git log --oneline --no-merges
> 5.17.0-rc6-1-amd64-clang13-lto..5.17.0-rc6-2-amd64-clang13-lto
> 96a4222bdd4c (for-5.17/kbuild-std_gnu11-arndb-20220301) Kbuild: use
> -std=gnu11 for KBUILD_USERCFLAGS
> c4e8cef401a8 treewide: use -Wdeclaration-after-statement
> 6a7cc105b238 Kbuild: move to -std=gnu11
>

I was able to build and boot on bare metal.

No new warnings in my build-log here after switching to -std=gnu11.

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 x86-64

- sed@ -

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

* Re: [PATCH 1/3] [v3] Kbuild: move to -std=gnu11
  2022-03-01 14:52 [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Arnd Bergmann
                   ` (2 preceding siblings ...)
  2022-03-01 16:53 ` [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Nathan Chancellor
@ 2022-03-04 11:24 ` Sedat Dilek
  2022-03-06 10:01   ` Sedat Dilek
  2022-03-04 11:37 ` Sedat Dilek
  2022-03-04 16:25 ` Sedat Dilek
  5 siblings, 1 reply; 28+ messages in thread
From: Sedat Dilek @ 2022-03-04 11:24 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Wed, Mar 2, 2022 at 5:29 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> During a patch discussion, Linus brought up the option of changing
> the C standard version from gnu89 to gnu99, which allows using variable
> declaration inside of a for() loop. While the C99, C11 and later standards
> introduce many other features, most of these are already available in
> gnu89 as GNU extensions as well.
>
> An earlier attempt to do this when gcc-5 started defaulting to
> -std=gnu11 failed because at the time that caused warnings about
> designated initializers with older compilers. Now that gcc-5.1 is
> the minimum compiler version used for building kernels, that is no
> longer a concern. Similarly, the behavior of 'inline' functions changes
> between gnu89 using gnu_inline behavior and gnu11 using standard c99+
> behavior, but this was taken care of by defining 'inline' to include
> __attribute__((gnu_inline)) in order to allow building with clang a
> while ago.
>
> One minor issue that remains is an added gcc warning for shifts of
> negative integers when building with -Wextra, which happens with the
> 'make W=1' option, as well as for three drivers in the kernel that always
> enable -Wextra, but it was only observed with the i915 driver so far.
> To be on the safe side, add -Wno-shift-negative-value to any -Wextra
> in a Makefile.
>
> Nathan Chancellor reported an additional -Wdeclaration-after-statement
> warning that appears in a system header on arm, this still needs a
> workaround.
>
> The differences between gnu99, gnu11, gnu1x and gnu17 are fairly
> minimal and mainly impact warnings at the -Wpedantic level that the
> kernel never enables. Between these, gnu11 is the newest version
> that is supported by all supported compiler versions, though it is
> only the default on gcc-5, while all other supported versions of
> gcc or clang default to gnu1x/gnu17.
>
> Link: https://lore.kernel.org/lkml/CAHk-=wiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpcovt8fYbVFW3TA@mail.gmail.com/
> Link: https://github.com/ClangBuiltLinux/linux/issues/1603
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Acked-by: Marco Elver <elver@google.com>
> Acked-by: Jani Nikula <jani.nikula@intel.com>
> Acked-by: David Sterba <dsterba@suse.com>
> Reviewed-by: Alex Shi <alexs@kernel.org>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-kbuild@vger.kernel.org
> Cc: llvm@lists.linux.dev
> Cc: linux-doc@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> [v3]
>  - split out USERCFLAGS to a separate patch
>  - add -Wdeclaration-after-statement patch from Mark Rutland
>  - leave out C17 reference
>  - more rewording the descrption
>

I was able to build and boot on bare metal.

No new warnings in my build-log here after switching to -std=gnu11.

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 x86-64

- sed@ -

> [v2]
>  - added -std=gnu11 back, rather than just relying on the default
>  - minor changes to changelog text
> ---
>  Documentation/process/programming-language.rst              | 6 +++---
>  .../translations/it_IT/process/programming-language.rst     | 4 ++--
>  .../translations/zh_CN/process/programming-language.rst     | 3 +--
>  .../translations/zh_TW/process/programming-language.rst     | 3 +--
>  Makefile                                                    | 4 ++--
>  arch/arm64/kernel/vdso32/Makefile                           | 2 +-
>  drivers/gpu/drm/i915/Makefile                               | 1 +
>  drivers/staging/greybus/tools/Makefile                      | 3 ++-
>  fs/btrfs/Makefile                                           | 1 +
>  scripts/Makefile.extrawarn                                  | 1 +
>  10 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/Documentation/process/programming-language.rst b/Documentation/process/programming-language.rst
> index ec474a70a02f..5fc9160ca1fa 100644
> --- a/Documentation/process/programming-language.rst
> +++ b/Documentation/process/programming-language.rst
> @@ -5,9 +5,9 @@ Programming Language
>
>  The kernel is written in the C programming language [c-language]_.
>  More precisely, the kernel is typically compiled with ``gcc`` [gcc]_
> -under ``-std=gnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90
> -(including some C99 features). ``clang`` [clang]_ is also supported, see
> -docs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> +under ``-std=gnu11`` [gcc-c-dialect-options]_: the GNU dialect of ISO C11.
> +``clang`` [clang]_ is also supported, see docs on
> +:ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
>
>  This dialect contains many extensions to the language [gnu-extensions]_,
>  and many of them are used within the kernel as a matter of course.
> diff --git a/Documentation/translations/it_IT/process/programming-language.rst b/Documentation/translations/it_IT/process/programming-language.rst
> index 41db2598ce11..c1a9b481a6f9 100644
> --- a/Documentation/translations/it_IT/process/programming-language.rst
> +++ b/Documentation/translations/it_IT/process/programming-language.rst
> @@ -10,8 +10,8 @@ Linguaggio di programmazione
>
>  Il kernel è scritto nel linguaggio di programmazione C [it-c-language]_.
>  Più precisamente, il kernel viene compilato con ``gcc`` [it-gcc]_ usando
> -l'opzione ``-std=gnu89`` [it-gcc-c-dialect-options]_: il dialetto GNU
> -dello standard ISO C90 (con l'aggiunta di alcune funzionalità da C99).
> +l'opzione ``-std=gnu11`` [it-gcc-c-dialect-options]_: il dialetto GNU
> +dello standard ISO C11.
>  Linux supporta anche ``clang`` [it-clang]_, leggete la documentazione
>  :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
>
> diff --git a/Documentation/translations/zh_CN/process/programming-language.rst b/Documentation/translations/zh_CN/process/programming-language.rst
> index 2a47a1d2ec20..fabdc338dbfb 100644
> --- a/Documentation/translations/zh_CN/process/programming-language.rst
> +++ b/Documentation/translations/zh_CN/process/programming-language.rst
> @@ -9,8 +9,7 @@
>  ============
>
>  内核是用C语言 :ref:`c-language <cn_c-language>` 编写的。更准确地说,内核通常是用 :ref:`gcc <cn_gcc>`
> -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C90的 GNU 方言(
> -包括一些C99特性)
> +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C11的 GNU 方言
>
>  这种方言包含对语言 :ref:`gnu-extensions <cn_gnu-extensions>` 的许多扩展,当然,它们许多都在内核中使用。
>
> diff --git a/Documentation/translations/zh_TW/process/programming-language.rst b/Documentation/translations/zh_TW/process/programming-language.rst
> index 54e3699eadf8..144bdaf81a41 100644
> --- a/Documentation/translations/zh_TW/process/programming-language.rst
> +++ b/Documentation/translations/zh_TW/process/programming-language.rst
> @@ -12,8 +12,7 @@
>  ============
>
>  內核是用C語言 :ref:`c-language <tw_c-language>` 編寫的。更準確地說,內核通常是用 :ref:`gcc <tw_gcc>`
> -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C90的 GNU 方言(
> -包括一些C99特性)
> +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C11的 GNU 方言
>
>  這種方言包含對語言 :ref:`gnu-extensions <tw_gnu-extensions>` 的許多擴展,當然,它們許多都在內核中使用。
>
> diff --git a/Makefile b/Makefile
> index 289ce2be8032..94fa9a849a7a 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -515,7 +515,7 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
>                    -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
>                    -Werror=implicit-function-declaration -Werror=implicit-int \
>                    -Werror=return-type -Wno-format-security \
> -                  -std=gnu89
> +                  -std=gnu11
>  KBUILD_CPPFLAGS := -D__KERNEL__
>  KBUILD_AFLAGS_KERNEL :=
>  KBUILD_CFLAGS_KERNEL :=
> @@ -782,7 +782,7 @@ KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
>
>  ifdef CONFIG_CC_IS_CLANG
>  KBUILD_CPPFLAGS += -Qunused-arguments
> -# The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable.
> +# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
>  KBUILD_CFLAGS += -Wno-gnu
>  # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
>  # source of a reference will be _MergedGlobals and not on of the whitelisted names.
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 6c01b63ff56d..9378ea055bf2 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,7 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> -               -std=gnu89
> +               -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
>  VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
> diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
> index 1b62b9f65196..1618a6e0af4e 100644
> --- a/drivers/gpu/drm/i915/Makefile
> +++ b/drivers/gpu/drm/i915/Makefile
> @@ -17,6 +17,7 @@ subdir-ccflags-y += -Wno-unused-parameter
>  subdir-ccflags-y += -Wno-type-limits
>  subdir-ccflags-y += -Wno-missing-field-initializers
>  subdir-ccflags-y += -Wno-sign-compare
> +subdir-ccflags-y += -Wno-shift-negative-value
>  subdir-ccflags-y += $(call cc-disable-warning, unused-but-set-variable)
>  subdir-ccflags-y += $(call cc-disable-warning, frame-address)
>  subdir-ccflags-$(CONFIG_DRM_I915_WERROR) += -Werror
> diff --git a/drivers/staging/greybus/tools/Makefile b/drivers/staging/greybus/tools/Makefile
> index ad0ae8053b79..a3bbd73171f2 100644
> --- a/drivers/staging/greybus/tools/Makefile
> +++ b/drivers/staging/greybus/tools/Makefile
> @@ -12,7 +12,8 @@ CFLAGS        += -std=gnu99 -Wall -Wextra -g \
>             -Wredundant-decls \
>             -Wcast-align \
>             -Wsign-compare \
> -           -Wno-missing-field-initializers
> +           -Wno-missing-field-initializers \
> +           -Wno-shift-negative-value
>
>  CC     := $(CROSS_COMPILE)gcc
>
> diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
> index 4188ba3fd8c3..99f9995670ea 100644
> --- a/fs/btrfs/Makefile
> +++ b/fs/btrfs/Makefile
> @@ -17,6 +17,7 @@ subdir-ccflags-y += $(condflags)
>  subdir-ccflags-y += -Wno-missing-field-initializers
>  subdir-ccflags-y += -Wno-sign-compare
>  subdir-ccflags-y += -Wno-type-limits
> +subdir-ccflags-y += -Wno-shift-negative-value
>
>  obj-$(CONFIG_BTRFS_FS) := btrfs.o
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 8be892887d71..650d0b8ceec3 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -36,6 +36,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
>  KBUILD_CFLAGS += -Wno-missing-field-initializers
>  KBUILD_CFLAGS += -Wno-sign-compare
>  KBUILD_CFLAGS += -Wno-type-limits
> +KBUILD_CFLAGS += -Wno-shift-negative-value
>
>  KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
>
> --
> 2.29.2
>

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

* Re: [PATCH 2/3] treewide: use -Wdeclaration-after-statement
  2022-03-01 14:52 ` [PATCH 2/3] treewide: use -Wdeclaration-after-statement Arnd Bergmann
                     ` (2 preceding siblings ...)
  2022-03-03  0:44   ` Masahiro Yamada
@ 2022-03-04 11:29   ` Sedat Dilek
  2022-03-06 10:03     ` Sedat Dilek
  3 siblings, 1 reply; 28+ messages in thread
From: Sedat Dilek @ 2022-03-04 11:29 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Tue, Mar 1, 2022 at 4:59 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Mark Rutland <mark.rutland@arm.com>
>
> In a subsequent patch we'll move the kernel from using `-std=gnu89` to
> `-std=gnu11`, permitting the use of additional C11 features such as
> for-loop initial declarations.
>
> One contentious aspect of C99 is that it permits mixed declarations and
> code, and for now at least, it seems preferable to enforce that
> declarations must come first.
>
> These warnings were already disabled in the kernel itself, but not
> for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
> a separate set of CFLAGS.
>
> This patch fixes an existing violation in modpost.c, which is not
> reported because of the missing flag in KBUILD_USERCFLAGS:
>
> | scripts/mod/modpost.c: In function ‘match’:
> | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
> |   837 |   const char *endp = p + strlen(p) - 1;
> |       |   ^~~~~
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> [arnd: don't add a duplicate flag to the default set, update changelog]
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

I was able to build and boot on bare metal.

No new warnings in my build-log here after switching to -std=gnu11.

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 x86-64

- sed@ -

> ---
>  Makefile                          | 3 ++-
>  arch/arm64/kernel/vdso32/Makefile | 1 +
>  scripts/mod/modpost.c             | 4 +++-
>  3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 94fa9a849a7a..37ef6a555dcd 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -432,7 +432,8 @@ HOSTCXX     = g++
>  endif
>
>  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> -                             -O2 -fomit-frame-pointer -std=gnu89
> +                           -O2 -fomit-frame-pointer -std=gnu89 \
> +                           -Wdeclaration-after-statement
>  export KBUILD_USERLDFLAGS :=
>
>  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 9378ea055bf2..ed181bedbffc 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> +               -Wdeclaration-after-statement \
>                 -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6bfa33217914..fe693304b120 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
>  {
>         const char *p;
>         while (*pat) {
> +               const char *endp;
> +
>                 p = *pat++;
> -               const char *endp = p + strlen(p) - 1;
> +               endp = p + strlen(p) - 1;
>
>                 /* "*foo*" */
>                 if (*p == '*' && *endp == '*') {
> --
> 2.29.2
>

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

* Re: [PATCH 1/3] [v3] Kbuild: move to -std=gnu11
  2022-03-01 14:52 [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Arnd Bergmann
                   ` (3 preceding siblings ...)
  2022-03-04 11:24 ` Sedat Dilek
@ 2022-03-04 11:37 ` Sedat Dilek
  2022-03-04 16:25 ` Sedat Dilek
  5 siblings, 0 replies; 28+ messages in thread
From: Sedat Dilek @ 2022-03-04 11:37 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Wed, Mar 2, 2022 at 5:29 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> During a patch discussion, Linus brought up the option of changing
> the C standard version from gnu89 to gnu99, which allows using variable
> declaration inside of a for() loop. While the C99, C11 and later standards
> introduce many other features, most of these are already available in
> gnu89 as GNU extensions as well.
>
> An earlier attempt to do this when gcc-5 started defaulting to
> -std=gnu11 failed because at the time that caused warnings about
> designated initializers with older compilers. Now that gcc-5.1 is
> the minimum compiler version used for building kernels, that is no
> longer a concern. Similarly, the behavior of 'inline' functions changes
> between gnu89 using gnu_inline behavior and gnu11 using standard c99+
> behavior, but this was taken care of by defining 'inline' to include
> __attribute__((gnu_inline)) in order to allow building with clang a
> while ago.
>
> One minor issue that remains is an added gcc warning for shifts of
> negative integers when building with -Wextra, which happens with the
> 'make W=1' option, as well as for three drivers in the kernel that always
> enable -Wextra, but it was only observed with the i915 driver so far.
> To be on the safe side, add -Wno-shift-negative-value to any -Wextra
> in a Makefile.
>
> Nathan Chancellor reported an additional -Wdeclaration-after-statement
> warning that appears in a system header on arm, this still needs a
> workaround.
>
> The differences between gnu99, gnu11, gnu1x and gnu17 are fairly
> minimal and mainly impact warnings at the -Wpedantic level that the
> kernel never enables. Between these, gnu11 is the newest version
> that is supported by all supported compiler versions, though it is
> only the default on gcc-5, while all other supported versions of
> gcc or clang default to gnu1x/gnu17.
>
> Link: https://lore.kernel.org/lkml/CAHk-=wiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpcovt8fYbVFW3TA@mail.gmail.com/
> Link: https://github.com/ClangBuiltLinux/linux/issues/1603
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Acked-by: Marco Elver <elver@google.com>
> Acked-by: Jani Nikula <jani.nikula@intel.com>
> Acked-by: David Sterba <dsterba@suse.com>
> Reviewed-by: Alex Shi <alexs@kernel.org>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-kbuild@vger.kernel.org
> Cc: llvm@lists.linux.dev
> Cc: linux-doc@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---

Arnd, please CC me on further patches/patchsets.
Thanks.

- Sedat -

> [v3]
>  - split out USERCFLAGS to a separate patch
>  - add -Wdeclaration-after-statement patch from Mark Rutland
>  - leave out C17 reference
>  - more rewording the descrption
>
> [v2]
>  - added -std=gnu11 back, rather than just relying on the default
>  - minor changes to changelog text
> ---
>  Documentation/process/programming-language.rst              | 6 +++---
>  .../translations/it_IT/process/programming-language.rst     | 4 ++--
>  .../translations/zh_CN/process/programming-language.rst     | 3 +--
>  .../translations/zh_TW/process/programming-language.rst     | 3 +--
>  Makefile                                                    | 4 ++--
>  arch/arm64/kernel/vdso32/Makefile                           | 2 +-
>  drivers/gpu/drm/i915/Makefile                               | 1 +
>  drivers/staging/greybus/tools/Makefile                      | 3 ++-
>  fs/btrfs/Makefile                                           | 1 +
>  scripts/Makefile.extrawarn                                  | 1 +
>  10 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/Documentation/process/programming-language.rst b/Documentation/process/programming-language.rst
> index ec474a70a02f..5fc9160ca1fa 100644
> --- a/Documentation/process/programming-language.rst
> +++ b/Documentation/process/programming-language.rst
> @@ -5,9 +5,9 @@ Programming Language
>
>  The kernel is written in the C programming language [c-language]_.
>  More precisely, the kernel is typically compiled with ``gcc`` [gcc]_
> -under ``-std=gnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90
> -(including some C99 features). ``clang`` [clang]_ is also supported, see
> -docs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> +under ``-std=gnu11`` [gcc-c-dialect-options]_: the GNU dialect of ISO C11.
> +``clang`` [clang]_ is also supported, see docs on
> +:ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
>
>  This dialect contains many extensions to the language [gnu-extensions]_,
>  and many of them are used within the kernel as a matter of course.
> diff --git a/Documentation/translations/it_IT/process/programming-language.rst b/Documentation/translations/it_IT/process/programming-language.rst
> index 41db2598ce11..c1a9b481a6f9 100644
> --- a/Documentation/translations/it_IT/process/programming-language.rst
> +++ b/Documentation/translations/it_IT/process/programming-language.rst
> @@ -10,8 +10,8 @@ Linguaggio di programmazione
>
>  Il kernel è scritto nel linguaggio di programmazione C [it-c-language]_.
>  Più precisamente, il kernel viene compilato con ``gcc`` [it-gcc]_ usando
> -l'opzione ``-std=gnu89`` [it-gcc-c-dialect-options]_: il dialetto GNU
> -dello standard ISO C90 (con l'aggiunta di alcune funzionalità da C99).
> +l'opzione ``-std=gnu11`` [it-gcc-c-dialect-options]_: il dialetto GNU
> +dello standard ISO C11.
>  Linux supporta anche ``clang`` [it-clang]_, leggete la documentazione
>  :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
>
> diff --git a/Documentation/translations/zh_CN/process/programming-language.rst b/Documentation/translations/zh_CN/process/programming-language.rst
> index 2a47a1d2ec20..fabdc338dbfb 100644
> --- a/Documentation/translations/zh_CN/process/programming-language.rst
> +++ b/Documentation/translations/zh_CN/process/programming-language.rst
> @@ -9,8 +9,7 @@
>  ============
>
>  内核是用C语言 :ref:`c-language <cn_c-language>` 编写的。更准确地说,内核通常是用 :ref:`gcc <cn_gcc>`
> -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C90的 GNU 方言(
> -包括一些C99特性)
> +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C11的 GNU 方言
>
>  这种方言包含对语言 :ref:`gnu-extensions <cn_gnu-extensions>` 的许多扩展,当然,它们许多都在内核中使用。
>
> diff --git a/Documentation/translations/zh_TW/process/programming-language.rst b/Documentation/translations/zh_TW/process/programming-language.rst
> index 54e3699eadf8..144bdaf81a41 100644
> --- a/Documentation/translations/zh_TW/process/programming-language.rst
> +++ b/Documentation/translations/zh_TW/process/programming-language.rst
> @@ -12,8 +12,7 @@
>  ============
>
>  內核是用C語言 :ref:`c-language <tw_c-language>` 編寫的。更準確地說,內核通常是用 :ref:`gcc <tw_gcc>`
> -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C90的 GNU 方言(
> -包括一些C99特性)
> +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C11的 GNU 方言
>
>  這種方言包含對語言 :ref:`gnu-extensions <tw_gnu-extensions>` 的許多擴展,當然,它們許多都在內核中使用。
>
> diff --git a/Makefile b/Makefile
> index 289ce2be8032..94fa9a849a7a 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -515,7 +515,7 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
>                    -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
>                    -Werror=implicit-function-declaration -Werror=implicit-int \
>                    -Werror=return-type -Wno-format-security \
> -                  -std=gnu89
> +                  -std=gnu11
>  KBUILD_CPPFLAGS := -D__KERNEL__
>  KBUILD_AFLAGS_KERNEL :=
>  KBUILD_CFLAGS_KERNEL :=
> @@ -782,7 +782,7 @@ KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
>
>  ifdef CONFIG_CC_IS_CLANG
>  KBUILD_CPPFLAGS += -Qunused-arguments
> -# The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable.
> +# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
>  KBUILD_CFLAGS += -Wno-gnu
>  # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
>  # source of a reference will be _MergedGlobals and not on of the whitelisted names.
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 6c01b63ff56d..9378ea055bf2 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,7 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> -               -std=gnu89
> +               -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
>  VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
> diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
> index 1b62b9f65196..1618a6e0af4e 100644
> --- a/drivers/gpu/drm/i915/Makefile
> +++ b/drivers/gpu/drm/i915/Makefile
> @@ -17,6 +17,7 @@ subdir-ccflags-y += -Wno-unused-parameter
>  subdir-ccflags-y += -Wno-type-limits
>  subdir-ccflags-y += -Wno-missing-field-initializers
>  subdir-ccflags-y += -Wno-sign-compare
> +subdir-ccflags-y += -Wno-shift-negative-value
>  subdir-ccflags-y += $(call cc-disable-warning, unused-but-set-variable)
>  subdir-ccflags-y += $(call cc-disable-warning, frame-address)
>  subdir-ccflags-$(CONFIG_DRM_I915_WERROR) += -Werror
> diff --git a/drivers/staging/greybus/tools/Makefile b/drivers/staging/greybus/tools/Makefile
> index ad0ae8053b79..a3bbd73171f2 100644
> --- a/drivers/staging/greybus/tools/Makefile
> +++ b/drivers/staging/greybus/tools/Makefile
> @@ -12,7 +12,8 @@ CFLAGS        += -std=gnu99 -Wall -Wextra -g \
>             -Wredundant-decls \
>             -Wcast-align \
>             -Wsign-compare \
> -           -Wno-missing-field-initializers
> +           -Wno-missing-field-initializers \
> +           -Wno-shift-negative-value
>
>  CC     := $(CROSS_COMPILE)gcc
>
> diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
> index 4188ba3fd8c3..99f9995670ea 100644
> --- a/fs/btrfs/Makefile
> +++ b/fs/btrfs/Makefile
> @@ -17,6 +17,7 @@ subdir-ccflags-y += $(condflags)
>  subdir-ccflags-y += -Wno-missing-field-initializers
>  subdir-ccflags-y += -Wno-sign-compare
>  subdir-ccflags-y += -Wno-type-limits
> +subdir-ccflags-y += -Wno-shift-negative-value
>
>  obj-$(CONFIG_BTRFS_FS) := btrfs.o
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 8be892887d71..650d0b8ceec3 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -36,6 +36,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
>  KBUILD_CFLAGS += -Wno-missing-field-initializers
>  KBUILD_CFLAGS += -Wno-sign-compare
>  KBUILD_CFLAGS += -Wno-type-limits
> +KBUILD_CFLAGS += -Wno-shift-negative-value
>
>  KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
>
> --
> 2.29.2
>

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

* Re: [PATCH 1/3] [v3] Kbuild: move to -std=gnu11
  2022-03-01 14:52 [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Arnd Bergmann
                   ` (4 preceding siblings ...)
  2022-03-04 11:37 ` Sedat Dilek
@ 2022-03-04 16:25 ` Sedat Dilek
  2022-03-06 15:31   ` Sedat Dilek
  5 siblings, 1 reply; 28+ messages in thread
From: Sedat Dilek @ 2022-03-04 16:25 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Wed, Mar 2, 2022 at 5:29 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> During a patch discussion, Linus brought up the option of changing
> the C standard version from gnu89 to gnu99, which allows using variable
> declaration inside of a for() loop. While the C99, C11 and later standards
> introduce many other features, most of these are already available in
> gnu89 as GNU extensions as well.
>
> An earlier attempt to do this when gcc-5 started defaulting to
> -std=gnu11 failed because at the time that caused warnings about
> designated initializers with older compilers. Now that gcc-5.1 is
> the minimum compiler version used for building kernels, that is no
> longer a concern. Similarly, the behavior of 'inline' functions changes
> between gnu89 using gnu_inline behavior and gnu11 using standard c99+
> behavior, but this was taken care of by defining 'inline' to include
> __attribute__((gnu_inline)) in order to allow building with clang a
> while ago.
>
> One minor issue that remains is an added gcc warning for shifts of
> negative integers when building with -Wextra, which happens with the
> 'make W=1' option, as well as for three drivers in the kernel that always
> enable -Wextra, but it was only observed with the i915 driver so far.
> To be on the safe side, add -Wno-shift-negative-value to any -Wextra
> in a Makefile.
>
> Nathan Chancellor reported an additional -Wdeclaration-after-statement
> warning that appears in a system header on arm, this still needs a
> workaround.
>
> The differences between gnu99, gnu11, gnu1x and gnu17 are fairly
> minimal and mainly impact warnings at the -Wpedantic level that the
> kernel never enables. Between these, gnu11 is the newest version
> that is supported by all supported compiler versions, though it is
> only the default on gcc-5, while all other supported versions of
> gcc or clang default to gnu1x/gnu17.
>
> Link: https://lore.kernel.org/lkml/CAHk-=wiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpcovt8fYbVFW3TA@mail.gmail.com/
> Link: https://github.com/ClangBuiltLinux/linux/issues/1603
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Acked-by: Marco Elver <elver@google.com>
> Acked-by: Jani Nikula <jani.nikula@intel.com>
> Acked-by: David Sterba <dsterba@suse.com>
> Reviewed-by: Alex Shi <alexs@kernel.org>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: linux-kbuild@vger.kernel.org
> Cc: llvm@lists.linux.dev
> Cc: linux-doc@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

When I saw the first patches in this area, I was thinking what about
the tools/ build-system?
This ECO system has its own rules.

I use CONFIG_DEBUG_INFO_BTF=y in my kernels which means
tools/bpf/resolve_btfids will be built.
This uses hardcoded -std=gnu89.

$ git grep 'std=gnu89' tools/
tools/lib/bpf/Makefile:override CFLAGS += -std=gnu89
tools/testing/selftests/sync/Makefile:CFLAGS += -O2 -g -std=gnu89
-pthread -Wall -Wextra

Furthermore, we have several places using C99 which can be replaced by C11 now.

$ git grep 'std=gnu99' tools/ | wc -l
20

We already have C11 in tools/:

$ git grep 'std=gnu11' tools/
tools/testing/selftests/wireguard/qemu/Makefile:        $(MUSL_CC) -o
$@ $(CFLAGS) $(LDFLAGS) -std=gnu11 $<

What about having a central place where we define the
STD_GNU_C_VERSION (as a suggestion)?
This might be helpful for people dealing with diverse C version standards.

Also with STD_GNU_CXX_VERSION which is used AFAICS only in tools/:

$ git grep 'std=gnu++' tools/
tools/build/feature/Makefile:   $(BUILDXX) -std=gnu++11
tools/build/feature/Makefile:   $(BUILDXX) -std=gnu++14
                 \
tools/build/feature/Makefile:   $(BUILDXX) -std=gnu++14
                 \
tools/build/feature/Makefile:   $(BUILDXX) -std=gnu++14
                 \
tools/perf/Makefile.config:CXXFLAGS += -std=gnu++14 -fno-exceptions -fno-rtti

Looks like one place should be -std=gnu++14.
( I had no deeper look. No testing. )

Just some thoughts.

- Sedat -

> ---
> [v3]
>  - split out USERCFLAGS to a separate patch
>  - add -Wdeclaration-after-statement patch from Mark Rutland
>  - leave out C17 reference
>  - more rewording the descrption
>
> [v2]
>  - added -std=gnu11 back, rather than just relying on the default
>  - minor changes to changelog text
> ---
>  Documentation/process/programming-language.rst              | 6 +++---
>  .../translations/it_IT/process/programming-language.rst     | 4 ++--
>  .../translations/zh_CN/process/programming-language.rst     | 3 +--
>  .../translations/zh_TW/process/programming-language.rst     | 3 +--
>  Makefile                                                    | 4 ++--
>  arch/arm64/kernel/vdso32/Makefile                           | 2 +-
>  drivers/gpu/drm/i915/Makefile                               | 1 +
>  drivers/staging/greybus/tools/Makefile                      | 3 ++-
>  fs/btrfs/Makefile                                           | 1 +
>  scripts/Makefile.extrawarn                                  | 1 +
>  10 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/Documentation/process/programming-language.rst b/Documentation/process/programming-language.rst
> index ec474a70a02f..5fc9160ca1fa 100644
> --- a/Documentation/process/programming-language.rst
> +++ b/Documentation/process/programming-language.rst
> @@ -5,9 +5,9 @@ Programming Language
>
>  The kernel is written in the C programming language [c-language]_.
>  More precisely, the kernel is typically compiled with ``gcc`` [gcc]_
> -under ``-std=gnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90
> -(including some C99 features). ``clang`` [clang]_ is also supported, see
> -docs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> +under ``-std=gnu11`` [gcc-c-dialect-options]_: the GNU dialect of ISO C11.
> +``clang`` [clang]_ is also supported, see docs on
> +:ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
>
>  This dialect contains many extensions to the language [gnu-extensions]_,
>  and many of them are used within the kernel as a matter of course.
> diff --git a/Documentation/translations/it_IT/process/programming-language.rst b/Documentation/translations/it_IT/process/programming-language.rst
> index 41db2598ce11..c1a9b481a6f9 100644
> --- a/Documentation/translations/it_IT/process/programming-language.rst
> +++ b/Documentation/translations/it_IT/process/programming-language.rst
> @@ -10,8 +10,8 @@ Linguaggio di programmazione
>
>  Il kernel è scritto nel linguaggio di programmazione C [it-c-language]_.
>  Più precisamente, il kernel viene compilato con ``gcc`` [it-gcc]_ usando
> -l'opzione ``-std=gnu89`` [it-gcc-c-dialect-options]_: il dialetto GNU
> -dello standard ISO C90 (con l'aggiunta di alcune funzionalità da C99).
> +l'opzione ``-std=gnu11`` [it-gcc-c-dialect-options]_: il dialetto GNU
> +dello standard ISO C11.
>  Linux supporta anche ``clang`` [it-clang]_, leggete la documentazione
>  :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
>
> diff --git a/Documentation/translations/zh_CN/process/programming-language.rst b/Documentation/translations/zh_CN/process/programming-language.rst
> index 2a47a1d2ec20..fabdc338dbfb 100644
> --- a/Documentation/translations/zh_CN/process/programming-language.rst
> +++ b/Documentation/translations/zh_CN/process/programming-language.rst
> @@ -9,8 +9,7 @@
>  ============
>
>  内核是用C语言 :ref:`c-language <cn_c-language>` 编写的。更准确地说,内核通常是用 :ref:`gcc <cn_gcc>`
> -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C90的 GNU 方言(
> -包括一些C99特性)
> +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C11的 GNU 方言
>
>  这种方言包含对语言 :ref:`gnu-extensions <cn_gnu-extensions>` 的许多扩展,当然,它们许多都在内核中使用。
>
> diff --git a/Documentation/translations/zh_TW/process/programming-language.rst b/Documentation/translations/zh_TW/process/programming-language.rst
> index 54e3699eadf8..144bdaf81a41 100644
> --- a/Documentation/translations/zh_TW/process/programming-language.rst
> +++ b/Documentation/translations/zh_TW/process/programming-language.rst
> @@ -12,8 +12,7 @@
>  ============
>
>  內核是用C語言 :ref:`c-language <tw_c-language>` 編寫的。更準確地說,內核通常是用 :ref:`gcc <tw_gcc>`
> -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C90的 GNU 方言(
> -包括一些C99特性)
> +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C11的 GNU 方言
>
>  這種方言包含對語言 :ref:`gnu-extensions <tw_gnu-extensions>` 的許多擴展,當然,它們許多都在內核中使用。
>
> diff --git a/Makefile b/Makefile
> index 289ce2be8032..94fa9a849a7a 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -515,7 +515,7 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
>                    -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
>                    -Werror=implicit-function-declaration -Werror=implicit-int \
>                    -Werror=return-type -Wno-format-security \
> -                  -std=gnu89
> +                  -std=gnu11
>  KBUILD_CPPFLAGS := -D__KERNEL__
>  KBUILD_AFLAGS_KERNEL :=
>  KBUILD_CFLAGS_KERNEL :=
> @@ -782,7 +782,7 @@ KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
>
>  ifdef CONFIG_CC_IS_CLANG
>  KBUILD_CPPFLAGS += -Qunused-arguments
> -# The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable.
> +# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
>  KBUILD_CFLAGS += -Wno-gnu
>  # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
>  # source of a reference will be _MergedGlobals and not on of the whitelisted names.
> diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> index 6c01b63ff56d..9378ea055bf2 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -68,7 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
>                 -fno-strict-aliasing -fno-common \
>                 -Werror-implicit-function-declaration \
>                 -Wno-format-security \
> -               -std=gnu89
> +               -std=gnu11
>  VDSO_CFLAGS  += -O2
>  # Some useful compiler-dependent flags from top-level Makefile
>  VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
> diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
> index 1b62b9f65196..1618a6e0af4e 100644
> --- a/drivers/gpu/drm/i915/Makefile
> +++ b/drivers/gpu/drm/i915/Makefile
> @@ -17,6 +17,7 @@ subdir-ccflags-y += -Wno-unused-parameter
>  subdir-ccflags-y += -Wno-type-limits
>  subdir-ccflags-y += -Wno-missing-field-initializers
>  subdir-ccflags-y += -Wno-sign-compare
> +subdir-ccflags-y += -Wno-shift-negative-value
>  subdir-ccflags-y += $(call cc-disable-warning, unused-but-set-variable)
>  subdir-ccflags-y += $(call cc-disable-warning, frame-address)
>  subdir-ccflags-$(CONFIG_DRM_I915_WERROR) += -Werror
> diff --git a/drivers/staging/greybus/tools/Makefile b/drivers/staging/greybus/tools/Makefile
> index ad0ae8053b79..a3bbd73171f2 100644
> --- a/drivers/staging/greybus/tools/Makefile
> +++ b/drivers/staging/greybus/tools/Makefile
> @@ -12,7 +12,8 @@ CFLAGS        += -std=gnu99 -Wall -Wextra -g \
>             -Wredundant-decls \
>             -Wcast-align \
>             -Wsign-compare \
> -           -Wno-missing-field-initializers
> +           -Wno-missing-field-initializers \
> +           -Wno-shift-negative-value
>
>  CC     := $(CROSS_COMPILE)gcc
>
> diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
> index 4188ba3fd8c3..99f9995670ea 100644
> --- a/fs/btrfs/Makefile
> +++ b/fs/btrfs/Makefile
> @@ -17,6 +17,7 @@ subdir-ccflags-y += $(condflags)
>  subdir-ccflags-y += -Wno-missing-field-initializers
>  subdir-ccflags-y += -Wno-sign-compare
>  subdir-ccflags-y += -Wno-type-limits
> +subdir-ccflags-y += -Wno-shift-negative-value
>
>  obj-$(CONFIG_BTRFS_FS) := btrfs.o
>
> diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> index 8be892887d71..650d0b8ceec3 100644
> --- a/scripts/Makefile.extrawarn
> +++ b/scripts/Makefile.extrawarn
> @@ -36,6 +36,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
>  KBUILD_CFLAGS += -Wno-missing-field-initializers
>  KBUILD_CFLAGS += -Wno-sign-compare
>  KBUILD_CFLAGS += -Wno-type-limits
> +KBUILD_CFLAGS += -Wno-shift-negative-value
>
>  KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
>
> --
> 2.29.2
>

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

* Re: [PATCH 1/3] [v3] Kbuild: move to -std=gnu11
  2022-03-04 11:24 ` Sedat Dilek
@ 2022-03-06 10:01   ` Sedat Dilek
  0 siblings, 0 replies; 28+ messages in thread
From: Sedat Dilek @ 2022-03-06 10:01 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Fri, Mar 4, 2022 at 12:24 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Wed, Mar 2, 2022 at 5:29 PM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > During a patch discussion, Linus brought up the option of changing
> > the C standard version from gnu89 to gnu99, which allows using variable
> > declaration inside of a for() loop. While the C99, C11 and later standards
> > introduce many other features, most of these are already available in
> > gnu89 as GNU extensions as well.
> >
> > An earlier attempt to do this when gcc-5 started defaulting to
> > -std=gnu11 failed because at the time that caused warnings about
> > designated initializers with older compilers. Now that gcc-5.1 is
> > the minimum compiler version used for building kernels, that is no
> > longer a concern. Similarly, the behavior of 'inline' functions changes
> > between gnu89 using gnu_inline behavior and gnu11 using standard c99+
> > behavior, but this was taken care of by defining 'inline' to include
> > __attribute__((gnu_inline)) in order to allow building with clang a
> > while ago.
> >
> > One minor issue that remains is an added gcc warning for shifts of
> > negative integers when building with -Wextra, which happens with the
> > 'make W=1' option, as well as for three drivers in the kernel that always
> > enable -Wextra, but it was only observed with the i915 driver so far.
> > To be on the safe side, add -Wno-shift-negative-value to any -Wextra
> > in a Makefile.
> >
> > Nathan Chancellor reported an additional -Wdeclaration-after-statement
> > warning that appears in a system header on arm, this still needs a
> > workaround.
> >
> > The differences between gnu99, gnu11, gnu1x and gnu17 are fairly
> > minimal and mainly impact warnings at the -Wpedantic level that the
> > kernel never enables. Between these, gnu11 is the newest version
> > that is supported by all supported compiler versions, though it is
> > only the default on gcc-5, while all other supported versions of
> > gcc or clang default to gnu1x/gnu17.
> >
> > Link: https://lore.kernel.org/lkml/CAHk-=wiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpcovt8fYbVFW3TA@mail.gmail.com/
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1603
> > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Acked-by: Marco Elver <elver@google.com>
> > Acked-by: Jani Nikula <jani.nikula@intel.com>
> > Acked-by: David Sterba <dsterba@suse.com>
> > Reviewed-by: Alex Shi <alexs@kernel.org>
> > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> > Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
> > Cc: Masahiro Yamada <masahiroy@kernel.org>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: linux-kbuild@vger.kernel.org
> > Cc: llvm@lists.linux.dev
> > Cc: linux-doc@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> > [v3]
> >  - split out USERCFLAGS to a separate patch
> >  - add -Wdeclaration-after-statement patch from Mark Rutland
> >  - leave out C17 reference
> >  - more rewording the descrption
> >
>
> I was able to build and boot on bare metal.
>
> No new warnings in my build-log here after switching to -std=gnu11.
>
> Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 x86-64
>

I have re-tested with Debian's LLVM/Clang v14.0.0-rc2.

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v14.0.0-rc2 (x86-64)

- sed@ -

> - sed@ -
>
> > [v2]
> >  - added -std=gnu11 back, rather than just relying on the default
> >  - minor changes to changelog text
> > ---
> >  Documentation/process/programming-language.rst              | 6 +++---
> >  .../translations/it_IT/process/programming-language.rst     | 4 ++--
> >  .../translations/zh_CN/process/programming-language.rst     | 3 +--
> >  .../translations/zh_TW/process/programming-language.rst     | 3 +--
> >  Makefile                                                    | 4 ++--
> >  arch/arm64/kernel/vdso32/Makefile                           | 2 +-
> >  drivers/gpu/drm/i915/Makefile                               | 1 +
> >  drivers/staging/greybus/tools/Makefile                      | 3 ++-
> >  fs/btrfs/Makefile                                           | 1 +
> >  scripts/Makefile.extrawarn                                  | 1 +
> >  10 files changed, 15 insertions(+), 13 deletions(-)
> >
> > diff --git a/Documentation/process/programming-language.rst b/Documentation/process/programming-language.rst
> > index ec474a70a02f..5fc9160ca1fa 100644
> > --- a/Documentation/process/programming-language.rst
> > +++ b/Documentation/process/programming-language.rst
> > @@ -5,9 +5,9 @@ Programming Language
> >
> >  The kernel is written in the C programming language [c-language]_.
> >  More precisely, the kernel is typically compiled with ``gcc`` [gcc]_
> > -under ``-std=gnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90
> > -(including some C99 features). ``clang`` [clang]_ is also supported, see
> > -docs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> > +under ``-std=gnu11`` [gcc-c-dialect-options]_: the GNU dialect of ISO C11.
> > +``clang`` [clang]_ is also supported, see docs on
> > +:ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> >
> >  This dialect contains many extensions to the language [gnu-extensions]_,
> >  and many of them are used within the kernel as a matter of course.
> > diff --git a/Documentation/translations/it_IT/process/programming-language.rst b/Documentation/translations/it_IT/process/programming-language.rst
> > index 41db2598ce11..c1a9b481a6f9 100644
> > --- a/Documentation/translations/it_IT/process/programming-language.rst
> > +++ b/Documentation/translations/it_IT/process/programming-language.rst
> > @@ -10,8 +10,8 @@ Linguaggio di programmazione
> >
> >  Il kernel è scritto nel linguaggio di programmazione C [it-c-language]_.
> >  Più precisamente, il kernel viene compilato con ``gcc`` [it-gcc]_ usando
> > -l'opzione ``-std=gnu89`` [it-gcc-c-dialect-options]_: il dialetto GNU
> > -dello standard ISO C90 (con l'aggiunta di alcune funzionalità da C99).
> > +l'opzione ``-std=gnu11`` [it-gcc-c-dialect-options]_: il dialetto GNU
> > +dello standard ISO C11.
> >  Linux supporta anche ``clang`` [it-clang]_, leggete la documentazione
> >  :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.
> >
> > diff --git a/Documentation/translations/zh_CN/process/programming-language.rst b/Documentation/translations/zh_CN/process/programming-language.rst
> > index 2a47a1d2ec20..fabdc338dbfb 100644
> > --- a/Documentation/translations/zh_CN/process/programming-language.rst
> > +++ b/Documentation/translations/zh_CN/process/programming-language.rst
> > @@ -9,8 +9,7 @@
> >  ============
> >
> >  内核是用C语言 :ref:`c-language <cn_c-language>` 编写的。更准确地说,内核通常是用 :ref:`gcc <cn_gcc>`
> > -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C90的 GNU 方言(
> > -包括一些C99特性)
> > +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <cn_gcc-c-dialect-options>` 下编译的:ISO C11的 GNU 方言
> >
> >  这种方言包含对语言 :ref:`gnu-extensions <cn_gnu-extensions>` 的许多扩展,当然,它们许多都在内核中使用。
> >
> > diff --git a/Documentation/translations/zh_TW/process/programming-language.rst b/Documentation/translations/zh_TW/process/programming-language.rst
> > index 54e3699eadf8..144bdaf81a41 100644
> > --- a/Documentation/translations/zh_TW/process/programming-language.rst
> > +++ b/Documentation/translations/zh_TW/process/programming-language.rst
> > @@ -12,8 +12,7 @@
> >  ============
> >
> >  內核是用C語言 :ref:`c-language <tw_c-language>` 編寫的。更準確地說,內核通常是用 :ref:`gcc <tw_gcc>`
> > -在 ``-std=gnu89`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C90的 GNU 方言(
> > -包括一些C99特性)
> > +在 ``-std=gnu11`` :ref:`gcc-c-dialect-options <tw_gcc-c-dialect-options>` 下編譯的:ISO C11的 GNU 方言
> >
> >  這種方言包含對語言 :ref:`gnu-extensions <tw_gnu-extensions>` 的許多擴展,當然,它們許多都在內核中使用。
> >
> > diff --git a/Makefile b/Makefile
> > index 289ce2be8032..94fa9a849a7a 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -515,7 +515,7 @@ KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
> >                    -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
> >                    -Werror=implicit-function-declaration -Werror=implicit-int \
> >                    -Werror=return-type -Wno-format-security \
> > -                  -std=gnu89
> > +                  -std=gnu11
> >  KBUILD_CPPFLAGS := -D__KERNEL__
> >  KBUILD_AFLAGS_KERNEL :=
> >  KBUILD_CFLAGS_KERNEL :=
> > @@ -782,7 +782,7 @@ KBUILD_CFLAGS += $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLICIT_FALLTHROUGH)
> >
> >  ifdef CONFIG_CC_IS_CLANG
> >  KBUILD_CPPFLAGS += -Qunused-arguments
> > -# The kernel builds with '-std=gnu89' so use of GNU extensions is acceptable.
> > +# The kernel builds with '-std=gnu11' so use of GNU extensions is acceptable.
> >  KBUILD_CFLAGS += -Wno-gnu
> >  # CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
> >  # source of a reference will be _MergedGlobals and not on of the whitelisted names.
> > diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> > index 6c01b63ff56d..9378ea055bf2 100644
> > --- a/arch/arm64/kernel/vdso32/Makefile
> > +++ b/arch/arm64/kernel/vdso32/Makefile
> > @@ -68,7 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
> >                 -fno-strict-aliasing -fno-common \
> >                 -Werror-implicit-function-declaration \
> >                 -Wno-format-security \
> > -               -std=gnu89
> > +               -std=gnu11
> >  VDSO_CFLAGS  += -O2
> >  # Some useful compiler-dependent flags from top-level Makefile
> >  VDSO_CFLAGS += $(call cc32-option,-Wdeclaration-after-statement,)
> > diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
> > index 1b62b9f65196..1618a6e0af4e 100644
> > --- a/drivers/gpu/drm/i915/Makefile
> > +++ b/drivers/gpu/drm/i915/Makefile
> > @@ -17,6 +17,7 @@ subdir-ccflags-y += -Wno-unused-parameter
> >  subdir-ccflags-y += -Wno-type-limits
> >  subdir-ccflags-y += -Wno-missing-field-initializers
> >  subdir-ccflags-y += -Wno-sign-compare
> > +subdir-ccflags-y += -Wno-shift-negative-value
> >  subdir-ccflags-y += $(call cc-disable-warning, unused-but-set-variable)
> >  subdir-ccflags-y += $(call cc-disable-warning, frame-address)
> >  subdir-ccflags-$(CONFIG_DRM_I915_WERROR) += -Werror
> > diff --git a/drivers/staging/greybus/tools/Makefile b/drivers/staging/greybus/tools/Makefile
> > index ad0ae8053b79..a3bbd73171f2 100644
> > --- a/drivers/staging/greybus/tools/Makefile
> > +++ b/drivers/staging/greybus/tools/Makefile
> > @@ -12,7 +12,8 @@ CFLAGS        += -std=gnu99 -Wall -Wextra -g \
> >             -Wredundant-decls \
> >             -Wcast-align \
> >             -Wsign-compare \
> > -           -Wno-missing-field-initializers
> > +           -Wno-missing-field-initializers \
> > +           -Wno-shift-negative-value
> >
> >  CC     := $(CROSS_COMPILE)gcc
> >
> > diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
> > index 4188ba3fd8c3..99f9995670ea 100644
> > --- a/fs/btrfs/Makefile
> > +++ b/fs/btrfs/Makefile
> > @@ -17,6 +17,7 @@ subdir-ccflags-y += $(condflags)
> >  subdir-ccflags-y += -Wno-missing-field-initializers
> >  subdir-ccflags-y += -Wno-sign-compare
> >  subdir-ccflags-y += -Wno-type-limits
> > +subdir-ccflags-y += -Wno-shift-negative-value
> >
> >  obj-$(CONFIG_BTRFS_FS) := btrfs.o
> >
> > diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
> > index 8be892887d71..650d0b8ceec3 100644
> > --- a/scripts/Makefile.extrawarn
> > +++ b/scripts/Makefile.extrawarn
> > @@ -36,6 +36,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
> >  KBUILD_CFLAGS += -Wno-missing-field-initializers
> >  KBUILD_CFLAGS += -Wno-sign-compare
> >  KBUILD_CFLAGS += -Wno-type-limits
> > +KBUILD_CFLAGS += -Wno-shift-negative-value
> >
> >  KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN1
> >
> > --
> > 2.29.2
> >

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

* Re: [PATCH 2/3] treewide: use -Wdeclaration-after-statement
  2022-03-04 11:29   ` Sedat Dilek
@ 2022-03-06 10:03     ` Sedat Dilek
  0 siblings, 0 replies; 28+ messages in thread
From: Sedat Dilek @ 2022-03-06 10:03 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Fri, Mar 4, 2022 at 12:29 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Tue, Mar 1, 2022 at 4:59 PM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > From: Mark Rutland <mark.rutland@arm.com>
> >
> > In a subsequent patch we'll move the kernel from using `-std=gnu89` to
> > `-std=gnu11`, permitting the use of additional C11 features such as
> > for-loop initial declarations.
> >
> > One contentious aspect of C99 is that it permits mixed declarations and
> > code, and for now at least, it seems preferable to enforce that
> > declarations must come first.
> >
> > These warnings were already disabled in the kernel itself, but not
> > for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
> > a separate set of CFLAGS.
> >
> > This patch fixes an existing violation in modpost.c, which is not
> > reported because of the missing flag in KBUILD_USERCFLAGS:
> >
> > | scripts/mod/modpost.c: In function ‘match’:
> > | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
> > |   837 |   const char *endp = p + strlen(p) - 1;
> > |       |   ^~~~~
> >
> > Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> > [arnd: don't add a duplicate flag to the default set, update changelog]
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> I was able to build and boot on bare metal.
>
> No new warnings in my build-log here after switching to -std=gnu11.
>
> Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 x86-64
>

I have re-tested with Debian's LLVM/Clang v14.0.0-rc2.

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v14.0.0-rc2 (x86-64)

- sed@ -

> - sed@ -
>
> > ---
> >  Makefile                          | 3 ++-
> >  arch/arm64/kernel/vdso32/Makefile | 1 +
> >  scripts/mod/modpost.c             | 4 +++-
> >  3 files changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 94fa9a849a7a..37ef6a555dcd 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -432,7 +432,8 @@ HOSTCXX     = g++
> >  endif
> >
> >  export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
> > -                             -O2 -fomit-frame-pointer -std=gnu89
> > +                           -O2 -fomit-frame-pointer -std=gnu89 \
> > +                           -Wdeclaration-after-statement
> >  export KBUILD_USERLDFLAGS :=
> >
> >  KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
> > diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/Makefile
> > index 9378ea055bf2..ed181bedbffc 100644
> > --- a/arch/arm64/kernel/vdso32/Makefile
> > +++ b/arch/arm64/kernel/vdso32/Makefile
> > @@ -68,6 +68,7 @@ VDSO_CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
> >                 -fno-strict-aliasing -fno-common \
> >                 -Werror-implicit-function-declaration \
> >                 -Wno-format-security \
> > +               -Wdeclaration-after-statement \
> >                 -std=gnu11
> >  VDSO_CFLAGS  += -O2
> >  # Some useful compiler-dependent flags from top-level Makefile
> > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > index 6bfa33217914..fe693304b120 100644
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
> > @@ -833,8 +833,10 @@ static int match(const char *sym, const char * const pat[])
> >  {
> >         const char *p;
> >         while (*pat) {
> > +               const char *endp;
> > +
> >                 p = *pat++;
> > -               const char *endp = p + strlen(p) - 1;
> > +               endp = p + strlen(p) - 1;
> >
> >                 /* "*foo*" */
> >                 if (*p == '*' && *endp == '*') {
> > --
> > 2.29.2
> >

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

* Re: [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS
  2022-03-04 11:12               ` Sedat Dilek
@ 2022-03-06 10:04                 ` Sedat Dilek
  0 siblings, 0 replies; 28+ messages in thread
From: Sedat Dilek @ 2022-03-06 10:04 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nick Desaulniers, Arnd Bergmann, Masahiro Yamada, Arnd Bergmann,
	Linus Torvalds, Marco Elver, Jani Nikula, David Sterba, Alex Shi,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Fri, Mar 4, 2022 at 12:12 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
>
> On Fri, Mar 4, 2022 at 8:18 AM Sedat Dilek <sedat.dilek@gmail.com> wrote:
> >
> > On Fri, Mar 4, 2022 at 7:47 AM Sedat Dilek <sedat.dilek@gmail.com> wrote:
> > >
> > > On Thu, Mar 3, 2022 at 6:37 PM Nathan Chancellor <nathan@kernel.org> wrote:
> > > >
> > > > Hi Sedat,
> > > >
> > > > On Thu, Mar 03, 2022 at 07:26:05AM +0100, Sedat Dilek wrote:
> > > > > Hey Nick!
> > > > >
> > > > > This only applies 1/3.
> > > > >
> > > > > $ b4 --version
> > > > > 0.8.0
> > > > >
> > > > > $ b4 am https://lore.kernel.org/lkml/20220301145233.3689119-1-arnd@kernel.org/
> > > > > -o - | git am -3
> > > > > Analyzing 14 messages in the thread
> > > > > Will use the latest revision: v3
> > > > > You can pick other revisions using the -vN flag
> > > > > Checking attestation on all messages, may take a moment...
> > > > > ---
> > > > >  ✓ [PATCH v3 1/3] Kbuild: move to -std=gnu11
> > > > >    ✓ Signed: DKIM/kernel.org
> > > > >    + Reviewed-by: Nathan Chancellor <nathan@kernel.org> (✓ DKIM/kernel.org)
> > > > >  ERROR: missing [2/3]!
> > > > >  ERROR: missing [3/3]!
> > > > >  ---
> > > > >  NOTE: install patatt for end-to-end signature verification
> > > > > ---
> > > > > Total patches: 1
> > > > > ---
> > > > > WARNING: Thread incomplete!
> > > > > Link: https://lore.kernel.org/r/20220301145233.3689119-1-arnd@kernel.org
> > > > > Base: not specified
> > > > > Wende an: Kbuild: move to -std=gnu11
> > > >
> > > > It looks like the threading somehow got broken, likely due to the [v3]
> > > > on the first patch and not the second or third:
> > > >
> > > > This worked for me on v5.17-rc6:
> > > >
> > > > $ for i in $(seq 1 3); do b4 shazam -P _ 20220301145233.3689119-"$i"-arnd@kernel.org; done
> > > >
> > > > "b4 shazam" is the equivalent of "b4 am -o - ... | git am" and the
> > > > "-P _" tells b4 to only fetch that exact message ID, not the whole
> > > > thread.
> > > >
> > >
> > > Hmm, the universe is not good to me...
> > >
> > > $ for i in $(seq 1 3); do b4 shazam -P _
> > > 20220301145233.3689119-"$i"-arnd@kernel.org; done
> > > usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
> > > b4: error: argument subcmd: invalid choice: 'shazam' (choose from
> > > 'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
> > > usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
> > > b4: error: argument subcmd: invalid choice: 'shazam' (choose from
> > > 'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
> > > usage: b4 [-h] [--version] [-d] [-q] {mbox,am,attest,pr,ty,diff,kr} ...
> > > b4: error: argument subcmd: invalid choice: 'shazam' (choose from
> > > 'mbox', 'am', 'attest', 'pr', 'ty', 'diff', 'kr')
> > >
> > > Do I need a higher version of b4 (here: v0.8.0)?
> > >
> > > Check myself... b4.git:
> > >
> > > commit 7c1d044ff1d5235e598d4c777c4abfe60e0a09a8
> > > ("shazam: change default behaviour to be "apply-here"")
> > >
> > > ...is post-v0.8.0.
> > >
> >
> > I brutally applied the post-v0.8.0 patches stolen from b4.git over my
> > local distro b4 files.
> >
> > And was able to apply the triple:
> >
> > $ git log --oneline --no-merges
> > 5.17.0-rc6-1-amd64-clang13-lto..5.17.0-rc6-2-amd64-clang13-lto
> > 96a4222bdd4c (for-5.17/kbuild-std_gnu11-arndb-20220301) Kbuild: use
> > -std=gnu11 for KBUILD_USERCFLAGS
> > c4e8cef401a8 treewide: use -Wdeclaration-after-statement
> > 6a7cc105b238 Kbuild: move to -std=gnu11
> >
>
> I was able to build and boot on bare metal.
>
> No new warnings in my build-log here after switching to -std=gnu11.
>
> Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 x86-64
>

I have re-tested with Debian's LLVM/Clang v14.0.0-rc2.

Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v14.0.0-rc2 (x86-64)

- sed@ -

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

* Re: [PATCH 1/3] [v3] Kbuild: move to -std=gnu11
  2022-03-04 16:25 ` Sedat Dilek
@ 2022-03-06 15:31   ` Sedat Dilek
  0 siblings, 0 replies; 28+ messages in thread
From: Sedat Dilek @ 2022-03-06 15:31 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Masahiro Yamada, Arnd Bergmann, Linus Torvalds, Marco Elver,
	Jani Nikula, David Sterba, Alex Shi, Nick Desaulniers,
	Miguel Ojeda, Mark Rutland, linux-kbuild, llvm, linux-doc,
	linux-kernel

On Fri, Mar 4, 2022 at 5:25 PM Sedat Dilek <sedat.dilek@gmail.com> wrote:
[ ... ]
> When I saw the first patches in this area, I was thinking what about
> the tools/ build-system?
> This ECO system has its own rules.
>

My other goal was to build perf with my selfmade or distro LLVM/Clang
and -std=gnu11.

I was able to do so:

$ git log --oneline --no-merges v5.17-rc6..for-5.17/tools-std_gnu11-dileks-v2
2d99b1cfa897 (for-5.17/tools-std_gnu11-dileks-v2) perf: Use -std=gnu11
c345a183c4ef tools: libtraceevent: Use -std=gnu11
26f77082f233 tools: libsubcmd: Use -std=gnu11
aaba58ec81c8 tools: libbpf: Use -std=gnu11
ffc800af3be4 tools: libapi: Use -std=gnu11

For perf/libperl-support I needed an extra patch:

$ git log --oneline --no-merges
v5.17-rc6..for-5.17/perf-libperl_support-clang-dileks
316a1917ec05 (for-5.17/perf-libperl_support-clang-dileks) perf: Fix
libperl support with clang and perl v5.34

For details see [1].

I can send the patches if someone wants them.

[1] https://marc.info/?t=164646683300002&r=1&w=2

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

end of thread, other threads:[~2022-03-06 15:32 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01 14:52 [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Arnd Bergmann
2022-03-01 14:52 ` [PATCH 2/3] treewide: use -Wdeclaration-after-statement Arnd Bergmann
2022-03-01 16:54   ` Nathan Chancellor
2022-03-01 19:57   ` Nick Desaulniers
2022-03-01 20:06     ` Nick Desaulniers
2022-03-01 20:20       ` Linus Torvalds
2022-03-01 20:28         ` Nick Desaulniers
2022-03-03  0:44   ` Masahiro Yamada
2022-03-04 11:29   ` Sedat Dilek
2022-03-06 10:03     ` Sedat Dilek
2022-03-01 14:52 ` [PATCH 3/3] Kbuild: use -std=gnu11 for KBUILD_USERCFLAGS Arnd Bergmann
2022-03-01 17:00   ` Nathan Chancellor
2022-03-01 19:56   ` Nick Desaulniers
2022-03-02 22:14   ` Sedat Dilek
2022-03-02 22:54     ` Nick Desaulniers
2022-03-03  6:26       ` Sedat Dilek
2022-03-03 17:37         ` Nathan Chancellor
2022-03-04  6:47           ` Sedat Dilek
2022-03-04  7:18             ` Sedat Dilek
2022-03-04 11:12               ` Sedat Dilek
2022-03-06 10:04                 ` Sedat Dilek
2022-03-01 16:53 ` [PATCH 1/3] [v3] Kbuild: move to -std=gnu11 Nathan Chancellor
2022-03-04  5:03   ` Masahiro Yamada
2022-03-04 11:24 ` Sedat Dilek
2022-03-06 10:01   ` Sedat Dilek
2022-03-04 11:37 ` Sedat Dilek
2022-03-04 16:25 ` Sedat Dilek
2022-03-06 15:31   ` Sedat Dilek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.