Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Naresh Kamboju <naresh.kamboju@linaro.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	open list <linux-kernel@vger.kernel.org>,
	regressions@lists.linux.dev, lkft-triage@lists.linaro.org,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	John Donnelly <john.p.donnelly@oracle.com>,
	Huacai Chen <chenhuacai@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	David Hildenbrand <david@redhat.com>,
	"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
	Zhen Lei <thunder.leizhen@huawei.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: Re: gcc-12: build errors: arch/arm64/kernel/setup.c:225:56: warning: array subscript -1 is outside array bounds of 'char[]' [-Warray-bounds]
Date: Mon, 6 Jun 2022 10:41:50 +0100	[thread overview]
Message-ID: <Yp3L0JgLpk+s54Lw@FVFF77S0Q05N> (raw)
In-Reply-To: <CAK8P3a3QKWxqGore3+_DJnWo7bJgvDhkZjtkyg5EUg4_D=mE2w@mail.gmail.com>

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.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-06-06  9:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-03  2:03 gcc-12: build errors: arch/arm64/kernel/setup.c:225:56: warning: array subscript -1 is outside array bounds of 'char[]' [-Warray-bounds] Naresh Kamboju
2022-06-03  7:40 ` Arnd Bergmann
2022-06-06  9:01   ` Maxime Ripard
2022-06-06  9:41   ` Mark Rutland [this message]
2022-06-08  6:54     ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yp3L0JgLpk+s54Lw@FVFF77S0Q05N \
    --to=mark.rutland@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=anshuman.khandual@arm.com \
    --cc=arnd@arndb.de \
    --cc=bjorn.andersson@linaro.org \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=david@redhat.com \
    --cc=gpiccoli@igalia.com \
    --cc=john.p.donnelly@oracle.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkft-triage@lists.linaro.org \
    --cc=naresh.kamboju@linaro.org \
    --cc=regressions@lists.linux.dev \
    --cc=thunder.leizhen@huawei.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox