GCC 12 warnings
Subsystems (4)
Jakub Kicinski
maintainerHi Kees,
I'm sure you're involved in a number of glorious GCC 12 conversations..
We have a handful of drivers in networking which get hit by -Warray-bounds because they allocate partial structures (I presume to save memory, misguided but more than 15min of work to refactor).
Since -Warray-bounds is included by default now this is making our lives a little hard [1]. Is there a wider effort to address this? If not do you have a recommendation on how to deal with it?
My best idea is to try to isolate the bad files and punt -Warray-bounds to W=1 for those, so we can prevent more of them getting in but not break WERROR builds on GCC 12. That said, I'm not sure how to achieve that.. This for example did not work:
drivers/net/ethernet/mediatek/Makefile +4 -0
@@ -9,5 +9,9 @@ mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o ifdef CONFIG_DEBUG_FS mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_debugfs.o endif obj-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_ops.o obj-$(CONFIG_NET_MEDIATEK_STAR_EMAC) += mtk_star_emac.o + +ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) +CFLAGS_mtk_ppe.o += -Wno-array-bounds +endif
Quoted 1 line · Jakub Kicinski
I'm sure you're involved in a number of glorious GCC 12 conversations..
Yeah, and I think I've even found a gcc bug. :|
Quoted 3 lines
We have a handful of drivers in networking which get hit by -Warray-bounds because they allocate partial structures (I presume to save memory, misguided but more than 15min of work to refactor).
Yeah, this idiom is pretty common I've noticed -- I fixed a few of these in the initial work for -Warray-bounds on GCC 11 and earlier, but wow did GCC 12 do something extra internally.
Quoted 3 lines
Since -Warray-bounds is included by default now this is making our lives a little hard [1]. Is there a wider effort to address this? If not do you have a recommendation on how to deal with it?
Looks like the issue was this?
https://lore.kernel.org/all/[email protected]/
Ah, from cf2df74e202d ("net: fix dev_fill_forward_path with pppoe + bridge")
You mean you missed this particular warning because of the other GCC 12 warnings?
Quoted 8 lines
My best idea is to try to isolate the bad files and punt -Warray-bounds to W=1 for those, so we can prevent more of them getting in but not break WERROR builds on GCC 12. That said, I'm not sure how to achieve that.. This for example did not work:
drivers/net/ethernet/mediatek/Makefile mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o · line 17
Quoted 9 lines
drivers/net/ethernet/mediatek/Makefile +4
-0@@ -9,5 +9,9 @@ mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o ifdef CONFIG_DEBUG_FS mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_debugfs.o endif obj-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_ops.o obj-$(CONFIG_NET_MEDIATEK_STAR_EMAC) += mtk_star_emac.o + +ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) +CFLAGS_mtk_ppe.o += -Wno-array-bounds +endif
This worked for me:
drivers/net/can/usb/kvaser_usb/Makefile +4 -0
@@ -1,3 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb.o kvaser_usb-y = kvaser_usb_core.o kvaser_usb_leaf.o kvaser_usb_hydra.o + +ifeq ($(KBUILD_EXTRA_WARN),) +CFLAGS_kvaser_usb_hydra.o += -Wno-array-bounds +endif
Signature · 1 line
Kees Cook
Jakub Kicinski
maintainerQuoted 11 lines · On Fri, 20 May 2022 09:46:36 -0700 Kees Cook wrote:
Quoted 3 lines
Since -Warray-bounds is included by default now this is making our lives a little hard [1]. Is there a wider effort to address this? If not do you have a recommendation on how to deal with it?
Looks like the issue was this?
https://lore.kernel.org/all/[email protected]/Ah, from
cf2df74e202d("net: fixdev_fill_forward_pathwith pppoe + bridge")You mean you missed this particular warning because of the other GCC 12 warnings?
Yup :(
Quoted 25 lines
Quoted 8 lines
My best idea is to try to isolate the bad files and punt -Warray-bounds to W=1 for those, so we can prevent more of them getting in but not break WERROR builds on GCC 12. That said, I'm not sure how to achieve that.. This for example did not work:
drivers/net/ethernet/mediatek/Makefile mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o · line 17
Quoted 9 lines
drivers/net/ethernet/mediatek/Makefile +4
-0@@ -9,5 +9,9 @@ mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed.o ifdef CONFIG_DEBUG_FS mtk_eth-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_debugfs.o endif obj-$(CONFIG_NET_MEDIATEK_SOC_WED) += mtk_wed_ops.o obj-$(CONFIG_NET_MEDIATEK_STAR_EMAC) += mtk_star_emac.o + +ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) +CFLAGS_mtk_ppe.o += -Wno-array-bounds +endifThis worked for me:
drivers/net/can/usb/kvaser_usb/Makefile +0
-0
drivers/net/can/usb/kvaser_usb/Makefile line 7
Quoted 7 lines
drivers/net/can/usb/kvaser_usb/Makefile +4
-0@@ -1,3 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb.o kvaser_usb-y = kvaser_usb_core.o kvaser_usb_leaf.o kvaser_usb_hydra.o + +ifeq ($(KBUILD_EXTRA_WARN),) +CFLAGS_kvaser_usb_hydra.o += -Wno-array-bounds +endif
Ah, thanks, I must have tried -Wno-array-bounds before I figured out the condition and reverted back to full $(call cc-disable-warning, ..) Let me redo the patches.
Thanks!
From: Jakub Kicinski
Quoted 1 line
Sent: 20 May 2022 18:24
...
Quoted 7 lines
drivers/net/can/usb/kvaser_usb/Makefile line 7
Quoted 3 lines
drivers/net/can/usb/kvaser_usb/Makefile +3
-0+ifeq ($(KBUILD_EXTRA_WARN),) +CFLAGS_kvaser_usb_hydra.o += -Wno-array-bounds +endifAh, thanks, I must have tried -Wno-array-bounds before I figured out the condition and reverted back to full $(call cc-disable-warning, ..) Let me redo the patches.
I think you need a check that the compiler actually supports -Wno-array-bounds.
But that only needs be done once, not for every file that needs the option.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 11 lines · David Laight
From: Jakub Kicinski
Quoted 1 line
Sent: 20 May 2022 18:24
...
Quoted 7 lines
drivers/net/can/usb/kvaser_usb/Makefile line 7
Quoted 3 lines
drivers/net/can/usb/kvaser_usb/Makefile +3
-0+ifeq ($(KBUILD_EXTRA_WARN),) +CFLAGS_kvaser_usb_hydra.o += -Wno-array-bounds +endifAh, thanks, I must have tried -Wno-array-bounds before I figured out the condition and reverted back to full $(call cc-disable-warning, ..) Let me redo the patches.
Quoted 4 lines
I think you need a check that the compiler actually supports -Wno-array-bounds.
But that only needs be done once, not for every file that needs the option.
godbolt tells me that all kernel supported versions of GCC and Clang handle -Wno-array-bounds. Let me know if there is a combination that doesn't?
Signature · 1 line
Kees Cook