添加Linux系统调用编译报错:undefined reference to `__x64_sys_pid'
解决Linux内核添加系统调用时的
undefined reference to __x64_sys_pid错误 报错信息
ld: arch/x86/entry/syscall_64.o:(.rodata+0xe08): undefined reference to `__x64_sys_pid' make: *** [Makefile:1183: vmlinux] Error 1
问题原因
链接器生成vmlinux时找不到__x64_sys_pid符号的定义,核心问题出在arch/x86/entry/syscalls/syscall_64.tbl文件:要么是误添加了指向sys_pid的系统调用条目(但你并未实现对应的sys_pid函数),要么是文件内存在拼写错误,导致内核尝试寻找不存在的符号。
排查与解决步骤
检查syscall_64.tbl文件
- 全局搜索文件中包含
pid的条目,删除或修正错误条目(比如误写的xxx common pid sys_pid这类内容)。 - 核对你添加的hello系统调用条目
442 common hello sys_hello:确保编号未被占用、名称和声明完全一致,无拼写错误。
- 全局搜索文件中包含
验证hello模块编译配置
- 确认hello目录下的Makefile内容为
obj-y := hello.o,保证hello.c会被编译为内核内置模块。 - 检查主Makefile中是否正确添加了
hello/目录,且make menuconfig时该模块已设为内置(对应选项为y)。
- 确认hello目录下的Makefile内容为
清理缓存重新编译
执行以下命令清理旧编译产物后重新编译:make clean make -j2
额外注意事项
- 系统调用编号要选择syscall_64.tbl中未被占用的数值(建议取现有最大编号+1),避免冲突。
- 系统调用声明
asmlinkage long sys_hello(int id);要与SYSCALL_DEFINE1(hello,int, id)的参数、返回值类型严格匹配。
内容的提问来源于stack exchange,提问作者Anvita Mahajan
相关产品推荐
相关产品推荐

