im trying to compile a dll as small as possible, i reduced the section alignmnent and it saved some size, and i also removed the stdlib with (-nostdlib) and all Optimizations on. now i have some questions
thanks.
Don't mess with sections, just use the -fPIC
flag to reduce relocations (otherwise references are always absolute on x86). You will still have a .reloc
, since it's used for linking. Also, always compile with -Os
and -fomit-frame-pointer
.
BTW, you should not have a .data
section. If you do it's because something is wrong: look for and fix your data references; everything should be constant. If you need to mess with data, first copy it to a buffer provided by the caller, or something like that.
If you can dedicate some time to learning the GCC attributes extension, you will find several attributes that enhance GCC's comprehension of the code thus enabling better optimizations (e.g. pure
and const
functions). This can cut a lot of bytes.
More importantly, try to give GCC basic hints about how you're using the code, e.g. use static
functions whenever appropriate.
GCC will still add some dummy sections which you can eliminate with the strip
utility. It doesn't remove everything by default, you need to specify the -s
flag to remove all symbols and -R name
to remove a section. You can do something similar with objcopy -S -R name ...
(just mentioning it because if you're going to do something else with it, you can do it all in one pass).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With