kheaders: rebuild kheaders_data.tar.xz when a file is modified within a minute
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 8 Jun 2025 16:59:55 +0000 (01:59 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Tue, 24 Jun 2025 11:30:37 +0000 (20:30 +0900)
commit626c54af35764b0b8a4ed5c446458ba6ddfe9cc8
tree28683d06209398a5fe53839caa276249fa0ae91f
parent694174f94ebeeb5ec5cc0e9de9b40c82057e1d95
kheaders: rebuild kheaders_data.tar.xz when a file is modified within a minute

When a header file is changed, kernel/gen_kheaders.sh may fail to update
kernel/kheaders_data.tar.xz.

[steps to reproduce]

[1] Build kernel/kheaders_data.tar.xz

  $ make -j$(nproc) kernel/kheaders.o
    DESCEND objtool
    INSTALL libsubcmd_headers
    CALL    scripts/checksyscalls.sh
    CHK     kernel/kheaders_data.tar.xz
    GEN     kernel/kheaders_data.tar.xz
    CC      kernel/kheaders.o

[2] Modify a header without changing the file size

  $ sed -i s/0xdeadbeef/0xfeedbeef/ include/linux/elfnote.h

[3] Rebuild kernel/kheaders_data.tar.xz

  $ make -j$(nproc) kernel/kheaders.o
    DESCEND objtool
    INSTALL libsubcmd_headers
    CALL    scripts/checksyscalls.sh
    CHK     kernel/kheaders_data.tar.xz

kernel/kheaders_data.tar.xz is not updated if steps [1] - [3] are run
within the same minute.

The headers_md5 variable stores the MD5 hash of the 'ls -l' output
for all header files. This hash value is used to determine whether
kheaders_data.tar.xz needs to be rebuilt. However, 'ls -l' prints the
modification times with minute-level granularity. If a file is modified
within the same minute and its size remains the same, the MD5 hash does
not change.

To reliably detect file modifications, this commit rewrites
kernel/gen_kheaders.sh to output header dependencies to
kernel/.kheaders_data.tar.xz.cmd. Then, Make compares the timestamps
and reruns kernel/gen_kheaders.sh when necessary. This is the standard
mechanism used by Make and Kbuild.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
kernel/.gitignore
kernel/Makefile
kernel/gen_kheaders.sh