On 3/30/09, Christopher Friedt <[email protected]> wrote:
>  I'm writing code in C for a very small static binary, and the code
>  doesn't use any headers or rely on any other libraries.

> I've noticed that there is a lot of static libc junk built into my binary
>  build my program with options like -nostdlib -nodefaultlibs
>  -nostartfiles, I get an error that says
>
>  warning: cannot find entry symbol _start; defaulting to 000000000000008074

These days it is fairly hard, and system- and architecture-dependent,
to get a minimal binary from a C program.
 For example, with GCC/glibc _start() is in /usr/lib/crt1.o, and that
is what sets up the environment variables, fills in argc and argv ,
calls main() and arranges to call the stdio function exit() if main()
returns.

It used to be (1985 BSD VAX) that if you only used Unix system calls
and included a function exit(n){_exit(n);} that would be enough to
prevent stdio from being pulled in, for objects of a few hundred
bytes.

"gcc -v" will tell you what it is raking in by default. You can play
with providing _start yourself, omitting /usr/lib/crt*.o and making
sure you call _exit() yourself. It's an interesting journey.

Some other people's trips can be relived by googling "tiny elf binary"

    M

Reply via email to