亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問板塊 發(fā)新帖
查看: 7696 | 回復(fù): 6
打印 上一主題 下一主題

[C] 請(qǐng)問GCC有沒有辦法只連接用到的函數(shù)? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2009-09-27 13:18 |只看該作者 |倒序?yàn)g覽
因?yàn)榍度胧骄幊讨,比較在意可執(zhí)行代碼的大小。

我用 --ffunction-sections --fdata-sections選項(xiàng)給讓gcc將每個(gè)函數(shù)都放到一個(gè)獨(dú)立的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.    
復(fù)制代碼

這樣的連接腳本控制連接過程,但gcc還是將每一個(gè)函數(shù)都連接到了最后的結(jié)果中去了,有沒有辦法讓gcc只連接需要的函數(shù)呢?謝謝。

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2009-09-27 13:24 |只看該作者
LDFLAGS += --gc-sections

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2009-09-27 13:28 |只看該作者

回復(fù) #2 prc 的帖子

加了,好像沒有效果。

  1. Building target: stm32test.elf
  2. Invoking: ARM Sourcery Linux GCC C Linker
  3. arm-none-eabi-gcc -T"/home/ifree/workspace/stm32test/src/usr/stm32f10x_flash_extsram.ld" -nostartfiles -nodefaultlibs -Wl,-Map,stm32test.map --gc-sections -mcpu=cortex-m3 -mthumb -o"stm32test.elf"  ./src/usr/main.o ./src/usr/stm32f10x_it.o  ./src/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.o ./src/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.o  ./src/Libraries/CMSIS/Core/CM3/core_cm3.o ./src/Libraries/CMSIS/Core/CM3/system_stm32f10x.o  ./src/Libraries/CMSIS/Core/CM3/startup/gcc/startup_stm32f10x_md.o   
  4. Finished building target: stm32test.elf
復(fù)制代碼


這樣連接后,我檢查得到的lst文件,還是全部的函數(shù)都在里面。

[ 本帖最后由 2eye 于 2009-9-27 13:30 編輯 ]

論壇徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:49:45
4 [報(bào)告]
發(fā)表于 2009-09-27 14:14 |只看該作者

回復(fù) #3 2eye 的帖子

應(yīng)該看stm32test.map這個(gè)文件吧
還有一個(gè)辦法,就是直接nm最終的elf,然后grep,就可以知道不使用的函數(shù)有沒有被連接進(jìn)去。
這個(gè)肯定是ld的一個(gè)參數(shù)而不是gcc的參數(shù),看一下ld的info吧。

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2009-09-27 14:14 |只看該作者
這個(gè)也許是你用的LD版本太老不支持

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2009-09-27 17:49 |只看該作者

回復(fù) #4 koolcoy 的帖子

-Map,stm32test.map

這個(gè)是我在man中查到的-Map參數(shù)的含義:

  1. -M
  2.        --print-map
  3.            Print a link map to the standard output.  A link map provides information about the link, including the following:

  4.            *   Where object files are mapped into memory.

  5.            *   How common symbols are allocated.

  6.            *   All archive members included in the link, with a mention of the symbol which caused the archive member to be brought in.

  7.            *   The values assigned to symbols.

  8.                Note  -  symbols  whose values are computed by an expression which involves a reference to a previous value of the same symbol
  9.                may not have correct result displayed in the link map.  This is because the linker  discards  intermediate  results  and  only
  10.                retains the final value of an expression.  Under such circumstances the linker will display the final value enclosed by square
  11.                brackets.  Thus for example a linker script containing:

  12.                           foo = 1
  13.                           foo = foo * 4
  14.                           foo = foo + 8

  15.                will produce the following output in the link map if the -M option is used:

  16.                           0x00000001                foo = 0x1
  17.                           [0x0000000c]                foo = (foo * 0x4)
  18.                           [0x0000000c]                foo = (foo + 0x8)

  19.                See Expressions for more information about expressions in linker scripts.


  20.      -Map mapfile
  21.            Print a link map to the file mapfile.  See the description of the -M option, above.
復(fù)制代碼

這樣說來,map文件是連接器生成的文件,應(yīng)該不是用于控制連接過程的。

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2009-09-27 20:51 |只看該作者
謝謝樓上諸位,問題已經(jīng)解決了。
應(yīng)該
LDFLAGS += -Wl,--gc-sections
否則參數(shù)沒有傳遞給連接器。
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP