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: 40463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1457897wrt; Sat, 7 Jan 2023 13:29:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXufaAkDRRxMikYrISlYbtfoDeM4xynKb6KhvloMg7HGglK7vL/ZtifYdCVPZ54r6F3Oxm4M X-Received: by 2002:a05:6a20:1586:b0:a3:8eb5:6869 with SMTP id h6-20020a056a20158600b000a38eb56869mr89875485pzj.14.1673126999139; Sat, 07 Jan 2023 13:29:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673126999; cv=none; d=google.com; s=arc-20160816; b=ycKdaigCxZn9D7XcFLjSB2IojTXhATejZe+peYUvT2KD/YplWzYBrvXsUP8PryNEub 4bLwTWkMTnPKCYvy3oRtx9/5bftQ0VkhFkdgPsAx65CGyese2pRl7cQ6CThb0OjiUI6v jMlQyrZQs2M2AdtkX1XQ/RmR7UJmvlt9bCgn2FH+4q7+PLvY8k8NOlSppKx8+xIvUc+Z 2Nv/m9dJ87sWh4mK6m59Yn4k7goIpZ5sBBifS5a3KPsnWK+C9ijtokpPqHC2wJpbdx4S ouCwk6J1hywqyYDjDRsMCmQy6HavjUVKlnskiVL7X2klpzI2pIjb/z9UpiIlHGLfqp4S S/qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Hi0FYsD7NcVb+jBwIVGHvpcRsO98FL3iLDEw2jttNiM=; b=p89TiMvVU+VuT4Y0L/7BuyoCEt0KbendD/SGcJvL2C3KhKNjy8eurHy0acnoXlAz84 3U3n8B928KIBCr+uYuABGf0LOg+Y3EF8uOGGmKhrseGXqYy00xoSTDZBL7BfNHAkewC9 E/NNIFHTKwdl02fDd+M9r6WMpElqe3esKhftrQ8kryqKEaU62WHMTLViFdMNX9Nk5mGj vn4EpLE/yk/1Vq+GoHMH/2UpHVV7wMMvQU3WYe1xtdwTdopvgVFvRBqZqqLxF3PEs3VU J4lbqCoPXEtXPUkPA9JUSQu6rSjxbLKTQ6sEG0Yq3jzLGgwB0ftFfMwhewQ30OaQJhXe yw8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BXjJBbvj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u14-20020a056a00158e00b00565cb1ebdb2si5312475pfk.267.2023.01.07.13.29.46; Sat, 07 Jan 2023 13:29:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BXjJBbvj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232417AbjAGVUb (ORCPT + 99 others); Sat, 7 Jan 2023 16:20:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjAGVUa (ORCPT ); Sat, 7 Jan 2023 16:20:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7225B4A9; Sat, 7 Jan 2023 13:20:28 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 6B26B60BCB; Sat, 7 Jan 2023 21:20:28 +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-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754400816359504374?= X-GMAIL-MSGID: =?utf-8?q?1754400816359504374?= 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) From patchwork Sat Jan 7 21:20:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 40462 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1457647wrt; Sat, 7 Jan 2023 13:28:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXvNNH8x0wURkty964HGoZ1mpLqHwXe0mI+y9SG9Tv7zp5Gtl98i1E1YXYHVOZQIqFWBh4fA X-Received: by 2002:a17:902:c14c:b0:192:ed16:905 with SMTP id 12-20020a170902c14c00b00192ed160905mr13798653plj.60.1673126931487; Sat, 07 Jan 2023 13:28:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673126931; cv=none; d=google.com; s=arc-20160816; b=OGTa50/C5FpN4iYEaVsVdEiheQD68RpgHLernUci9BoWLOGT4Xp3ac1w1xEQvnK6xL 7a7o/P64Vn8f7lA70K+/l0QNXQb5DAYsvwQyb3FfoT1AaJZE4fF92kT/dXRwpVnvc9FM qxqkXJx9I0a+29gaHE49NCKOlDT1eJpTLsi7Es/ztnSfve1ROZ7aqeh63CsElkVEdTuq HqnM2lQrhh4vXUcZ/xF+oWDnJ/GOJKdGXtDO0flo6tEg0z6EPbpIuAdT9aZAkFRR2bCl lSZB8GJL70IO3gMq546H8/ist7rE6uto2VIzTdMmO959ZsoesGXQUl+hd0mHiswvRpkp NVIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N4CtgIB0ID6PzoLOC7Oi2A1IOJYGlBoTUGb/UmCj+eo=; b=mEoHNlx0u2Y5RNc1WNMHmwczST0/g2jZiIYuohhblW2u8Ux9pQsVnrq3WZoLzRlHUN KN85elQUPcv12S3cz/lI1drqd8fi2lgS4hUKJ4ACoxPdvJdzaJs6gBTH+yXONZD4Yf5O J6kiQWcYxGkeEPWXUydkbC27jMx7yWu1n2I+o3a1UcKBYHZkica7VCZJfsrHaMOqfumB uogaPcU0wI9WlDAfUcCqjwLaDDLlguuB5NQDwpx7dGcX22/ATXYCWq0vkWKJfDZm+KMV d0MPHK+pCmWC4r2sIrIdaSmJeXwOjIS5A9QMe05btdrxj3qpzt/NygkEDB9uCj6uvwpl bf4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UaQJcrIP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s11-20020a65584b000000b0049d000c59desi5316682pgr.553.2023.01.07.13.28.38; Sat, 07 Jan 2023 13:28:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UaQJcrIP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232665AbjAGVUd (ORCPT + 99 others); Sat, 7 Jan 2023 16:20:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232151AbjAGVUb (ORCPT ); Sat, 7 Jan 2023 16:20:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3A8FB7E4; Sat, 7 Jan 2023 13:20:30 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 3E9FF60BC7; Sat, 7 Jan 2023 21:20:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5482AC433F2; Sat, 7 Jan 2023 21:20:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673126429; bh=YElGyz6l5ZcYNhvjI8IBAD2Fy1zN10N4toXct3WSyF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UaQJcrIP7SIkmWhcydRGrylrzfOhENBrb7nb6Dum05ZMBMgEta8csV7uyMLV2UICI 7hpOsOaEJD8f/43u81pTYlrpC/ocx3QyXquxhEGpnP0zwiOxSkyYL+URc+eTrgQGxq 6vIuVwt81JvTQxp8fThZrELvAqbdAfB9+RXuXlH8ouTx+2Q+dalV+Z8ipAJzvRKb0C em/uEmqX34ai/TLN4Bn1LV3b8eIj6Fmgvc3LTsC2mR17rWi4rd/L8EEP0YkmEbhj1U 7GwogCqi8idR+KHG8XR70+1rWg77VnYig8WYbyZsqryOkypinssx4pJfBlO296TB+a Xa8XxJC+uNH2Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Masahiro Yamada , Nick Desaulniers , Nicolas Schier Subject: [PATCH 2/2] kbuild: do not export LDFLAGS_vmlinux to decompressor Makefiles Date: Sun, 8 Jan 2023 06:20:19 +0900 Message-Id: <20230107212019.2575770-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230107212019.2575770-1-masahiroy@kernel.org> References: <20230107212019.2575770-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754400745737414452?= X-GMAIL-MSGID: =?utf-8?q?1754400745737414452?= Commit 3ec8a5b33dea ("kbuild: do not export LDFLAGS_vmlinux") unexported LDFLAGS_vmlinux because LDFLAGS_vmlinux in the top Makefile and the one in arch/*/boot/compressed/Makefile are unrelated to each other. It is just the decompressors, arch/*/boot/compressed/vmlinux just happen to have the same base name. Commit 5d4aeffbf709 ("kbuild: rebuild .vmlinux.export.o when its prerequisite is updated") accidentally exported it again. The issue reported so far is $(NM) error message when building the ARM decompressor with GNU Make >= 4.4. This was fixed by refactoring arch/arm/boot/compressed/Makefile. The error message fixed by 3ec8a5b33dea is very likely to happen in the current cleaning code, but it would still be possible on systems with a huge number of CPUs. Anyway, LDFLAGS_vmlinux should not be exported to the decompressor Makefiles. Fixes: 5d4aeffbf709 ("kbuild: rebuild .vmlinux.export.o when its prerequisite is updated") Signed-off-by: Masahiro Yamada --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dfba294ae790..146cdf195e56 100644 --- a/Makefile +++ b/Makefile @@ -549,7 +549,7 @@ LDFLAGS_MODULE = CFLAGS_KERNEL = RUSTFLAGS_KERNEL = AFLAGS_KERNEL = -export LDFLAGS_vmlinux = +LDFLAGS_vmlinux = # Use USERINCLUDE when you must reference the UAPI directories only. USERINCLUDE := \ @@ -1248,6 +1248,11 @@ vmlinux.o modules.builtin.modinfo modules.builtin: vmlinux_o @: PHONY += vmlinux +# LDFLAGS_vmlinux flags from the top Makefile and arch/*/Makefile should be +# exported for building the top vmlinux, but not for building decompressors. +# They have the same base name (arch/*/boot/compressed/vmlinux), but the +# decompressor Makefiles should not inherit LDFLAGS_vmlinux. +vmlinux: export LDFLAGS_vmlinux := $(LDFLAGS_vmlinux) vmlinux: vmlinux.o $(KBUILD_LDS) modpost $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux