gcc优化

本文关注GCC的性能优化,介绍了如何通过不同级别的优化选项(如-O2)来减小可执行文件的大小,包括去除符号信息和仅链接必要组件。在不确定优化需求时,-O2通常是一个平衡的选择。
摘要由CSDN通过智能技术生成

一、空间优化(减少可执行文件的大小)

主要有两个方向:1)去除符号信息 2)只链接有用的东西

示例引自http://wiki.wxwidgets.org/Reducing_Executable_Size:
Test #1
# wxGTK compiled with:
#   ./configure --disable-debug --disable-shared
#   make
$ ls -l minimal
-rwxr-xr-x 1 frm frm 4,3M 2009-02-11 17:04 minimal*
$ size minimal
   text    data     bss     dec     hex filename
3698330   10436   49692 3758458  39597a minimal
$ strip --strip-all minimal
$ ls -l minimal
-rwxr-xr-x 1 frm frm 3,6M 2009-02-11 17:23 minimal*
$ strip --remove-section=.comment --remove-section=.note minimal
$ ls -l minimal
-rwxr-xr-x 1 frm frm 3,6M 2009-02-11 17:28 minimal*
I.e. using --strip-all provided a 17% improvement. Removing the .comment and .note sections didn't produce any noti
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值