Kernel Section

숲사람·2022년 3월 24일
0

Linux Kernel

목록 보기
5/10

Kernel Section Mismatch 에러 발생 원인

커널 링킹 타임에 발생하는 에러

  • 에러로그
MODPOST vmlinux.symvers
WARNING: modpost: vmlinux.o(.text+0xc2d4d0): Section mismatch in reference from the function check_cmdline() to the function .init.text:of_get_flat_dt_root()
The function check_cmdline() references
the function __init of_get_flat_dt_root().
This is often because check_cmdline lacks a __init
annotation or the annotation of of_get_flat_dt_root is wrong.

.init.text 섹션(__init) 의 함수는 임시로 사용되고 해제 된다. 부팅시 한번 호출된다. 따라서 일반 .text 섹션의 함수가 .init 섹션의 코드나 데이터를 접근할때 링킹 에러가 발생한다. 가령 위의 예에서 check_cmdline() 함수가 of_get_flat_dt_root() 함수를 호출하는데 이 함수는 __init 지시자가 있는 .init.text섹션에 존재하는 함수다. 반면 check_cmdline는 아니다. 그래서 check_cmdline 함수가 해제 되어버린 함수를 호출하게 되므로 섹션 mismatch가 발생하는것이다.

추가 궁금증:
__init section에 등록된 함수에서 text섹션에 있는 함수 호출시 에러 발생한다면, 그럼 서로다른 섹션간의 함수 호출은 전혀 못하는지?

참고:

실행파일 포맷 ELF

UNIX에서는 모든것이 파일이다. 그 파일중에 어떤파일은 실행가능하다. 실행 할수 있는파일을 실행파일이라고 한다. 우리가 사용하는 프로그램도 이 실행파일이다.

섹션이란?

링커가 서로다른 오브젝트에서 같은 타입의 섹션을 elf에 모음.
Linkers use this information to combine different parts of the program coming from different modules into one executable file or a library, by merging sections of the same type (gluing pages together, if you will).

| https://stackoverflow.com/questions/16812574/elf-files-what-is-a-section-and-why-do-we-need-it

A section is the smallest unit of an object that can be relocated. Use the elfdump command to inspect the components of an object or executable file generated by the assembler.

https://docs.oracle.com/cd/E37838_01/html/E61063/elf-23207.html#:~:text=A%20section%20is%20the%20smallest,Executable%20text

세종류의 object 파일

  • A relocarable file
  • An executable file
  • A shared object file

section은 only relevant at link time
segment 는 only relevant at runtime

elf 실행포맷이 실행되는 원리

init 외에 다른섹션 함수는 호출가능?

간단한 실험을 해보자.

what is vmlinux

https://en.wikipedia.org/wiki/Vmlinux

Is a kernel module elf?

profile
기록 & 정리 아카이브 용도 (보다 완성된 글은 http://soopsaram.com/documentudy)

0개의 댓글