2012-07-31 40 views
0

我已经做了以下虚设码测试objdump的如何处理

/tmp/test.c全局变量包含以下内容:

#include "test.h" 
#include <stdio.h> 
#include <stdlib.h> 
struct s* p; 
unsigned char *c; 

void main(int argc, char ** argv) { 
    memset(c, 0, 10); 
    p->a = 10; 
    p->b = 20; 
} 

/tmp/test.h包含以下内容:

struct s { 
    int a; 
    int b; 
}; 

我编译和运行objdump的如下:

CD/tmp目录 GCC -c test.c的-o test.o objdump的-gdsMIntel test.o

我得到以下输出:

test.o:  file format elf32-i386 

Contents of section .text: 
0000 5589e5a1 00000000 c7000000 0000c740 [email protected] 
0010 04000000 0066c740 080000a1 00000000 [email protected] 
0020 c7000a00 0000a100 000000c7 40041400 [email protected] 
0030 00005dc3        ..].    
Contents of section .comment: 
0000 00474343 3a202855 62756e74 752f4c69 .GCC: (Ubuntu/Li 
0010 6e61726f 20342e36 2e332d31 7562756e naro 4.6.3-1ubun 
0020 74753529 20342e36 2e3300    tu5) 4.6.3.  
Contents of section .eh_frame: 
0000 14000000 00000000 017a5200 017c0801 .........zR..|.. 
0010 1b0c0404 88010000 1c000000 1c000000 ................ 
0020 00000000 34000000 00410e08 8502420d ....4....A....B. 
0030 05700c04 04c50000     .p......   

Disassembly of section .text: 

00000000 <main>: 
    0: 55      push ebp 
    1: 89 e5     mov ebp,esp 
    3: a1 00 00 00 00   mov eax,ds:0x0 ;;;; should be the address of unsigned char *c 
    8: c7 00 00 00 00 00  mov DWORD PTR [eax],0x0 ;;;; setting 10 bytes to 0 
    e: c7 40 04 00 00 00 00 mov DWORD PTR [eax+0x4],0x0 
    15: 66 c7 40 08 00 00  mov WORD PTR [eax+0x8],0x0 
    1b: a1 00 00 00 00   mov eax,ds:0x0 
    20: c7 00 0a 00 00 00  mov DWORD PTR [eax],0xa ;;;; p->a = 10; 
    26: a1 00 00 00 00   mov eax,ds:0x0 
    2b: c7 40 04 14 00 00 00 mov DWORD PTR [eax+0x4],0x14 ;;;; p->b = 20; 
    32: 5d      pop ebp 
    33: c3      ret  

在上面的拆解,我发现:

在C的情况下, ,以下完成:

mov eax, ds:0x0 
mov DWORD PTR [eax], 0 

在对 - 的情况下>一以下完成:

mov eax, ds:0x0 
mov DWORD PTR [eax],0x0 

在这种情况下,c和p-> a是否位于同一地址(ds:0x0)?

+0

那么,按照我在阅读[此链接](http://www.ivor.it/cle266/guide.html)后的理解,地址实际上是重定位地址,当objdump与-r选项(-R代表.so,-r代表.o's) – 2012-08-02 06:19:31

回答

0

.o文件尚不可执行,将有重定位项指向链接器将稍后修复的那些0。由于您的源文件似乎大部分是独立的,您是否可以删除-c标志以生成(完全链接的)可执行文件而不是可重定位的目标文件?