zhiyuan1106 发表于 2009-12-14 15:13:24

ARM-LINUX-GCC编译出来文件大小优化问题

我现在在虚拟机下开发基于linux的S3C2440的程序,我在程序中加入了液晶显示logo的功能,logo有个图片,240x240大小的,16bit的色深,算起来就是240x240x2=115200Byte的大小,使应用程序增加了许多。为了减小体积,方便调试,调试版本没加入logo函数的调用,但是并没有减小体积。
    其他有些平台编译的时候,自动去掉未用到的变量,函数等,gcc下可以自动去掉未用到的内容么?
    我用-O2优化是130927,-O3是132219,-Os是130188,直接去掉logo后的大小是14915,也就是是说我所用到的所有优化选项都并未删除没用到的函数和变量。请问哪位大侠知道什么选项可以减小可执行二进制文件的体积么?谢谢!

开发板:mini2440
编译器:arm-linux-gcc 4.3.2(arm-none-gnueabi-gcc)
目标操作系统:Linux FriendlyARM 2.6.29.4-FriendlyARM #2 Wed Jul 8 18:17:16 CST 2009 armv4tl unknown

编译发发   目标文件大小
-O2      130927
-O3      132219
-Os      130188
删除函数    14915

参考资料:http://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Optimize-Options.html
-O
-O1
Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
With -O, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time.

-O turns on the following optimization flags:

          -fdefer-pop
          -fmerge-constants
          -fthread-jumps
          -floop-optimize
          -fif-conversion
          -fif-conversion2
          -fdelayed-branch
          -fguess-branch-probability
          -fcprop-registers
   
-O also turns on -fomit-frame-pointer on machines where doing so does not interfere with debugging.


-O2
Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code.
-O2 turns on all optimization flags specified by -O. It also turns on the following optimization flags:

          -fforce-mem
          -foptimize-sibling-calls
          -fstrength-reduce
          -fcse-follow-jumps-fcse-skip-blocks
          -frerun-cse-after-loop-frerun-loop-opt
          -fgcse-fgcse-lm-fgcse-sm-fgcse-las
          -fdelete-null-pointer-checks
          -fexpensive-optimizations
          -fregmove
          -fschedule-insns-fschedule-insns2
          -fsched-interblock-fsched-spec
          -fcaller-saves
          -fpeephole2
          -freorder-blocks-freorder-functions
          -fstrict-aliasing
          -funit-at-a-time
          -falign-functions-falign-jumps
          -falign-loops-falign-labels
          -fcrossjumping
   
Please note the warning under -fgcse about invoking -O2 on programs that use computed gotos.


-O3
Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -fweb and -frename-registers options.

-O0
Do not optimize. This is the default.

-Os
Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
-Os disables the following optimization flags:

          -falign-functions-falign-jumps-falign-loops
          -falign-labels-freorder-blocks-fprefetch-loop-arrays

zm2002 发表于 2009-12-14 17:20:28

编译好 strip看看!!

zhiyuan1106 发表于 2009-12-14 18:59:26

多谢楼上!strip后是125894,已经用其他办法解决!
保存到文件,然后从文件加载。
页: [1]
查看完整版本: ARM-LINUX-GCC编译出来文件大小优化问题