zoukankan      html  css  js  c++  java
  • (转)ecos最简单的helloword程序的elf格式文件内容分析!

    http://mcuos.com/thread-209-1-3.html

    当你编译好了最简单的helloword程序时候是不是迫不及待的去运行看看效果呢?
    我们还是先分析一下这个elf文件的内容吧!(本hello文件装在我的板子内存0x8000处运行
      ELF Header:
      Magic:   7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 //elf头,16位,标志文件为32位LSB,elf格式的文件。
      Class:                             ELF32//
      Data:                              2's complement, little endian//小头
      Version:                           1 (current)//版本
      OS/ABI:                            ARM//运行的平台是arm(w90p710)
      ABI Version:                       0
      Type:                              EXEC (Executable file)//可执行文件
      Machine:                           ARM//arm corp
      Version:                           0x1
      Entry point address:               0x8040//程序的入口点
      Start of program headers:          52 (bytes into file)//段表的在文件的偏移位置
      Start of section headers:          139172 (bytes into file)//节表在文件的偏移位置
      Flags:                             0x2, has entry point, GNU EABI//arm处理器的标志
      Size of this header:               52 (bytes)//elf头的大小
      Size of program headers:           32 (bytes)//段表的大小
      Number of program headers:         1//段表的表项,就是说一共有多少段表了
      Size of section headers:           40 (bytes)//节表头的大小,段是由各个节组成
      Number of section headers:         22//一共有多少节
      Section header string table index: 19//节区名称的标项索引
    /****************************************************************************
    该elf文件有以下的节组成,由于是elf文件前7个都是debug的信息,第8个开始安装异常向量,第9个就是组成下面段的节了,那么段(见蓝色)是由哪几个节组成呢?(见红色)第10个为代码段,占约46k,第12、16数据段约为2k,一共约为48k,正好我的hello.bin 就是48K左右吧!
      Section Headers:
      [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
      [ 0]                   NULL            00000000 000000 000000 00      0   0  0
      [ 1] .debug_aranges    PROGBITS        00000000 013f90 000340 00      0   0  8
      [ 2] .debug_pubnames   PROGBITS        00000000 0142d0 0002ed 00      0   0  1
      [ 3] .debug_info       PROGBITS        00000000 0145bd 0084b5 00      0   0  1
      [ 4] .debug_abbrev     PROGBITS        00000000 01ca72 0026d2 00      0   0  1
      [ 5] .debug_line       PROGBITS        00000000 01f144 0014e9 00      0   0  1
      [ 6] .debug_frame      PROGBITS        00000000 020630 000684 00      0   0  4
      [ 7] .debug_str        PROGBITS        00000000 020cb4 000e7f 01  MS  0   0  1
      [ 8] .fixed_vectors    PROGBITS        00000200 021b40 000140 00      0   0 32
      [ 9] .rom_vectors      PROGBITS        00008000 008000 000040 00  AX  0   0  1
      [10] .text             PROGBITS        00008040 008040 00b4e4 00  AX  0   0  4
      [11] .fini             PROGBITS        00013524 021c80 000000 00   W  0   0  1
      [12] .rodata           PROGBITS        00013524 013524 0002d4 00   A  0   0  4
      [13] .rodata1          PROGBITS        000137f8 021c80 000000 00   W  0   0  1
      [14] .fixup            PROGBITS        000137f8 021c80 000000 00   W  0   0  1
      [15] .gcc_except_table PROGBITS        000137f8 021c80 000000 00   W  0   0  1
      [16] .data             PROGBITS        000137f8 0137f8 000794 00  WA  0   0  4
      [17] .bss              NOBITS          00013f8c 013f8c 00683c 00  WA  0   0 16
      [18] .debug_ranges     PROGBITS        00000000 021c80 000240 00      0   0  1
      [19] .shstrtab         STRTAB          00000000 021ec0 0000e3 00      0   0  1
      [20] .symtab           SYMTAB          00000000 022314 003360 10     21 200  4
      [21] .strtab           STRTAB          00000000 025674 003a6a 00      0   0  1
    /****************************************************************************/
    段表头的具体内容,type是load表示是一个可加载的段,该段在文件中的偏移地址和在内存中的物理地址都是0x8000,在文件中的大小是0x0bf8c(49k),然而给其分配内存的时候,分配了0x127c8(75k)的内存,大概是由于对其等的缘故吧,Flg 属性是可读写的,对其方式是0x8000。该段由上面的小节组成。
       Program Headers:
       Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
       LOAD           0x008000 0x00008000 0x00008000 0x0bf8c 0x127c8 RWE 0x8000
       Section to Segment mapping:
       Segment Sections...
       00     .rom_vectors .text .rodata .data .bss
    以上是我针对elf的简单分析,如果你对elf格式有深入研究,希望您的批评指正。因为很多东西我的确得不到答案只能自己钻研!

  • 相关阅读:
    代码301的弊端和处理方法
    seo如何发外链
    seo工程师是什么,需要什么技能?
    优化一个关键词到百度首页需要多少钱
    搜索引擎优化顾问机构好不好
    谷歌分析(GA)新版的有哪些改变
    什么是相关性链接/网站相关性
    JS的部分部分疑问和小结
    Groovy学习:第一章 用Groovy简化Java代码
    SpringMVC学习(8):国际化
  • 原文地址:https://www.cnblogs.com/kuainiao/p/2844406.html
Copyright © 2011-2022 走看看