在 Ubuntu 20.04 中实现自定义系统调用时出错
我主要遵循此教程,但出现错误。
这就是我所做的:
cd linux-5.16.15
mkdir helloworld
cd helloworld
gedit helloworld.c
#include <linux/kernel.h>
asmlinkage long sys_helloworld(void){
printk(“Hello World\n”);
return 0;
}
gedit Makefile
obj-y := helloworld.o
cd ..
gedit Makefile
找到第二个核心-y 并将
helloworld/
添加到该行
cd include/linux
gedit syscalls.h
在 syscalls.h 文件末尾之前#endif 添加, asmlinkage long sys_helloworld(void);
cd ../..
cd arch/x86/entry/syscalls
gedit syscall_64.tbl
450 64 helloworld sys_helloworld
当我运行 make 命令时,出现此错误:
ld: arch/x86/entry/syscall_64.o:(.rodata+0xe10): undefined reference to `__x64_sys_helloworld'
make: *** [Makefile:1161: vmlinux] Error 1
我尝试将 syscalls.h 文件和 syscall_64.tbl 文件中的 sys_helloworld 更改为 __x64_sys_helloworld,但这导致了这个错误:
ld: arch/x86/entry/syscall_64.o:(.rodata+0xe10): undefined reference to `__x64___x64_sys_helloworld'
ld: arch/x86/entry/syscall_x32.o:(.rodata+0xe10): undefined reference to `__x64___x64_sys_helloworld'
make: *** [Makefile:1161: vmlinux] Error 1
我做错了什么?有人可以帮我吗?
编辑: 我得到了那部分。刚刚将 helloworld.c 更改为:
#include <linux/kernel.h>
#include <linux/syscalls.h>
//asmlinkage long sys_helloworld(void){
SYSCALL_DEFINE0(helloworld)
{
printk("Hello world\n");
return 0;
}
但是现在当我运行 make module_install install
时,我收到此错误:
arch/x86/Makefile:142: CONFIG_X86_X32 enabled but no binutils support
ln: target '/source' is not a directory
make[1]: *** [Makefile:1477: __modinst_pre] Error 1
make: *** [Makefile:350: __build_one_by_one] Error 2
现在出了什么问题?请帮忙。
I mainly followed this tutorial but got an error.
Here's what I did:
cd linux-5.16.15
mkdir helloworld
cd helloworld
gedit helloworld.c
#include <linux/kernel.h>
asmlinkage long sys_helloworld(void){
printk(“Hello World\n”);
return 0;
}
gedit Makefile
obj-y := helloworld.o
cd ..
gedit Makefile
find second core-y and add
helloworld/
to that line
cd include/linux
gedit syscalls.h
in the end of the syscalls.h file before #endif add,asmlinkage long sys_helloworld(void);
cd ../..
cd arch/x86/entry/syscalls
gedit syscall_64.tbl
450 64 helloworld sys_helloworld
When I ran the make command, I got this error:
ld: arch/x86/entry/syscall_64.o:(.rodata+0xe10): undefined reference to `__x64_sys_helloworld'
make: *** [Makefile:1161: vmlinux] Error 1
I tried changing the sys_helloworld to __x64_sys_helloworld in the syscalls.h file and the syscall_64.tbl file but that led to this error:
ld: arch/x86/entry/syscall_64.o:(.rodata+0xe10): undefined reference to `__x64___x64_sys_helloworld'
ld: arch/x86/entry/syscall_x32.o:(.rodata+0xe10): undefined reference to `__x64___x64_sys_helloworld'
make: *** [Makefile:1161: vmlinux] Error 1
What did I do wrong? Can someone please help me out?
Edit:
I got that part. Just changed helloworld.c to this:
#include <linux/kernel.h>
#include <linux/syscalls.h>
//asmlinkage long sys_helloworld(void){
SYSCALL_DEFINE0(helloworld)
{
printk("Hello world\n");
return 0;
}
But now when I run make modules_install install
I get this error:
arch/x86/Makefile:142: CONFIG_X86_X32 enabled but no binutils support
ln: target '/source' is not a directory
make[1]: *** [Makefile:1477: __modinst_pre] Error 1
make: *** [Makefile:350: __build_one_by_one] Error 2
What's wrong now? Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论