- An ELF file is made up of both Sections and Segments (also called programs) that overlap in the actual binary
- The sizes and space are defined by sequential headers
- The start of the ELF file has a single ELF header that defines things like the binary size and entry point
- More notably, the ELF header also specifies the number of program headers and section headers
- A program header will point to where the program starts in memory. These are your assembly blocks
- EX
.text,.data-- these are the only two we used in this program - A segment called
.shstrtabstores the names of the other segments for tools like readelf to show
- EX
- You don't have to have any sections -- we didn't need for our hello world program
- During development, I found the following unix commands helpful:
file- the values shown here are pulled from the ELF header, useful for showing if the ELF header is rightreadelf -a- will show the ELF header values and a bunch of other useful infohexdump -C- shows the bytes in hex from a file, as well as the "artwork", which is really usefulobjdump -S- see the assembly instructions and accompanying binary commands- This mostly helped when comparing to an actual compiled assembly file
If you want to try a project like this yourself, these are the main resources I used online that helped me out here.
man elf- Wikipedia article
- See also the diagram at the top of the page as well
- Crafting executables from raw bytes - Key Lack
- Handmade Linux x86 executables - David Smith
- In-depth ELF - stacksmashing