rust-lang/rust

Need to be able to explicitly set --whole-archive linker flag when building a binary

jkryl opened this issue · 2 comments

jkryl commented

I'm using 1.32.0-nightly (6bfb46e4a 2018-11-26) but it likely applies to all rust versions. The default behaviour when building a binary is to include only static/shared libraries which are actually referenced from the code. There is a legitimate use case when you want to include everything from a native library regardless if it appears to be used or not. Native library can contain functions marked as __attribute__((constructor, used)) which are executed at the time when the library is loaded and can influence behaviour of other libraries which are explicitly referenced. One such example is DPDK library. Currently there does not seem to be a way to instruct explicitly rustc to include the lib even if not used.

Using .cargo/config to override rustc flags looks more like a workaround than a proper solution. Or maybe I missed some other way how to accomplish the same without hacking the code? I will be thankful for any advice. Thanks!

For more in-depth discussion about the particular case of DPDK/SPDK see:
jkozlowski/starfish#6 or spdk/spdk#518 or a PR jkozlowski/starfish#8 .

I have submitted an RFC about supporting whole archive - rust-lang/rfcs#2951.

Closing this issue, the whole-archive modifier was implemented about 9 months ago, and #93901 now intends to make it available on stable.