搜索
bottom↓
回复: 2

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

[复制链接]

出20入0汤圆

发表于 2009-12-14 15:13:24 | 显示全部楼层 |阅读模式
我现在在虚拟机下开发基于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

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2009-12-14 17:20:28 | 显示全部楼层
编译好 strip看看!!

出20入0汤圆

 楼主| 发表于 2009-12-14 18:59:26 | 显示全部楼层
多谢楼上!strip后是125894,已经用其他办法解决!
保存到文件,然后从文件加载。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-20 20:01

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表