Can anyone please share some link or book that explains in detail about how a process is created from an ELF file. Most of the materials freely available seems to be abstract with out explaining most details like what information is taken from program headers and how the process image is in memory using that information. Thanks
问题:
回答1:
elf files work in the following way
Every segment describes a bunch of sections sharing the same charcteristics together, such as Load to memory, each section has its permission such as read write or execute, what basically happens is that each segment has some header (phdr) that header contains the virtual address this segment should be loaded to memory its size and the offset to the actual binary data within the ELF this goes the same for sections, each section has some virtual address it would be loaded to, size offset to binary data within file, also permissions for thag memory (Write/Read/Execute) now what the operating system does to create a process out of the file image is read and parse all the sections, load their binary data to memory if a load flag exists, and give that memory section suitable permissions. An example to binary data is machine instructions - actual code, e.g. .text
section would usually contain binary instructions (code). Another good example for a section is .data that would contain global variables of some process and should have only Read Write permissions, also the general elf headers contain something that is called an entry point - The virtual address of the first instruction to be executed (given that the section containing machine code was loadex succesfuly to the virtual address it was given)
The elf file is much more complex but in general this is what it contains, it has data that is useful for linkers and dynamic linkers such as relocation and symbol tables yet basically this is what happens when loading an elf file, here's some good link to learn more about this subject: http://flint.cs.yale.edu/cs422/doc/ELF_Format.pdf
Also if you're using some linux based system try playing around with readelf
and objdump
, personally it helped me learn a lot