Page 1 of 1

Make the compiled ASM binary small?

Posted: Mon Jun 01, 2009 9:44 pm
by junkoi
Hi,

I am writing some (32bit) ASM code, and compile it with gcc. The output binary is quite big, however. I want to make it as small as possible.

The current gcc options I am using is like:

gcc -nostdlib -fno-builtin -c a.S -o a.bin

And the size of a.bin is around 400 bytes.

I am sure I can reduce the size of a.bin, as the similar code compiled with nasm has the size of only 123 bytes.

Which gcc options should I use now?

Thanks a lot,
J

Re: Make the compiled ASM binary small?

Posted: Mon Jun 01, 2009 10:19 pm
by junkoi
I think I found the reason: beside .text section (which is only thing I want), gcc produces some other sections, such as .data, .bss and .shstrtab.
And that makes the final binary bigger.

Now I want gcc not to produce those sections, but only give me .text. Which gcc options should I use?

Thanks,
J

Re: Make the compiled ASM binary small?

Posted: Tue Jun 02, 2009 12:38 am
by xenos
Try -oformat binary to omit string tables and such, and use a linker script if you really want to remove any other section besides .text.