linux/arch
Masahiro Yamada c4db7ff7a9
riscv: add dependency among Image(.gz), loader(.bin), and vmlinuz.efi
A common issue in Makefile is a race in parallel building.

You need to be careful to prevent multiple threads from writing to the
same file simultaneously.

Commit 3939f33450 ("ARM: 8418/1: add boot image dependencies to not
generate invalid images") addressed such a bad scenario.

A similar symptom occurs with the following command:

  $ make -j$(nproc) ARCH=riscv Image Image.gz loader loader.bin vmlinuz.efi
    [ snip ]
    SORTTAB vmlinux
    OBJCOPY arch/riscv/boot/Image
    OBJCOPY arch/riscv/boot/Image
    OBJCOPY arch/riscv/boot/Image
    OBJCOPY arch/riscv/boot/Image
    OBJCOPY arch/riscv/boot/Image
    GZIP    arch/riscv/boot/Image.gz
    AS      arch/riscv/boot/loader.o
    AS      arch/riscv/boot/loader.o
    Kernel: arch/riscv/boot/Image is ready
    PAD     arch/riscv/boot/vmlinux.bin
    GZIP    arch/riscv/boot/vmlinuz
    Kernel: arch/riscv/boot/loader is ready
    OBJCOPY arch/riscv/boot/loader.bin
    Kernel: arch/riscv/boot/loader.bin is ready
    Kernel: arch/riscv/boot/Image.gz is ready
    OBJCOPY arch/riscv/boot/vmlinuz.o
    LD      arch/riscv/boot/vmlinuz.efi.elf
    OBJCOPY arch/riscv/boot/vmlinuz.efi
    Kernel: arch/riscv/boot/vmlinuz.efi is ready

The log "OBJCOPY arch/riscv/boot/Image" is displayed 5 times.
(also "AS      arch/riscv/boot/loader.o" twice.)

It indicates that 5 threads simultaneously enter arch/riscv/boot/
and write to arch/riscv/boot/Image.

It occasionally leads to a build failure:

  $ make -j$(nproc) ARCH=riscv Image Image.gz loader loader.bin vmlinuz.efi
    [ snip ]
    SORTTAB vmlinux
    OBJCOPY arch/riscv/boot/Image
    OBJCOPY arch/riscv/boot/Image
    OBJCOPY arch/riscv/boot/Image
    OBJCOPY arch/riscv/boot/Image
    PAD     arch/riscv/boot/vmlinux.bin
  truncate: Invalid number: 'arch/riscv/boot/vmlinux.bin'
  make[2]: *** [drivers/firmware/efi/libstub/Makefile.zboot:13: arch/riscv/boot/vmlinux.bin] Error 1
  make[2]: *** Deleting file 'arch/riscv/boot/vmlinux.bin'
  make[1]: *** [arch/riscv/Makefile:167: vmlinuz.efi] Error 2
  make[1]: *** Waiting for unfinished jobs....
    Kernel: arch/riscv/boot/Image is ready
    GZIP    arch/riscv/boot/Image.gz
    AS      arch/riscv/boot/loader.o
    AS      arch/riscv/boot/loader.o
    Kernel: arch/riscv/boot/loader is ready
    OBJCOPY arch/riscv/boot/loader.bin
    Kernel: arch/riscv/boot/loader.bin is ready
    Kernel: arch/riscv/boot/Image.gz is ready
  make: *** [Makefile:234: __sub-make] Error 2

Image.gz, loader, vmlinuz.efi depend on Image. loader.bin depends
on loader. Such dependencies are not specified in arch/riscv/Makefile.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
Tested-by: Samuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20231119100024.2370992-1-masahiroy@kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2024-01-17 18:18:20 -08:00
..
alpha TTY/Serial changes for 6.7-rc1 2023-11-03 15:44:25 -10:00
arc kprobes: unify kprobes_exceptions_nofify() prototypes 2023-11-10 19:59:05 +09:00
arm mm: Introduce pudp/p4dp/pgdp_get() functions 2023-12-20 10:48:13 -08:00
arm64 Probes fixes for v6.7-rc1: 2023-11-10 16:35:04 -08:00
csky Kbuild updates for v6.7 2023-11-04 08:07:19 -10:00
hexagon TTY/Serial changes for 6.7-rc1 2023-11-03 15:44:25 -10:00
loongarch LoongArch changes for v6.7 2023-11-12 10:58:08 -08:00
m68k Many singleton patches against the MM code. The patch series which are 2023-11-02 19:38:47 -10:00
microblaze asm-generic updates for v6.7 2023-11-01 15:28:33 -10:00
mips Probes fixes for v6.7-rc1: 2023-11-10 16:35:04 -08:00
nios2 vgacon, arch/*: remove unused screen_info definitions 2023-10-17 10:17:02 +02:00
openrisc OpenRISC updates for 6.6 2023-09-05 10:09:31 -07:00
parisc parisc: Prevent booting 64-bit kernels on PA1.x machines 2023-11-10 16:17:32 +01:00
powerpc powerpc fixes for 6.7 #2 2023-11-12 10:50:38 -08:00
riscv riscv: add dependency among Image(.gz), loader(.bin), and vmlinuz.efi 2024-01-17 18:18:20 -08:00
s390 kprobes: unify kprobes_exceptions_nofify() prototypes 2023-11-10 19:59:05 +09:00
sh kprobes: unify kprobes_exceptions_nofify() prototypes 2023-11-10 19:59:05 +09:00
sparc kprobes: unify kprobes_exceptions_nofify() prototypes 2023-11-10 19:59:05 +09:00
um um,ethertap: Replace deprecated strncpy() with strscpy() 2023-09-29 11:37:50 -07:00
x86 kprobes: unify kprobes_exceptions_nofify() prototypes 2023-11-10 19:59:05 +09:00
xtensa TTY/Serial changes for 6.7-rc1 2023-11-03 15:44:25 -10:00
.gitignore
Kconfig arch: Remove Itanium (IA-64) architecture 2023-09-11 08:13:17 +00:00