Adrian Boeing <aboeing@xxxxxxxxx> writes: > Thanks! You were infact correct, it does prefix with an '_'. This > produces an executable of only 4kb now. (a 50% saving) > > When I try to execute the program I get a 'bus error', presumably > because the cleanup/startup code is not run. > I know this is getting a bit off the topic of GCC, but does anyone > know what the stdlib does / what I need to do to make the program > startup/cleanup nicely? On debian, I can get it to work pretty well by doing: (1) Call "_exit" instead of returning from main (2) Use "-nostdlib" to avoid standard crt0 etc (3) Use "-Wl,-emain" to tell the linker to use "main" as the entry point (4) Explicitly link against libc (-nostdlib turns off the implicit link against it), to at least get the definition of _exit (5) Link statically with "-static" Source file "small.c": #include <unistd.h> int main () { _exit (99); } Compiling: $ gcc -O2 -static -o small small.c -Wl,-emain -nostdlib -lc $ ./small; echo $? 99 $ size small text data bss dec hex filename 204 0 4 208 d0 small -Miles -- "Don't just question authority, Don't forget to question me." -- Jello Biafra