
Anatomy of an ELF executable - kishu18
https://kishuagarwal.github.io/life-of-a-binary.html
======
dietrichepp
Strongly recommend reading "How To Write Shared Libraries" by Ulrich Drepper
[https://software.intel.com/sites/default/files/m/a/1/e/dsoho...](https://software.intel.com/sites/default/files/m/a/1/e/dsohowto.pdf)

I recently dove into ELF files so I could convert ELF binaries to DOS EXE, for
a little bit of retro programming with modern compilers. Not that I couldn't
have used DJGPP.

~~~
unqueued
> I recently dove into ELF files so I could convert ELF binaries to DOS EXE,
> for a little bit of retro programming with modern compilers. Not that I
> couldn't have used DJGPP.

That sounds pretty cool, did you make anything you could share?

~~~
dietrichepp
Going to post it to GitHub when I have a moment. I literally wrote the code a
couple weeks ago.

Edit: [https://github.com/depp/elf2dos](https://github.com/depp/elf2dos)

------
zonovar
Interesting article. When I was studying the elf format myself in the past
I've also found very useful this poster.
[https://github.com/corkami/pics/blob/master/binary/elf101/el...](https://github.com/corkami/pics/blob/master/binary/elf101/elf101.pdf)
The author has made many more for similar binary formats.

~~~
russellbeattie
COM files are great... no headers, you just sort of start. Data, code...
whatever.

------
saagarjha
> You can ignore the directives starting with cfi. They are used for call
> stack unwinding in case of exceptions.

It might be worth compiling with -fno-asynchronous-unwind-tables, which will
get rid of those.

~~~
kishu18
Thanks for the suggestion. Do you have any good reference for reading about
this feature?

~~~
saagarjha
GCC's option page lists what it does:
[https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-
Options.html](https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html).
However, it's not all that obvious that this is the flag that controls whether
the "cfi" labels are emitted. Here's a more general Stack Overflow question
about creating nice assembly output:
[https://stackoverflow.com/questions/38552116/how-to-
remove-n...](https://stackoverflow.com/questions/38552116/how-to-remove-noise-
from-gcc-clang-assembly-output)

~~~
kishu18
Nice. Thanks for sharing the stackoverflow link. Will check that.

------
ddcc7
Are you the author? Great job for the detailed writeup. Small nit, I noticed
you misspelled the interpreter section, it should be .interp instead of
.intrep

~~~
kishu18
Thanks @ddcc7. Yes, I am the author. Fixed the spelling mistake.

------
ncmncm
ELF may find new life as a format for data structures in persistent RAM, given
a few extensions.

------
tantalor
Mods fix title: "Life of a binary"

~~~
kishu18
I don't see any option to edit the title now. Anyways, I don't see it would
change any meaning of the article.

~~~
js2
I would suggest "Anatomy of a Linux ELF executable" for the title. A binary
file could be anything.

~~~
kishu18
I agree. You know of any way to edit now? Edit option is disabled now.

~~~
sctb
OK, we've done that now!

~~~
kishu18
thanks @sctb

------
hk__2
Title should have (2017).

~~~
sk0g
A lot has changed in the world of ELF executables, this information is just
_soo_ misleading.

