005-v5.17-02-Kbuild-move-to-std-gnu11.patch 2.7 KB

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