久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 GCC 和 ld 刪除未使用的 C/C++ 符號?

How to remove unused C/C++ symbols with GCC and ld?(如何使用 GCC 和 ld 刪除未使用的 C/C++ 符號?)
本文介紹了如何使用 GCC 和 ld 刪除未使用的 C/C++ 符號?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要嚴格優化我的可執行文件的大小(ARM 開發)并且我注意到在我當前的構建方案 (gcc + ld) 中未使用的符號沒有被剝離.

I need to optimize the size of my executable severely (ARM development) and I noticed that in my current build scheme (gcc + ld) unused symbols are not getting stripped.

arm-strip --strip-unneeded 用于生成的可執行文件/庫不會改變可執行文件的輸出大小 (我不知道為什么,也許是根本不能).

The usage of the arm-strip --strip-unneeded for the resulting executables / libraries doesn't change the output size of the executable (I have no idea why, maybe it simply can't).

如何(如果存在)修改我的構建管道,以便從生成的文件中刪除未使用的符號?

What would be the way (if it exists) to modify my building pipeline, so that the unused symbols are stripped from the resulting file?

我什至不會想到這一點,但我當前的嵌入式環境不是很強大",而且甚至將 500K 保存在 2M 中,都會帶來非常好的加載性能提升.

I wouldn't even think of this, but my current embedded environment isn't very "powerful" and saving even 500K out of 2M results in a very nice loading performance boost.

更新:

不幸的是,我使用的當前 gcc 版本沒有 -dead-strip 選項和 -ffunction-sections... + --gcld 的 -sections 對結果輸出沒有任何顯著差異.

Unfortunately the current gcc version I use doesn't have the -dead-strip option and the -ffunction-sections... + --gc-sections for ld doesn't give any significant difference for the resulting output.

我很震驚這甚至成為一個問題,因為我確信 gcc + ld 應該自動去除未使用的符號(為什么他們甚至必須保留它們?).

I'm shocked that this even became a problem, because I was sure that gcc + ld should automatically strip unused symbols (why do they even have to keep them?).

推薦答案

對于 GCC,這分兩個階段完成:

For GCC, this is accomplished in two stages:

首先編譯數據,但告訴編譯器將代碼分成翻譯單元內的單獨部分.這將通過使用以下兩個編譯器標志為函數、類和外部變量完成:

First compile the data but tell the compiler to separate the code into separate sections within the translation unit. This will be done for functions, classes, and external variables by using the following two compiler flags:

-fdata-sections -ffunction-sections

使用鏈接器優化標志將翻譯單元鏈接在一起(這會導致鏈接器丟棄未引用的部分):

Link the translation units together using the linker optimization flag (this causes the linker to discard unreferenced sections):

-Wl,--gc-sections

因此,如果您有一個名為 test.cpp 的文件,其中聲明了兩個函數,但其??中一個未使用,您可以使用以下 gcc(g++) 命令省略未使用的那個:

So if you had one file called test.cpp that had two functions declared in it, but one of them was unused, you could omit the unused one with the following command to gcc(g++):

gcc -Os -fdata-sections -ffunction-sections test.cpp -o test -Wl,--gc-sections

(注意 -Os 是一個額外的編譯器標志,它告訴 GCC 優化大小)

(Note that -Os is an additional compiler flag that tells GCC to optimize for size)

這篇關于如何使用 GCC 和 ld 刪除未使用的 C/C++ 符號?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(將 RGB 轉換為 HSV 并將 HSV 轉換為 RGB 的算法,范圍為 0-255)
How to convert an enum type variable to a string?(如何將枚舉類型變量轉換為字符串?)
When to use inline function and when not to use it?(什么時候使用內聯函數,什么時候不使用?)
Examples of good gotos in C or C++(C 或 C++ 中好的 goto 示例)
Significance of ios_base::sync_with_stdio(false); cin.tie(NULL);(ios_base::sync_with_stdio(false) 的意義;cin.tie(NULL);)
Is TCHAR still relevant?(TCHAR 仍然相關嗎?)
主站蜘蛛池模板: 精品视频一区二区 | 久久69精品久久久久久久电影好 | 99视频网站 | 一区二区三区视频在线观看 | 久久久免费少妇高潮毛片 | 欧美中文字幕一区 | 91在线播| 精品视频一区二区三区四区 | 丁香五月缴情综合网 | 亚洲一区二区三区在线视频 | av在线播放网 | 中文字幕一区在线观看视频 | 亚洲欧美视频在线观看 | 中文天堂网 | 精品日韩一区二区 | 亚洲va欧美va天堂v国产综合 | 手机看片在线播放 | 色婷婷综合久久久中文字幕 | 久久久久九九九女人毛片 | 色综合久久伊人 | 亚洲国产精品一区二区久久 | 中文字幕在线视频网站 | 成人h免费观看视频 | 日韩久久久久 | 一区二区av | 亚洲淫视频 | 亚洲美女视频 | 天天操天天射综合网 | 天堂一区二区三区四区 | 国产一级片一区二区三区 | aaaa网站| 天天操伊人 | 天天干天天色 | 欧美一级欧美一级在线播放 | 中文成人无字幕乱码精品 | 久久久这里只有17精品 | 亚洲在线 | 久久国产精品免费视频 | 国产视频第一页 | 精品久久电影 | 日韩在线资源 |