I was reading about sections and segments. Seems you could list the mapping between sections and segments as below.
$ readelf -l test
Elf file type is EXEC (Executable file)
Entry point 0x8048330
There are 9 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x08048034 0x08048034 0x00120 0x00120 R E 0x4
INTERP 0x000154 0x08048154 0x08048154 0x00013 0x00013 R 0x1
[Requesting program interpreter: /lib/ld-linux.so.2]
LOAD 0x000000 0x08048000 0x08048000 0x0065c 0x0065c R E 0x1000
LOAD 0x000f14 0x08049f14 0x08049f14 0x00104 0x00110 RW 0x1000
DYNAMIC 0x000f28 0x08049f28 0x08049f28 0x000c8 0x000c8 RW 0x4
NOTE 0x000168 0x08048168 0x08048168 0x00044 0x00044 R 0x4
GNU_EH_FRAME 0x000564 0x08048564 0x08048564 0x00034 0x00034 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
GNU_RELRO 0x000f14 0x08049f14 0x08049f14 0x000ec 0x000ec R 0x1
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 .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame
03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss
04 .dynamic
05 .note.ABI-tag .note.gnu.build-id
06 .eh_frame_hdr
07
08 .ctors .dtors .jcr .dynamic .got
My questions,
- I couldn't understand what the program headers mean? How are they related to segments?
- Section to segment mapping is clear. But could someone name it? I see only numbers. I identified the code seg (03), data seg (02) and stack (07).
To understand the output of
readelf
it will help for you to understand the format of anELF
file. Please reference this document.As far as understanding how to interpret the output of
readelf
this link may be of help.As to your question 2, this link describes the segments. In that document search for "Various sections hold program and control information:" to find the area where the segment names are described.
That document describes the segments as follows:
Various sections hold program and control information: