Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370480
  • 博文数量: 94
  • 博客积分: 3421
  • 博客等级: 中校
  • 技术积分: 919
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-18 16:27
文章分类

全部博文(94)

文章存档

2015年(8)

2013年(6)

2012年(26)

2011年(8)

2010年(26)

2009年(20)

我的朋友

分类: C/C++

2011-10-10 16:17:28

(gdb) list
1       int loc = 1234;
2       char *x;

3       int main()
4       {
5           int m,n, i;
6           x="abcd";
7           loc = 5;
8          for (i=0; i<9; i++)
9            m=n=i;
10          return 0;

(gdb) disass main
Dump of assembler code for function main:
0x08048310 :    push   %ebp
0x08048311 :    mov    %esp,%ebp
0x08048313 :    sub    $0x18,%esp
0x08048316 :    and    $0xfffffff0,%esp
0x08048319 :    mov    $0x0,%eax
0x0804831e :   sub    %eax,%esp
0x08048320 :   movl   $0x8048430,0x8049540
0x0804832a :   movl   $0x5,0x8049448

0x08048334 :   movl   $0x0,0xfffffff4(%ebp)
0x0804833b :   cmpl   $0x8,0xfffffff4(%ebp)
0x0804833f :   jle    0x8048343
0x08048341 :   jmp    0x8048353
0x08048343 :   mov    0xfffffff4(%ebp),%eax
0x08048346 :   mov    %eax,0xfffffff8(%ebp)
0x08048349 :   mov    %eax,0xfffffffc(%ebp)
0x0804834c :   lea    0xfffffff4(%ebp),%eax
0x0804834f :   incl   (%eax)
0x08048351 :   jmp    0x804833b
0x08048353 :   mov    $0x0,%eax
0x08048358 :   leave
0x08048359 :   ret
End of assembler dump.

gcc -c try3.c -o try 没link的binary
gcc -o try try3.c 生成可以执行的binary

try:     file format elf32-i386
try
architecture: i386, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000004a  00000000  00000000  00000034  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .data         00000004  00000000  00000000  00000080  2**2   <<                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  00000000  00000000  00000084  2**2
                  ALLOC
  3 .rodata       00000005  00000000  00000000  00000084  2**0   <<< x = "abcd"
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

  4 .note.GNU-stack 00000000  00000000  00000000  00000089  2**0
                  CONTENTS, READONLY
  5 .comment      00000034  00000000  00000000  00000089  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
00000000 l    df *ABS*  00000000 try3.c
00000000 l    d  .text  00000000
00000000 l    d  .data  00000000
00000000 l    d  .bss   00000000
00000000 l    d  .rodata        00000000
00000000 l    d  .note.GNU-stack        00000000
00000000 l    d  .comment       00000000
00000000 g     O .data  00000004 loc
00000000 g     F .text  0000004a main
00000004       O *COM*  00000004 x


RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE
00000012 R_386_32          x         <<<一些用到的变量
00000016 R_386_32          .rodata
0000001c R_386_32          loc


代码种如果是内部变量不会出现在.data 和 .bss段, 只会以栈的形式出现,地址类似
$1 = (int *) 0xbfffae74
即在段中不会出现局部变量. 局部变量都是以寄存器的形式传递.



阅读(1614) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~