Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux多文件驱动项目编译失败 Kernel 5.19+ #2875

Closed
yinntian opened this issue Sep 27, 2022 · 2 comments
Closed

Linux多文件驱动项目编译失败 Kernel 5.19+ #2875

yinntian opened this issue Sep 27, 2022 · 2 comments
Labels
Milestone

Comments

@yinntian
Copy link
Contributor

Xmake 版本

xmake v2.7.1+202209191332

操作系统版本和架构

Linux wl-kernel 6.0.0-rc5 #1 SMP PREEMPT_DYNAMIC Sat Sep 17 14:58:17 CST 2022 x86_64 x86_64 x86_64 GNU/Linux

描述问题

多文件编译错误
modpost 报错:文件未找到

期待的结果

编译通过

工程配置

xmake.lua

target("hello")
    add_rules("platform.linux.driver")
    set_values("linux.driver.linux-headers", "/home/luna/linux/kernel/linux-5.19.1")
    set_optimize("faster")
    add_files("src/*.c")
    set_license("GPL")

main.c

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

#include "greet.h"

static int __init module_load(void) {
    printk("Loading hello module...");
	greet();
    printk("hello module initialization");
    return 0;
}

static void __exit module_unload(void) {
    printk("Goodbye.");
}

module_init(module_load);
module_exit(module_unload);

///< The author -- visible when you use modinfo
MODULE_AUTHOR("Someones");

///< The description -- see modinfo
MODULE_DESCRIPTION("A simple Hello world LKM!");

///< The version of the module
MODULE_VERSION("0.1");

///< The license type -- this affects runtime behavior
MODULE_LICENSE("GPL");

greet.h

void greet(void);

greet.c

#include <linux/printk.h>
#include "greet.h"

void greet() {
    printk(KERN_INFO "greet(): howdy!\n");
}

附加信息和错误日志

