While building Linux kernel with gcc-12 for arm64 the following warnings/errors noticed. These are specific to gcc-12 builds.
Reported-by: Linux Kernel Functional Testing lkft@linaro.org
make --silent --keep-going --jobs=8 O=/home/tuxbuild/.cache/tuxmake/builds/2/build CROSS_COMPILE_COMPAT=arm-linux-gnueabihf- ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- 'CC=sccache aarch64-linux-gnu-gcc' 'HOSTCC=sccache gcc' In file included from arch/arm64/include/asm/thread_info.h:17, from include/linux/thread_info.h:60, from arch/arm64/include/asm/preempt.h:6, from include/linux/preempt.h:78, from include/linux/smp.h:110, from include/linux/lockdep.h:14, from include/linux/mutex.h:17, from include/linux/kernfs.h:11, from include/linux/sysfs.h:16, from include/linux/kobject.h:20, from include/linux/of.h:17, from include/linux/irqdomain.h:35, from include/linux/acpi.h:13, from arch/arm64/kernel/setup.c:9: In function 'request_standard_resources', inlined from 'setup_arch' at arch/arm64/kernel/setup.c:350:2: arch/arm64/kernel/setup.c:225:56: warning: array subscript -1 is outside array bounds of 'char[]' [-Warray-bounds] 225 | kernel_code.end = __pa_symbol(__init_begin - 1);
steps to reproduce: # To install tuxmake on your system globally: # sudo pip3 install -U tuxmake
tuxmake --runtime podman --target-arch arm64 --toolchain gcc-12 --kconfig tinyconfig CROSS_COMPILE_COMPAT=arm-linux-gnueabihf-
Build link: https://builds.tuxbuild.com/2A2iyFqotDfgkLynaKzmpf8H7Nf/
-- Linaro LKFT https://lkft.linaro.org
On Fri, Jun 3, 2022 at 4:03 AM Naresh Kamboju naresh.kamboju@linaro.org wrote:
inlined from 'setup_arch' at arch/arm64/kernel/setup.c:350:2:
arch/arm64/kernel/setup.c:225:56: warning: array subscript -1 is outside array bounds of 'char[]' [-Warray-bounds] 225 | kernel_code.end = __pa_symbol(__init_begin - 1);
Is this the only warning of this type that you get for arm64?
I think the easy fix would be to reword this line to
kernel_code.end = __pa_symbol(__init_begin) - 1;
Arnd
Hi,
On Fri, Jun 03, 2022 at 09:40:07AM +0200, Arnd Bergmann wrote:
On Fri, Jun 3, 2022 at 4:03 AM Naresh Kamboju naresh.kamboju@linaro.org wrote:
inlined from 'setup_arch' at arch/arm64/kernel/setup.c:350:2:
arch/arm64/kernel/setup.c:225:56: warning: array subscript -1 is outside array bounds of 'char[]' [-Warray-bounds] 225 | kernel_code.end = __pa_symbol(__init_begin - 1);
Is this the only warning of this type that you get for arm64?
In that function, both kernel_code.end and kernel_data_end show a similar warning in 5.19-rc1
I think the easy fix would be to reword this line to
kernel_code.end = __pa_symbol(__init_begin) - 1;
Doing this for both fix the warnings.
Maxime
On Fri, Jun 03, 2022 at 09:40:07AM +0200, Arnd Bergmann wrote:
On Fri, Jun 3, 2022 at 4:03 AM Naresh Kamboju naresh.kamboju@linaro.org wrote:
inlined from 'setup_arch' at arch/arm64/kernel/setup.c:350:2:
arch/arm64/kernel/setup.c:225:56: warning: array subscript -1 is outside array bounds of 'char[]' [-Warray-bounds] 225 | kernel_code.end = __pa_symbol(__init_begin - 1);
Is this the only warning of this type that you get for arm64?
There are a handful of those subscript warnings. Looking at v5.19-rc1 defconfig, using the kernel.org GCC 12.1.0 cross toolchain:
| [mark@lakrids:~/src/linux]% usekorg 12.1.0 make ARCH=arm64 CROSS_COMPILE=aarch64-linux- -j50 2>&1 | grep -A1 subscript | arch/arm64/kernel/setup.c:225:56: warning: array subscript -1 is outside array bounds of 'char[]' [-Warray-bounds] | 225 | kernel_code.end = __pa_symbol(__init_begin - 1); | -- | arch/arm64/kernel/setup.c:227:48: warning: array subscript -1 is outside array bounds of 'char[]' [-Warray-bounds] | 227 | kernel_data.end = __pa_symbol(_end - 1); | -- | arch/arm64/kernel/hibernate.c:94:65: warning: array subscript -1 is outside array bounds of 'const void[]' [-Warray-bounds] | 94 | unsigned long nosave_end_pfn = sym_to_pfn(&__nosave_end - 1);
The last of those can't have the `- 1` pulled out, but we could stuff a RELOC_HIDE() in there, as __pa_symbol() has internally.
Ideally we'd rework the section markers to not have this problem, either rethinking the way we mark them as flexible arrays, or giving them accessors, e.g.
#define va_init_begin() RELOC_HIDE((unsigned long)__init_begin)
... which'd be a pain, but at least it'd solve this generally.
I think the easy fix would be to reword this line to
kernel_code.end = __pa_symbol(__init_begin) - 1;
I agree that'd work for the __pa_symbol() cases.
For consistency it might be worth using RELOC_HIDE(), e.g.
kernel_code.end = __pa_symbol(RELOC_HIDE(__init_begin)) - 1);
... which IIUC should do the trick.
Thanks, Mark.
On Mon, Jun 6, 2022 at 11:41 AM Mark Rutland mark.rutland@arm.com wrote:
On Fri, Jun 03, 2022 at 09:40:07AM +0200, Arnd Bergmann wrote:
#define va_init_begin() RELOC_HIDE((unsigned long)__init_begin)
... which'd be a pain, but at least it'd solve this generally.
I think the easy fix would be to reword this line to
kernel_code.end = __pa_symbol(__init_begin) - 1;
I agree that'd work for the __pa_symbol() cases.
For consistency it might be worth using RELOC_HIDE(), e.g.
kernel_code.end = __pa_symbol(RELOC_HIDE(__init_begin)) - 1);
asm-gener ... which IIUC should do the trick.
I see we have similar logic on each architecture, and they probably all have the same issue now, so maybe we can just do a helper function in include/linux/ioport.h (which has all the struct resource logic) that can be called like
resource_set_pa(&kernel_code, _stext, __init_begin); resource_set_pa(&kernel_data, _sdata, _end);
Arnd