Executable Object Files

Fig: Format of an executable object file
Most of it is similar to Relocatable Object Files except for a few detail. Components are:
-
ELF header: Same as for relocatable object file but also includes program's entry point i.e the address of the first instruction to execute upon entry, the _start function.
-
.text, .rodata and .data sections are similar to those in relocatable object file, but they have been relocated to their run-time memory
-
the .init section described a small function called _init that is calledby program's initialization code
-
Since it's fully linked, there is no need for .rel sections.
-
Segment header table: Executable object file is read by the OS and it just needs to know what permission is needed for code, so each segment is divided by permission:
-
ELF header, Segmened header table .init, .text and .rodata is loaded with read-execute permission
-
.data, .bss is loaded with Read/ Write permission
-
If it uses some dynamic lib, then it's loaded with read permission or sometimes .rodata is also loaded in read only section etc.
-
The symbol table and debugging are NOT loaded into the memory
And Segment header table has the instructions for the OS regarding how to load stuff from the executable into the memory. Here's a short snippet of how this might look like:

-
At line 1, it's asking the OS to Load (project) the file from offset 0x0 to virtual address 0x400000, making sure, the alignment 2 ** 21 means 2 to power 21 which is like 2MB.
-
There's the size of that segement beside filesz and memsz is how much memory OS should allocate for it.
A bit about alignment stuff: -
The Disk and RAM is divided into pages, sometimes 2MB others 4KB, our executable file is stored in the disk in such fashion, here let's assume it's 2MB aligned.
-
When we first run the executable, the CPU just projects the executable's page chunks into the virtual memory, nothing is actually copied into the RAM, but the chunk is projected in aligned manner, such that if a data is in line 500 of some 2MB page then it's also in the same line in the virtual memory's page.
-
The page is only pulled up the the RAM when it's acutally demanded by the CPU, it's called demand paging, and the mechanism through which it occurs is after a page fault.
-
Alignment requirement: vaddr mod align = off mod align
-