tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
__attribute__((constructor)) in kernel
What I've learned about it.
TL;DR - .not really useful for kernel
*
- It generates a .ctors (or .init_array on arm or something) section
- GCC has __attribute__((constructor(n))) where n is priority, and the
section entries are sorted in ascending order, which is a handy syntax
- But not that great; easily replaced with ``sort'' function in linker script
- Userland needs this syntax, because userland applications have no
control about how it is linked; it sets function pointers in .ctors,
to ask ``system'' (linker, run-time) to call those functions before
main().
- In kernel, this is not the case; kernel itself has to call the
functions by itself. This way the section name (.ctors) doesn't
matter at all.
- To not confuse, ELF section (.ctors) is better to be hidden in final kernel.
- Rump will use link-set anyway.
Home |
Main Index |
Thread Index |
Old Index