gcc代码反汇编查看内存分布[2]: arm-linux-gcc
生活随笔
收集整理的這篇文章主要介紹了
gcc代码反汇编查看内存分布[2]: arm-linux-gcc
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
arm-none-linux-gnueabi-gcc -v
gcc version 4.4.1 (Sourcery G++ Lite 2010q1-202)
?
重點:
代碼中的內(nèi)存分配, 地址從低到高: 代碼段(RO, 保存函數(shù)代碼) --> 只讀數(shù)據(jù)段(RO, 保存常量) --> 數(shù)據(jù)段(RW, 已初始化并且初始值不為0的全局變量和靜態(tài)變量) -->bss段(RW,? 未初始化或者初始化為0的全局變量和靜態(tài)變量).
程序運行起來之后, 堆區(qū)和棧區(qū)的變量地址是動態(tài)分配的.
可以看出arm-none-linux-gnueabi-gcc編譯和gcc編譯結(jié)果是類似的.
#include<stdio.h> #include<stdlib.h>int global_ni; // .bss int global_iz = 0 ; // .bssint global_inz = 1; // .dataconst int global_const0 = 0; const int global_const1 = 1;void function(void) {int local_fni;int local_finz = 1;int local_fiz = 0 ;static int static_fni;static int static_finz = 1;static int static_fiz = 0 ;int *p2 = (int*)malloc(sizeof(int));printf("子函數(shù) 局部變量 : \n");printf(" local_fni: %p \n", &local_fni);printf(" local_finz: %p \n", &local_finz);printf(" local_fiz: %p \n", &local_fiz);printf("子函數(shù) 靜態(tài)變量 : \n");printf(" static_fni: %p \n", &static_fni);printf(" static_finz: %p \n", &static_finz);printf(" static_fiz: %p \n", &static_fiz);printf("子函數(shù) 指針變量 : \n");printf(" p2 : %p \n", p2);printf("子函數(shù)地址 : \n");printf(" function : %p \n", function); }int main(int argc, char **argv) {int local_mni;int local_minz = 1;int local_miz = 0 ;static int static_mni;static int static_minz = 1;static int static_miz = 0 ;int *p1 = (int*)malloc(sizeof(int));const int local_const0 = 0;const int local_const1 = 1;char* str_ptr = "char";printf("主函數(shù) 局部變量 : \n");printf(" local_mni : %p \n", &local_mni);printf(" local_minz : %p \n", &local_minz);printf(" local_miz : %p \n", &local_miz);printf("const 變量: \n");printf(" local_const0 : %p \n", &local_const0);printf(" local_const1 : %p \n", &local_const1);printf(" global_const0 : %p \n", &global_const0);printf(" global_const1 : %p \n", &global_const1);printf("主函數(shù) malloc指針變量 : \n");printf(" p1 : %p \n", p1);printf("全局變量 : \n");printf(" global_ni : %p \n", &global_ni);printf(" global_inz : %p \n", &global_inz);printf(" global_iz : %p \n", &global_iz);printf("主函數(shù) 靜態(tài)變量 : \n");printf(" static_mni: %p \n", &static_mni);printf(" static_minz: %p \n", &static_minz);printf(" static_miz: %p \n", &static_miz);printf("字符串常量 : \n");printf(" str_ptr : %p \n", str_ptr);printf("主函數(shù)地址 : \n");printf(" main : %p \n", main);printf("= = = = = = = = = = = = = = = \n");function();return 0; }/* = = = = = = = = = = = = = = = 測試:arm-none-linux-gnueabi-gcc -o test main.c arm-none-linux-gnueabi-objdump -Dhs test > test.dis 分析: Disassembly of section .text: 000083e0 { 子函數(shù)地址 : function : 主函數(shù)地址 : main : }Disassembly of section .rodata: 000088c0 { const 變量: 全局global_const0 global_const1 字符串常量 : str_ptr } //.data中是初始化為非0的全局變量和靜態(tài)變量 Disassembly of section .data: 00010d5c { global_inz static_minz static_finz } //.bss中是初始化為0以及沒有初始化的全局變量和靜態(tài)變量 Disassembly of section .bss: 00010d70 {global_iz static_mni static_miz static_fni static_fiz global_ni }堆空間: //動態(tài)的 { 主函數(shù) malloc指針變量 : p1 : 子函數(shù) malloc指針變量 : p2 : }棧空間: //動態(tài)的 { 子函數(shù) 局部變量 : local_fiz : local_finz: local_fni : const 變量: 局部local_const1 : local_const0 : 主函數(shù) 局部變量 : local_miz : local_minz: local_mni : } */?
反匯編文件test.dis節(jié)選
test: file format elf32-littlearmSections: Idx Name Size VMA LMA File off Algn0 .interp 00000013 00008134 00008134 00000134 2**0CONTENTS, ALLOC, LOAD, READONLY, DATA1 .note.ABI-tag 00000020 00008148 00008148 00000148 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA, LINK_ONCE_SAME_CONTENTS2 .hash 0000003c 00008168 00008168 00000168 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA3 .dynsym 000000a0 000081a4 000081a4 000001a4 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA4 .dynstr 000000a7 00008244 00008244 00000244 2**0CONTENTS, ALLOC, LOAD, READONLY, DATA5 .gnu.version 00000014 000082ec 000082ec 000002ec 2**1CONTENTS, ALLOC, LOAD, READONLY, DATA6 .gnu.version_r 00000040 00008300 00008300 00000300 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA7 .rel.dyn 00000008 00008340 00008340 00000340 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA8 .rel.plt 00000030 00008348 00008348 00000348 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA9 .init 0000000c 00008378 00008378 00000378 2**2CONTENTS, ALLOC, LOAD, READONLY, CODE10 .plt 0000005c 00008384 00008384 00000384 2**2CONTENTS, ALLOC, LOAD, READONLY, CODE11 .text 000004d8 000083e0 000083e0 000003e0 2**2CONTENTS, ALLOC, LOAD, READONLY, CODE12 .fini 00000008 000088b8 000088b8 000008b8 2**2CONTENTS, ALLOC, LOAD, READONLY, CODE13 .rodata 00000314 000088c0 000088c0 000008c0 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA14 .ARM.extab 00000024 00008bd4 00008bd4 00000bd4 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA15 .ARM.exidx 00000040 00008bf8 00008bf8 00000bf8 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA16 .init_array 00000004 00010c38 00010c38 00000c38 2**2CONTENTS, ALLOC, LOAD, DATA17 .fini_array 00000004 00010c3c 00010c3c 00000c3c 2**2CONTENTS, ALLOC, LOAD, DATA18 .jcr 00000004 00010c40 00010c40 00000c40 2**2CONTENTS, ALLOC, LOAD, DATA19 .dynamic 000000f0 00010c44 00010c44 00000c44 2**2CONTENTS, ALLOC, LOAD, DATA20 .got 00000028 00010d34 00010d34 00000d34 2**2CONTENTS, ALLOC, LOAD, DATA21 .data 00000014 00010d5c 00010d5c 00000d5c 2**2CONTENTS, ALLOC, LOAD, DATA22 .bss 0000001c 00010d70 00010d70 00000d70 2**2ALLOC23 .ARM.attributes 0000002b 00000000 00000000 00000d70 2**0CONTENTS, READONLY24 .comment 0000002b 00000000 00000000 00000d9b 2**0CONTENTS, READONLY25 .debug_frame 00000044 00000000 00000000 00000dc8 2**2CONTENTS, READONLY, DEBUGGING?
轉(zhuǎn)載于:https://www.cnblogs.com/mylinux/p/5611287.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的gcc代码反汇编查看内存分布[2]: arm-linux-gcc的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VM虚拟机中CentOS6.4操作系统安
- 下一篇: ios多线程 -- NSOperatio