kbuild: Ctrl-C of parallel kernel build sometimes corrupts .o.cmd files permanently

From: Ingo Molnar
Date: Wed Jun 02 2021 - 11:50:38 EST



There's a sporadic kbuild bug that's been happening for years, maybe you
guys can think of where it comes from.

Sometimes when I Ctrl-C a kernel build job, the .o.cmd file becomes
corrupted and this breaks the build:


kernel/.panic.o.cmd:5: *** unterminated call to function 'wildcard': missing ')'. Stop.

...

drivers/gpu/drm/.drm_blend.o.cmd:5: *** unterminated call to function 'wildcard': missing ')'. Stop.

The file was just partially created and didn't get cleaned up:

kepler:~/tip> ls -l drivers/gpu/drm/.drm_blend.o.cmd.corrupted drivers/gpu/drm/.drm_blend.o.cmd.good
-rw-rw-r-- 1 mingo mingo 28672 Jun 2 17:46 drivers/gpu/drm/.drm_blend.o.cmd.corrupted
-rw-rw-r-- 1 mingo mingo 51331 Jun 2 17:46 drivers/gpu/drm/.drm_blend.o.cmd.good

The file just got cut in half due to the Ctrl-C:

--- drivers/gpu/drm/.drm_blend.o.cmd.corrupted 2021-06-02 17:46:16.951428326 +0200
+++ drivers/gpu/drm/.drm_blend.o.cmd.good 2021-06-02 17:46:34.391111668 +0200
@@ -646,4 +646,578 @@ deps_drivers/gpu/drm/drm_blend.o := \
$(wildcard include/config/OF_OVERLAY) \
include/linux/kobject.h \
$(wildcard include/config/UEVENT_HELPER) \
- $(wildcard include
\ No newline at end of file
+ $(wildcard include/config/DEBUG_KOBJECT_RELEASE) \
+ include/linux/sysfs.h \
+ include/linux/kernfs.h \
+ $(wildcard include/config/KERNFS) \


... but once in this state it can only be fixed by 'make clean' (which
loses all build progress), or by removing the stale file manually.

It happens more frequently on systems with a lot of CPUs.

Thanks,

Ingo