почему размер .bss плюс filesiz сегмента данных не одинаковый memsiz сегмента данных - PullRequest
0 голосов
/ 26 августа 2018

Моя машина - Ubuntu 16.04. И я хочу понять связь между разделом .bss и памятью. Поэтому я печатаю

readelf -e /usr/bin/find

и получите

  ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x7340
  Start of program headers:          64 (bytes into file)
  Start of section headers:          219912 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         9
  Size of section headers:           64 (bytes)
  Number of section headers:         29
  Section header string table index: 28

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000000238  00000238
       000000000000001c  0000000000000000   A       0     0     1
  [ 2] .note.ABI-tag     NOTE             0000000000000254  00000254
       0000000000000020  0000000000000000   A       0     0     4
  [ 3] .note.gnu.build-i NOTE             0000000000000274  00000274
       0000000000000024  0000000000000000   A       0     0     4
  [ 4] .gnu.hash         GNU_HASH         0000000000000298  00000298
       0000000000000164  0000000000000000   A       5     0     8
  [ 5] .dynsym           DYNSYM           0000000000000400  00000400
       0000000000001200  0000000000000018   A       6     2     8
  [ 6] .dynstr           STRTAB           0000000000001600  00001600
       0000000000000751  0000000000000000   A       0     0     1
  [ 7] .gnu.version      VERSYM           0000000000001d52  00001d52
       0000000000000180  0000000000000002   A       5     0     2
  [ 8] .gnu.version_r    VERNEED          0000000000001ed8  00001ed8
       00000000000000a0  0000000000000000   A       6     2     8
  [ 9] .rela.dyn         RELA             0000000000001f78  00001f78
       0000000000004c38  0000000000000018   A       5     0     8
  [10] .rela.plt         RELA             0000000000006bb0  00006bb0
       0000000000000048  0000000000000018  AI       5    24     8
  [11] .init             PROGBITS         0000000000006bf8  00006bf8
       000000000000001a  0000000000000000  AX       0     0     4
  [12] .plt              PROGBITS         0000000000006c20  00006c20
       0000000000000040  0000000000000010  AX       0     0     16
  [13] .plt.got          PROGBITS         0000000000006c60  00006c60
       0000000000000470  0000000000000000  AX       0     0     8
  [14] .text             PROGBITS         00000000000070d0  000070d0
       000000000001ebc9  0000000000000000  AX       0     0     16
  [15] .fini             PROGBITS         0000000000025c9c  00025c9c
       0000000000000009  0000000000000000  AX       0     0     4
  [16] .rodata           PROGBITS         0000000000025cc0  00025cc0
       00000000000064e6  0000000000000000   A       0     0     32
  [17] .eh_frame_hdr     PROGBITS         000000000002c1a8  0002c1a8
       0000000000000fc4  0000000000000000   A       0     0     4
  [18] .eh_frame         PROGBITS         000000000002d170  0002d170
       00000000000059cc  0000000000000000   A       0     0     8
  [19] .init_array       INIT_ARRAY       0000000000233188  00033188
       0000000000000008  0000000000000000  WA       0     0     8
  [20] .fini_array       FINI_ARRAY       0000000000233190  00033190
       0000000000000008  0000000000000000  WA       0     0     8
  [21] .jcr              PROGBITS         0000000000233198  00033198
       0000000000000008  0000000000000000  WA       0     0     8
  [22] .data.rel.ro      PROGBITS         00000000002331a0  000331a0
       00000000000016e0  0000000000000000  WA       0     0     32
  [23] .dynamic          DYNAMIC          0000000000234880  00034880
       0000000000000210  0000000000000010  WA       6     0     8
  [24] .got              PROGBITS         0000000000234a90  00034a90
       0000000000000570  0000000000000008  WA       0     0     8
  [25] .data             PROGBITS         0000000000235000  00035000
       00000000000009c8  0000000000000000  WA       0     0     32
  [26] .bss              NOBITS           00000000002359e0  000359c8
       00000000000012b0  0000000000000000  WA       0     0     32
  [27] .gnu_debuglink    PROGBITS         0000000000000000  000359c8
       0000000000000034  0000000000000000           0     0     1
  [28] .shstrtab         STRTAB           0000000000000000  000359fc
       0000000000000106  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040
                 0x00000000000001f8 0x00000000000001f8  R E    8
  INTERP         0x0000000000000238 0x0000000000000238 0x0000000000000238
                 0x000000000000001c 0x000000000000001c  R      1
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000032b3c 0x0000000000032b3c  R E    200000
  LOAD           0x0000000000033188 0x0000000000233188 0x0000000000233188
                 0x0000000000002840 0x0000000000003b08  RW     200000
  DYNAMIC        0x0000000000034880 0x0000000000234880 0x0000000000234880
                 0x0000000000000210 0x0000000000000210  RW     8
  NOTE           0x0000000000000254 0x0000000000000254 0x0000000000000254
                 0x0000000000000044 0x0000000000000044  R      4
  GNU_EH_FRAME   0x000000000002c1a8 0x000000000002c1a8 0x000000000002c1a8
                 0x0000000000000fc4 0x0000000000000fc4  R      4
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     10
  GNU_RELRO      0x0000000000033188 0x0000000000233188 0x0000000000233188
                 0x0000000000001e78 0x0000000000001e78  R      1

 Section to Segment mapping:
  Segment Sections...
   00     
   01     .interp 
   02     .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .plt.got .text .fini .rodata .eh_frame_hdr .eh_frame 
   03     .init_array .fini_array .jcr .data.rel.ro .dynamic .got .data .bss 
   04     .dynamic 
   05     .note.ABI-tag .note.gnu.build-id 
   06     .eh_frame_hdr 
   07     
   08     .init_array .fini_array .jcr .data.rel.ro .dynamic .got 

И мой вопрос: почему FileSiz сегмента данных плюс размер .bss не равен MemSiz сегмента данных (0x2840 + 0x12B0 = 0x3AF0! = 0x3B08)?

Я также пытаюсь добавить все разделы сегмента данных (.init_array .fini_array .jcr .data.rel.ro .dynamic .got .data .bss) и получить 0x3AF0. Где находится память байтов 0x18 (0x3B08-0x3AF0)?

...