Skip to content

costowell/elf-fun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ELF Fun (🧝?)

I am working on a compiler and wanted to write the object file from scratch instead of using assembly as an intermediary language.

This is the result of messing around while following a tutorial for libelf.

Structure

There are 4 programs that I've written, each more useful than the last!

phdr - Prints all the Program Headers of an ELF

  • Not useful to my end goal since relocatable ELFs don't have Program Headers, but still useful to know.

shdr - Prints all the Section Headers + some data associated of an ELF

  • Will print the symbol table and the section header string table data too
  • Some other random bits will get printed too because I was debugging my generated binary which brings me too...

write - Writes an object file/relocatable ELF with a small amount of assembly

  • This is the thing I was after
  • Program generated exits with unique status code to make sure its running
  • Linkable with ld

prog - Prints the symbols of a file

  • Made this so that I could debug why I couldn't print symbols in my program
  • Turned it into a fun exercise in manually indexing the strtab buffer to map the symbol names instead of using elf_strptr()

Compiling

make

All binaries are in the out/ folder.

All objects are in the obj/ folder.

Compatability

This commit fixed the problem with certain linkers not working.

Thank god to LLVM's lld which told me what I was doing wrong.

Tested Linkers

  • ld
  • lld
  • mold
  • Maybe 🫵 YOU could find a linker that fails...

Thanks to...

About

Playing around with generating relocateable ELFs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published