How to decrease the size of generated binaries?

后端 未结 7 1276
谎友^
谎友^ 2021-02-01 05:53

I know that there is an option \"-Os\" to \"Optimize for size\", but it has little affect, or even increase the size on some occasion :(

strip (or \"-s\" option) remov

7条回答
  •  逝去的感伤
    2021-02-01 06:21

    When using strip(1), you'll want to make sure you use all the relevant options. For some reason, --strip-all doesn't always strip everything. Removing unnecessary sections may be helpful.

    Ultimately, though, the best way to reduce the size of the binary is to remove code and static data from the program. Make it do less, or select programming constructs that result in fewer instructions. For example, you might build data structures at runtime, or load them from a file, on-demand, rather than have a statically initialized array.

提交回复
热议问题