久久久久久久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 仍然相關嗎?)
主站蜘蛛池模板: 一区二区三区日韩 | 91网站在线播放 | 一区在线播放 | 搞av.com | 一区二区三区小视频 | 91在线免费视频 | 日韩精品在线一区 | 亚洲成人免费电影 | 天天视频一区二区三区 | 国产成人综合亚洲欧美94在线 | 日本欧美在线视频 | 国产一区二区在线播放 | 羞羞色在线观看 | 午夜精品一区二区三区在线观看 | 污视频在线免费观看 | 日韩a级片 | 久久久久久久久久性 | 成年人网站免费 | 精品国产欧美 | 免费观看成人性生生活片 | 日韩一区二区三区四区五区六区 | 在线观看视频91 | 成人免费在线播放 | 午夜精品久久久 | 91aiai| 国产偷久久一级精品60部 | 亚洲电影一区 | 国产一区二区三区在线 | 一级黄色淫片 | 久久久久久久久久久蜜桃 | 狠狠躁躁夜夜躁波多野结依 | 精品欧美一区二区三区久久久 | 亚洲精品亚洲人成人网 | 精品欧美一区二区精品久久久 | 在线观看免费国产 | 天天操天天射天天舔 | 久久久精品一区二区三区 | 欧美一区二区三区在线免费观看 | 国产日韩欧美激情 | 国产精品视频一二三区 | 亚洲欧美一区二区三区在线 |