BSS初始化
1、BSS段的作用
初始化的全局變量:數據段
局部變量: 棧
malloc:堆
未初始化的全局變量:bss段
bss.c
#include <stdio.h>
int year;
int main()
{
????year = 2014;
????return year;
}
[root@localhost lesson11_bss]# arm-linux-gcc -c bss.c -o bss
[root@localhost lesson11_bss]# arm-linux-readelf -a bss >dump
80: 00008410 0 NOTYPE GLOBAL DEFAULT ABS __exidx_end 81: 00010528 0 OBJECT GLOBAL HIDDEN 22 __dso_handle 82: 00010530 4 OBJECT GLOBAL DEFAULT 23 year????????????????????????? ? 10530是year的位置 83: 00010534 0 NOTYPE GLOBAL DEFAULT ABS __end__ 84: 00008384 116 FUNC GLOBAL DEFAULT 12 __libc_csu_init 85: 00010534 0 NOTYPE GLOBAL DEFAULT ABS __bss_end__ ? ? ? ? ? ? ? ? ? ?結尾是10534 86: 0001052c 0 NOTYPE GLOBAL DEFAULT ABS __bss_start ? ? ? ? ? ? ? ? ? ?起始是1052c,所以year在bss段中 87: 00010534 0 NOTYPE GLOBAL DEFAULT ABS _bss_end__
2、未初始化的變量,需要全部清零
clean_bss:
????ldr r0, =bss_start ? ? ? ? ? ? ? ? ? ? bss_start是起始地址,在gboot.lds中獲得的
????ldr r1, =bss_end ? ? ? ? ? ? ? ? ? ? ? bss_end是結束地址,在gboot.lds中獲得的
????cmp r0,r1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?比較r0,和r1
????moveq pc,lr ? ? ? ? ? ? ? ? ? ? ? ? ? ?如果相同就跳轉回bl clean_bss
clean_loop:
????mov r2, #0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? 設置r2為0
????str r2, [r0], #4 ? ? ? ? ? ? ? ? ? ? ? 初始化r0指向的內容,并將r0往下移動一格
????cmp r0,r1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?比較r0,r1
????bne clean_loop ? ? ? ? ? ? ? ? ? ? ? ? 如果不相同就循環clean_loop
????mov pc,lr ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?跳轉回bl clean_bss
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> 閱讀(30) | 評論(0) | 轉發(0) | 0
初始化的全局變量:數據段
局部變量: 棧
malloc:堆
未初始化的全局變量:bss段
bss.c
2、未初始化的變量,需要全部清零
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> 閱讀(30) | 評論(0) | 轉發(0) | 0
上一篇:棧初始化
下一篇:一躍進入C大門
相關熱門文章- SHTML是什么_SSI有什么用...
- 查看linux中某個端口(port)...
- 卡爾曼濾波的原理說明...
- shell中字符串操作
- 關于java中的“錯誤:找不到或...
總結
- 上一篇: python实现日历功能_基于pytho
- 下一篇: Mac清理软件CleanMymac X