当前位置:网站首页>riscv ELF bss段解析
riscv ELF bss段解析
2022-07-18 09:04:00 【dumpcore】
在调试risc-v-bm的时候,实现malloc函数后,risc-v-bm出现错误。原因是在exec中,没有实现对bss段的初始化。
怎么找到这个问题的呢?malloc代码
#ifdef UMALLOCK_TEST
void *_malloc(size_t size)
#else
void *malloc(size_t size)
#endif
{
block_metadata_t *ptr = _block_head;
while(ptr){
/*查找一个和想分配内存size一样大的block
如果没有一样大的block就分配一个
*/
if(ptr->size >= size){
remove_from_freelist(ptr);
if(ptr->size == size){
return BLOCK_MEM(ptr);
......
_block_head变量是全局定义为0的。但是第一次调用malloc时,ptr应该是0,但是却不是。
编译器将其放在了bss段。
$ riscv64-linux-gnu-readelf -S ./user/_sh
There are 17 section headers, starting at offset 0xcfd0:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .text PROGBITS 0000001000000000 00001000
00000000000012a6 0000000000000000 AX 0 0 2
[ 2] .rodata PROGBITS 0000001000002000 00003000
00000000000002a7 0000000000000000 A 0 0 8
[ 3] .rodata.str1.8 PROGBITS 00000010000022a8 000032a8
0000000000000133 0000000000000001 AMS 0 0 8
[ 4] .sbss NOBITS 0000001000003000 00004000
0000000000000008 0000000000000000 WA 0 0 8
使用readelf可以读取每个段的信息。
bss的type为NOBITS,flags为WA, WA意思是可写、需要分配内存,size为8,sh程序只定义了一个全局变量,变量值为0。注意:只有全局变量,且值为0才会放在bss段。
边栏推荐
- 微信小程序一些常用方法
- Boolean expression satisfiability problem (SAT) and cook Levin theorem (Part 2)
- Identity server4 authorization successful page Jump encountered an error: exception: correlation failed Solution of unknown location
- SkiaSharp 之 WPF 自绘弹跳球(案例版)
- 交叉编译工具
- Use of vim editor
- 全新第三代荣威RX5/超混eRX5 预售12.49万起,产品实力如何?
- JVM如何知道一个对象该回收了呢?
- 4、聊聊大名鼎鼎的张正友标定法
- Force deduction brush question 82 Delete duplicate Element II in the sorting linked list
猜你喜欢
The data of the tables in the datagrip database is inexplicably gone, and so is the self-contained data
Potential competition when using queues, notifiers, semaphores, or rendezvous points in LabVIEW
[英雄星球七月集训LeetCode解题日报] 第18日 树
网页与浏览器的关系(0)
sql join和correlated subenquiry的区别
iptables防止nmap扫描以及binlog
[Niuke algorithm - binary search] it's up to you to give consideration to question brushing and interview
Design idea of third-party system docking (case sharing)
C和指针 第18章 运行时环境 18.1 判断运行时环境
关于No module named 'django.db.backends.mysql'的问题
随机推荐
File system and log analysis
Enumerating and converting maps and lists
2022 low voltage electrician examination simulation 100 questions and simulation examination
二叉树的前中后序遍历——统一递归遍历和迭代遍历
两个链表的公共结点+筛选链表
拓扑排序(学习笔记)入门+判断是否有环
Li Kou brushes questions 231 Power of 2
C language dynamic memory development
Web3会重塑互联商业吗?
力扣今日题-565. 数组嵌套
Yesdev: easily collaborate on every project
基于51单片机的电子秤设计
14个市场底部信号,如今被印证了几个?
94.二叉树的中序遍历
[英雄星球七月集训LeetCode解题日报] 第18日 树
Shell Programming Notes (III)
Go entry file and package initialization (to be reviewed again)
Tags & tag selectors & Notes
文件系统与日志分析
微信小程序适配问题