Hacker News new | ask | show | jobs
by nsguy 802 days ago
IIRC there's some setup code that's injected before main is called and can be turned off in most compilers (_start?). Should be possible to get down to essentially the same thing you can do with an assembler. C (and so C++ for the most part) is essentially a portable assembler. You can probably also just inline those 10 x86 instructions directly.
1 comments

It may or may not not possible, but it definitely won't be as easy. Binaries compiled with GCC (and other mainstream compilers) are pretty bloated. You may be able to get the same thing as assembler by manually excluding sections and functions from the output, but it's not just a single commandline parameters.

And the setup code is not completely useless, for example it is responsible for parsing command line parameters and actually running main. If you want to actually use libc instead of just writing assembly directly, you may need it.

You can strip

>_start Almost but not quite! _start is the name of the symbol that is executed first in the program. If you compile with -nostdlib, you need to provide this symbol yourself (this will be your new main).