r/programming • u/iximiuz • Jul 25 '26
Writing a (valid) C program without main()
https://labs.iximiuz.com/tutorials/c-program-without-main-a1eea557
193
Upvotes
r/programming • u/iximiuz • Jul 25 '26
View all comments
Show parent comment
2
u/yowhyyyy Aug 15 '26 edited Aug 15 '26
Sorry for the late response, didn’t get a notification for some reason. It’s how they compile it to my understanding! Passing a separate entry point option (-e) while still compiling as a shared object which is actually possible via GCC. It’s more or less the thought process of making a shared object executable. You also have to manually add an ELF interpreter attribute. That more or less is necessary for every process on Linux to execute if it’s dynamically compiled.
Normally when compiling a shared object it isn’t present as there is no execution/runtime info really needed. When you want it to actually execute though like a normal binary, you need to manually add the attribute.
TLDR: Manually specify an entry point, align stack depending on architecture, add ELF interpreter and go about with your regular routines. I’ve manually implemented this as stated above for playing around with shared objects that can execute for AIO concepts I had previously.
Edit: formatting and spelling