Subject: [PATCH] kbuild: modpost: Fix the order of includes in .vmlinux.export.c

From: Alexey Gladkov <[email-masked]>
Date: Wed, 30 Jul 2025 11:00:25 +0200

The linux/module.h cannot be used at the beginning of file because
linux/dynamic_debug.h adds linux/string.h and then string_32.h, where
some functions may be redefined as `__builtin_<name>` under certain
conditions.

This results in the following error (i386 defconfig):

ld: .vmlinux.export.o: in function `__ksymtab___builtin_memcmp':
.vmlinux.export.c:(___ksymtab+__builtin_memcmp+0x0): undefined reference to `__builtin_memcmp'

Link: https://lore.kernel.org/all/[email-masked]/
Fixes: c4b487ddc51f ("modpost: Create modalias for builtin modules")
Signed-off-by: Alexey Gladkov <[email-masked]>
---
 scripts/mod/modpost.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 67f9cd76bdd2..47c8aa2a6939 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2070,12 +2070,12 @@ static void write_vmlinux_export_c_file(struct module *mod)
 	struct module_alias *alias, *next;
 
 	buf_printf(&buf,
-		   "#include <linux/export-internal.h>\n"
-		   "#include <linux/module.h>\n");
+		   "#include <linux/export-internal.h>\n");
 
 	add_exported_symbols(&buf, mod);
 
 	buf_printf(&buf,
+		   "#include <linux/module.h>\n"
 		   "#undef __MODULE_INFO_PREFIX\n"
 		   "#define __MODULE_INFO_PREFIX\n");
 
-- 
2.50.1