0

I’m trying to understand the rationale behind the Linux kernel’s initcall mechanism. My current understanding:

Kernel subsystems expose one-time initialization functions using macros like core_initcall(), device_initcall(), etc. The build system places these functions into named sections (e.g., .initcall0.init, .initcall1.init, …).

At boot, the kernel iterates over these sections in order and calls each function once.

From the linker script (vmlinux.lds.S), I see something like:

#define INIT_CALLS                           \
        __initcall_start = .;                \
        KEEP(*(.initcallearly.init))         \
        INIT_CALLS_LEVEL(0)                  \
        INIT_CALLS_LEVEL(1)                  \
        INIT_CALLS_LEVEL(2)                  \
        INIT_CALLS_LEVEL(3)                  \
        INIT_CALLS_LEVEL(4)                  \
        INIT_CALLS_LEVEL(5)                  \
        INIT_CALLS_LEVEL(rootfs)             \
        INIT_CALLS_LEVEL(6)                  \
        INIT_CALLS_LEVEL(7)                  \
        __initcall_end = .;

Is the understanding above correct (i.e., functions are grouped into .initcall* sections and invoked in a defined order during boot)?

Why does the kernel use initcalls instead of calling these init functions “manually” from start_kernel() or early assembly? What concrete problems does the initcall mechanism solve?

Why are the initcall entries laid out contiguously between __initcall_start and __initcall_end?

4
  • Does this help? kernelnewbies.org/InitcallMechanism/HowItWorks Commented Aug 12 at 10:44
  • @teapot418 No it does not Commented Aug 12 at 11:23
  • 3
    "What concrete problems does the initcall mechanism solve ?" - (1) The number of routines to call is unknown until link time. (2) These routines are located in a section of memory that is repurposed after the boot phase, so they cannot be called again. (3) Built-in modules and loadable modules have/use the same source code constructs. (4) A list of just addresses to call is more compact & maintainable than a code block of many call statements, especially when which routines to call are conditionally compiled/built. Commented Aug 14 at 9:29
  • What is "manually calling" a function? Do you mean executing a CALL machine instruction with an immediate address, no indirection? Commented Aug 14 at 9:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.