文章目录
1. 编译内核
1.1. 修改gcc优化等级
1.2. 防止`modpost: Section mismatches detected.`错误
1.3. 根据需要编译内核
1.4. 修改子目录Makefile
1.5. 重新执行编译
2. 参考资料
1. 编译内核
进入kernel 源码目录
1.1. 修改gcc优化等级
diff --git a/Makefile b/Makefile
index d4d36c619..1047c83c6 100644
--- a/Makefile
+++ b/Makefile
@@ -701,11 +701,11 @@ KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
-KBUILD_CFLAGS += -O2
+KBUILD_CFLAGS += -O0
else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3
-KBUILD_CFLAGS += -O3
+KBUILD_CFLAGS += -O0
else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
-KBUILD_CFLAGS += -Os
+KBUILD_CFLAGS += -O0
endif
ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED
1.2. 防止modpost: Section mismatches detected.错误
如果此时直接执行make进行编译,会出现modpost: Section mismatches detected.错误。
解决方法是修改scripts/mod/modpost.c。
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index d2a30a7b3..58e2237c2 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@