添加系统调用后编译Linux 5.15.2内核出现vmlinux链接错误求助
问题描述
- 当前系统内核版本:
5.15.0-58-generic - 操作目标:为解压后的Linux 5.15.2版本内核添加自定义系统调用,操作参考5.8.1版本内核的教程
- 编译命令:
make -j4 - 错误输出:
UPD include/generated/compile.h
AR init/built-in.a
LD vmlinux.old: cannot find block : file format not recognized
make: *** [Makefile: 1183: vmlinux] Error 1
- 触发错误的Makefile代码段:
1182 vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE 1183 +$(call if_changed_dep,link-vmlinux)
解决方法
排查Makefile修改错误
你参考的是5.8.1版本的教程,5.15.2的Makefile结构存在差异,重点检查:- 是否在
core-y/libs-y等链接列表中误写了block(无后缀的非法目标),正确的应该是block/built-in.a这类完整路径的目标文件 - 确认系统调用相关代码文件的路径、文件名是否正确添加到Makefile,有无拼写错误
- 是否在
清理编译缓存后重新编译
执行以下命令清除残留编译文件,再重新构建:make clean make mrproper make olddefconfig make -j4匹配工具链版本
确保gcc、ld版本与5.15.2内核兼容,Ubuntu 20.04默认的gcc-9适配该内核版本,若使用了高版本gcc,可切换到gcc-9:sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100 sudo update-alternatives --install /usr/bin/ld ld /usr/bin/ld.bfd 100检查链接脚本
查看scripts/link-vmlinux.sh脚本,对比未修改的5.15.2内核同文件,确认是否存在异常的block相关参数或错误修改。
内容的提问来源于stack exchange,提问作者melody
相关产品推荐
相关产品推荐

