Linux是一个复杂的大型软件.系统中正在运行的内核不会使用所有代码.
我正在寻找一个工具,它可以为我提供我用于构建内核的.config所需的源代码.我希望它删除ifdefs跳过的所有行和未用于构建的源文件,甚至是drivers文件夹中的文件.
有这样的工具吗?
我正在寻找这个的原因是我不确定在内核中实际构建了哪些代码.我同意我可以手动完成,但我认为没有不需要的ifdefs会让我更清楚地了解代码.
解决方法:
Linux内核的配置最终定义了C编译器的预处理器指令.预处理源的输出应该接近您正在寻找的输出,尽管也可能存在由编译器优化的死代码.
可以告诉gcc编译器使用-E生成预处理输出到stdout(然后停止):
-E Stop after the preprocessing stage; do not run the compiler
proper. The output is in the form of preprocessed source code,
which is sent to the standard output.
对于整个内核,可能更容易合并–save-temps编译器标志:
-save-temps
-save-temps=cwd
Store the usual "temporary" intermediate files permanently; place
them in the current directory and name them based on the source
file. Thus, compiling foo.c with -c -save-temps would produce
files foo.i and foo.s, as well as foo.o. This creates a
preprocessed foo.i output file even though the compiler now
normally uses an integrated preprocessor.
When used in combination with the -x command line option,
-save-temps is sensible enough to avoid over writing an input
source file with the same extension as an intermediate file. The
corresponding intermediate file may be obtained by renaming the
source file before using -save-temps.