linux - How to decrease the size of generated binaries? -


i know there option "-os" "optimize size", has little affect, or increase size on occasion :(

strip (or "-s" option) removes debug symbol table, works fine; can decrease small propotion of size.

is there other way go furthur?

apart obvious (-os -s), aligning functions smallest possible value not crash (i don't know arm alignment requirements) might squeeze out few bytes per function.
-os should disable aligning functions, might still default value 4 or 8. if aligning e.g. 1 possible arm, might save bytes.

-ffast-math (or less abrasive -fno-math-errno) not set errno , avoid checks, reduces code size. if, people, don't read errno anyway, that's option.

properly using __restrict (or restrict) , const removes redundant loads, making code both faster , smaller (and more correct). marking pure functions such eleminates function calls.

enabling lto may help, , if not available, compiling source files binary in 1 go (gcc foo.c bar.c baz.c -o program instead of compiling foo.c, bar.c, , baz.c object files first , linking) have similar effect. makes visible optimizer @ 1 time, possibly allowing work better.

-fdelete-null-pointer-checks may option (note enabled "o", not on embedded targets).

putting static globals (you don't have many, still) struct can eleminate a lot of overhead initializing them. learned when writing first opengl loader. having function pointers in struct , initializing struct = {} generates 1 call memset, whereas initializing pointers "normal way" generates hundred kilobytes of code set each 1 0 individually.

avoid non-trivial-constructor static local variables devil (pod types no problem). gcc initialize non-trivial-constructor static locals threadsafe unless compile -fno-threadsafe-statics, links in a lot of code (even if don't use threads @ all).

using libowfat instead of normal crt can greatly reduce binary size.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -