From patchwork Mon Dec 18 08:01:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 180195 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1091155dyi; Mon, 18 Dec 2023 00:02:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRULOuVuuHCPj/MrBeOfGltHjdwuzp9BWLnHba1/Iu4w00DMmy7zmoHWOSDs7gcLdEf5XG X-Received: by 2002:a05:6a21:7883:b0:194:7e63:bd1e with SMTP id bf3-20020a056a21788300b001947e63bd1emr44145pzc.47.1702886527994; Mon, 18 Dec 2023 00:02:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702886527; cv=none; d=google.com; s=arc-20160816; b=GfNuUr+8DGNLhSL3qat2TuA3cIpX5wg5KF1onP7jkifuR8uG17CmzF9aXM8ATQB4My QlGBmZE7SOUCa5s5FQ8Vvxlb7y32Gr/7JvcWspnO/piwDuvbTRmB0326axCTDkN0Vyvo oKXATIVeWK2hNpC02BJQbeLKo7msRboNBIieMYyHBO3PBlnwj2gP6MBq5XowmQUzsda+ JGzjjRA8uebMl5dnGVg3hL2hWerMm7qfnTIeIu/Qbv1pnNSuy9GVbjBj+DOcGJxT9Hzp Tm/N/4lNEncwNo78I62KlZxVVCrCNnzkxYXCFV5MAkke4v7J0NMndDUeKROcOlH5/ghn UY7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=YFeY8ZPCBiWURWniTjtSxSPF0UYBbKwE+BbfChzpZmg=; fh=U8++JqQ6jJjIzie8e9JcE+AteAbS0ujA3uf9Ghh/U08=; b=JvTbqdfAFs2vrjNBmUNTUNZ9h6VN6+mZ2HX2Qh1B+G4xad63Z6W6vzoywFOy6iwskL YL723ugDcuXvCvsu/sHUNxEHd/XxLo0b8d7OB/TW0Nmpfz+ZmcKdIy7dFUWV01e4WTf3 UtrzvjPDGhhKfidHlNu5YiDcMofxRoPCjplUPl2dV6lwXMLtTE1a+mwsEHbEdINBC9e2 ghbsstaHGJmLnCw5RN8BCMncgTaW6hq9JpR6NP56pg+ARuteGs4Eg4DVOMB7zWQPmdAw GyWBdb9mDenz33WR6TdZYc3O4zv9NiL+L9xO21j5/cnt/TluAmVt2sJLNBwUAF0uUBx6 PbZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a3yU54TF; spf=pass (google.com: domain of linux-kernel+bounces-3133-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3133-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d15-20020a056a00198f00b006ce6ef58aa4si17582807pfl.344.2023.12.18.00.02.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 00:02:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3133-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a3yU54TF; spf=pass (google.com: domain of linux-kernel+bounces-3133-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3133-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8FD83B21038 for ; Mon, 18 Dec 2023 08:02:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07BAC101EC; Mon, 18 Dec 2023 08:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="a3yU54TF" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E67210780; Mon, 18 Dec 2023 08:01:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A421C433C8; Mon, 18 Dec 2023 08:01:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702886504; bh=TvhXLKajBdXbCsQQLg4hu2vsZVvrLjECtEuBXZ7kJy4=; h=From:To:Cc:Subject:Date:From; b=a3yU54TF+HZHPuRqFso6ODttKWlDRU1vur6KFo+az6ovsTHZECNg4XcXZH9TMd5uR MRxLaD50O2a/YTNm/EJHMv6R9z8fgMT8Tn+FCfYY/y/TtHti7HlRuYXPDLkqEUogxi 5KmdH3rR9NVbvOW1gEl93UluxpdurxNBoBuUQ/+fCD3tlik4jHNZd+/ck1xDmIV7OL wr6gTim0iHBuQU3a9JEUoYS7ORGKFiOC2hjHEoesO7Hl22pM9+ZtnRArPpc6y8C0x9 cFmpRJNERHRCi4RXw1q5/Ys2mcpYHHjLWAkxDeYkwUCNTD8ZliwLM/+LH3vUA6t8H9 OCMQKkULZH4vw== From: Masahiro Yamada To: Ard Biesheuvel , linux-efi@vger.kernel.org Cc: linux-kbuild@vger.kernel.org, Masahiro Yamada , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] efi/libstub: zboot: do not use $(shell ...) in cmd_copy_and_pad Date: Mon, 18 Dec 2023 17:01:27 +0900 Message-Id: <20231218080127.907460-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785605943737077982 X-GMAIL-MSGID: 1785605943737077982 You do not need to use $(shell ...) in recipe lines, as they are already executed in a shell. An alternative solution is $$(...), which is an escaped sequence of the shell's command substituion, $(...). For this case, there is a reason to avoid $(shell ...). Kbuild detects command changes by using the if_changed macro, which compares the previous command recorded in .*.cmd with the current command from Makefile. If they differ, Kbuild re-runs the build rule. To diff the commands, Make must expand $(shell ...) first. It means that hexdump is executed every time, even when nothing needs rebuilding. If Kbuild determines that vmlinux.bin needs rebuilding, hexdump will be executed again to evaluate the 'cmd' macro, one more time to really build vmlinux.bin, and finally yet again to record the expanded command into .*.cmd. Replace $(shell ...) with $$(...) to avoid multiple, unnecessay shell evaluations. Since Make is agnostic about the shell code, $(...), the if_changed macro compares the string "$(hexdump -s16 -n4 ...)" verbatim, so hexdump is run only for building vmlinux.bin. For the same reason, $(shell ...) in EFI_ZBOOT_OBJCOPY_FLAGS should be eliminated. While I was here, I replaced '&&' with ';' because a command for if_changed is executed with 'set -e'. Signed-off-by: Masahiro Yamada Reviewed-by: Ard Biesheuvel --- arch/arm64/boot/Makefile | 2 +- drivers/firmware/efi/libstub/Makefile.zboot | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/Makefile b/arch/arm64/boot/Makefile index 1761f5972443..a5a787371117 100644 --- a/arch/arm64/boot/Makefile +++ b/arch/arm64/boot/Makefile @@ -44,7 +44,7 @@ EFI_ZBOOT_BFD_TARGET := elf64-littleaarch64 EFI_ZBOOT_MACH_TYPE := ARM64 EFI_ZBOOT_FORWARD_CFI := $(CONFIG_ARM64_BTI_KERNEL) -EFI_ZBOOT_OBJCOPY_FLAGS = --add-symbol zboot_code_size=0x$(shell \ +EFI_ZBOOT_OBJCOPY_FLAGS = --add-symbol zboot_code_size=0x$$( \ $(NM) vmlinux|grep _kernel_codesize|cut -d' ' -f1) include $(srctree)/drivers/firmware/efi/libstub/Makefile.zboot diff --git a/drivers/firmware/efi/libstub/Makefile.zboot b/drivers/firmware/efi/libstub/Makefile.zboot index 2c489627a807..65ffd0b760b2 100644 --- a/drivers/firmware/efi/libstub/Makefile.zboot +++ b/drivers/firmware/efi/libstub/Makefile.zboot @@ -5,8 +5,8 @@ # EFI_ZBOOT_FORWARD_CFI quiet_cmd_copy_and_pad = PAD $@ - cmd_copy_and_pad = cp $< $@ && \ - truncate -s $(shell hexdump -s16 -n4 -e '"%u"' $<) $@ + cmd_copy_and_pad = cp $< $@; \ + truncate -s $$(hexdump -s16 -n4 -e '"%u"' $<) $@ # Pad the file to the size of the uncompressed image in memory, including BSS $(obj)/vmlinux.bin: $(obj)/$(EFI_ZBOOT_PAYLOAD) FORCE