본문 바로가기

리눅스 커널의 구조와 원리/2. 라즈베리 파이 설정

[리눅스 커널] 전처리 파일 생성 (v6.10)

During compilation, the compiler may generate various files, such as object file, libraray file and preprocessed file. Among these, preprocessed file contain the valuable information because the compiler parses the representation macro into the readable statement. 

To get preprocessed in the Linux kernel, we have to modify Makefile. The following is the patchset to generate preprocessed in the Linux kernel (v6.10).

diff --git a/Makefile b/Makefile
index 9b88055ea112..13369bde03ba 100644
--- a/Makefile
+++ b/Makefile
@@ -548,6 +548,7 @@ KBUILD_CFLAGS += -funsigned-char
 KBUILD_CFLAGS += -fno-common
 KBUILD_CFLAGS += -fno-PIE
 KBUILD_CFLAGS += -fno-strict-aliasing
+KBUILD_CFLAGS += -save-temps=obj

 KBUILD_CPPFLAGS := -D__KERNEL__
 KBUILD_RUSTFLAGS := $(rust_common_flags) \

 

After above patch set is applied to your source tree in Linux kernel, we can identify that the preprocessed files are generated during compilation:

out-riscv64/crypto$ ls
aead.i    algapi.s               bpf_crypto_skcipher.s  compress.s       lskcipher.s    scatterwalk.s
aead.o    api.i                  cipher.i               crypto_engine.i  proc.i         skcipher.i
aead.s    api.o                  cipher.o               crypto_engine.o  proc.o         skcipher.o
ahash.i   api.s                  cipher.s               crypto_engine.s  proc.s         skcipher.s
algapi.i  bpf_crypto_skcipher.i  compress.i             lskcipher.i      scatterwalk.i
algapi.o  bpf_crypto_skcipher.o  compress.o             lskcipher.o      scatterwalk.o

 


Note that *.i is preprocessed file, such as aead.i, api.i and so on.