Skip to content

Commit 97ba441

Browse files
masahir0ywilldeacon
authored andcommitted
efi/libstub: zboot: do not use $(shell ...) in cmd_copy_and_pad
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 <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 7b21ed7 commit 97ba441

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

arch/arm64/boot/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ EFI_ZBOOT_BFD_TARGET := elf64-littleaarch64
4444
EFI_ZBOOT_MACH_TYPE := ARM64
4545
EFI_ZBOOT_FORWARD_CFI := $(CONFIG_ARM64_BTI_KERNEL)
4646

47-
EFI_ZBOOT_OBJCOPY_FLAGS = --add-symbol zboot_code_size=0x$(shell \
47+
EFI_ZBOOT_OBJCOPY_FLAGS = --add-symbol zboot_code_size=0x$$( \
4848
$(NM) vmlinux|grep _kernel_codesize|cut -d' ' -f1)
4949

5050
include $(srctree)/drivers/firmware/efi/libstub/Makefile.zboot

drivers/firmware/efi/libstub/Makefile.zboot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# EFI_ZBOOT_FORWARD_CFI
66

77
quiet_cmd_copy_and_pad = PAD $@
8-
cmd_copy_and_pad = cp $< $@ && \
9-
truncate -s $(shell hexdump -s16 -n4 -e '"%u"' $<) $@
8+
cmd_copy_and_pad = cp $< $@; \
9+
truncate -s $$(hexdump -s16 -n4 -e '"%u"' $<) $@
1010

1111
# Pad the file to the size of the uncompressed image in memory, including BSS
1212
$(obj)/vmlinux.bin: $(obj)/$(EFI_ZBOOT_PAYLOAD) FORCE

0 commit comments

Comments
 (0)