linux+c+gcc:objdump -dS bit_field 反汇编程序各种疑惑

wlqiuxing 2012-09-01 05:19:04
一直在学习linux c嵌入式开发,最近在从汇编角度理解c语言程序运行原理,按照例程简单反汇编了一小段程序,查阅各种资料,明白了一些,但还有很多疑惑的地方,请指教,谢谢。

Question 1:.init段主要都初始化什么?请帮忙详细解释下_init段各个指令背后的逻辑
Question 2:.plt 叫过程连接表,是做什么的?
Question 3:.fini(看名字是finish了)main函数返回后执行的代码,最后调用exit,谁能详细解释下?
Question 4:frame_dummy是什么?

源程序:bit_field.c

#include<stdio.h>

typedef struct {
unsigned int one:1;
unsigned int two:3;
unsigned int three:10;
unsigned int four:5;
unsigned int :2;
unsigned int five:8;
unsigned int six:8;
} demo_type;

int main()
{
demo_type s = {1,5,513,17,129,0x81};
printf("sizeof demo_type = %u\n",sizeof(demo_type));
printf("values: s=%u,%u,%u,%u,%u,%u\n",s.one,s.two,s.three,s.four,s.five,s.six);

return 0;
}

因发帖过长,我把汇编程序发在回复里:jmp 1楼

...全文
206 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlqiuxing 2012-09-01
  • 打赏
  • 举报
回复
1楼:
反汇编程序(未完):

bit_field: file format elf32-i386


Disassembly of section .init:

08048294 <_init>:
8048294: 55 push %ebp #栈底入栈,保存栈底
8048295: 89 e5 mov %esp,%ebp #用栈顶做新栈底
8048297: 53 push %ebx #基地址入栈
8048298: 83 ec 04 sub $0x4,%esp #栈顶向下增4,分配4字节
804829b: e8 00 00 00 00 call 80482a0 <_init+0xc> #跳转到下4字节
80482a0: 5b pop %ebx #基地址出栈
80482a1: 81 c3 54 1d 00 00 add $0x1d54,%ebx #此处不理解,是将基地址做什么操作?作用?
80482a7: 8b 93 fc ff ff ff mov -0x4(%ebx),%edx #%ebx偏移4送入%edx
80482ad: 85 d2 test %edx,%edx #测试是否相等
80482af: 74 05 je 80482b6 <_init+0x22> #相等则跳转
80482b1: e8 1e 00 00 00 call 80482d4 <__gmon_start__@plt>
80482b6: e8 e5 00 00 00 call 80483a0 <frame_dummy>
80482bb: e8 90 02 00 00 call 8048550 <__do_global_ctors_aux>
80482c0: 58 pop %eax
80482c1: 5b pop %ebx
80482c2: c9 leave
80482c3: c3 ret

Disassembly of section .plt:

080482c4 <__gmon_start__@plt-0x10>:
80482c4: ff 35 f8 9f 04 08 pushl 0x8049ff8
80482ca: ff 25 fc 9f 04 08 jmp *0x8049ffc
80482d0: 00 00 add %al,(%eax)
...

080482d4 <__gmon_start__@plt>:
80482d4: ff 25 00 a0 04 08 jmp *0x804a000
80482da: 68 00 00 00 00 push $0x0
80482df: e9 e0 ff ff ff jmp 80482c4 <_init+0x30>

080482e4 <__libc_start_main@plt>:
80482e4: ff 25 04 a0 04 08 jmp *0x804a004
80482ea: 68 08 00 00 00 push $0x8
80482ef: e9 d0 ff ff ff jmp 80482c4 <_init+0x30>

080482f4 <printf@plt>:
80482f4: ff 25 08 a0 04 08 jmp *0x804a008
80482fa: 68 10 00 00 00 push $0x10
80482ff: e9 c0 ff ff ff jmp 80482c4 <_init+0x30>



21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