From nobody Tue Jun 23 19:20:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49542C4332F for ; Sun, 27 Feb 2022 21:54:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231970AbiB0VzJ (ORCPT ); Sun, 27 Feb 2022 16:55:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230511AbiB0VzH (ORCPT ); Sun, 27 Feb 2022 16:55:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0083F3ED3B; Sun, 27 Feb 2022 13:54:29 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 813AF61182; Sun, 27 Feb 2022 21:54:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 668FDC340E9; Sun, 27 Feb 2022 21:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645998868; bh=3t/p0jjcIOQ9cnqtHEjQ0OotL7Yc14GpfGoJxO8STBo=; h=From:To:Cc:Subject:Date:From; b=fEN1qIU97LxKCmuCdc9bVegKovR9x6UfjibzNHVn1irr0D+YEfGHf0yjjfo7iHueV 4QgkmaAV4DSyjmNuWtZeHjsRM2jMUq0GjuVX47A2MeqPhpCY1+8G+anF3UaRWe7WqW ZgtocMGvAP2SC692l+obVuP6XHhAGoE8FGhgR3ofJZXpmYJlkxhPaWHdsxHto9/N8X bNwXhbBWv6P4LAa2hH6Escq0WtJV/NIhBCMO84e2RkGvxu7TmlN3zkB6yMNAwUfCtx FzOUXESTY0K3zlmNMpF+/voHgGnrAVayMih5W6jj+FQE4pUuWy4UZPFPZrhf4CuvdQ KEQHjoNZIeq4g== From: Arnd Bergmann To: linux-kbuild@vger.kernel.org Cc: Arnd Bergmann , Linus Torvalds , Masahiro Yamada , llvm@lists.linux.dev, Jonathan Corbet , Federico Vaga , Alex Shi , Hu Haowen , Michal Marek , Nick Desaulniers , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc-tw-discuss@lists.sourceforge.net, linux-arm-kernel@lists.infradead.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-btrfs@vger.kernel.org Subject: [PATCH] Kbuild: remove -std=gnu89 from compiler arguments Date: Sun, 27 Feb 2022 22:52:43 +0100 Message-Id: <20220227215408.3180023-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann 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=3Dgnu11 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 and gnu89, 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 -Werror, which happens with the 'make W=3D1' option, as well as for three drivers in the kernel that always enable -Werror, but it was only observed with the i915 driver so far. Nathan Chancellor reported an additional -Wdeclaration-after-statement warning that appears in a system header on arm, this still needs a workaround. Since the differences between gnu99, gnu11 and gnu17 are fairly minimal and mainly impact warnings at the -Wpedantic level that the kernel never enables, the easiest way is to just leave out the -std=3Dgnu89 argument entirely, and rely on the compiler default language setting, which is gnu11 for gcc-5, and gnu1x/gnu17 for all other supported versions of gcc or clang. Link: https://lore.kernel.org/lkml/CAHk-=3DwiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpc= ovt8fYbVFW3TA@mail.gmail.com/ Link: https://github.com/ClangBuiltLinux/linux/issues/1603 Suggested-by: Linus Torvalds Cc: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org Cc: llvm@lists.linux.dev Signed-off-by: Arnd Bergmann --- I put the suggestion into patch form, based on what we discussed in the thread. I only gave it minimal testing, but it would be good to have it in linux-next if we want to do this in the merge window. --- Documentation/process/programming-language.rst | 4 ++-- .../translations/it_IT/process/programming-language.rst | 4 ++-- .../translations/zh_CN/process/programming-language.rst | 4 ++-- .../translations/zh_TW/process/programming-language.rst | 4 ++-- Makefile | 7 +++---- arch/arm64/kernel/vdso32/Makefile | 3 +-- drivers/gpu/drm/i915/Makefile | 1 + drivers/staging/greybus/tools/Makefile | 3 ++- fs/btrfs/Makefile | 1 + scripts/Makefile.extrawarn | 1 + 10 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Documentation/process/programming-language.rst b/Documentation= /process/programming-language.rst index ec474a70a02f..894f2a6eb9db 100644 --- a/Documentation/process/programming-language.rst +++ b/Documentation/process/programming-language.rst @@ -5,8 +5,8 @@ Programming Language =20 The kernel is written in the C programming language [c-language]_. More precisely, the kernel is typically compiled with ``gcc`` [gcc]_ -under ``-std=3Dgnu89`` [gcc-c-dialect-options]_: the GNU dialect of ISO C90 -(including some C99 features). ``clang`` [clang]_ is also supported, see +under ``-std=3Dgnu11`` [gcc-c-dialect-options]_: the GNU dialect of ISO C11 +(including some C17 features). ``clang`` [clang]_ is also supported, see docs on :ref:`Building Linux with Clang/LLVM `. =20 This dialect contains many extensions to the language [gnu-extensions]_, diff --git a/Documentation/translations/it_IT/process/programming-language.= rst b/Documentation/translations/it_IT/process/programming-language.rst index 41db2598ce11..aa21097737ae 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 =20 Il kernel =C3=A8 scritto nel linguaggio di programmazione C [it-c-language= ]_. Pi=C3=B9 precisamente, il kernel viene compilato con ``gcc`` [it-gcc]_ usa= ndo -l'opzione ``-std=3Dgnu89`` [it-gcc-c-dialect-options]_: il dialetto GNU -dello standard ISO C90 (con l'aggiunta di alcune funzionalit=C3=A0 da C99). +l'opzione ``-std=3Dgnu11`` [it-gcc-c-dialect-options]_: il dialetto GNU +dello standard ISO C11 (con l'aggiunta di alcune funzionalit=C3=A0 da C17). Linux supporta anche ``clang`` [it-clang]_, leggete la documentazione :ref:`Building Linux with Clang/LLVM `. =20 diff --git a/Documentation/translations/zh_CN/process/programming-language.= rst b/Documentation/translations/zh_CN/process/programming-language.rst index 2a47a1d2ec20..58d2b3bd2d85 100644 --- a/Documentation/translations/zh_CN/process/programming-language.rst +++ b/Documentation/translations/zh_CN/process/programming-language.rst @@ -9,8 +9,8 @@ =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 =E5=86=85=E6=A0=B8=E6=98=AF=E7=94=A8C=E8=AF=AD=E8=A8=80 :ref:`c-language <= cn_c-language>` =E7=BC=96=E5=86=99=E7=9A=84=E3=80=82=E6=9B=B4=E5=87=86=E7= =A1=AE=E5=9C=B0=E8=AF=B4=EF=BC=8C=E5=86=85=E6=A0=B8=E9=80=9A=E5=B8=B8=E6=98= =AF=E7=94=A8 :ref:`gcc ` -=E5=9C=A8 ``-std=3Dgnu89`` :ref:`gcc-c-dialect-options ` =E4=B8=8B=E7=BC=96=E8=AF=91=E7=9A=84=EF=BC=9AISO C90=E7=9A=84 GNU = =E6=96=B9=E8=A8=80=EF=BC=88 -=E5=8C=85=E6=8B=AC=E4=B8=80=E4=BA=9BC99=E7=89=B9=E6=80=A7=EF=BC=89 +=E5=9C=A8 ``-std=3Dgnu11`` :ref:`gcc-c-dialect-options ` =E4=B8=8B=E7=BC=96=E8=AF=91=E7=9A=84=EF=BC=9AISO C11=E7=9A=84 GNU = =E6=96=B9=E8=A8=80=EF=BC=88 +=E5=8C=85=E6=8B=AC=E4=B8=80=E4=BA=9BC17=E7=89=B9=E6=80=A7=EF=BC=89 =20 =E8=BF=99=E7=A7=8D=E6=96=B9=E8=A8=80=E5=8C=85=E5=90=AB=E5=AF=B9=E8=AF=AD= =E8=A8=80 :ref:`gnu-extensions ` =E7=9A=84=E8=AE=B8=E5= =A4=9A=E6=89=A9=E5=B1=95=EF=BC=8C=E5=BD=93=E7=84=B6=EF=BC=8C=E5=AE=83=E4=BB= =AC=E8=AE=B8=E5=A4=9A=E9=83=BD=E5=9C=A8=E5=86=85=E6=A0=B8=E4=B8=AD=E4=BD=BF= =E7=94=A8=E3=80=82 =20 diff --git a/Documentation/translations/zh_TW/process/programming-language.= rst b/Documentation/translations/zh_TW/process/programming-language.rst index 54e3699eadf8..235de05f7e2c 100644 --- a/Documentation/translations/zh_TW/process/programming-language.rst +++ b/Documentation/translations/zh_TW/process/programming-language.rst @@ -12,8 +12,8 @@ =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 =E5=85=A7=E6=A0=B8=E6=98=AF=E7=94=A8C=E8=AA=9E=E8=A8=80 :ref:`c-language <= tw_c-language>` =E7=B7=A8=E5=AF=AB=E7=9A=84=E3=80=82=E6=9B=B4=E6=BA=96=E7= =A2=BA=E5=9C=B0=E8=AA=AA=EF=BC=8C=E5=85=A7=E6=A0=B8=E9=80=9A=E5=B8=B8=E6=98= =AF=E7=94=A8 :ref:`gcc ` -=E5=9C=A8 ``-std=3Dgnu89`` :ref:`gcc-c-dialect-options ` =E4=B8=8B=E7=B7=A8=E8=AD=AF=E7=9A=84=EF=BC=9AISO C90=E7=9A=84 GNU = =E6=96=B9=E8=A8=80=EF=BC=88 -=E5=8C=85=E6=8B=AC=E4=B8=80=E4=BA=9BC99=E7=89=B9=E6=80=A7=EF=BC=89 +=E5=9C=A8 ``-std=3Dgnu11`` :ref:`gcc-c-dialect-options ` =E4=B8=8B=E7=B7=A8=E8=AD=AF=E7=9A=84=EF=BC=9AISO C11=E7=9A=84 GNU = =E6=96=B9=E8=A8=80=EF=BC=88 +=E5=8C=85=E6=8B=AC=E4=B8=80=E4=BA=9BC17=E7=89=B9=E6=80=A7=EF=BC=89 =20 =E9=80=99=E7=A8=AE=E6=96=B9=E8=A8=80=E5=8C=85=E5=90=AB=E5=B0=8D=E8=AA=9E= =E8=A8=80 :ref:`gnu-extensions ` =E7=9A=84=E8=A8=B1=E5= =A4=9A=E6=93=B4=E5=B1=95=EF=BC=8C=E7=95=B6=E7=84=B6=EF=BC=8C=E5=AE=83=E5=80= =91=E8=A8=B1=E5=A4=9A=E9=83=BD=E5=9C=A8=E5=85=A7=E6=A0=B8=E4=B8=AD=E4=BD=BF= =E7=94=A8=E3=80=82 =20 diff --git a/Makefile b/Makefile index 289ce2be8032..3ff6ba766f02 100644 --- a/Makefile +++ b/Makefile @@ -432,7 +432,7 @@ HOSTCXX =3D g++ endif =20 export KBUILD_USERCFLAGS :=3D -Wall -Wmissing-prototypes -Wstrict-prototyp= es \ - -O2 -fomit-frame-pointer -std=3Dgnu89 + -O2 -fomit-frame-pointer export KBUILD_USERLDFLAGS :=3D =20 KBUILD_HOSTCFLAGS :=3D $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFL= AGS) @@ -514,8 +514,7 @@ KBUILD_AFLAGS :=3D -D__ASSEMBLY__ -fno-PIE KBUILD_CFLAGS :=3D -Wall -Wundef -Werror=3Dstrict-prototypes -Wno-trigra= phs \ -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \ -Werror=3Dimplicit-function-declaration -Werror=3Dimplicit-int \ - -Werror=3Dreturn-type -Wno-format-security \ - -std=3Dgnu89 + -Werror=3Dreturn-type -Wno-format-security KBUILD_CPPFLAGS :=3D -D__KERNEL__ KBUILD_AFLAGS_KERNEL :=3D KBUILD_CFLAGS_KERNEL :=3D @@ -782,7 +781,7 @@ KBUILD_CFLAGS +=3D $(KBUILD_CFLAGS-y) $(CONFIG_CC_IMPLI= CIT_FALLTHROUGH) =20 ifdef CONFIG_CC_IS_CLANG KBUILD_CPPFLAGS +=3D -Qunused-arguments -# The kernel builds with '-std=3Dgnu89' so use of GNU extensions is accept= able. +# The kernel builds with '-std=3Dgnu11' so use of GNU extensions is accept= able. KBUILD_CFLAGS +=3D -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 whitelist= ed names. diff --git a/arch/arm64/kernel/vdso32/Makefile b/arch/arm64/kernel/vdso32/M= akefile index 6c01b63ff56d..3250d0e25782 100644 --- a/arch/arm64/kernel/vdso32/Makefile +++ b/arch/arm64/kernel/vdso32/Makefile @@ -67,8 +67,7 @@ VDSO_CFLAGS +=3D -DENABLE_COMPAT_VDSO=3D1 VDSO_CFLAGS +=3D -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common \ -Werror-implicit-function-declaration \ - -Wno-format-security \ - -std=3Dgnu89 + -Wno-format-security VDSO_CFLAGS +=3D -O2 # Some useful compiler-dependent flags from top-level Makefile VDSO_CFLAGS +=3D $(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 +=3D -Wno-unused-parameter subdir-ccflags-y +=3D -Wno-type-limits subdir-ccflags-y +=3D -Wno-missing-field-initializers subdir-ccflags-y +=3D -Wno-sign-compare +subdir-ccflags-y +=3D -Wno-shift-negative-value subdir-ccflags-y +=3D $(call cc-disable-warning, unused-but-set-variable) subdir-ccflags-y +=3D $(call cc-disable-warning, frame-address) subdir-ccflags-$(CONFIG_DRM_I915_WERROR) +=3D -Werror diff --git a/drivers/staging/greybus/tools/Makefile b/drivers/staging/greyb= us/tools/Makefile index ad0ae8053b79..a3bbd73171f2 100644 --- a/drivers/staging/greybus/tools/Makefile +++ b/drivers/staging/greybus/tools/Makefile @@ -12,7 +12,8 @@ CFLAGS +=3D -std=3Dgnu99 -Wall -Wextra -g \ -Wredundant-decls \ -Wcast-align \ -Wsign-compare \ - -Wno-missing-field-initializers + -Wno-missing-field-initializers \ + -Wno-shift-negative-value =20 CC :=3D $(CROSS_COMPILE)gcc =20 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 +=3D $(condflags) subdir-ccflags-y +=3D -Wno-missing-field-initializers subdir-ccflags-y +=3D -Wno-sign-compare subdir-ccflags-y +=3D -Wno-type-limits +subdir-ccflags-y +=3D -Wno-shift-negative-value =20 obj-$(CONFIG_BTRFS_FS) :=3D btrfs.o =20 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 +=3D $(call cc-option, -Wstringop-truncatio= n) KBUILD_CFLAGS +=3D -Wno-missing-field-initializers KBUILD_CFLAGS +=3D -Wno-sign-compare KBUILD_CFLAGS +=3D -Wno-type-limits +KBUILD_CFLAGS +=3D -Wno-shift-negative-value =20 KBUILD_CPPFLAGS +=3D -DKBUILD_EXTRA_WARN1 =20 --=20 2.29.2