refer wiki: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format

need refine when have time. The point is to notice the relationship between program header and section header and the mapping. The readelf -a illustrates this relationship very nicely.

File layout

Each ELF file is made up of one ELF header, followed by file data. The data can include:

  • Program header table, describing zero or more memory segments
  • Section header table, describing zero or more sections
  • Data referred to by entries in the program header table or section header table

The segments (program header) contain information that is needed for run time execution of the file, while sections contain important data for linking and relocation.

ELF brief introduction

 

[email protected]:~/projects/6.828/jos/obj$ readelf -a kern/kernel
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x10000c
  Start of program headers:          52 (bytes into file)  ## at the start of file
  Start of section headers:          86776 (bytes into file) ## a the end of file

  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         3
  Size of section headers:           40 (bytes)
  Number of section headers:         15
  Section header string table index: 14

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        f0100000 001000 0019e9 00  AX  0   0 16
  [ 2] .rodata           PROGBITS        f0101a00 002a00 0006c0 00   A  0   0 32
  [ 3] .stab             PROGBITS        f01020c0 0030c0 003b95 0c   A  4   0  4
  [ 4] .stabstr          STRTAB          f0105c55 006c55 001948 00   A  0   0  1
  [ 5] .data             PROGBITS        f0108000 009000 009300 00  WA  0   0 4096
  [ 6] .got              PROGBITS        f0111300 012300 000008 00  WA  0   0  4
  [ 7] .got.plt          PROGBITS        f0111308 012308 00000c 04  WA  0   0  4
  [ 8] .data.rel.local   PROGBITS        f0112000 013000 001000 00  WA  0   0 4096
  [ 9] .data.rel.ro.loca PROGBITS        f0113000 014000 000044 00  WA  0   0  4
  [10] .bss              PROGBITS        f0113060 014060 000648 00  WA  0   0 32
  [11] .comment          PROGBITS        00000000 0146a8 00002b 01  MS  0   0  1
  [12] .symtab           SYMTAB          00000000 0146d4 0007c0 10     13  66  4
  [13] .strtab           STRTAB          00000000 014e94 0003e6 00      0   0  1
  [14] .shstrtab         STRTAB          00000000 01527a 00007d 00      0   0  1
Key to Flags:

  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)

There are no section groups in this file.

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x001000 0xf0100000 0x00100000 0x0759d 0x0759d R E 0x1000
  LOAD           0x009000 0xf0108000 0x00108000 0x0b6a8 0x0b6a8 RW  0x1000
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x10

 Section to Segment mapping:
  Segment Sections...
   00     .text .rodata .stab .stabstr
   01     .data .got .got.plt .data.rel.local .data.rel.ro.local .bss
   02     

 

 

相关文章:

  • 2021-10-14
  • 2021-08-27
  • 2021-12-16
  • 2021-10-24
  • 2021-06-05
  • 2021-10-02
  • 2022-02-06
猜你喜欢
  • 2022-01-04
  • 2021-10-06
  • 2021-06-21
  • 2021-08-13
  • 2021-10-03
  • 2021-12-15
  • 2021-12-24
相关资源
相似解决方案