引出过程:
net_dev_init() // net/core/dev.c 网络初始化
这个函数什么被调用呢?
subsys_initcall(net_dev_init) // 可能是这
继续找
#define subsys_initcall(fn) __define_initcall(fn, 4) // include/linux/init.h
go on
#define __define_initcall(fn, id) \ |
static initcall_t __initcall_##fn##id __used \ |#define INIT_CALLS_LEVEL(level) \
__attribute__((__section__(".initcall" #id ".init"))) = fn
看不懂。网上找找
http://blog.csdn.net/skyflying2012/article/details/8764486。
写的不错。
但自己水平有限,看不懂。不过作者提供了个思路。
used做什么(看gcc.pdf)
找到了:
used This attribute, attached to a variable with static storage, means that the variable
must be emitted even if it appears that the variable is not referenced.
When applied to a static data member of a C++ class template, the attribute
also means that the member is instantiated if the class itself is instantiated.
但不理解。
找找。stackoverflow有一个类似问题,豁然开朗
Q:How can I force GCC to compile functions that are not used?
A:You could try __attribute__ ((used)) - see Declaring Attributes of Functions in the gcc manual.s
也就是函数不被使用,但也不希望编译器优化掉。
section又是什么鬼?
也在gcc.pdf P432
差不多了。
作者找到.initcall4.init段了。我也找找
grep 找__initcall_start
在include/asm-generic/vmlinux.lds.h中
#define INIT_CALLS_LEVEL(level) \
VMLINUX_SYMBOL(__initcall##level##_start) = .; \
*(.initcall##level##.init) \
*(.initcall##level##s.init) \
#define INIT_CALLS \
VMLINUX_SYMBOL(__initcall_start) = .; \
*(.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) \
VMLINUX_SYMBOL(__initcall_end) = .;
这个样子,差不多了。
今天就这样。有点收获。
明天了解一下section(只以为有BS,CS,SS。之前想弄明白readelf,结果半途而废,明天拾起来重新来)
readelf介绍了elf文件的格式。其中,有section的介绍(有系统定义的section,有用户定义的section)
section的概念,需要找汇编语言的书籍去了解。阅读LALP,了解个大概,但还讲不出来。需要多看看。