3bcf480cb2297b059d321afe649175a1d84964c5
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 005-v5.17-02-Kbuild-move-to-std-gnu11.patch
1 From b810c8e719ea082e47c7a8f7cf878bc84fa2455d Mon Sep 17 00:00:00 2001
2 From: Arnd Bergmann <arnd@arndb.de>
3 Date: Tue, 8 Mar 2022 22:56:14 +0100
4 Subject: [PATCH 2/3] Kbuild: move to -std=gnu11
5
6 During a patch discussion, Linus brought up the option of changing
7 the C standard version from gnu89 to gnu99, which allows using variable
8 declaration inside of a for() loop. While the C99, C11 and later standards
9 introduce many other features, most of these are already available in
10 gnu89 as GNU extensions as well.
11
12 An earlier attempt to do this when gcc-5 started defaulting to
13 -std=gnu11 failed because at the time that caused warnings about
14 designated initializers with older compilers. Now that gcc-5.1 is
15 the minimum compiler version used for building kernels, that is no
16 longer a concern. Similarly, the behavior of 'inline' functions changes
17 between gnu89 using gnu_inline behavior and gnu11 using standard c99+
18 behavior, but this was taken care of by defining 'inline' to include
19 __attribute__((gnu_inline)) in order to allow building with clang a
20 while ago.
21
22 Nathan Chancellor reported a new -Wdeclaration-after-statement
23 warning that appears in a system header on arm, this still needs a
24 workaround.
25
26 The differences between gnu99, gnu11, gnu1x and gnu17 are fairly
27 minimal and mainly impact warnings at the -Wpedantic level that the
28 kernel never enables. Between these, gnu11 is the newest version
29 that is supported by all supported compiler versions, though it is
30 only the default on gcc-5, while all other supported versions of
31 gcc or clang default to gnu1x/gnu17.
32
33 Link: https://lore.kernel.org/lkml/CAHk-=wiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpcovt8fYbVFW3TA@mail.gmail.com/
34 Link: https://github.com/ClangBuiltLinux/linux/issues/1603
35 Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
36 Acked-by: Marco Elver <elver@google.com>
37 Acked-by: Jani Nikula <jani.nikula@intel.com>
38 Acked-by: David Sterba <dsterba@suse.com>
39 Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
40 Reviewed-by: Alex Shi <alexs@kernel.org>
41 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
42 Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
43 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
44 Reviewed-by: Nathan Chancellor <nathan@kernel.org>
45 Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
46 ---
47 Makefile | 2 +-
48 1 file changed, 1 insertion(+), 1 deletion(-)
49
50 --- a/Makefile
51 +++ b/Makefile
52 @@ -517,7 +517,7 @@ KBUILD_CFLAGS := -Wall -Wundef -Werror
53 -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
54 -Werror=implicit-function-declaration -Werror=implicit-int \
55 -Werror=return-type -Wno-format-security \
56 - -std=gnu89
57 + -std=gnu11
58 KBUILD_CPPFLAGS := -D__KERNEL__
59 KBUILD_AFLAGS_KERNEL :=
60 KBUILD_CFLAGS_KERNEL :=