Subject: Re: [mainline]Error while running make modules_install command

From: Nathan Chancellor <[email-masked]>
Date: Tue, 4 Nov 2025 17:56:03 -0700

+ Nicolas and Alexey, just as an FYI.

Top of thread is:

https://lore.kernel.org/[email-masked]/

On Tue, Nov 04, 2025 at 04:54:38PM +0530, Venkat Rao Bagalkote wrote:
> IBM CI has also reported this error.
> 
> 
> Error:
> 
> 
> depmod: ERROR: kmod_builtin_iter_next: unexpected string without modname
> prefix
>   INSTALL /boot
> depmod: ERROR: kmod_builtin_iter_next: unexpected string without modname
> prefix
> depmod: ERROR: kmod_builtin_iter_next: unexpected string without modname
> prefix
> 
> 
> Git bisect is pointing to below commit as first bad commit.
> 
> 
> d50f21091358b2b29dc06c2061106cdb0f030d03 is the first bad commit
> commit d50f21091358b2b29dc06c2061106cdb0f030d03
> Author: Dimitri John Ledkov <[email-masked]>
> Date:   Sun Oct 26 20:21:00 2025 +0000
> 
>     kbuild: align modinfo section for Secureboot Authenticode EDK2 compat

Thank you for the bisect. I can reproduce this with at least kmod 29.1,
which is the version I can see failing in drgn's CI from Ubuntu Jammy
(but I did not see it with kmod 34, which is the latest version in Arch
Linux at the moment).

Could you and Omar verify if the following diff resolves the error for
you? I think this would allow us to keep Dimitri's fix for the
Authenticode EDK2 calculation (i.e., the alignment) while keeping kmod
happy. builtin.modules.modinfo is the same after this diff as it was
before Dimitri's change for me.

Cheers,
Nathan

diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index ced4379550d7..c3f135350d7e 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -102,11 +102,23 @@ vmlinux: vmlinux.unstripped FORCE
 # modules.builtin.modinfo
 # ---------------------------------------------------------------------------
 
+# .modinfo in vmlinux is aligned to 8 bytes for compatibility with tools that
+# expect sufficiently aligned sections but the additional NULL bytes used for
+# padding to satisfy this requirement break certain versions of kmod with
+#
+#   depmod: ERROR: kmod_builtin_iter_next: unexpected string without modname prefix
+#
+# Strip the trailing padding bytes after extracting the .modinfo sections to
+# comply with what kmod expects to parse.
+quiet_cmd_modules_builtin_modinfo = GEN     $@
+      cmd_modules_builtin_modinfo = $(cmd_objcopy); \
+                                    sed -i 's/\x00\+$$/\x00/g' $@
+
 OBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary
 
 targets += modules.builtin.modinfo
 modules.builtin.modinfo: vmlinux.unstripped FORCE
-	$(call if_changed,objcopy)
+	$(call if_changed,modules_builtin_modinfo)
 
 # modules.builtin
 # ---------------------------------------------------------------------------