Dear coreboot folks,
*gcc-12* snapshot packages are available in Debian sid/unstable, and build testing coreboot with that shows new array out of bounds warnings. For qemu/i440fx:
``` $ gcc-12 --version gcc-12 (Debian 12-20220313-1) 12.0.1 20220314 (experimental) [master r12-7638-g823b3b79cd2] Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ make V=1 […] x86_64-linux-gnu-gcc-12 -MMD -Isrc -Isrc/include -Isrc/commonlib/include -Isrc/commonlib/bsd/include -Ibuild -I3rdparty/vboot/firmware/include -include src/include/kconfig.h -include src/include/rules.h -include src/commonlib/bsd/include/commonlib/bsd/compiler.h -I3rdparty -D__BUILD_DIR__="build" -Isrc/arch/x86/include -D__ARCH_x86_32__ -pipe -g -nostdinc -std=gnu11 -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wno-trigraphs -Wimplicit-fallthrough -Wshadow -Wdate-time -Wtype-limits -Wvla -Wdangling-else -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -fno-pie -Wno-packed-not-aligned -fconserve-stack -Wnull-dereference -Wreturn-type -Wlogical-op -Wduplicated-cond -Wno-unused-but-set-variable -Werror -Os -Wno-address-of-packed-member -m32 -Wl,-b,elf32-i386 -Wl,-melf_i386 -m32 -fuse-ld=bfd -fno-stack-protector -Wl,--build-id=none -fno-delete-null-pointer-checks -Wlogical-op -march=i686 -mno-mmx -MT build/bootblock/cpu/x86/lapic/lapic.o -D__BOOTBLOCK__ -c -o build/bootblock/cpu/x86/lapic/lapic.o src/cpu/x86/lapic/lapic.c In file included from src/include/cpu/x86/lapic.h:4, from src/cpu/x86/lapic/lapic.c:5: In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_read' at src/include/cpu/x86/lapic.h:80:10, inlined from 'lapicid' at src/include/cpu/x86/lapic.h:138:21, inlined from 'enable_lapic' at src/cpu/x86/lapic/lapic.c:41:3: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:73:2: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:73:2: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:77:2: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:77:2: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:86:3: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:86:3: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:84:3: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:84:3: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ In function 'read32', inlined from 'xapic_read' at src/include/cpu/x86/lapic.h:13:9, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:103:11, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:89:2: src/arch/x86/include/arch/mmio.h:20:16: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 20 | return *((volatile uint32_t *)(addr)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'write32', inlined from 'xapic_write' at src/include/cpu/x86/lapic.h:18:2, inlined from 'lapic_update32' at src/include/cpu/x86/lapic.h:106:3, inlined from 'setup_lapic_interrupts' at src/cpu/x86/lapic/lapic.c:89:2: src/arch/x86/include/arch/mmio.h:40:40: error: array subscript 0 is outside array bounds of 'const volatile void[0]' [-Werror=array-bounds] 40 | *((volatile uint32_t *)(addr)) = value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ cc1: all warnings being treated as errors
```
I have no idea, if it’s valid or not, but judging from the discussion in the GCC bug report *[11/12 Regression] gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a pointer from integer literal* [1], the new behavior is controversial.
Could more knowledgeable people please take a look, and give feedback, so in case we consider it a regression for coreboot, we can give feedback to the GCC folks?
Kind regards,
Paul