luna@wl-dev22:~/linux/test$ xmake -vD
[ 20%]: cache compiling.release src/main.c
/usr/bin/gcc -c -O2 -DKBUILD_MODNAME=\"hello\" -I/home/luna/linux/kernel/linux-5.19.1/arch/x86/include -I/home/luna/linux/kernel/linux-5.19.1/arch/x86/include/generated -I/home/luna/linux/kernel/linux-5.19.1/include -I/home/luna/linux/kernel/linux-5.19.1/arch/x86/include/uapi -I/home/luna/linux/kernel/linux-5.19.1/arch/x86/include/generated/uapi -I/home/luna/linux/kernel/linux-5.19.1/include/uapi -I/home/luna/linux/kernel/linux-5.19.1/include/generated/uapi -include /home/luna/linux/kernel/linux-5.19.1/include/linux/compiler-version.h -include /home/luna/linux/kernel/linux-5.19.1/include/linux/kconfig.h -include /home/luna/linux/kernel/linux-5.19.1/include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=branch -fno-jump-tables -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 -mharden-sls=all -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -fno-allow-store-data-races -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining -Wframe-larger-than=2048 -fstack-protector-strong -Werror -Wimplicit-fallthrough=5 -Wno-main -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-stack-clash-protection -fzero-call-used-regs=used-gpr -mrecord-mcount -mfentry -DCC_USING_FENTRY -fno-inline-functions-called-once -falign-functions=64 -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-stringop-truncation -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -Wno-alloc-size-larger-than -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -fsanitize=kernel-address -fasan-shadow-offset=0xdffffc0000000000 -fsanitize=bounds -fsanitize=shift -fsanitize=integer-divide-by-zero -fsanitize=bool -fsanitize=enum -fsanitize-coverage=trace-pc -fsanitize-coverage=trace-cmp -DMODULE -Wno-error -DCONFIG_X86_X32_ABI -DKBUILD_BASENAME=\"main\" -o build/.objs/hello/linux/x86_64/release/src/main.c.o src/main.c
[ 20%]: cache compiling.release src/greet.c
/usr/bin/gcc -c -O2 -DKBUILD_MODNAME=\"hello\" -I/home/luna/linux/kernel/linux-5.19.1/arch/x86/include -I/home/luna/linux/kernel/linux-5.19.1/arch/x86/include/generated -I/home/luna/linux/kernel/linux-5.19.1/include -I/home/luna/linux/kernel/linux-5.19.1/arch/x86/include/uapi -I/home/luna/linux/kernel/linux-5.19.1/arch/x86/include/generated/uapi -I/home/luna/linux/kernel/linux-5.19.1/include/uapi -I/home/luna/linux/kernel/linux-5.19.1/include/generated/uapi -include /home/luna/linux/kernel/linux-5.19.1/include/linux/compiler-version.h -include /home/luna/linux/kernel/linux-5.19.1/include/linux/kconfig.h -include /home/luna/linux/kernel/linux-5.19.1/include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=branch -fno-jump-tables -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 -mharden-sls=all -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -fno-allow-store-data-races -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining -Wframe-larger-than=2048 -fstack-protector-strong -Werror -Wimplicit-fallthrough=5 -Wno-main -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-stack-clash-protection -fzero-call-used-regs=used-gpr -mrecord-mcount -mfentry -DCC_USING_FENTRY -fno-inline-functions-called-once -falign-functions=64 -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-stringop-truncation -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -Wno-alloc-size-larger-than -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -fsanitize=kernel-address -fasan-shadow-offset=0xdffffc0000000000 -fsanitize=bounds -fsanitize=shift -fsanitize=integer-divide-by-zero -fsanitize=bool -fsanitize=enum -fsanitize-coverage=trace-pc -fsanitize-coverage=trace-cmp -DMODULE -Wno-error -DCONFIG_X86_X32_ABI -DKBUILD_BASENAME=\"greet\" -o build/.objs/hello/linux/x86_64/release/src/greet.c.o src/greet.c
[ 60%]: linking.release build/linux/x86_64/release/hello.ko
/usr/bin/ld -m elf_x86_64 -r -o build/.objs/hello/linux/x86_64/release/build/linux/x86_64/release/hello.ko.o build/.objs/hello/linux/x86_64/release/src/main.c.o build/.objs/hello/linux/x86_64/release/src/greet.c.o
/home/luna/linux/kernel/linux-5.19.1/scripts/mod/modpost -m -a -o build/.objs/hello/linux/x86_64/release/build/linux/x86_64/release/Module.symvers -e -N -w -T -
build/.objs/hello/linux/x86_64/release/src/main.c.o build/.objs/hello/linux/x86_64/release/src/.greet.c.o.cmd: No such file or directory
error: @programdir/modules/private/async/runjobs.lua:256: @programdir/core/sandbox/modules/os.lua:372: execv(/home/luna/linux/kernel/linux-5.19.1/scripts/mod/modpost -m -a -o build/.objs/hello/linux/x86_64/release/build/linux/x86_64/release/Module.symvers -e -N -w -T -) failed(1)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:890]:
    [@programdir/core/sandbox/modules/os.lua:372]:
    [@programdir/core/sandbox/modules/os.lua:285]: in function 'vrunv'
    [@programdir/rules/platform/linux/driver/driver_modules.lua:278]: in function 'callback'
    [@programdir/modules/core/project/depend.lua:193]: in function 'on_changed'
    [@programdir/rules/platform/linux/driver/driver_modules.lua:229]: in function 'link'
    [@programdir/rules/platform/linux/driver/xmake.lua:31]: in function 'on_link'
    [@programdir/actions/build/kinds/binary.lua:88]:
    [@programdir/actions/build/kinds/binary.lua:129]: in function '_link_target'
    [@programdir/actions/build/kinds/binary.lua:157]: in function 'jobfunc'
    [@programdir/modules/private/async/runjobs.lua:232]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:890: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/modules/private/async/runjobs.lua:256: in field 'catch'
        @programdir/core/sandbox/modules/try.lua:123: in global 'try'
        @programdir/modules/private/async/runjobs.lua:218: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:388: in function <@programdir/core/base/scheduler.lua:385>
@yinntian yinntian added the bug label Sep 27, 2022
@yinntian yinntian changed the title Linux Kernel 5.19及后续版本xmake多文件编译错误 Linux多文件驱动项目编译失败 Kernel 5.19+ Sep 27, 2022
@yinntian
Copy link
Contributor Author

Linux社区在Kernel 5.19-rc1中更改了<module>.mod文件结构

5.19+

/home/luna/linux/test/src/main.o
/home/luna/linux/test/src/greet.o


5.19-

/home/luna/linux/test/src/main.o /home/luna/linux/test/src/greet.o


对应提交:
torvalds/linux@9413e76
torvalds/linux@22f26f2

@waruqi waruqi added this to the v2.7.2 milestone Sep 27, 2022
@waruqi
Copy link
Member

waruqi commented Sep 27, 2022

既然已经修了,这里我先关了

@waruqi waruqi closed this as completed Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants