How are ELF programs laid out in memory?
ELF programs have a somewhat different layout from a.out programs. The stack is the segment with the lowest address; it normally grows down from 0x08048000. The text or code segment starts contiguously above the stack. The data segment follows the text segment. The data segment isn’t normally page-aligned in the ELF file; instead, the beginning of the data segment overlaps with the end of the text segment in the file, and when the system loads the program, it maps this shared page twice, once with read-only protection for the end of the text segment and once with read-write protection for the start of the data segment. The second mapping immediately follows the first one. The bss or zero-filled data segment takes up no space in the ELF file, even for padding; the system zeroes out any part of the last page of data that is beyond the end of the data segment, and adds enough zero-filled pages to complete the segment. The heap or dynamically-allocated memory segment follows the bss segmen