理解内核initcall
2015-12-18 09:44
183 查看
引出过程:
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,了解个大概,但还讲不出来。需要多看看。
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,了解个大概,但还讲不出来。需要多看看。
相关文章推荐
- java、javac -version不一致(java编译及运行环境不一致)的环境变量设置问题解决
- 兼容ie8以下的圆角头像制作方法
- android开发游记:DrawerLayout 实现抽屉效果的导航菜单
- poj--2955--Brackets(区间dp)
- 电商平台稳定性的保证 分布式压力测试
- Android之Intent
- 迭代器失效
- Android实用的任务管理器—tractor
- linux文件权限以及权限修改命令
- NGINX 配置Thinkphp
- 错误:unrecognized command line option “-std=c++11”
- 怎样成为一个天才
- ubuntu iptables设置【转】
- oneinstack一键部署linux生产环境那点事(ubuntu)
- operator
- Java 工程师成神之路
- java中路径的问题
- 架构师学习方向
- modelsim-win64-10.4-se 下载、安装、破解全攻略
- Android源码分析—带你认识不一样的AsyncTask(串并行)