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: 13496345 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 CCF50C35274 for ; Mon, 18 Dec 2023 08:02:21 +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=KxyAunBkFMUgSgKf+URSDh2XkF1MPEkFNnesGtsZ0fo=; b=4895Z/lNWuDGA9 s7KQDeo46wPMHAhHG180lbYcw1ZXrCLtn+DyP0yT8ALqTBouzg6Oc+ZyGYWoOMymT3Q9LraJQvO4I 9FUtcUUAt3shF/E4dkz1i5FzqxYWZsnsClWTayoatAatTvzCwEgWqwp+NcxAz5frHeACw2D4I8b7X HEHwLgNTwq5LQb6XmI1fLH0AFDkTS63CQ2pwg9xtmNGympa2Sx9OJMEb+3hDEQKzA3ROzDEo2Zp7P AJ+Bj+8tN5AsIEqmBp5aIViycknXFuSKPS8bK28bzDOiChtwuyoYwfgC4trqe0yTKcuhyNauKYNL9 hspMjE1KuwtuJ4JQpgEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rF8ZU-009Q7f-1R; Mon, 18 Dec 2023 08:01:52 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rF8ZQ-009Q6w-1M for linux-arm-kernel@lists.infradead.org; Mon, 18 Dec 2023 08:01:50 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 78EECCE0F51; Mon, 18 Dec 2023 08:01:45 +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 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231218_000148_918397_AFAA8D25 X-CRM114-Status: GOOD ( 13.60 ) 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 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