GCC wastes thousands of bytes

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
George

GCC wastes thousands of bytes

Post by George »

Hi,
I was trying to write a little kernel in C++ using gcc, nasm and ld.
Everything works fine and my kernel can even write to screen ;) but any of this tools wastes much space by filling the binary with about 10 kb of zero-bytes.
(That is very much if the kernel is only about 17kb all in all)
It also puts lots of NOPs into the binary although I never said so.
What can I do to prevent gcc/ld from doing this?

Thx, George
Gandalf

RE:GCC wastes thousands of bytes

Post by Gandalf »

hi,

I think the solution lies in your linker script(if u can please show it here). Also do you strip your kernel ? It removes all debugging info but at the same time reduces kernel size.

Hope it helps.

rgds
Gandalf
George

RE:GCC wastes thousands of bytes

Post by George »

I just found out what it was. I just copied the linker script from another project and I didn't recognize the align(4096) in round about line 60. Removing it stoped the linker from generating the zeros, but the 0x90s(nop) remained.
But I think I can live with these 20 bytes and 40 cycles overhead.

thx, bye George
Guest

RE:GCC wastes thousands of bytes

Post by Guest »

nop are added for optimization
Gnome

RE:GCC wastes thousands of bytes

Post by Gnome »

Yes, if I recall correctly, they force the code into alignment on the dword(?) boundary. Believe it or not, GCC knows what it's doing :)

Gnome
Post Reply