在内核中通过/proc/kallsyms获得符号的地址

http://hi.baidu.com/zengzhaonong/blog/item/bd6c4be7a0bd3f36b8382061.html


在内核中通过/proc/kallsyms获得符号的地址

 

Linux内核符号表/proc/kallsyms的形成过程
---------------------------------------------------------------------------

./scripts/kallsyms.c负责生成System.map
./kernel/kallsyms.c负责生成/proc/kallsyms

./scripts/kallsyms.c解析vmlinux(.tmp_vmlinux)生成kallsyms.S(.tmp_kallsyms.S),然后内核编译过程中将kallsyms.S(内核符号表)编入内核镜像uImage

内核启动后./kernel/kallsyms.c解析uImage形成/proc/kallsyms


/proc/kallsyms包含了内核中的函数符号(包括没有EXPORT_SYMBOL)、全局变量(用EXPORT_SYMBOL导出的全局变量)



如何将内核中的函数、全局变量、静态变量都导出到/proc/kallsyms
------------------------------------------------------------------------
./scripts/kallsyms

static int all_symbols = 0;
==>
static int all_symbols = 1;

 

 

引入kallsyms
------------------------------------------------------------------------
    在2.6内核中,为了更好地调试内核,引入了kallsyms。kallsyms抽取了内核用到的所有函数地址(全局的、静态的)和非栈数据变量地址,生成一个数据块,作为只读数据链接进kernel image,相当于内核中存了一个System.map。需要配置CONFIG_KALLSYMS

.config
CONFIG_KALLSYMS=y
CONFIG_KALLSYMS_ALL=y 符号表中包括所有的变量(包括没有用EXPORT_SYMBOL导出的变量)
CONFIG_KALLSYMS_EXTRA_PASS=y


make menuconfig
General setup  --->  
    [*] Configure standard kernel features (for small systems)  --->
        [*]   Load all symbols for debugging/ksymoops
        [*]     Include all symbols in kallsyms
        [*]     Do an extra kallsyms pass  

 

注: 配置CONFIG_KALLSYMS_ALL之后,就不需要修改all_symbol静态变量为1了

 

 

 

 

 

 

 

 

                   |--------------------|
                   |                    |
                   |                    |
                   ~                    ~
                   |                    |
                   |                    |
0xc05d 1dc0       
|--------------------| _end
                  
|                    |
                  
|                    |
                  
|    BSS             |
                  
|                    |
                  
|                    |
0xc05a 4500       
|--------------------| __bss_start
                   |                    |
0xc05a 44e8       
|--------------------| _edata
                  
|                    |
                  
|                    |
                  
|    DATA            |
                  
|                    |
                  
|                    |
0xc058 2000       
|--------------------| __data_start  init_thread_union
                   |                    |
0xc058 1000
_etext |--------------------|
                  
|                    |
                  
| rodata             |
                  
|                    |
0xc056 d000       
|--------------------| __start_rodata
                   |                    |
                   |                    |
                   | Real text          |
                   |                    |
                   |                    |
0xc02a 6000  
TEXT |--------------------| _text        __init_end    
                  
|                    |
                  
| Exit code and data | DISCARD 这个section在内核完成初始化后
                  
|                    |         会被释放掉
0xc002 30d4       
|--------------------| _einittext
                  
|                    |
                  
| Init code and data |
                  
|                    |
0xc000 8000
_stext |--------------------|<------------ __init_begin
                   |                    |
0xc000 0000        |--------------------|

 

arch/arm/kernel/vmlinux.lds.S

 

注:
1. 文本段中的只读段均为变量
2. 文本段中的INIT断,可视为变量,因为命令中不会调用初始化函数,另外该区域在内核启动完成后,已经被bootmem释放了,所以该区域可能会被另作它用
3.
T   The symbol is in the text(code) section
D   The symbol is in the initialized data section
R   The sysbol is in a read only data section
t   static
d   static
R   const
r   static const



你可能感兴趣的:(Linux)