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

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

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

問題描述

我需要嚴格優(yōu)化我的可執(zhí)行文件的大小(ARM 開發(fā))并且我注意到在我當前的構建方案 (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 用于生成的可執(zhí)行文件/庫不會改變可執(zhí)行文件的輸出大小 (我不知道為什么,也許是根本不能).

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?

我什至不會想到這一點,但我當前的嵌入式環(huán)境不是很強大",而且甚至將 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:

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

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

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

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

-Wl,--gc-sections

因此,如果您有一個名為 test.cpp 的文件,其中聲明了兩個函數(shù),但其??中一個未使用,您可以使用以下 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 優(yōu)化大小)

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

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

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

相關文檔推薦

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?(什么時候使用內聯(lián)函數(shù),什么時候不使用?)
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 仍然相關嗎?)
主站蜘蛛池模板: 一区二区三区网站 | 亚洲激情在线视频 | 丰满少妇高潮 | 免费观看一区二区 | 日韩欧美在线看 | 欧美三级韩国三级日本三斤在线观看 | 欧美精品一区二区三区四区 | 国产在线日韩 | 中文字幕系列 | 久久只有精品 | 97精品国产露脸对白 | 偷偷操不一样 | 午夜性色 | 成人欧美日韩 | 成人国产精品久久久网站 | 欧美性猛交xxxx黑人猛交 | 成人h片在线观看 | a视频在线免费观看 | 四虎在线免费视频 | 成人免费看片在线观看 | 成人a在线 | www.啪啪| 成年人免费视频网站 | 国产精品视频在线观看 | 国产精品久久久久久99 | 中文字幕一区二区在线播放 | 成人三级晚上看 | 亚洲欧美一区二区三区四区 | 成人精品一区二区三区 | 国产日韩免费 | 亚洲精品乱码久久久久久动漫 | 亚洲精品视频一区 | 成人av播放 | 中文字幕自拍偷拍 | 电家庭影院午夜 | 98久久| 一极黄色片 | 欧美一区二区三区在线视频 | 久久在线免费观看 | 天天天天操 | 超碰99在线|