linux源码包含了大量的头文件,又包宏定义的条件编译,给人工阅读可能带来困难,突然想起gcc -E 可以输出源文件展开所有头文件及宏后的预处理后的文件内容,当然,直接arm-linux-gnueabihf-gcc -E xxx.c肯定是不行的,会找不到头文件,这里借助顶层makefile 的 V=1 选项,将要包含的目录给打印出来

例如,想要看 arch/arm/boot/compressed/head.S预处理后是什么样子
第一步
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage -j4 V=1

然后找到编译 arch/arm/boot/compressed/head.o的那一条完整命令

arm-linux-gnueabihf-gcc -Wp,-MD,arch/arm/boot/compressed/.head.o.d  -nostdinc -isystem /home/fang/ti-processor-sdk-linux-am335x-evm-04.00.00.04/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/../lib/gcc/arm-linux-gnueabihf/6.2.1/include -I./arch/arm/include -I./arch/arm/include/generated/uapi -I./arch/arm/include/generated  -I./include -I./arch/arm/include/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -D__ASSEMBLY__ -fno-PIE -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -include asm/unified.h -msoft-float -DCC_HAVE_ASM_GOTO -DZIMAGE -DTEXT_OFFSET=0x00008000   -c -o arch/arm/boot/compressed/head.o arch/arm/boot/compressed/head.S
第二步:应用-E选项
将上面的完整命令,改一改
arm-linux-gnueabihf-gcc  -nostdinc -isystem /home/fang/ti-processor-sdk-linux-am335x-evm-04.00.00.04/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/../lib/gcc/arm-linux-gnueabihf/6.2.1/include -I./arch/arm/include -I./arch/arm/include/generated/uapi -I./arch/arm/include/generated  -I./include -I./arch/arm/include/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -D__ASSEMBLY__ -fno-PIE -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -marm -D__LINUX_ARM_ARCH__=7 -march=armv7-a -include asm/unified.h -msoft-float -DCC_HAVE_ASM_GOTO -DZIMAGE -DTEXT_OFFSET=0x00008000   -E arch/arm/boot/compressed/head.S -o arch/arm/boot/compressed/head.i
这样,arch/arm/boot/compressed/head.i就是预处理head.S后的内容了

09-10 09:02