How to understand the p_align in Elf Program Header Table

Jason kaffe@bj1860.net
Wed Sep 15 07:38:00 GMT 2004


HI all,

I read the Elf File Format, In program header chapter, there are some 
sentences for explain p_align.

p_align
    Loadable process segments must have congruent values for p_vaddr 
and p_offset, modulo the page size. This member gives the value to which 
the segments are aligned in memory and in the file. Values 0 and 1 mean 
no alignment is required. Otherwise, p_align should be a positive, 
integral power of 2, and p_vaddr should equal p_offset, modulo p_align.

it's mean: p_offset = p_vaddr mod p_align.

I think it is impossible. how relationship is there is p_offset  with 
(p_vaddr mod p_align)? I use readelf utils to verify it.

========================================================================
readelf  -l /bin/ls

Elf file type is EXEC (Executable file)
Entry point 0x8049570
There are 8 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x08048034 0x08048034 0x00100 0x00100 R E 0x4
  INTERP         0x000134 0x08048134 0x08048134 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /lib/ld-linux.so.2]
  LOAD           0x000000 0x08048000 0x08048000 0x0e458 0x0e458 R E 0x1000
  LOAD           0x00e460 0x08057460 0x08057460 0x00318 0x006ac RW  0x1000
  DYNAMIC        0x00e54c 0x0805754c 0x0805754c 0x000d0 0x000d0 RW  0x4
  NOTE           0x000148 0x08048148 0x08048148 0x00020 0x00020 R   0x4
  GNU_EH_FRAME   0x00e3c8 0x080563c8 0x080563c8 0x0001c 0x0001c R   0x4
  STACK          0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4

=========================================================================

In segment 3, p_vaddr is 0x08048000, p_align is 0x1000, p_offset is 0x0, 
obviously, p_offset != p_vaddr mod p_align.

In segment 4, p_vaddr is 0x08057460, p_align is 0x4, p_offset is 0x00e460,
p_vaddr mod p_align  is 0. is not 0x4.


I know my English is very pool, I may not correctly understand it. who can 
help me? thanks in advance!

Jason




More information about the Binutils mailing list