2016-03-16

Linux Kernel Module Makefile 디버깅




정말 간단한 HelloWorld 커널을 모듈하면서, 시행착오가 많았다.
정리하면 소스 자체는 간단하니 문제가 없었지만, Makefile및 환경 설정에서 문제가 많이 발생했다.



  • CASE 1
원인 : 리눅스는 Makefile의 대소문자를 구분한다. 그냥 makefile로 파일을 생성하면
다음과 같은 에러를 얻는다.

# make
make -C /lib/modules/3.10.0-229.el7.x86_64/build SUBDIRS=/root/drivers KBUILD_VERBOSE=0 modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-229.el7.x86_64'
scripts/Makefile.build:44: /root/drivers/Makefile: No such file or directory
make[2]: *** No rule to make target `/root/drivers/Makefile'.  Stop.
make[1]: *** [_module_/root/drivers] Error 2
make[1]: Leaving directory `/usr/src/kernels/3.10.0-229.el7.x86_64'
make: *** [all] Error 2
해결 : 파일이름을 makefile -> Makefile 로 대소문자 구분하도록 수정한다.




  • CASE 2
원인 : 커널 모듈 컴파일시 'make'가 사용하는 모듈 설치 도구가 없는 경우 발생.
나는 CentOS7.1의 기본 커널 버전인 3.10 을 3.14.64 버전으로 업데이트 했는데,
이때 모듈 설치 도구는 컴파일에서 제외되어 있었음.

# make -d
 Successfully remade target file `FORCE'.
   Finished prerequisites of target file `/root/workspace/drivers/src/helloworld.o'.
   Prerequisite `/root/workspace/drivers/src/helloworld.c' is older than target `/root/workspace/drivers/src/helloworld.o'.
   Prerequisite `/usr/src/kernels/linux-3.14.64/scripts/recordmcount.c' is older than target `/root/workspace/drivers/src/helloworld.o'.
   Prerequisite `/usr/src/kernels/linux-3.14.64/scripts/recordmcount.h' is older than target `/root/workspace/drivers/src/helloworld.o'.
   Prerequisite `FORCE' of target `/root/workspace/drivers/src/helloworld.o' does not exist.
  Must remake target `/root/workspace/drivers/src/helloworld.o'.
Invoking recipe from scripts/Makefile.build:314 to update target `/root/workspace/drivers/src/helloworld.o'.
Putting child 0x1267170 (/root/workspace/drivers/src/helloworld.o) PID 78769 on the chain.
Live child 0x1267170 (/root/workspace/drivers/src/helloworld.o) PID 78769 
  CC [M]  /root/workspace/drivers/src/helloworld.o
/bin/sh: /usr/src/kernels/linux-3.14.64/scripts/recordmcount: No such file or directory
Reaping losing child 0x1267170 PID 78769 
make[2]: *** [/root/workspace/drivers/src/helloworld.o] Error 1
Removing child 0x1267170 PID 78769 from chain.
Reaping losing child 0x9cb2d0 PID 78766 
make[1]: *** [_module_/root/workspace/drivers/src] Error 2
Removing child 0x9cb2d0 PID 78766 from chain.
make[1]: Leaving directory `/usr/src/kernels/linux-3.14.64'
Reaping losing child 0x2341fd0 PID 78546 
make: *** [all] Error 2
Removing child 0x2341fd0 PID 78546 from chain.
※ 위의 recordmcount 뿐만 아닐라 모듈 관리에 설치된 툴들이 계속 없다고 설치 중지되므로 다  개별 처리 하거나 한꺼번에 처리 해줘야 한다.

해결 : 모듈 설치 도구를 컴파일해 준다.
개별 컴파일도 가능하다.
# cd /usr/src/kernels/linux-3.14.64
# make modules_prepare
 make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `relocs'.
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CALL    scripts/checksyscalls.sh
  HOSTCC  scripts/genksyms/genksyms.o
  SHIPPED scripts/genksyms/lex.lex.c
  SHIPPED scripts/genksyms/keywords.hash.c
  SHIPPED scripts/genksyms/parse.tab.h
  HOSTCC  scripts/genksyms/lex.lex.o
  SHIPPED scripts/genksyms/parse.tab.c
  HOSTCC  scripts/genksyms/parse.tab.o
  HOSTLD  scripts/genksyms/genksyms
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  CC      scripts/mod/devicetable-offsets.s
  GEN     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/modpost.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  HOSTCC  scripts/selinux/genheaders/genheaders
  HOSTCC  scripts/selinux/mdp/mdp
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/pnmtologo
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/recordmcount
  HOSTCC  scripts/sortextable
  HOSTCC  scripts/asn1_compiler

No comments:

Post a Comment