Why is the ELF header loaded into memory along with the text segment?

I compiled this program with -m32 -nostdlibinto an ELF executable:

void _start() {}

And when I did readelf -l, I was surprised to see that the offset in the LOAD segment was 0x000000, as this would mean that the executable header would be loaded into memory at the same time as the text segment. So I checked with GDB, and it really is:

(gdb) b _start
Breakpoint 1 at 0x8048083
(gdb) r
Starting program: /home/tbodt/ish/build/a.out 

Breakpoint 1, 0x08048083 in _start ()
(gdb) x/4c 0x08048000
0x8048000:      127 '\177'      69 'E'  76 'L'  70 'F'

Why is this useful?

+4
source share
1 answer

I was surprised to see that the offset on the LOAD segment was 0x000000

Why were you surprised?

since this would mean that the executable header would be loaded into memory at the same time as the text segment.

. ?

, mmap ed mmap ; mmap , 0x34.

, .text 4096 ( ELF ), PT_LOAD 4096. : 52 .

+3

Source: https://habr.com/ru/post/1675998/


All Articles