ELF file from scratch

(This topic may only be of interest to the neurodiverse...)
So, recently I needed to create an ELF file from scratch for a hobby project of mine. (When I say, "from scratch" I mean declaring [pretty much] every byte in the ELF image explicitly). As I was doing it, I thought that maybe I should document it as someone else may find it useful or interesting. The code can be found here:
https://www.github.com/SanctaMaria1997/elf.git
The only dependency is lang/fasm .
I was pleasantly surprised (taken aback actually) to find that only a couple of changes needed to be made to end up with a program that builds and runs on both FreeBSD and Linux (I honestly assumed when I tried this that I'd be debugging for hours - days even - but I got it working on Ubuntu quite quickly).
It's also easily extensible; you just add references to any libraries and functions you may need, and stick any extra assembly code under SECTION_TEXT. I've had some success combining this "skeleton" code with the output of a compiler to build simple x11/SDL games (not ready to share yet though).
It's actually amazing to me that our whole modern world is so utterly dependent on ELF files, yet the intricacies of them are so arcane and only understood by a handful of people! elf(5)() is fantastically written but it misses out a huge amount - I had to dig around in the system headers and read a bunch of obscure blog posts to really understand it all.
 
Back
Top