Make the compiled ASM binary small?

Programming, for all ages and all languages.
Post Reply
junkoi
Member
Member
Posts: 63
Joined: Wed Jan 23, 2008 8:55 pm

Make the compiled ASM binary small?

Post 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
junkoi
Member
Member
Posts: 63
Joined: Wed Jan 23, 2008 8:55 pm

Re: Make the compiled ASM binary small?

Post 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
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Make the compiled ASM binary small?

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Post Reply