From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F32AD23BD for ; Mon, 6 Jun 2022 09:42:08 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 955B52B; Mon, 6 Jun 2022 02:42:02 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.39.103]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D1EAA3F66F; Mon, 6 Jun 2022 02:41:59 -0700 (PDT) Date: Mon, 6 Jun 2022 10:41:50 +0100 From: Mark Rutland To: Arnd Bergmann Cc: Naresh Kamboju , Linux ARM , open list , regressions@lists.linux.dev, lkft-triage@lists.linaro.org, Catalin Marinas , Will Deacon , Andrew Morton , John Donnelly , Huacai Chen , Bjorn Andersson , Andy Shevchenko , David Hildenbrand , "Guilherme G. Piccoli" , Zhen Lei , Anshuman Khandual , Kefeng Wang 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] Message-ID: References: Precedence: bulk X-Mailing-List: regressions@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Jun 03, 2022 at 09:40:07AM +0200, Arnd Bergmann wrote: > On Fri, Jun 3, 2022 at 4:03 AM Naresh Kamboju 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. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 993A1C43334 for ; Mon, 6 Jun 2022 09:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ke79X4ssso45/KdmwN5r0YkAfvcDyc0hs+B4zUmW8eI=; b=XOwRfNLJLuWBRj FEcbS0T5l5/DjLTsBlE6bTgLS5EUSSqtbb8Qiu1vsK0xCft2AwB0HByppSqqD923B7n2bbhj6qBQM dcVURAraWVFk4/S6cFm1VY4Kh2n61dHfb20FdrDuKi/M+iYjxOkdhwaKu2TEQE4M/0ThOdrCH6bt/ q75kcoByOKiZtpQGtS6knQImZLy/DwwhSCjQgLI9sbK5P2w/FZ9TZf6Kqw2RpWa2bwFlDLIwfR2GP Ig78NmYRfeyxGqhxFAlND1OXYfjaYIKOz1COxrgm/i0mo7o9w3VDSH7zzkNdFTRVTBhGzNDkeuQt8 f7Jnlsxn76mTix8xclfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ny9FS-000Tft-KW; Mon, 06 Jun 2022 09:42:10 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ny9FO-000TZh-GF for linux-arm-kernel@lists.infradead.org; Mon, 06 Jun 2022 09:42:08 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 955B52B; Mon, 6 Jun 2022 02:42:02 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.39.103]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D1EAA3F66F; Mon, 6 Jun 2022 02:41:59 -0700 (PDT) Date: Mon, 6 Jun 2022 10:41:50 +0100 From: Mark Rutland To: Arnd Bergmann Cc: Naresh Kamboju , Linux ARM , open list , regressions@lists.linux.dev, lkft-triage@lists.linaro.org, Catalin Marinas , Will Deacon , Andrew Morton , John Donnelly , Huacai Chen , Bjorn Andersson , Andy Shevchenko , David Hildenbrand , "Guilherme G. Piccoli" , Zhen Lei , Anshuman Khandual , Kefeng Wang 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] Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220606_024206_628765_542D7C88 X-CRM114-Status: GOOD ( 14.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jun 03, 2022 at 09:40:07AM +0200, Arnd Bergmann wrote: > On Fri, Jun 3, 2022 at 4:03 AM Naresh Kamboju 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