Enable -Wstringop-overflow globally

Hi Linus,
 
 Please, pull the following patches that enable -Wstringop-overflow,
 globally. These patches have been baking in linux-next for a whole
 development cycle.
 
 I waited for the release of -rc1 to run a final build-test on top of
 it before sending this pull request. Fortunatelly, after building
 358 kernels overnight (basically all supported archs with a wide
 variety of configs), no more warnings have surfaced! :)
 
 Thus, we are in a good position to enable this compiler option for
 all versions of GCC that support it, with the exception of GCC-11,
 which appears to have some issues with this option[1].
 
 [1] https://lore.kernel.org/lkml/b3c99290-40bc-426f-b3d2-1aa903f95c4e@embeddedor.com/
 
 Thanks
 --
 Gustavo
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEkmRahXBSurMIg1YvRwW0y0cG2zEFAmWuiFUACgkQRwW0y0cG
 2zGfKQ/+LS/H1AepM0ehS1NYr8Y4WC+eiNNLQc/5h/SmV0Mb3W38vRq/VGbm5Jj8
 fp/5sWpEsCskeThzGag65jIizdmqr3mqTz7tkHVpzwwqFUOG9Q7z7YAmCtQjsvl8
 BIKnHierBu2SWc31Sa0zclkjPu8GEt2YMROVq0opkqsw74h7QvQtfqUkHiPvxW5H
 TgejCmpjJNu5Z4PZl50A70IkdcwXtKFmHZki8tblslYD6jY5Whzv1UHbBpgtn0ec
 pt793J+bj2xxUm4QRMPyJU6eIXpW/VFyG2815+lRrRApcLqzJAqxvFLQcJDftOMR
 7pidsx+w4rHLzomgAYW+FvF00dwoiiB3IcPKRLl/reCNEQnzT0+yo/eoEZWAuu+4
 RdRxhSz+Y6ZLfG0bV2DJ4mNinZYwqwSjTdmCvBZ8gzbTul3keW7sAuQnlt2VpC4J
 4SLuRF+o7p3cxm/36f4CP1YPEhqVKtSCyCMKBISfrPNmna4ilHf4Ut4lhmDZX8R9
 1qIWygeRPMcHAuQANfAvRJ0ftn4sXpHfZGF0QblVLSKU4dJCEmeLrY0G/DZ7eri5
 cp51qxMK/Y3HibdzW8hNLKNczHGsoJxGShA5K517BLjRa94qqNKmqSQ7MJMzxaYw
 ayDneyxs9VJqwvoqPtj69gU9g298MUeKaO2R4u0QnHqCj3uEcnY=
 =SDV5
 -----END PGP SIGNATURE-----

Merge tag 'Wstringop-overflow-for-6.8-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux

Pull stringop-overflow warning update from Gustavo A. R. Silva:
 "Enable -Wstringop-overflow globally.

  I waited for the release of -rc1 to run a final build-test on top of
  it before sending this pull request. Fortunatelly, after building 358
  kernels overnight (basically all supported archs with a wide variety
  of configs), no more warnings have surfaced! :)

  Thus, we are in a good position to enable this compiler option for all
  versions of GCC that support it, with the exception of GCC-11, which
  appears to have some issues with this option [1]"

Link: https://lore.kernel.org/lkml/b3c99290-40bc-426f-b3d2-1aa903f95c4e@embeddedor.com/ [1]

* tag 'Wstringop-overflow-for-6.8-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux:
  init: Kconfig: Disable -Wstringop-overflow for GCC-11
  Makefile: Enable -Wstringop-overflow globally
This commit is contained in:
Linus Torvalds 2024-01-22 09:47:24 -08:00
commit 610347effc
3 changed files with 16 additions and 2 deletions

View File

@ -986,6 +986,10 @@ NOSTDINC_FLAGS += -nostdinc
# perform bounds checking.
KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
#Currently, disable -Wstringop-overflow for GCC 11, globally.
KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
# disable invalid "can't wrap" optimizations for signed / pointers
KBUILD_CFLAGS += -fno-strict-overflow

View File

@ -876,6 +876,18 @@ config CC_NO_ARRAY_BOUNDS
bool
default y if CC_IS_GCC && GCC_VERSION >= 110000 && GCC11_NO_ARRAY_BOUNDS
# Currently, disable -Wstringop-overflow for GCC 11, globally.
config GCC11_NO_STRINGOP_OVERFLOW
def_bool y
config CC_NO_STRINGOP_OVERFLOW
bool
default y if CC_IS_GCC && GCC_VERSION >= 110000 && GCC_VERSION < 120000 && GCC11_NO_STRINGOP_OVERFLOW
config CC_STRINGOP_OVERFLOW
bool
default y if CC_IS_GCC && !CC_NO_STRINGOP_OVERFLOW
#
# For architectures that know their GCC __int128 support is sound
#

View File

@ -97,7 +97,6 @@ KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
KBUILD_CFLAGS += $(call cc-option, -Wformat-overflow)
KBUILD_CFLAGS += $(call cc-option, -Wformat-truncation)
KBUILD_CFLAGS += $(call cc-option, -Wstringop-overflow)
KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
KBUILD_CPPFLAGS += -Wundef
@ -113,7 +112,6 @@ KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
ifdef CONFIG_CC_IS_CLANG