From patchwork Sat Jan 7 21:20:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13092332 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 46790C46467 for ; Sat, 7 Jan 2023 21:22:02 +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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=pROxy9UrXA4Dami+qsZiVvXWSUJFUUdkwv9lHuNktt0=; b=1kvAKhjbaZObIy PBj3zTUraXj0V4Z7TYs0Vsql0yTiuPpjLrNIlXU9AHU3AuU2TX2adDgo4qc2Qj0y5JIIUgQuBfqa3 QKWTBHTvJoi+qi9PQmk7rnAtcIJk/o3U+I6igoZ6ewtbqv/I71oufYrLsTwHxpsMnUKWxS5gb7Ukx sWzTSWXFs+EqKtonghyWiZ8qlMPTA0HcB0q1ObdIexHpfB8xRZTUVzYc39WprEiJka7vpqbBvh3sp y2SXY0KNoDNeVvobI5za+nJOljcelGFuDlLoyfw5+5bN4sWLg9F6t55XUx9mungR4f5jafCsI9dcd +yX5G5UnhknHbuzy3ykw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pEGcL-008Qz7-W8; Sat, 07 Jan 2023 21:20:42 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pEGcG-008Qvd-0t for linux-arm-kernel@lists.infradead.org; Sat, 07 Jan 2023 21:20:38 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 18E6BB801BE; Sat, 7 Jan 2023 21:20:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DDCEC433D2; Sat, 7 Jan 2023 21:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673126427; bh=XpMX+uZxjGGJ3KfRz6Yz4WKx99Etyhlw516mSlREReU=; h=From:To:Cc:Subject:Date:From; b=BXjJBbvjFtfjpvVVYOzpZrsJ6kFEcWpZwAYuzpO+V6/cDveJbcDY/mo9LbO2sXNqa JA3VWAzP8Q0p51Y86TzSJkr54P4KNyqrlM1nbrrYZCfkQHngK5OEVmEyWPwTlnQJ2D 2dZA9IAFLmtucDk8UcOCwBiTNI5sLFRau14EtEpS+92hvFeSGEf7ca3lzCO+kTiGFJ 5aKLGhpToqlrDmZy2c1rTwRLa/rONuQktGeTc5f1GY9yZeKBkws8zXbpxaDDgVVQB2 6C1+/CrpQw0JD/Dt6IJEAQLcepoHs8XSUu5UCl/SVT4Q7DBflMWBwSSreOtKt14nG1 nQtxVZ6fV9K6Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Masahiro Yamada , Arnd Bergmann , Nick Desaulniers , Nicolas Schier , "Russell King (Oracle)" , Russell King , Seung-Woo Kim , Xin Li , linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] ARM: fix nm error message when GNU Make >= 4.4 is used Date: Sun, 8 Jan 2023 06:20:18 +0900 Message-Id: <20230107212019.2575770-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230107_132036_414144_DF297A1B X-CRM114-Status: GOOD ( 20.20 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Nathan Chancellor reports an error message from $(NM) if GNU Make 4.4 is used to build the ARM decompressor. $ make-4.4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- O=build defconfig all [snip] LD vmlinux NM System.map SORTTAB vmlinux OBJCOPY arch/arm/boot/Image Kernel: arch/arm/boot/Image is ready arm-linux-gnueabi-nm: 'arch/arm/boot/compressed/../../../../vmlinux': No such file /bin/sh: 1: arithmetic expression: expecting primary: " " LDS arch/arm/boot/compressed/vmlinux.lds AS arch/arm/boot/compressed/head.o GZIP arch/arm/boot/compressed/piggy_data AS arch/arm/boot/compressed/piggy.o CC arch/arm/boot/compressed/misc.o This occurs with GNU Make commit 98da874c4303 ("[SV 10593] Export variables to $(shell ...) commands"), and the O= option is needed to reproduce it. The generated zImage is correct despite the error message. As the commit description of 98da874c4303 [1] says, exported variables are passed down to $(shell ) functions, which means exported recursive variables might be expanded earlier than before, in the parse stage. The following test code demonstrates the change for GNU Make 4.4. [Test Makefile] $(shell echo hello > foo) export foo = $(shell cat bar/../foo) $(shell mkdir bar) all: @echo $(foo) [GNU Make 4.3] $ rm -rf bar; make-4.3 hello [GNU Make 4.4] $ rm -rf bar; make-4.4 cat: bar/../foo: No such file or directory hello The 'foo' is a resursively expanded (or lazily expanded) variable. GNU Make 4.3 expands it just before running the recipe '@echo $(foo)', at this point, the directory 'bar' exists. GNU Make 4.4 expands it to evaluate $(shell mkdir bar) because 'foo' is exported. At this point, the directory 'bar' does not exit yet. The cat command cannot resolve the bar/../foo path, hence the error message. Let's get back to the kernel Makefile. 'KBSS_SZ' in arch/arm/boot/compressed/Makefile is a recursive variable, which is referenced by 'LDFLAGS_vmlinux', which is also a recursive variable. GNU Make 4.3 expands 'KBSS_SZ' just before running the recipes. Before that, $(shell mkdir -p $(obj-dirs)) in scripts/Makefile.build creates the output directory, arch/arm/boot/compressed. GNU Make 4.4 expands 'KBSS_SZ' in the parse stage because LDFLAGS_vmlinux was (accidentally) exported by commit 5d4aeffbf709 ("kbuild: rebuild .vmlinux.export.o when its prerequisite is updated"). $(NM) cannot resolve the path arch/arm/boot/compressed/../../../../vmlinux. I admit this is a bug caused by 5d4aeffbf709 (I will fix it in the next commit), but do not see any good reason in writing the vmlinux path in such an indirect way. Just say 'vmlinux'. [1]: https://git.savannah.gnu.org/cgit/make.git/commit/?id=98da874c43035a490cdca81331724f233a3d0c9a Link: https://lore.kernel.org/all/Y7i8+EjwdnhHtlrr@dev-arch.thelio-3990X/ Fixes: 5d4aeffbf709 ("kbuild: rebuild .vmlinux.export.o when its prerequisite is updated") Reported-by: Nathan Chancellor Signed-off-by: Masahiro Yamada --- arch/arm/boot/compressed/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile index 2ef651a78fa2..726ecabcef09 100644 --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -107,7 +107,7 @@ ccflags-remove-$(CONFIG_FUNCTION_TRACER) += -pg asflags-y := -DZIMAGE # Supply kernel BSS size to the decompressor via a linker symbol. -KBSS_SZ = $(shell echo $$(($$($(NM) $(obj)/../../../../vmlinux | \ +KBSS_SZ = $(shell echo $$(($$($(NM) vmlinux | \ sed -n -e 's/^\([^ ]*\) [ABD] __bss_start$$/-0x\1/p' \ -e 's/^\([^ ]*\) [ABD] __bss_stop$$/+0x\1/p') )) ) LDFLAGS_vmlinux = --defsym _kernel_bss_size=$(KBSS_SZ)