这篇博客接前面两篇:在Ubuntu上编译特定版本的Linux Kernel_蛐蛐蛐的博客-CSDN博客和怎样编译Linux Kernel中的尽可能多的源码_蛐蛐蛐的博客-CSDN博客。
有时候我们想尽量用O0来编译Kernel,以进行一些后续分析,但是就像上面第二个链接中说的,基本上用O0编译是很难的。我主要参考了一下这篇博客:使用-O0编译Linux内核_玉双龙的博客-CSDN博客
首先,将makefile中的O2,O3,Os都改成O0。(我这里依然以v5.12-rc2为例)
其次
make allmodconfig
然后
sudo make -j 10
这时候就会有下面的报错:
./include/linux/compiler-gcc.h:91:38: error: impossible constraint in ‘asm’
#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
^
./arch/x86/include/asm/jump_label.h:25:2: note: in expansion of macro ‘asm_volatile_goto’
asm_volatile_goto("1:"
^~~~~~~~~~~~~~~~~
解决方法就和上面那篇博客的评论里说的一样:
如果没有使能CONFIG_JUMP_LABEL,直接把asm_volatile_goto定义为do{}while(0)即可
我们找到:/include/linux/compiler-gcc.h,将其打开后,将这一行:
#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
修改为:
#define asm_volatile_goto(x...) do {} while (0)
然后再尝试一下编译:
sudo make -j 10
这时候可以发现没有上面的error了,但是会有很多warning,类似于下面这样:
./arch/x86/include/asm/cpufeature.h:214:1: warning: label ‘t_yes’ defined but not used [-Wunused-label]
t_yes:
^~~~~
In file included from ./arch/x86/include/asm/tsc.h:9:0,
from ./arch/x86/include/asm/timex.h:6,
from ./include/linux/timex.h:65,
from ./include/linux/time32.h:13,
from ./include/linux/time.h:60,
from ./include/linux/stat.h:19,
from ./include/linux/module.h:13,
from sound/soc/codecs/simple-mux.c:8:
./arch/x86/include/asm/cpufeature.h: In function ‘_static_cpu_has’:
./arch/x86/include/asm/cpufeature.h:216:1: warning: label ‘t_no’ defined but not used [-Wunused-label]
t_no:
^~~~
./arch/x86/include/asm/cpufeature.h:214:1: warning: label ‘t_yes’ defined but not used [-Wunused-label]
t_yes:
^~~~~
很快就跑完了,所以肯定没编译多少,这时候我们数数文件夹下的.o和.ko文件,发现只有4616个。感觉这也太少了吧,而且我也不知道怎么修改,因为和上面博客中说的不一样,并没有出现后面的报错。
于是想着能不能尽量再多一点,于是想到了那个make allmodconfig命令。我实在不知道其具体含义,搜了一下,解释如下(出自:Linux Kernel Configuration - Configuration Targets):
Target | Description |
---|---|
config | Updates the current kernel configuration by using a line-oriented program. |
menuconfig | Updates the current kernel configuration by using a text based menu program. |
xconfig | Updates the current kernel configuration by using a QT-based graphical program. |
gconfig | Updates the current kernel configuration by using a GTK+-based graphical program. |
oldconfig | Updates the current kernel configuration by using the current .config file and prompting for any new options that have been added to the kernel. |
silentoldconfig | Just like oldconfig, but prints nothing to the screen except when a question needs to be answered. |
randconfig | Generates a new kernel configuration with random answers to all of the different options. |
defconfig | Generates a new kernel configuration with the default answer being used for all options. The default values are taken from a file located in the arch/$ARCH/defconfig file, where $ARCH refers to the specific architecture for which the kernel is being built. |
allmodconfig | Generates a new kernel configuration in which modules are enabled whenever possible. |
allyesconfig | Generates a new kernel configuration with all options set to yes. |
allnoconfig | Generates a new kernel configuration with all options set to no. |
于是想尝试一下这个:
make allyesconfig
然后再编译一次,然后数一数,是4689个文件,也没什么太大的差别。说实话,这些选项之间的区别我真的不是很清楚。就先准备拿这些文件分析了,说实话也没有其他什么更好的办法了。
更新:另外总结一个很奇怪的事情,在同一个配置下,如果多次运行sudo make -j 10,会发现目标代码的个数在缓慢增加,惊呆了!难道意思是越努力越有结果??