From patchwork Sun Jan 8 09:53:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 40488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1639425wrt; Sun, 8 Jan 2023 01:54:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXvuduWZ4w+/Md78brVorOiMmxSaOh8AazgGCQYBcxL9KIyXBtWDmVfk2p1hPN/Jx8XQmNZJ X-Received: by 2002:a17:902:7287:b0:192:e0ab:a4c8 with SMTP id d7-20020a170902728700b00192e0aba4c8mr16545237pll.22.1673171691190; Sun, 08 Jan 2023 01:54:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673171691; cv=none; d=google.com; s=arc-20160816; b=oItI9w3C9dXtPE/W+GKH7RhnWFy1doHNdOromXs4avKqz1Ju0UKkBWn2b7ldnWqvWt c+TUnNpSPKdX26p76w/k3sSJdsIXRAADWcLbYEi3PpgIgdAIEkr0FRCt8FfqC9dQQKJY 4PW9AAGA9NTojph+HAaSlvqEXT6kkP5gZvV+FkL9I+GiF+86iO474kSi7rELT/7DaVzN a3tCnhqLSiKTG80jkTwKB5LxOFTcrnro2WFMLotgVA0edoLPymqb1kHay+2e+4NwOtVc PqLTMt7P7rnrIqVAq3sHXdLfl9JxajntTBMHh0nt3XuqQnMUUG0kKCN5+bwHqk3s8bVm 3KTw== 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=72yWSy9gNQjQV7A8owQXFWpVeDtTmxTAVBLx7BsRHtQ=; b=vumdLM10PcB5el0o69BcUbTR+p4T5GySvX3tQK5R2jkhm0brgZKOVGw+2tbcF/8R4x FIqkK+F95FlLVt6/Pr0OsgHrTP5sCbCCBnhPwkHJIsX1DuNcSEmT1nZ0OY8G+kq8dJa0 XP1X+hdAfFfcnHiTosuzu74/sr67Ib4bSnPKtRDOOLDE42A+QmnjKHr0gehJNonnoZN4 GSEuc1OLIk4DpCfqScAZ5KItjErP212f6D6PY8bp2oiS7l/Kutwek04mh4FCQOAqtC0Q DveckTzzylnBMc5AUH/KPoi1jWCH9y22/utTV0YoiyisgIHUhWrD2T7Ueo6RjN6vCnv3 HKvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hRNxu+Vs; 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 k8-20020a170902d58800b00192b09ce09asi6076040plh.318.2023.01.08.01.54.39; Sun, 08 Jan 2023 01:54: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=hRNxu+Vs; 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 S232711AbjAHJx7 (ORCPT + 99 others); Sun, 8 Jan 2023 04:53:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbjAHJx4 (ORCPT ); Sun, 8 Jan 2023 04:53:56 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E9A1DBF; Sun, 8 Jan 2023 01:53:52 -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 A96A960C57; Sun, 8 Jan 2023 09:53:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BA54C433EF; Sun, 8 Jan 2023 09:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673171631; bh=AxFFW7gAD/hGkqqH/1eltNah71ELaSI+2AAH9yFwTKE=; h=From:To:Cc:Subject:Date:From; b=hRNxu+VsHh2bYMCRQHcb12PPXn6L8XEkFtOaVSNJJO1TrGK3q/4dw10uslT7eaf7a kmsPbDnFnfh3ptYqnLd/okYcpZX8TI3ZOqs4w/sWCWZIN4Y9XrwZ0S8T4UHYM/6u6p ZcAkHtdPKgF1xpR02DfjLR6RdJ/EdUQtKCYolf9Np1eckuRq3HlVORWy6OwmygYCHE hlEEAMVY1ioXpJa9oVQsgbbAF6yc5OKtnsaz6vaYjZmoRrxjAC4TRahu3GJKtgLYSQ Ng8OMn9p/JExTuHCE3k05PRRAUBhwZwLngod0zKUV9+Vgg7ZLQer3XFMax5zMedNdP 1aIJr2chsygmw== 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 v2] kbuild: do not export LDFLAGS_vmlinux to decompressor Makefiles Date: Sun, 8 Jan 2023 18:53:42 +0900 Message-Id: <20230108095342.2766757-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?1754447679317641718?= X-GMAIL-MSGID: =?utf-8?q?1754447679317641718?= 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 zImage [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 since 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 (i.e. lazily expanded) variable. GNU Make 4.3 expands 'foo' just before running the recipe '@echo $(foo)', at this point, the directory 'bar' exists. GNU Make 4.4 expands 'foo' to evaluate $(shell mkdir bar) because it 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. In arch/arm/boot/compressed/Makefile, KBSS_SZ is referenced by LDFLAGS_vmlinux, which is recursive and also exported by the top Makefile. GNU Make 4.3 expands KBSS_SZ just before running the recipes, so it works fine. GNU Make 4.4 expands KBSS_SZ in the parse stage, where the directory arm/arm/boot/compressed does not exit yet. When compiled O= option, the output directory is created by $(shell mkdir -p $(obj-dirs)) in scripts/Makefile.build. There are two ways to fix this particular issue: - change "$(obj)/../../../../vmlinux" in KBSS_SZ to "vmlinux" - unexport LDFLAGS_vmlinux This commit takes the latter course because it is what I originally intended. Commit 3ec8a5b33dea ("kbuild: do not export LDFLAGS_vmlinux") unexported LDFLAGS_vmlinux. Commit 5d4aeffbf709 ("kbuild: rebuild .vmlinux.export.o when its prerequisite is updated") accidentally exported it again. We can clean up arch/arm/boot/compressed/Makefile later. [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 Reviewed-by: Nicolas Schier --- Changes in v2: - Postpone the change for arch/arm/boot/compressed/Makefile - Update the commit description Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dfba294ae790..658fc0e602c9 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 happen to have the same base name (arch/*/boot/compressed/vmlinux). +# 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