Kernel
GCC 12.1 的 Linux 核心 5.15.54 編譯錯誤
我正在嘗試重新編譯核心(遵循官方 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
首先,您的 make 不是“崩潰”,它是由於 GCC 錯誤而退出的。
不建議 GCC 12.1 編譯某些核心,因為它在程式碼方面啟用了新的更嚴格的檢查
$$ quality $$這意味著各種
-Werror
選項(“將警告視為錯誤”)可能會導致早期版本的編譯器中不存在的錯誤。 你有幾個選擇:
- 使用較舊的 GCC 版本,例如 GCC 11.4
- 使用 GCC 12.1:編輯 Makefile 並刪除
-Werror=use-after-free
- 等待核心更新檔(可能會也可能不會)來修復這些錯誤