去掉编译内核的优化选项
优化级别从 -O2 改为 -O1
修改内核源代码根目录下的Makefile:
```bash
sed -i 's/KBUILD_CFLAGS += -O2/KBUILD_CFLAGS += -O1/g' Makefile
```
内核调试选项
```text
Kernel hacking --->
Compile-time checks and compiler options --->
[*] Compile the kernel with debug info
[*] Provide GDB scripts for kernel debugging
[*] Enable full Section mismatch analysis
[*] Kernel debugging
```
对应编译选项如下:
```text
CONFIG_DEBUG_INFO = y
CONFIG_GDB_SCRIPTS = y
CONFIG_DEBUG_SECTION_MISMATCH = y
CONFIG_DEBUG_KERNEL = y
```
为了支持`CONFIG_DEBUG_SECTION_MISMATCH`特性,还需开启`CONFIG_X86_5LEVEL`特性:
```text
[*] Enable 5-level page tables support
```
对应编译选项如下:
```text
CONFIG_X86_5LEVEL = y
```
关闭内核随机地址选项
```text
Processor type and features ---->
[] Randomize the address of the kernel image (KASLR)
```
对应编译选项如下:
```text
CONFIG_RANDOMIZE_BASE = n
```
`make menuconfig`确认上述编译选项后输出如下:

编译内核
```bash
make -j`expr $(nproc) \* 2`
```
More
💬 评论