LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1329|回复: 2

[求助]gcc能不能控制只连接需要的函数?

[复制链接]
发表于 2009-9-27 13:20:18 | 显示全部楼层 |阅读模式
因为嵌入式编程中,比较在意可执行代码的大小。

我用 --ffunction-sections --fdata-sections选项给让gcc将每个函数都放到一个独立的sections里面,然后用

  1. /* the program code is stored in the .text section, which goes to Flash */

  2.     .text :

  3.     {

  4.             . = ALIGN(4);

  5.             

  6.         *(.text)                   /* remaining code */

  7.         *(.text.*)                   /* remaining code */

  8.         *(.rodata)                 /* read-only data (constants) */

  9.         *(.rodata*)

  10.         *(.glue_7)

  11.         *(.glue_7t)



  12.             . = ALIGN(4);

  13.             _etext = .;

  14.             /* This is used by the startup in order to initialize the .data secion */

  15.             _sidata = _etext;

  16.     } >FLASH

  17.    
复制代码

这样的连接脚本控制连接过程,但gcc还是将每一个函数都连接到了最后的结果中去了,有没有办法让gcc只连接需要的函数呢?谢谢。
 楼主| 发表于 2009-9-27 22:41:10 | 显示全部楼层
已解决,使用参数 -Wl,--gc-sections
回复 支持 反对

使用道具 举报

发表于 2009-10-9 19:02:44 | 显示全部楼层
该选项是否有副作用,执行上速度是否有影响?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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