有选择地链接存档中的符号
Selectively linking symbols in archive
我有一个项目正在 libcrypto.a 中链接。但我感兴趣的只是,例如,SHA 功能。有没有办法指定应从生成的二进制文件中删除所有其他未使用的函数?
GCC 4.8 是工具链的一部分。
默认情况下,GNU 链接器应该只引入必要的目标文件,除非您指定 --whole_archive
flag.
如果您想要消除死代码,请使用以下链接器标志:
-Wl,-static
Link against static libraries. Required for dead-code elimination.
-fvtable-gc
C++ virtual method table instrumented with garbage collection information for the linker.
-fdata-sections
Keeps data in separate data sections, so they can be discarded if unused.
-ffunction-sections
Keeps functions in separate data sections, so they can be discarded if unused.
-Wl,--gc-sections
Tell the linker to garbage collect and discard unused sections.
-s
Strip the debug information, so as to make the code as small as possible. (I presume that you'd want to do this in a dead-code
removal build.)
我有一个项目正在 libcrypto.a 中链接。但我感兴趣的只是,例如,SHA 功能。有没有办法指定应从生成的二进制文件中删除所有其他未使用的函数?
GCC 4.8 是工具链的一部分。
默认情况下,GNU 链接器应该只引入必要的目标文件,除非您指定 --whole_archive
flag.
如果您想要消除死代码,请使用以下链接器标志:
-Wl,-static
Link against static libraries. Required for dead-code elimination.
-fvtable-gc
C++ virtual method table instrumented with garbage collection information for the linker.
-fdata-sections
Keeps data in separate data sections, so they can be discarded if unused.
-ffunction-sections
Keeps functions in separate data sections, so they can be discarded if unused.
-Wl,--gc-sections
Tell the linker to garbage collect and discard unused sections.
-s
Strip the debug information, so as to make the code as small as possible. (I presume that you'd want to do this in a dead-code removal build.)