|
楼主 |
发表于 2012-6-30 21:36:11
|
显示全部楼层
刚才写了个程序,研究下段的问题 #include <stdio.h>
int temp[1024*1024];
int main()
{
int i;
int m;
int str[1024*1024];
i=0;
m=10;
for (i=0;i++;i<1024*1024)
str[i]=i;
for (i=0;i++;i<1024*1024)
temp[i]=i;
printf("%d\n",str[0]);
return 0;
}
gcc -o 1 1.c
***
ls -l 1
-rwxr-xr-x 1 jianxueqd1 group20 6831 Jun 30 21:21 1
显示文件有6831个字节,用ultra edit 打开后,可以看到文件有1aae字节.
***
用objdump 分析文件的段
objdump -h 1
1: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .interp 0000001c 0000000000400200 0000000000400200 00000200 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .note.ABI-tag 00000020 000000000040021c 000000000040021c 0000021c 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .gnu.hash 0000001c 0000000000400240 0000000000400240 00000240 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .dynsym 00000060 0000000000400260 0000000000400260 00000260 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .dynstr 0000003f 00000000004002c0 00000000004002c0 000002c0 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .gnu.version 00000008 0000000000400300 0000000000400300 00000300 2**1
CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .gnu.version_r 00000020 0000000000400308 0000000000400308 00000308 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .rela.dyn 00000018 0000000000400328 0000000000400328 00000328 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .rela.plt 00000030 0000000000400340 0000000000400340 00000340 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .init 00000018 0000000000400370 0000000000400370 00000370 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
10 .plt 00000030 0000000000400388 0000000000400388 00000388 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
11 .text 00000238 00000000004003c0 00000000004003c0 000003c0 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
12 .fini 0000000e 00000000004005f8 00000000004005f8 000005f8 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
13 .rodata 00000014 0000000000400608 0000000000400608 00000608 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
14 .eh_frame_hdr 00000024 000000000040061c 000000000040061c 0000061c 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
15 .eh_frame 00000094 0000000000400640 0000000000400640 00000640 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
16 .ctors 00000010 00000000006006d8 00000000006006d8 000006d8 2**3
CONTENTS, ALLOC, LOAD, DATA
17 .dtors 00000010 00000000006006e8 00000000006006e8 000006e8 2**3
CONTENTS, ALLOC, LOAD, DATA
18 .jcr 00000008 00000000006006f8 00000000006006f8 000006f8 2**3
CONTENTS, ALLOC, LOAD, DATA
19 .dynamic 00000190 0000000000600700 0000000000600700 00000700 2**3
CONTENTS, ALLOC, LOAD, DATA
20 .got 00000008 0000000000600890 0000000000600890 00000890 2**3
CONTENTS, ALLOC, LOAD, DATA
21 .got.plt 00000028 0000000000600898 0000000000600898 00000898 2**3
CONTENTS, ALLOC, LOAD, DATA
22 .data 00000004 00000000006008c0 00000000006008c0 000008c0 2**2
CONTENTS, ALLOC, LOAD, DATA
23 .bss 00400020 00000000006008e0 00000000006008e0 000008c4 2**5
ALLOC
24 .comment 00000114 0000000000000000 0000000000000000 000008c4 2**0
CONTENTS, READONLY
***
里面的file off字段,说明了每个段在文件的位置。 如果与文件想对应的位置比较每个段的内容,大部分都能对起来。对于这个程序有以下地方与文件对应不起来。
1) 23 .bss 段
按照它的提示是从文件偏移000008c4处 有00400020 个字节是bss段。 但是这部分不知道如何用objdump出来。
24 .comment
这一段也不知道如何用objdump。 为啥它和.bss段的偏移地址一样。
前面也提到文件是1aae个字节,可是从objdump中,只看到从8c4的偏移。那剩下的字节是属于什么的 |
|