Skip to content

Commit c5e6ae5

Browse files
masahir0yvineetgarc
authored andcommitted
ARC: build: move symlink creation to arch/arc/Makefile to avoid race
If you run 'make uImage uImage.gz' with the parallel option, uImage.gz will be created by two threads simultaneously. This is because arch/arc/Makefile does not specify the dependency between uImage and uImage.gz. Hence, GNU Make assumes they can be built in parallel. One thread descends into arch/arc/boot/ to create uImage, and another to create uImage.gz. Please notice the same log is displayed twice in the following steps: $ export CROSS_COMPILE=<your-arc-compiler-prefix> $ make -s ARCH=arc defconfig $ make -j$(nproc) ARCH=arc uImage uImage.gz [ snip ] LD vmlinux SORTTAB vmlinux SYSMAP System.map OBJCOPY arch/arc/boot/vmlinux.bin OBJCOPY arch/arc/boot/vmlinux.bin GZIP arch/arc/boot/vmlinux.bin.gz GZIP arch/arc/boot/vmlinux.bin.gz UIMAGE arch/arc/boot/uImage.gz UIMAGE arch/arc/boot/uImage.gz Image Name: Linux-5.10.0-rc4-00003-g62f23044 Created: Sun Nov 22 02:52:26 2020 Image Type: ARC Linux Kernel Image (gzip compressed) Data Size: 2109376 Bytes = 2059.94 KiB = 2.01 MiB Load Address: 80000000 Entry Point: 80004000 Image arch/arc/boot/uImage is ready Image Name: Linux-5.10.0-rc4-00003-g62f23044 Created: Sun Nov 22 02:52:26 2020 Image Type: ARC Linux Kernel Image (gzip compressed) Data Size: 2815455 Bytes = 2749.47 KiB = 2.69 MiB Load Address: 80000000 Entry Point: 80004000 This is a race between the two threads trying to write to the same file arch/arc/boot/uImage.gz. This is a potential problem that can generate a broken file. I fixed a similar problem for ARM by commit 3939f33 ("ARM: 8418/1: add boot image dependencies to not generate invalid images"). I highly recommend to avoid such build rules that cause a race condition. Move the uImage rule to arch/arc/Makefile. Another strangeness is that arch/arc/boot/Makefile compares the timestamps between $(obj)/uImage and $(obj)/uImage.*: $(obj)/uImage: $(obj)/uImage.$(suffix-y) @ln -sf $(notdir $<) $@ @echo ' Image $@ is ready' This does not work as expected since $(obj)/uImage is a symlink. The symlink should be created in a phony target rule. I used $(kecho) instead of echo to suppress the message 'Image arch/arc/boot/uImage is ready' when the -s option is given. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
1 parent 0cfccb3 commit c5e6ae5

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

arch/arc/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,22 @@ libs-y += arch/arc/lib/ $(LIBGCC)
102102

103103
boot := arch/arc/boot
104104

105-
boot_targets := uImage uImage.bin uImage.gz uImage.lzma
105+
boot_targets := uImage.bin uImage.gz uImage.lzma
106106

107107
PHONY += $(boot_targets)
108108
$(boot_targets): vmlinux
109109
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
110110

111+
uimage-default-y := uImage.bin
112+
uimage-default-$(CONFIG_KERNEL_GZIP) := uImage.gz
113+
uimage-default-$(CONFIG_KERNEL_LZMA) := uImage.lzma
114+
115+
PHONY += uImage
116+
uImage: $(uimage-default-y)
117+
@ln -sf $< $(boot)/uImage
118+
@$(kecho) ' Image $(boot)/uImage is ready'
119+
120+
CLEAN_FILES += $(boot)/uImage
121+
111122
archclean:
112123
$(Q)$(MAKE) $(clean)=$(boot)

arch/arc/boot/Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
targets := vmlinux.bin vmlinux.bin.gz uImage
2+
targets := vmlinux.bin vmlinux.bin.gz
33

44
# uImage build relies on mkimage being availble on your host for ARC target
55
# You will need to build u-boot for ARC, rename mkimage to arc-elf32-mkimage
@@ -13,11 +13,6 @@ LINUX_START_TEXT = $$(readelf -h vmlinux | \
1313
UIMAGE_LOADADDR = $(CONFIG_LINUX_LINK_BASE)
1414
UIMAGE_ENTRYADDR = $(LINUX_START_TEXT)
1515

16-
suffix-y := bin
17-
suffix-$(CONFIG_KERNEL_GZIP) := gz
18-
suffix-$(CONFIG_KERNEL_LZMA) := lzma
19-
20-
targets += uImage
2116
targets += uImage.bin
2217
targets += uImage.gz
2318
targets += uImage.lzma
@@ -42,7 +37,3 @@ $(obj)/uImage.gz: $(obj)/vmlinux.bin.gz FORCE
4237

4338
$(obj)/uImage.lzma: $(obj)/vmlinux.bin.lzma FORCE
4439
$(call if_changed,uimage,lzma)
45-
46-
$(obj)/uImage: $(obj)/uImage.$(suffix-y)
47-
@ln -sf $(notdir $<) $@
48-
@echo ' Image $@ is ready'

0 commit comments

Comments
 (0)