xmake-io / xmake

๐Ÿ”ฅ A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.18k stars 785 forks source link

modpost: "_printk" [<...>/<redacted>.ko.ko] undefined #5721

Open TheAifam5 opened 1 month ago

TheAifam5 commented 1 month ago

Xmake Version

v2.9.5+20241016

Operating System Version and Architecture

Gentoo (AMD64)

Describe Bug

While compiling a kernel module with "-v" (verbose) flag, modpost shows a warnings:

WARNING: modpost: "_printk" [build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.ko] undefined!
WARNING: modpost: "__x86_return_thunk" [build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.ko] undefined!
WARNING: modpost: "module_layout" [build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.ko] undefined!

Notice in file listing below that .ko.ko has duplicate extensions and file is non-existing.

Expected Behavior

There should be no warnings for such simple example. The module compiles fine and runs.

Project Configuration

xmake.lua:

option("linux-headers", { showmenu = true, description = "Set linux-headers path." })

target("<redacted>")
    add_rules("platform.linux.driver")
    add_files("src/*.c")
    set_values("linux.driver.linux-headers", "$(linux-headers)")
    set_license("GPL-2.0")

entry.c:

#include <linux/init.h>   // Needed for the macros
#include <linux/kernel.h> // Needed for KERN_INFO
#include <linux/module.h> // Needed by all modules

MODULE_LICENSE("GPL-2.0");
MODULE_AUTHOR("<redacted> <redacted>");
MODULE_DESCRIPTION("<redacted>");

static int __init dw_init(void) {
  printk(KERN_INFO "<redacted>: Hello, World!\n");
  return 0;
}

static void __exit dw_exit(void) {
  printk(KERN_INFO "<redacted>: Goodbye, World!\n");
}

module_init(dw_init);
module_exit(dw_exit);

Additional Information and Error Logs

[ 50%]: cache compiling.release dw-kmod/src/entry.c
/usr/bin/gcc -c -DKBUILD_MODNAME=\"<redacted>\" -I/usr/src/linux/arch/x86/include -I/usr/src/linux/arch/x86/include/generated -I/usr/src/linux/include -I/usr/src/linux/arch/x86/include/uapi -I/usr/src/linux/arch/x86/include/generated/uapi -I/usr/src/linux/include/uapi -I/usr/src/linux/include/generated/uapi -include /usr/src/linux/include/linux/compiler-version.h -include /usr/src/linux/include/linux/kconfig.h -include /usr/src/linux/include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mindirect-branch-cs-prefix -mfunction-return=thunk-extern -fno-jump-tables -fpatchable-function-entry=16,16 -fno-delete-null-pointer-checks -fno-allow-store-data-races -fstack-protector -fno-stack-clash-protection -mrecord-mcount -mfentry -DCC_USING_FENTRY -fmin-function-alignment=16 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -Wall -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-larger-than=2048 -Wno-main -Wno-dangling-pointer -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-stringop-overflow -Wno-array-bounds -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wextra -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-unused-parameter -DMODULE -DKBUILD_BASENAME=\"entry\" -o build/.objs/<redacted>/linux/x86_64/release/dw-kmod/src/entry.c.o dw-kmod/src/entry.c
[ 75%]: linking.release build/linux/x86_64/release/<redacted>.ko
/usr/bin/ld -m elf_x86_64 -z noexecstack --no-warn-rwx-segments -r -o build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.o build/.objs/<redacted>/linux/x86_64/release/dw-kmod/src/entry.c.o
/usr/src/linux/scripts/mod/modpost -m -a -o build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/Module.symvers -e -N -w -T build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/modules.order
WARNING: modpost: "_printk" [build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.ko] undefined!
WARNING: modpost: "__x86_return_thunk" [build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.ko] undefined!
WARNING: modpost: "module_layout" [build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.ko] undefined!
/usr/bin/gcc -c -DKBUILD_MODNAME=\"<redacted>\" -I/usr/src/linux/arch/x86/include -I/usr/src/linux/arch/x86/include/generated -I/usr/src/linux/include -I/usr/src/linux/arch/x86/include/uapi -I/usr/src/linux/arch/x86/include/generated/uapi -I/usr/src/linux/include/uapi -I/usr/src/linux/include/generated/uapi -include /usr/src/linux/include/linux/compiler-version.h -include /usr/src/linux/include/linux/kconfig.h -include /usr/src/linux/include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mindirect-branch-cs-prefix -mfunction-return=thunk-extern -fno-jump-tables -fpatchable-function-entry=16,16 -fno-delete-null-pointer-checks -fno-allow-store-data-races -fstack-protector -fno-stack-clash-protection -mrecord-mcount -mfentry -DCC_USING_FENTRY -fmin-function-alignment=16 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -Wall -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-larger-than=2048 -Wno-main -Wno-dangling-pointer -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-stringop-overflow -Wno-array-bounds -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wextra -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-unused-parameter -DMODULE -o build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.mod.o build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.mod.c
/usr/bin/ld -r -m elf_x86_64 -z noexecstack --no-warn-rwx-segments --build-id=sha1 -T /usr/src/linux/scripts/module.lds -o build/linux/x86_64/release/<redacted>.ko build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.o build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.mod.o

build cache stats:
cache directory: /home/theaifam5/Projects/<redacted>/build/.build_cache
cache hit rate: 100%
cache hit: 2
cache hit total time: 0.000s
cache miss: 0
cache miss total time: 0.000s
new cached files: 0
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 0.000s

[100%]: build ok, spent 0.347s

Build dir file listing:

โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ # โ”‚                                          name                                          โ”‚ type โ”‚  size   โ”‚    modified    โ”‚
โ”œโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 0 โ”‚ build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.mod.c โ”‚ file โ”‚   847 B โ”‚ 24 minutes ago โ”‚
โ”‚ 1 โ”‚ build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.mod   โ”‚ file โ”‚    65 B โ”‚ 3 minutes ago  โ”‚
โ”‚ 2 โ”‚ build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.mod.o โ”‚ file โ”‚ 4.1 KiB โ”‚ 3 minutes ago  โ”‚
โ”‚ 3 โ”‚ build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/Module.symvers    โ”‚ file โ”‚     0 B โ”‚ 3 minutes ago  โ”‚
โ”‚ 4 โ”‚ build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/modules.order     โ”‚ file โ”‚    83 B โ”‚ 3 minutes ago  โ”‚
โ”‚ 5 โ”‚ build/.objs/<redacted>/linux/x86_64/release/build/linux/x86_64/release/<redacted>.ko.o     โ”‚ file โ”‚ 3.7 KiB โ”‚ 3 minutes ago  โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
waruqi commented 1 month ago

you can debug here. try to rename targetfile_o. xxx.ko.o -> xxx.o

https://github.com/xmake-io/xmake/blob/a7aab9dc7e64bd2a211c4d7937a7ffd7d6993a4d/xmake/rules/platform/linux/driver/driver_modules.lua#L287