我正在尝试重新编译内核(遵循官方 Arch Linux 指南:https://wiki.archlinux.org/title/Kernel/Traditional_compilation)但每次我收到编译错误时:
In file included from help.c:12:
In function ‘xrealloc’,
inlined from ‘add_cmdname’ at help.c:24:2:
subcmd-util.h:56:23: error: pointer may be used after ‘realloc’ [-Werror=use-after-free]
56 | ret = realloc(ptr, size);
| ^~~~~~~~~~~~~~~~~~
subcmd-util.h:52:21: note: call to ‘realloc’ here
52 | void *ret = realloc(ptr, size);
| ^~~~~~~~~~~~~~~~~~
subcmd-util.h:58:31: error: pointer may be used after ‘realloc’ [-Werror=use-after-free]
58 | ret = realloc(ptr, 1);
| ^~~~~~~~~~~~~~~
subcmd-util.h:52:21: note: call to ‘realloc’ here
52 | void *ret = realloc(ptr, size);
| ^~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[4]: *** [/home/jenusi/Downloads/linux-5.15/tools/build/Makefile.build:97: /home/jenusi/Downloads/linux-5.15/tools/objtool/help.o] Error 1
make[3]: *** [Makefile:59: /home/jenusi/Downloads/linux-5.15/tools/objtool/libsubcmd-in.o] Error 2
make[2]: *** [Makefile:63: /home/jenusi/Downloads/linux-5.15/tools/objtool/libsubcmd.a] Error 2
make[1]: *** [Makefile:69: objtool] Error 2
make: *** [Makefile:1371: tools/objtool] Error 2
内核:5.15.54,GCC:12.1.0
答案1
首先,你的 make 并没有“崩溃”,而是由于 GCC 错误而退出。
GCC 12.1 不建议编译某些内核,因为它在代码[质量]方面启用了新的更严格的检查,这意味着各种-Werror
选项(“将警告视为错误”)可能会导致早期版本的编译器中不存在的错误。
您有多种选择:
- 使用较旧的 GCC 版本,例如 GCC 11.4
- 使用 GCC 12.1:编辑 Makefile 并删除
-Werror=use-after-free
- 等待内核补丁(可能会也可能不会)来修复这些错误
答案2
添加-Wno-use-after-free
到 makefiletools/lib/subcmd/Makefile
第 22 行。
看起来像下面这样。
CFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC -Wno-use-after-free